Skip to content

Commit

Permalink
Add project key to GetAllRepositoriesFiltered
Browse files Browse the repository at this point in the history
  • Loading branch information
Or-Geva committed Aug 20, 2024
1 parent c6062ab commit 3fc5f9c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
47 changes: 21 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
- [Using Artifactory Services](#using-artifactory-services)
- [Uploading Files to Artifactory](#uploading-files-to-artifactory)
- [Downloading Files from Artifactory](#downloading-files-from-artifactory)
- [Downloading Release Bundles from Artifactory](#downloading-release-bundles-v1-from-artifactory)
- [Downloading Release Bundles v1 from Artifactory](#downloading-release-bundles-v1-from-artifactory)
- [Uploading and Downloading Files with Summary](#uploading-and-downloading-files-with-summary)
- [Copying Files in Artifactory](#copying-files-in-artifactory)
- [Moving Files in Artifactory](#moving-files-in-artifactory)
Expand Down Expand Up @@ -128,14 +128,14 @@
- [Creating New Distribution Service Manager](#creating-new-distribution-service-manager)
- [Using Distribution Services](#using-distribution-services)
- [Setting Distribution Signing Key](#setting-distribution-signing-key)
- [Creating a Release Bundle](#creating-a-release-bundle-v1)
- [Updating a Release Bundle](#updating-a-release-bundle-v1)
- [Signing a Release Bundle](#signing-a-release-bundle-v1)
- [Async Distributing a Release Bundle](#async-distributing-a-release-bundle-v1)
- [Sync Distributing a Release Bundle](#sync-distributing-a-release-bundle-v1)
- [Creating a Release Bundle v1](#creating-a-release-bundle-v1)
- [Updating a Release Bundle v1](#updating-a-release-bundle-v1)
- [Signing a Release Bundle v1](#signing-a-release-bundle-v1)
- [Async Distributing a Release Bundle v1](#async-distributing-a-release-bundle-v1)
- [Sync Distributing a Release Bundle v1](#sync-distributing-a-release-bundle-v1)
- [Getting Distribution Status](#getting-distribution-status)
- [Deleting a Remote Release Bundle](#deleting-a-remote-release-bundle-v1)
- [Deleting a Local Release Bundle](#deleting-a-local-release-bundle-v1)
- [Deleting a Remote Release Bundle v1](#deleting-a-remote-release-bundle-v1)
- [Deleting a Local Release Bundle v1](#deleting-a-local-release-bundle-v1)
- [Using ContentReader](#using-contentreader)
- [Xray APIs](#xray-apis)
- [Creating Xray Service Manager](#creating-xray-service-manager)
Expand Down Expand Up @@ -175,13 +175,13 @@
- [Get Violations Report Content](#get-violations-report-content)
- [Delete Violations Report](#delete-violations-report)
- [Get Artifact Summary](#get-artifact-summary)
- [Get Entitlement info](#get-entitlement-info)
- [XSC APIs](#xsc-apis)
- [Creating XSC Service Manager](#creating-xray-service-manager)
- [Get Entitlement Info](#get-entitlement-info)
- [XSC APIs](#xsc-apis)
- [Creating XSC Service Manager](#creating-xsc-service-manager)
- [Creating XSC Details](#creating-xsc-details)
- [Creating XSC Service Config](#creating-xsc-service-config)
- [Creating New XSC Service Manager](#creating-new-xsc-service-manager)
- [Using XSC Services](#using-xsc-services)
- [Using XSC Services](#using-xsc-services)
- [Fetching XSC's Version](#fetching-xscs-version)
- [Report XSC analytics metrics](#report-xsc-analytics-metrics)
- [Add analytics general event](#add-analytics-general-event)
Expand Down Expand Up @@ -212,11 +212,11 @@
- [Get Pipeline Sync Status](#get-pipeline-sync-status)
- [Cancel Run](#cancel-run)
- [Lifecycle APIs](#lifecycle-apis)
- [Creating Lifecycle Service Manager](#creating-lifeCycle-service-manager)
- [Creating Lifecycle Details](#creating-lifeCycle-details)
- [Creating Lifecycle Service Config](#creating-lifeCycle-service-config)
- [Creating New Lifecycle Service Manager](#creating-new-lifeCycle-service-manager)
- [Using Lifecycle Services](#using-lifeCycle-services)
- [Creating Lifecycle Service Manager](#creating-lifecycle-service-manager)
- [Creating Lifecycle Details](#creating-lifecycle-details)
- [Creating Lifecycle Service Config](#creating-lifecycle-service-config)
- [Creating New Lifecycle Service Manager](#creating-new-lifecycle-service-manager)
- [Using Lifecycle Services](#using-lifecycle-services)
- [Creating a Release Bundle From AQL](#creating-a-release-bundle-from-aql)
- [Creating a Release Bundle From Artifacts](#creating-a-release-bundle-from-artifacts)
- [Creating a Release Bundle From Published Builds](#creating-a-release-bundle-from-published-builds)
Expand All @@ -225,19 +225,13 @@
- [Get Release Bundle Creation Status](#get-release-bundle-creation-status)
- [Get Release Bundle Promotion Status](#get-release-bundle-promotion-status)
- [Get Release Bundle Promotions](#get-release-bundle-promotions)
- [Get Release Bundle Specification](#get-release-bundle-specification)
- [Distribute Release Bundle](#distribute-release-bundle)
- [Export Release Bundle Archive](#export-release-bundle-archive)
- [Import Release Bundle Archive](#import-release-bundle-archive)
- [Delete Release Bundle Version](#delete-release-bundle-version)
- [Delete Release Bundle Version Promotion](#delete-release-bundle-version-promotion)
- [Export Release Bundle Archive](#export-release-bundle-archive)
- [Import Release Bundle](#import-release-bundle)
- [Remote Delete Release Bundle](#remote-delete-release-bundle)
- [Lifecycle APIs](#lifecycle-apis)
- [Creating Lifecycle Service Manager](#creating-lifeCycle-service-manager)
- [Creating Lifecycle Details](#creating-lifeCycle-details)
- [Creating Lifecycle Service Config](#creating-lifeCycle-service-config)
- [Creating New Lifecycle Service Manager](#creating-new-lifeCycle-service-manager)
- [Using Lifecycle Services](#using-lifeCycle-services)
- [Creating a Release Bundle From AQL](#creating-a-release-bundle-from-aql)
- [Evidence APIs](#evidence-apis)
- [Creating Evidence Service Manager](#creating-evidence-service-manager)
- [Creating Evidence Details](#creating-evidence-details)
Expand Down Expand Up @@ -1081,6 +1075,7 @@ You can get all repositories from Artifactory filtered according to theirs type
params := services.NewRepositoriesFilterParams()
params.RepoType = "remote"
params.PackageType = "maven"
params.ProjectKey = "my-project-key"
err := servicesManager.GetAllRepositoriesFiltered(params)
```

Expand Down
22 changes: 18 additions & 4 deletions artifactory/services/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package services

import (
"encoding/json"
"fmt"
"net/http"

"github.com/jfrog/jfrog-client-go/auth"
Expand Down Expand Up @@ -46,12 +45,11 @@ func (rs *RepositoriesService) IsExists(repoKey string) (exists bool, err error)

func (rs *RepositoriesService) GetAll() (*[]RepositoryDetails, error) {
log.Info("Getting all repositories ...")
return rs.GetWithFilter(RepositoriesFilterParams{RepoType: "", PackageType: ""})
return rs.GetWithFilter(RepositoriesFilterParams{})
}

func (rs *RepositoriesService) GetWithFilter(params RepositoriesFilterParams) (*[]RepositoryDetails, error) {
url := fmt.Sprintf("%s?type=%s&packageType=%s", apiRepositories, params.RepoType, params.PackageType)
body, err := rs.sendGet(url)
body, err := rs.sendGet(createWithFilterUrl(params))
if err != nil {
return nil, err
}
Expand All @@ -60,6 +58,21 @@ func (rs *RepositoriesService) GetWithFilter(params RepositoriesFilterParams) (*
return repoDetails, errorutils.CheckError(err)
}

func createWithFilterUrl(params RepositoriesFilterParams) string {
endpoint := apiRepositories
if params.RepoType != "" {
endpoint += "?type=" + params.RepoType
}
if params.PackageType != "" {
endpoint += "&packageType=" + params.PackageType
}
if params.ProjectKey != "" {
log.Info("Getting repositories with project key:", params.ProjectKey)
endpoint += "&project=" + params.ProjectKey
}
return endpoint
}

func (rs *RepositoriesService) sendGet(api string) ([]byte, error) {
httpClientsDetails := rs.ArtDetails.CreateHttpClientDetails()
resp, body, _, err := rs.client.SendGet(rs.ArtDetails.GetUrl()+api, true, &httpClientsDetails)
Expand Down Expand Up @@ -113,6 +126,7 @@ func (rd RepositoryDetails) GetRepoType() string {
type RepositoriesFilterParams struct {
RepoType string
PackageType string
ProjectKey string
}

func NewRepositoriesFilterParams() RepositoriesFilterParams {
Expand Down

0 comments on commit 3fc5f9c

Please sign in to comment.