Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apptrust/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
SourceTypeReleaseBundlesFlag = "source-type-release-bundles"
SourceTypeApplicationVersionsFlag = "source-type-application-versions"
PropertiesFlag = "properties"
DeletePropertyFlag = "delete-property"
DeletePropertiesFlag = "delete-properties"
)

// Flag keys mapped to their corresponding components.Flag definition.
Expand Down Expand Up @@ -83,7 +83,7 @@ var flagsMap = map[string]components.Flag{
SourceTypeReleaseBundlesFlag: components.NewStringFlag(SourceTypeReleaseBundlesFlag, "List of semicolon-separated (;) release bundles in the form of 'name=releaseBundleName1, version=version1; name=releaseBundleName2, version=version2' to be included in the new version.", func(f *components.StringFlag) { f.Mandatory = false }),
SourceTypeApplicationVersionsFlag: components.NewStringFlag(SourceTypeApplicationVersionsFlag, "List of semicolon-separated (;) application versions in the form of 'application-key=app1, version=version1; application-key=app2, version=version2' to be included in the new version.", func(f *components.StringFlag) { f.Mandatory = false }),
PropertiesFlag: components.NewStringFlag(PropertiesFlag, "Sets or updates custom properties for the application version in format 'key1=value1[,value2,...];key2=value3[,value4,...]'", func(f *components.StringFlag) { f.Mandatory = false }),
DeletePropertyFlag: components.NewStringFlag(DeletePropertyFlag, "Remove a property key and all its values", func(f *components.StringFlag) { f.Mandatory = false }),
DeletePropertiesFlag: components.NewStringFlag(DeletePropertiesFlag, "Remove a property key and all its values", func(f *components.StringFlag) { f.Mandatory = false }),
}

var commandFlags = map[string][]string{
Expand Down Expand Up @@ -142,7 +142,7 @@ var commandFlags = map[string][]string{
serverId,
TagFlag,
PropertiesFlag,
DeletePropertyFlag,
DeletePropertiesFlag,
},

PackageBind: {
Expand Down
4 changes: 2 additions & 2 deletions apptrust/commands/version/update_app_version_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (uv *updateAppVersionCommand) buildRequestPayload(ctx *components.Context)
}

// Handle delete properties
if ctx.IsFlagSet(commands.DeletePropertyFlag) {
deleteProps := utils.ParseSliceFlag(ctx.GetStringFlagValue(commands.DeletePropertyFlag))
if ctx.IsFlagSet(commands.DeletePropertiesFlag) {
deleteProps := utils.ParseSliceFlag(ctx.GetStringFlagValue(commands.DeletePropertiesFlag))
request.DeleteProperties = deleteProps
}

Expand Down
4 changes: 2 additions & 2 deletions apptrust/commands/version/update_app_version_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
name: "delete properties only",
ctxSetup: func(ctx *components.Context) {
ctx.Arguments = []string{"app-key", "1.0.0"}
ctx.AddStringFlag(commands.DeletePropertyFlag, "legacy_param;toBeDeleted")
ctx.AddStringFlag(commands.DeletePropertiesFlag, "legacy_param;toBeDeleted")
},
expectsPayload: &model.UpdateAppVersionRequest{
DeleteProperties: []string{"legacy_param", "toBeDeleted"},
Expand All @@ -156,7 +156,7 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
ctx.Arguments = []string{"app-key", "1.0.0"}
ctx.AddStringFlag(commands.TagFlag, "release/1.2.3")
ctx.AddStringFlag(commands.PropertiesFlag, "status=rc,validated")
ctx.AddStringFlag(commands.DeletePropertyFlag, "old_param")
ctx.AddStringFlag(commands.DeletePropertiesFlag, "old_param")
},
expectsPayload: &model.UpdateAppVersionRequest{
Tag: "release/1.2.3",
Expand Down
14 changes: 11 additions & 3 deletions apptrust/commands/version/version_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ func BuildPromotionParams(ctx *components.Context) (string, []string, []string,
}

// ParseArtifactProps extracts artifact properties from command context
func ParseArtifactProps(ctx *components.Context) (map[string]string, error) {
func ParseArtifactProps(ctx *components.Context) ([]model.ArtifactProperty, error) {
if propsStr := ctx.GetStringFlagValue(commands.PropsFlag); propsStr != "" {
props, err := utils.ParseMapFlag(propsStr)
props, err := utils.ParseListPropertiesFlag(propsStr)
if err != nil {
return nil, errorutils.CheckErrorf("failed to parse properties: %s", err.Error())
}
return props, nil

var artifactProps []model.ArtifactProperty
for key, values := range props {
artifactProps = append(artifactProps, model.ArtifactProperty{
Key: key,
Values: values,
})
}
return artifactProps, nil
}
return nil, nil
}
13 changes: 9 additions & 4 deletions apptrust/model/promote_app_version_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ var PromotionTypeValues = []string{
}

type CommonPromoteAppVersion struct {
PromotionType string `json:"promotion_type,omitempty"`
IncludedRepositoryKeys []string `json:"included_repository_keys,omitempty"`
ExcludedRepositoryKeys []string `json:"excluded_repository_keys,omitempty"`
ArtifactAdditionalProperties map[string]string `json:"artifact_additional_properties,omitempty"`
PromotionType string `json:"promotion_type,omitempty"`
IncludedRepositoryKeys []string `json:"included_repository_keys,omitempty"`
ExcludedRepositoryKeys []string `json:"excluded_repository_keys,omitempty"`
ArtifactAdditionalProperties []ArtifactProperty `json:"artifact_additional_properties,omitempty"`
}

type ArtifactProperty struct {
Key string `json:"key"`
Values []string `json:"values"`
}

type PromoteAppVersionRequest struct {
Expand Down
2 changes: 1 addition & 1 deletion apptrust/model/release_app_version_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewReleaseAppVersionRequest(
promotionType string,
includedRepositoryKeys []string,
excludedRepositoryKeys []string,
artifactProperties map[string]string,
artifactProperties []ArtifactProperty,
) *ReleaseAppVersionRequest {
return &ReleaseAppVersionRequest{
CommonPromoteAppVersion: CommonPromoteAppVersion{
Expand Down
4 changes: 2 additions & 2 deletions apptrust/service/versions/version_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestReleaseAppVersion(t *testing.T) {
model.PromotionTypeCopy,
[]string{"repo1", "repo2"},
[]string{"repo3"},
map[string]string{"key1": "value1"},
[]model.ArtifactProperty{{Key: "key1", Values: []string{"value1"}}},
),
sync: true,
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/release",
Expand All @@ -229,7 +229,7 @@ func TestReleaseAppVersion(t *testing.T) {
model.PromotionTypeCopy,
[]string{"repo1", "repo2"},
[]string{"repo3"},
map[string]string{"key1": "value1"},
[]model.ArtifactProperty{{Key: "key1", Values: []string{"value1"}}},
),
sync: false,
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/release",
Expand Down