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

     1  package services
     2  
     3  import (
     4  	"errors"
     5  
     6  	rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient"
     7  	"github.com/cobalt77/jfrog-client-go/artifactory/services/utils"
     8  	"github.com/cobalt77/jfrog-client-go/auth"
     9  	"github.com/cobalt77/jfrog-client-go/utils/errorutils"
    10  	"github.com/cobalt77/jfrog-client-go/utils/io/content"
    11  )
    12  
    13  type SearchService struct {
    14  	client     *rthttpclient.ArtifactoryHttpClient
    15  	ArtDetails auth.ServiceDetails
    16  }
    17  
    18  func NewSearchService(client *rthttpclient.ArtifactoryHttpClient) *SearchService {
    19  	return &SearchService{client: client}
    20  }
    21  
    22  func (s *SearchService) GetArtifactoryDetails() auth.ServiceDetails {
    23  	return s.ArtDetails
    24  }
    25  
    26  func (s *SearchService) SetArtifactoryDetails(rt auth.ServiceDetails) {
    27  	s.ArtDetails = rt
    28  }
    29  
    30  func (s *SearchService) IsDryRun() bool {
    31  	return false
    32  }
    33  
    34  func (s *SearchService) GetJfrogHttpClient() (*rthttpclient.ArtifactoryHttpClient, error) {
    35  	return s.client, nil
    36  }
    37  
    38  func (s *SearchService) Search(searchParams SearchParams) (*content.ContentReader, error) {
    39  	return SearchBySpecFiles(searchParams, s, utils.ALL)
    40  }
    41  
    42  type SearchParams struct {
    43  	*utils.ArtifactoryCommonParams
    44  }
    45  
    46  func (s *SearchParams) GetFile() *utils.ArtifactoryCommonParams {
    47  	return s.ArtifactoryCommonParams
    48  }
    49  
    50  func NewSearchParams() SearchParams {
    51  	return SearchParams{ArtifactoryCommonParams: &utils.ArtifactoryCommonParams{}}
    52  }
    53  
    54  func SearchBySpecFiles(searchParams SearchParams, flags utils.CommonConf, requiredArtifactProps utils.RequiredArtifactProps) (*content.ContentReader, error) {
    55  	switch searchParams.GetSpecType() {
    56  	case utils.WILDCARD:
    57  		return utils.SearchBySpecWithPattern(searchParams.GetFile(), flags, requiredArtifactProps)
    58  	case utils.BUILD:
    59  		return utils.SearchBySpecWithBuild(searchParams.GetFile(), flags)
    60  	case utils.AQL:
    61  		return utils.SearchBySpecWithAql(searchParams.GetFile(), flags, requiredArtifactProps)
    62  	default:
    63  		return nil, errorutils.CheckError(errors.New("Error at SearchBySpecFiles: Unknown spec type"))
    64  	}
    65  }