Skip to content

Commit

Permalink
Modify release bundle promotion properties
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Feb 1, 2024
1 parent 07e7f31 commit e81f0c3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 64 deletions.
54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2396,13 +2396,12 @@ lifecycleManager, err := lifecycle.New(serviceConfig)
```go
rbDetails := ReleaseBundleDetails{"rbName", "rbVersion"}
params := CreateOrPromoteReleaseBundleParams{}
// The GPG/RSA key-pair name given in Artifactory.
params.SigningKeyName = "key-pair"
// Optional:
params.ProjectKey = "project"
params.Async = true
queryParams := CommonOptionalQueryParams{}
queryParams.ProjectKey = "project"
queryParams.Async = true

// The GPG/RSA key-pair name given in Artifactory.
signingKeyName = "key-pair"

source := CreateFromBuildsSource{Builds: []BuildSource{
{
Expand All @@ -2412,19 +2411,19 @@ source := CreateFromBuildsSource{Builds: []BuildSource{
BuildRepository: "artifactory-build-info",
},
}}
serviceManager.CreateReleaseBundleFromBuilds(rbDetails, params, source)
serviceManager.CreateReleaseBundleFromBuilds(rbDetails, queryParams, signingKeyName, source)
```
#### Creating a Release Bundle From Release Bundles
```go
rbDetails := ReleaseBundleDetails{"rbName", "rbVersion"}
params := CreateOrPromoteReleaseBundleParams{}
queryParams := CommonOptionalQueryParams{}
queryParams.ProjectKey = "project"
queryParams.Async = true

// The GPG/RSA key-pair name given in Artifactory.
params.SigningKeyName = "key-pair"
// Optional:
params.ProjectKey = "project"
params.Async = true
signingKeyName = "key-pair"

source := CreateFromReleaseBundlesSource{ReleaseBundles: []ReleaseBundleSource{
{
Expand All @@ -2433,23 +2432,25 @@ source := CreateFromReleaseBundlesSource{ReleaseBundles: []ReleaseBundleSource{
ProjectKey: "default",
},
}}
serviceManager.CreateReleaseBundleFromBundles(rbDetails, params, source)
serviceManager.CreateReleaseBundleFromBundles(rbDetails, params, signingKeyName, source)
```
#### Promoting a Release Bundle
```go
rbDetails := ReleaseBundleDetails{"rbName", "rbVersion"}
params := CreateOrPromoteReleaseBundleParams{}
queryParams := CommonOptionalQueryParams{}
queryParams.ProjectKey = "project"
queryParams.Async = true

// The GPG/RSA key-pair name given in Artifactory.
params.SigningKeyName = "key-pair"
// Optional:
params.ProjectKey = "project"
params.Async = true
signingKeyName = "key-pair"

promotionParams := RbPromotionParams{}
promotionParams.Environment := "target-env"
promotionParams.IncludedRepositoryKeys := []string{"generic-local"}

environment := "target-env"
overwrite:=true
resp, err := serviceManager.PromoteReleaseBundle(rbDetails, params, environment, overwrite)
resp, err := serviceManager.PromoteReleaseBundle(rbDetails, queryParams, signingKeyName, promotionParams)
```
#### Get Release Bundle Creation Status
Expand Down Expand Up @@ -2498,14 +2499,11 @@ resp, err := serviceManager.DistributeReleaseBundle(params, autoCreateRepo, path
```go
rbDetails := ReleaseBundleDetails{"rbName", "rbVersion"}
params := CreateOrPromoteReleaseBundleParams{}
// The GPG/RSA key-pair name given in Artifactory.
params.SigningKeyName = "key-pair"
// Optional:
params.ProjectKey = "project"
params.Async = true
queryParams := CommonOptionalQueryParams{}
queryParams.ProjectKey = "project"
queryParams.Async = true

resp, err := serviceManager.DeleteReleaseBundle(rbDetails, params)
resp, err := serviceManager.DeleteReleaseBundle(rbDetails, queryParams)
```
#### Remote Delete Release Bundle
Expand Down
16 changes: 8 additions & 8 deletions lifecycle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ func (lcs *LifecycleServicesManager) Client() *jfroghttpclient.JfrogHttpClient {
}

func (lcs *LifecycleServicesManager) CreateReleaseBundleFromBuilds(rbDetails lifecycle.ReleaseBundleDetails,
params lifecycle.CreateOrPromoteReleaseBundleParams, sourceBuilds lifecycle.CreateFromBuildsSource) error {
queryParams lifecycle.CommonOptionalQueryParams, signingKeyName string, sourceBuilds lifecycle.CreateFromBuildsSource) error {
rbService := lifecycle.NewReleaseBundlesService(lcs.config.GetServiceDetails(), lcs.client)
return rbService.CreateFromBuilds(rbDetails, params, sourceBuilds)
return rbService.CreateFromBuilds(rbDetails, queryParams, signingKeyName, sourceBuilds)
}

func (lcs *LifecycleServicesManager) CreateReleaseBundleFromBundles(rbDetails lifecycle.ReleaseBundleDetails,
params lifecycle.CreateOrPromoteReleaseBundleParams, sourceReleaseBundles lifecycle.CreateFromReleaseBundlesSource) error {
queryParams lifecycle.CommonOptionalQueryParams, signingKeyName string, sourceReleaseBundles lifecycle.CreateFromReleaseBundlesSource) error {
rbService := lifecycle.NewReleaseBundlesService(lcs.config.GetServiceDetails(), lcs.client)
return rbService.CreateFromBundles(rbDetails, params, sourceReleaseBundles)
return rbService.CreateFromBundles(rbDetails, queryParams, signingKeyName, sourceReleaseBundles)
}

func (lcs *LifecycleServicesManager) PromoteReleaseBundle(rbDetails lifecycle.ReleaseBundleDetails, params lifecycle.CreateOrPromoteReleaseBundleParams, environment string, overwrite bool) (lifecycle.RbPromotionResp, error) {
func (lcs *LifecycleServicesManager) PromoteReleaseBundle(rbDetails lifecycle.ReleaseBundleDetails, queryParams lifecycle.CommonOptionalQueryParams, signingKeyName string, promotionParams lifecycle.RbPromotionParams) (lifecycle.RbPromotionResp, error) {
rbService := lifecycle.NewReleaseBundlesService(lcs.config.GetServiceDetails(), lcs.client)
return rbService.Promote(rbDetails, params, environment, overwrite)
return rbService.Promote(rbDetails, queryParams, signingKeyName, promotionParams)
}

func (lcs *LifecycleServicesManager) GetReleaseBundleCreationStatus(rbDetails lifecycle.ReleaseBundleDetails, projectKey string, sync bool) (lifecycle.ReleaseBundleStatusResponse, error) {
Expand All @@ -63,9 +63,9 @@ func (lcs *LifecycleServicesManager) GetReleaseBundlePromotionStatus(rbDetails l
return rbService.GetReleaseBundlePromotionStatus(rbDetails, projectKey, createdMillis, sync)
}

func (lcs *LifecycleServicesManager) DeleteReleaseBundle(rbDetails lifecycle.ReleaseBundleDetails, params lifecycle.ReleaseBundleQueryParams) error {
func (lcs *LifecycleServicesManager) DeleteReleaseBundle(rbDetails lifecycle.ReleaseBundleDetails, queryParams lifecycle.CommonOptionalQueryParams) error {
rbService := lifecycle.NewReleaseBundlesService(lcs.config.GetServiceDetails(), lcs.client)
return rbService.DeleteReleaseBundle(rbDetails, params)
return rbService.DeleteReleaseBundle(rbDetails, queryParams)
}

func (lcs *LifecycleServicesManager) DistributeReleaseBundle(params distribution.DistributionParams, autoCreateRepo bool, pathMapping lifecycle.PathMapping) error {
Expand Down
21 changes: 14 additions & 7 deletions lifecycle/services/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const (
)

type createOperation struct {
reqBody RbCreationBody
params CreateOrPromoteReleaseBundleParams
reqBody RbCreationBody
params CommonOptionalQueryParams
signingKeyName string
}

func (c *createOperation) getOperationRestApi() string {
Expand All @@ -28,29 +29,35 @@ func (c *createOperation) getOperationSuccessfulMsg() string {
return "Release Bundle successfully created"
}

func (c *createOperation) getOperationParams() CreateOrPromoteReleaseBundleParams {
func (c *createOperation) getOperationParams() CommonOptionalQueryParams {
return c.params
}

func (rbs *ReleaseBundlesService) CreateFromBuilds(rbDetails ReleaseBundleDetails, params CreateOrPromoteReleaseBundleParams, sourceBuilds CreateFromBuildsSource) error {
func (c *createOperation) getSigningKeyName() string {
return c.signingKeyName
}

func (rbs *ReleaseBundlesService) CreateFromBuilds(rbDetails ReleaseBundleDetails, params CommonOptionalQueryParams, signingKeyName string, sourceBuilds CreateFromBuildsSource) error {
operation := createOperation{
reqBody: RbCreationBody{
ReleaseBundleDetails: rbDetails,
SourceType: builds,
Source: sourceBuilds},
params: params,
params: params,
signingKeyName: signingKeyName,
}
_, err := rbs.doOperation(&operation)
return err
}

func (rbs *ReleaseBundlesService) CreateFromBundles(rbDetails ReleaseBundleDetails, params CreateOrPromoteReleaseBundleParams, sourceReleaseBundles CreateFromReleaseBundlesSource) error {
func (rbs *ReleaseBundlesService) CreateFromBundles(rbDetails ReleaseBundleDetails, params CommonOptionalQueryParams, signingKeyName string, sourceReleaseBundles CreateFromReleaseBundlesSource) error {
operation := createOperation{
reqBody: RbCreationBody{
ReleaseBundleDetails: rbDetails,
SourceType: releaseBundles,
Source: sourceReleaseBundles},
params: params,
params: params,
signingKeyName: signingKeyName,
}
_, err := rbs.doOperation(&operation)
return err
Expand Down
2 changes: 1 addition & 1 deletion lifecycle/services/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
remoteDeleteEndpoint = "remote_delete"
)

func (rbs *ReleaseBundlesService) DeleteReleaseBundle(rbDetails ReleaseBundleDetails, params ReleaseBundleQueryParams) error {
func (rbs *ReleaseBundlesService) DeleteReleaseBundle(rbDetails ReleaseBundleDetails, params CommonOptionalQueryParams) error {
queryParams := getProjectQueryParam(params.ProjectKey)
queryParams[async] = strconv.FormatBool(params.Async)
restApi := path.Join(releaseBundleBaseApi, records, rbDetails.ReleaseBundleName, rbDetails.ReleaseBundleVersion)
Expand Down
13 changes: 4 additions & 9 deletions lifecycle/services/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type ReleaseBundleOperation interface {
getOperationRestApi() string
getRequestBody() any
getOperationSuccessfulMsg() string
getOperationParams() CreateOrPromoteReleaseBundleParams
getOperationParams() CommonOptionalQueryParams
getSigningKeyName() string
}

func (rbs *ReleaseBundlesService) doOperation(operation ReleaseBundleOperation) ([]byte, error) {
Expand All @@ -43,7 +44,7 @@ func (rbs *ReleaseBundlesService) doOperation(operation ReleaseBundleOperation)
}

httpClientDetails := rbs.GetLifecycleDetails().CreateHttpClientDetails()
rtUtils.AddSigningKeyNameHeader(operation.getOperationParams().SigningKeyName, &httpClientDetails.Headers)
rtUtils.AddSigningKeyNameHeader(operation.getSigningKeyName(), &httpClientDetails.Headers)
rtUtils.SetContentType("application/json", &httpClientDetails.Headers)

content, err := json.Marshal(operation.getRequestBody())
Expand Down Expand Up @@ -79,13 +80,7 @@ type ReleaseBundleDetails struct {
ReleaseBundleVersion string `json:"release_bundle_version,omitempty"`
}

type CreateOrPromoteReleaseBundleParams struct {
ReleaseBundleQueryParams
// Header:
SigningKeyName string
}

type ReleaseBundleQueryParams struct {
type CommonOptionalQueryParams struct {
ProjectKey string
Async bool
}
34 changes: 23 additions & 11 deletions lifecycle/services/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const (
)

type promoteOperation struct {
reqBody RbPromotionBody
rbDetails ReleaseBundleDetails
params CreateOrPromoteReleaseBundleParams
reqBody RbPromotionBody
rbDetails ReleaseBundleDetails
queryParams CommonOptionalQueryParams
signingKeyName string
}

func (p *promoteOperation) getOperationRestApi() string {
Expand All @@ -29,18 +30,24 @@ func (p *promoteOperation) getOperationSuccessfulMsg() string {
return "Release Bundle successfully promoted"
}

func (p *promoteOperation) getOperationParams() CreateOrPromoteReleaseBundleParams {
return p.params
func (p *promoteOperation) getOperationParams() CommonOptionalQueryParams {
return p.queryParams
}

func (rbs *ReleaseBundlesService) Promote(rbDetails ReleaseBundleDetails, params CreateOrPromoteReleaseBundleParams, environment string, overwrite bool) (RbPromotionResp, error) {
func (p *promoteOperation) getSigningKeyName() string {
return p.signingKeyName
}

func (rbs *ReleaseBundlesService) Promote(rbDetails ReleaseBundleDetails, queryParams CommonOptionalQueryParams, signingKeyName string, promotionParams RbPromotionParams) (RbPromotionResp, error) {
operation := promoteOperation{
reqBody: RbPromotionBody{

Check failure on line 43 in lifecycle/services/promote.go

View workflow job for this annotation

GitHub Actions / Static-Check

S1016: should convert promotionParams (type RbPromotionParams) to RbPromotionBody instead of using struct literal (gosimple)
Environment: environment,
Overwrite: overwrite,
Environment: promotionParams.Environment,
IncludedRepositoryKeys: promotionParams.IncludedRepositoryKeys,
ExcludedRepositoryKeys: promotionParams.ExcludedRepositoryKeys,
},
rbDetails: rbDetails,
params: params,
rbDetails: rbDetails,
queryParams: queryParams,
signingKeyName: signingKeyName,
}
respBody, err := rbs.doOperation(&operation)
if err != nil {
Expand All @@ -51,9 +58,14 @@ func (rbs *ReleaseBundlesService) Promote(rbDetails ReleaseBundleDetails, params
return promotionResp, errorutils.CheckError(err)
}

type RbPromotionParams struct {
Environment string
IncludedRepositoryKeys []string
ExcludedRepositoryKeys []string
}

type RbPromotionBody struct {
Environment string `json:"environment,omitempty"`
Overwrite bool `json:"overwrite_existing_artifacts,omitempty"`
IncludedRepositoryKeys []string `json:"included_repository_keys,omitempty"`
ExcludedRepositoryKeys []string `json:"excluded_repository_keys,omitempty"`
}
Expand Down

0 comments on commit e81f0c3

Please sign in to comment.