github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/utils/specutils.go (about)

     1  package utils
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  const (
     8  	WILDCARD SpecType = "wildcard"
     9  	AQL      SpecType = "aql"
    10  	BUILD    SpecType = "build"
    11  )
    12  
    13  type SpecType string
    14  
    15  type Aql struct {
    16  	ItemsFind string `json:"items.find"`
    17  }
    18  
    19  type ArtifactoryCommonParams struct {
    20  	Aql     Aql
    21  	Pattern string
    22  	// Deprecated, use Exclusions instead
    23  	ExcludePatterns []string
    24  	Exclusions      []string
    25  	Target          string
    26  	Props           string
    27  	ExcludeProps    string
    28  	SortOrder       string
    29  	SortBy          []string
    30  	Offset          int
    31  	Limit           int
    32  	Build           string
    33  	Bundle          string
    34  	Recursive       bool
    35  	IncludeDirs     bool
    36  	Regexp          bool
    37  	ArchiveEntries  string
    38  }
    39  
    40  type FileGetter interface {
    41  	GetAql() Aql
    42  	GetPattern() string
    43  	SetPattern(pattern string)
    44  	GetExclusions() []string
    45  	// Deprecated, Use Exclusions instead
    46  	GetExcludePatterns() []string
    47  	GetTarget() string
    48  	SetTarget(target string)
    49  	IsExplode() bool
    50  	GetProps() string
    51  	GetSortOrder() string
    52  	GetSortBy() []string
    53  	GetOffset() int
    54  	GetLimit() int
    55  	GetBuild() string
    56  	GetBundle() string
    57  	GetSpecType() (specType SpecType)
    58  	IsRegexp() bool
    59  	IsRecursive() bool
    60  	IsIncludeDirs() bool
    61  	GetArchiveEntries() string
    62  	SetArchiveEntries(archiveEntries string)
    63  }
    64  
    65  func (params ArtifactoryCommonParams) GetArchiveEntries() string {
    66  	return params.ArchiveEntries
    67  }
    68  
    69  func (params *ArtifactoryCommonParams) SetArchiveEntries(archiveEntries string) {
    70  	params.ArchiveEntries = archiveEntries
    71  }
    72  
    73  func (params *ArtifactoryCommonParams) GetPattern() string {
    74  	return params.Pattern
    75  }
    76  
    77  func (params *ArtifactoryCommonParams) SetPattern(pattern string) {
    78  	params.Pattern = pattern
    79  }
    80  
    81  func (params *ArtifactoryCommonParams) SetTarget(target string) {
    82  	params.Target = target
    83  }
    84  
    85  func (params *ArtifactoryCommonParams) GetTarget() string {
    86  	return params.Target
    87  }
    88  
    89  func (params *ArtifactoryCommonParams) GetProps() string {
    90  	return params.Props
    91  }
    92  
    93  func (params *ArtifactoryCommonParams) GetExcludeProps() string {
    94  	return params.ExcludeProps
    95  }
    96  
    97  func (params *ArtifactoryCommonParams) IsExplode() bool {
    98  	return params.Recursive
    99  }
   100  
   101  func (params *ArtifactoryCommonParams) IsRecursive() bool {
   102  	return params.Recursive
   103  }
   104  
   105  func (params *ArtifactoryCommonParams) IsRegexp() bool {
   106  	return params.Regexp
   107  }
   108  
   109  func (params *ArtifactoryCommonParams) GetAql() Aql {
   110  	return params.Aql
   111  }
   112  
   113  func (params *ArtifactoryCommonParams) GetBuild() string {
   114  	return params.Build
   115  }
   116  
   117  func (params *ArtifactoryCommonParams) GetBundle() string {
   118  	return params.Bundle
   119  }
   120  
   121  func (params ArtifactoryCommonParams) IsIncludeDirs() bool {
   122  	return params.IncludeDirs
   123  }
   124  
   125  func (params *ArtifactoryCommonParams) SetProps(props string) {
   126  	params.Props = props
   127  }
   128  
   129  func (params *ArtifactoryCommonParams) SetExcludeProps(excludeProps string) {
   130  	params.ExcludeProps = excludeProps
   131  }
   132  
   133  func (params *ArtifactoryCommonParams) GetSortBy() []string {
   134  	return params.SortBy
   135  }
   136  
   137  func (params *ArtifactoryCommonParams) GetSortOrder() string {
   138  	return params.SortOrder
   139  }
   140  
   141  func (params *ArtifactoryCommonParams) GetOffset() int {
   142  	return params.Offset
   143  }
   144  
   145  func (params *ArtifactoryCommonParams) GetLimit() int {
   146  	return params.Limit
   147  }
   148  
   149  func (params *ArtifactoryCommonParams) GetExcludePatterns() []string {
   150  	return params.ExcludePatterns
   151  }
   152  
   153  func (params *ArtifactoryCommonParams) GetExclusions() []string {
   154  	return params.Exclusions
   155  }
   156  
   157  func (aql *Aql) UnmarshalJSON(value []byte) error {
   158  	str := string(value)
   159  	first := strings.Index(str[strings.Index(str, "{")+1:], "{")
   160  	last := strings.LastIndex(str, "}")
   161  
   162  	aql.ItemsFind = str[first+1 : last]
   163  	return nil
   164  }
   165  
   166  func (params ArtifactoryCommonParams) GetSpecType() (specType SpecType) {
   167  	switch {
   168  	case params.Build != "" && params.Aql.ItemsFind == "" && (params.Pattern == "*" || params.Pattern == ""):
   169  		specType = BUILD
   170  	case params.Aql.ItemsFind != "":
   171  		specType = AQL
   172  	default:
   173  		specType = WILDCARD
   174  	}
   175  	return specType
   176  }