Skip to content

Commit b8116ce

Browse files
authored
Updated the structure of artifact_additional_properties to support multiple values (#37)
1 parent c958c10 commit b8116ce

File tree

7 files changed

+30
-17
lines changed

7 files changed

+30
-17
lines changed

apptrust/commands/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const (
5050
SourceTypeReleaseBundlesFlag = "source-type-release-bundles"
5151
SourceTypeApplicationVersionsFlag = "source-type-application-versions"
5252
PropertiesFlag = "properties"
53-
DeletePropertyFlag = "delete-property"
53+
DeletePropertiesFlag = "delete-properties"
5454
)
5555

5656
// Flag keys mapped to their corresponding components.Flag definition.
@@ -83,7 +83,7 @@ var flagsMap = map[string]components.Flag{
8383
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 }),
8484
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 }),
8585
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 }),
86-
DeletePropertyFlag: components.NewStringFlag(DeletePropertyFlag, "Remove a property key and all its values", func(f *components.StringFlag) { f.Mandatory = false }),
86+
DeletePropertiesFlag: components.NewStringFlag(DeletePropertiesFlag, "Remove a property key and all its values", func(f *components.StringFlag) { f.Mandatory = false }),
8787
}
8888

8989
var commandFlags = map[string][]string{
@@ -142,7 +142,7 @@ var commandFlags = map[string][]string{
142142
serverId,
143143
TagFlag,
144144
PropertiesFlag,
145-
DeletePropertyFlag,
145+
DeletePropertiesFlag,
146146
},
147147

148148
PackageBind: {

apptrust/commands/version/update_app_version_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ func (uv *updateAppVersionCommand) buildRequestPayload(ctx *components.Context)
101101
}
102102

103103
// Handle delete properties
104-
if ctx.IsFlagSet(commands.DeletePropertyFlag) {
105-
deleteProps := utils.ParseSliceFlag(ctx.GetStringFlagValue(commands.DeletePropertyFlag))
104+
if ctx.IsFlagSet(commands.DeletePropertiesFlag) {
105+
deleteProps := utils.ParseSliceFlag(ctx.GetStringFlagValue(commands.DeletePropertiesFlag))
106106
request.DeleteProperties = deleteProps
107107
}
108108

apptrust/commands/version/update_app_version_cmd_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
132132
name: "delete properties only",
133133
ctxSetup: func(ctx *components.Context) {
134134
ctx.Arguments = []string{"app-key", "1.0.0"}
135-
ctx.AddStringFlag(commands.DeletePropertyFlag, "legacy_param;toBeDeleted")
135+
ctx.AddStringFlag(commands.DeletePropertiesFlag, "legacy_param;toBeDeleted")
136136
},
137137
expectsPayload: &model.UpdateAppVersionRequest{
138138
DeleteProperties: []string{"legacy_param", "toBeDeleted"},
@@ -156,7 +156,7 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
156156
ctx.Arguments = []string{"app-key", "1.0.0"}
157157
ctx.AddStringFlag(commands.TagFlag, "release/1.2.3")
158158
ctx.AddStringFlag(commands.PropertiesFlag, "status=rc,validated")
159-
ctx.AddStringFlag(commands.DeletePropertyFlag, "old_param")
159+
ctx.AddStringFlag(commands.DeletePropertiesFlag, "old_param")
160160
},
161161
expectsPayload: &model.UpdateAppVersionRequest{
162162
Tag: "release/1.2.3",

apptrust/commands/version/version_utils.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,21 @@ func BuildPromotionParams(ctx *components.Context) (string, []string, []string,
3939
}
4040

4141
// ParseArtifactProps extracts artifact properties from command context
42-
func ParseArtifactProps(ctx *components.Context) (map[string]string, error) {
42+
func ParseArtifactProps(ctx *components.Context) ([]model.ArtifactProperty, error) {
4343
if propsStr := ctx.GetStringFlagValue(commands.PropsFlag); propsStr != "" {
44-
props, err := utils.ParseMapFlag(propsStr)
44+
props, err := utils.ParseListPropertiesFlag(propsStr)
4545
if err != nil {
4646
return nil, errorutils.CheckErrorf("failed to parse properties: %s", err.Error())
4747
}
48-
return props, nil
48+
49+
var artifactProps []model.ArtifactProperty
50+
for key, values := range props {
51+
artifactProps = append(artifactProps, model.ArtifactProperty{
52+
Key: key,
53+
Values: values,
54+
})
55+
}
56+
return artifactProps, nil
4957
}
5058
return nil, nil
5159
}

apptrust/model/promote_app_version_request.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ var PromotionTypeValues = []string{
1515
}
1616

1717
type CommonPromoteAppVersion struct {
18-
PromotionType string `json:"promotion_type,omitempty"`
19-
IncludedRepositoryKeys []string `json:"included_repository_keys,omitempty"`
20-
ExcludedRepositoryKeys []string `json:"excluded_repository_keys,omitempty"`
21-
ArtifactAdditionalProperties map[string]string `json:"artifact_additional_properties,omitempty"`
18+
PromotionType string `json:"promotion_type,omitempty"`
19+
IncludedRepositoryKeys []string `json:"included_repository_keys,omitempty"`
20+
ExcludedRepositoryKeys []string `json:"excluded_repository_keys,omitempty"`
21+
ArtifactAdditionalProperties []ArtifactProperty `json:"artifact_additional_properties,omitempty"`
22+
}
23+
24+
type ArtifactProperty struct {
25+
Key string `json:"key"`
26+
Values []string `json:"values"`
2227
}
2328

2429
type PromoteAppVersionRequest struct {

apptrust/model/release_app_version_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func NewReleaseAppVersionRequest(
1313
promotionType string,
1414
includedRepositoryKeys []string,
1515
excludedRepositoryKeys []string,
16-
artifactProperties map[string]string,
16+
artifactProperties []ArtifactProperty,
1717
) *ReleaseAppVersionRequest {
1818
return &ReleaseAppVersionRequest{
1919
CommonPromoteAppVersion: CommonPromoteAppVersion{

apptrust/service/versions/version_service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func TestReleaseAppVersion(t *testing.T) {
212212
model.PromotionTypeCopy,
213213
[]string{"repo1", "repo2"},
214214
[]string{"repo3"},
215-
map[string]string{"key1": "value1"},
215+
[]model.ArtifactProperty{{Key: "key1", Values: []string{"value1"}}},
216216
),
217217
sync: true,
218218
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/release",
@@ -229,7 +229,7 @@ func TestReleaseAppVersion(t *testing.T) {
229229
model.PromotionTypeCopy,
230230
[]string{"repo1", "repo2"},
231231
[]string{"repo3"},
232-
map[string]string{"key1": "value1"},
232+
[]model.ArtifactProperty{{Key: "key1", Values: []string{"value1"}}},
233233
),
234234
sync: false,
235235
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/release",

0 commit comments

Comments
 (0)