66 "path"
77 "strings"
88
9- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
10-
119 "github.com/jfrog/jfrog-client-go/artifactory"
1210 "github.com/jfrog/jfrog-client-go/artifactory/services"
1311 clientUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
@@ -57,26 +55,6 @@ var blacklistedRepositories = []string{
5755 "jfrog-usage-logs" , "jfrog-billing-logs" , "jfrog-logs" , "artifactory-pipe-info" , "auto-trashcan" , "jfrog-support-bundle" , "_intransit" , "artifactory-edge-uploads" ,
5856}
5957
60- // GetRepositories returns the names of local, remote, virtual or federated repositories filtered by their type.
61- // artDetails - Artifactory server details
62- // repoTypes - Repository types to filter. If empty - return all repository types.
63- func GetRepositories (artDetails * config.ServerDetails , repoTypes ... RepoType ) ([]string , error ) {
64- sm , err := CreateServiceManager (artDetails , 3 , 0 , false )
65- if err != nil {
66- return nil , err
67- }
68- repos := []string {}
69- for _ , repoType := range repoTypes {
70- filteredRepos , err := GetFilteredRepositoriesByNameAndType (sm , nil , nil , repoType )
71- if err != nil {
72- return repos , err
73- }
74- repos = append (repos , filteredRepos ... )
75- }
76-
77- return repos , nil
78- }
79-
8058// Since we can't search dependencies in a remote repository, we will turn the search to the repository's cache.
8159// Local/Virtual repository name will be returned as is.
8260func GetRepoNameForDependenciesSearch (repoName string , serviceManager artifactory.ArtifactoryServicesManager ) (string , error ) {
@@ -99,74 +77,52 @@ func IsRemoteRepo(repoName string, serviceManager artifactory.ArtifactoryService
9977 return repoDetails .GetRepoType () == "remote" , nil
10078}
10179
102- // GetFilteredRepositoriesByName returns the names of local, remote, virtual and federated repositories filtered by their names.
103- // includePatterns - patterns of repository names (can contain wildcards) to include in the results. A repository's name
80+ // GetFilteredRepositoriesWithFilterParams returns the names of local, remote, virtual, and federated repositories filtered by their names and type.
81+ // servicesManager - The Artifactory services manager used to interact with the Artifactory server.
82+ // includePatterns - Patterns of repository names (can contain wildcards) to include in the results. A repository's name
10483// must match at least one of these patterns in order to be included in the results. If includePatterns' length is zero,
10584// all repositories are included.
106- // excludePatterns - patterns of repository names (can contain wildcards) to exclude from the results. A repository's name
85+ // excludePatterns - Patterns of repository names (can contain wildcards) to exclude from the results. A repository's name
10786// must NOT match any of these patterns in order to be included in the results.
108- func GetFilteredRepositoriesByName (servicesManager artifactory.ArtifactoryServicesManager , includePatterns , excludePatterns []string ) ([]string , error ) {
109- repoDetailsList , err := servicesManager .GetAllRepositories ()
87+ // filterParams - Parameters to filter the repositories by their type.
88+ // Returns a slice of repository names that match the given patterns and type, or an error if the operation fails.
89+ func GetFilteredRepositoriesWithFilterParams (servicesManager artifactory.ArtifactoryServicesManager , includePatterns , excludePatterns []string , filterParams services.RepositoriesFilterParams ) ([]string , error ) {
90+ repoDetailsList , err := servicesManager .GetAllRepositoriesFiltered (filterParams )
11091 if err != nil {
11192 return nil , err
11293 }
11394
114- return getFilteredRepositories (repoDetailsList , includePatterns , excludePatterns )
115- }
116-
117- // GetFilteredRepositoriesByNameAndType returns the names of local, remote, virtual and federated repositories filtered by their names and type.
118- // includePatterns - patterns of repository names (can contain wildcards) to include in the results. A repository's name
119- // must match at least one of these patterns in order to be included in the results. If includePatterns' length is zero,
120- // all repositories are included.
121- // excludePatterns - patterns of repository names (can contain wildcards) to exclude from the results. A repository's name
122- // must NOT match any of these patterns in order to be included in the results.
123- // repoType - only repositories of this type will be returned.
124- func GetFilteredRepositoriesByNameAndType (servicesManager artifactory.ArtifactoryServicesManager , includePatterns , excludePatterns []string , repoType RepoType ) ([]string , error ) {
125- repoDetailsList , err := servicesManager .GetAllRepositoriesFiltered (services.RepositoriesFilterParams {RepoType : repoType .String ()})
126- if err != nil {
127- return nil , err
128- }
129-
130- return getFilteredRepositories (repoDetailsList , includePatterns , excludePatterns )
131- }
132-
133- func getFilteredRepositories (repoDetailsList * []services.RepositoryDetails , includePatterns , excludePatterns []string ) ([]string , error ) {
134- var repoKeys []string
135- for _ , repoDetails := range * repoDetailsList {
136- repoKeys = append (repoKeys , repoDetails .Key )
95+ repoKeys := make ([]string , len (* repoDetailsList ))
96+ for i , repoDetails := range * repoDetailsList {
97+ repoKeys [i ] = repoDetails .Key
13798 }
13899
139- return filterRepositoryNames (& repoKeys , includePatterns , excludePatterns )
100+ return filterRepositoryNames (repoKeys , includePatterns , excludePatterns )
140101}
141102
142- // GetFilteredBuildInfoRepositories returns the names of all build-info repositories filtered by their names.
143- // storageInfo - storage info response from Artifactory
144- // includePatterns - patterns of repository names (can contain wildcards) to include in the results. A repository's name
145- // must match at least one of these patterns in order to be included in the results. If includePatterns' length is zero,
146- // all repositories are included.
147- // excludePatterns - patterns of repository names (can contain wildcards) to exclude from the results. A repository's name
148- // must NOT match any of these patterns in order to be included in the results.
103+ // GetFilteredBuildInfoRepositories gets build info repositories and applies the include/exclude patterns to return the relevant repository names.
149104func GetFilteredBuildInfoRepositories (storageInfo * clientUtils.StorageInfo , includePatterns , excludePatterns []string ) ([]string , error ) {
150- var repoKeys []string
105+ repoKeys := make ([]string , 0 , len (storageInfo .RepositoriesSummaryList ))
106+
151107 for _ , repoSummary := range storageInfo .RepositoriesSummaryList {
152108 if strings .ToLower (repoSummary .PackageType ) == buildInfoPackageType {
153109 repoKeys = append (repoKeys , repoSummary .RepoKey )
154110 }
155111 }
156- return filterRepositoryNames (& repoKeys , includePatterns , excludePatterns )
112+ return filterRepositoryNames (repoKeys , includePatterns , excludePatterns )
157113}
158114
159115// Filter repositories by name and return a list of repository names
160116// repos - The repository keys to filter
161117// includePatterns - Repositories inclusion wildcard pattern
162118// excludePatterns - Repositories exclusion wildcard pattern
163- func filterRepositoryNames (repoKeys * []string , includePatterns , excludePatterns []string ) ([]string , error ) {
119+ func filterRepositoryNames (repoKeys []string , includePatterns , excludePatterns []string ) ([]string , error ) {
164120 includedRepos := datastructures .MakeSet [string ]()
165- includeExcludeFilter := & IncludeExcludeFilter {
121+ includeExcludeFilter := IncludeExcludeFilter {
166122 IncludePatterns : includePatterns ,
167123 ExcludePatterns : excludePatterns ,
168124 }
169- for _ , repoKey := range * repoKeys {
125+ for _ , repoKey := range repoKeys {
170126 repoIncluded , err := includeExcludeFilter .ShouldIncludeRepository (repoKey )
171127 if err != nil {
172128 return nil , err
0 commit comments