Skip to content

Commit 6d54e92

Browse files
authored
Update renamed fields in operations on OSUpdatePolicy (#164)
1 parent b5cf0fb commit 6d54e92

File tree

20 files changed

+112
-75
lines changed

20 files changed

+112
-75
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ rest-client-gen:
116116
oapi-codegen -generate client -old-config-style -package rps -o pkg/rest/rps/client.go pkg/rest/rps/amc-opendmt-rps-openapi.yaml
117117
oapi-codegen -generate types -old-config-style -package rps -o pkg/rest/rps/types.go pkg/rest/rps/amc-opendmt-rps-openapi.yaml
118118

119+
# Supported mockgen version v0.5.2
120+
# install command: go install go.uber.org/mock/[email protected]
119121
mock-client-gen:
120122
@# Help: Generate mock clients for testing
121123
mockgen -source=pkg/rest/catalog/client.go -destination=pkg/rest/catalog/mock_client.go -package=catalog

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ require (
115115
github.com/zclconf/go-cty-yaml v1.1.0 // indirect
116116
go.yaml.in/yaml/v3 v3.0.4 // indirect
117117
golang.org/x/arch v0.18.0 // indirect
118-
golang.org/x/crypto v0.40.0 // indirect
118+
golang.org/x/crypto v0.41.0 // indirect
119119
golang.org/x/mod v0.27.0 // indirect
120-
golang.org/x/net v0.42.0 // indirect
120+
golang.org/x/net v0.43.0 // indirect
121121
golang.org/x/oauth2 v0.30.0 // indirect
122122
golang.org/x/sync v0.16.0 // indirect
123123
golang.org/x/sys v0.36.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
337337
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
338338
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
339339
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
340-
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
341-
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
340+
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
341+
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
342342
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
343343
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
344344
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@@ -362,8 +362,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
362362
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
363363
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
364364
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
365-
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
366-
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
365+
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
366+
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
367367
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
368368
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
369369
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=

internal/cli/mocks/infra/infra_mock.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,14 +2016,14 @@ func CreateInfraMock(mctrl *gomock.Controller, timestamp time.Time) interfaces.I
20162016
return &infra.OSUpdatePolicyGetOSUpdatePolicyResponse{
20172017
HTTPResponse: &http.Response{StatusCode: 200, Status: "OK"},
20182018
JSON200: &infra.OSUpdatePolicy{
2019-
Name: "security-policy-v1.2",
2020-
ResourceId: stringPtr(policyId),
2021-
Description: stringPtr("Monthly security update policy"),
2022-
TargetOsId: stringPtr("os-1234abcd"),
2023-
InstallPackages: stringPtr("curl wget vim"),
2024-
UpdatePolicy: (*infra.UpdatePolicy)(stringPtr("UPDATE_POLICY_LATEST")),
2025-
UpdateSources: &[]string{"https://updates.example.com"},
2026-
KernelCommand: stringPtr("console=ttyS0"),
2019+
Name: "security-policy-v1.2",
2020+
ResourceId: stringPtr(policyId),
2021+
Description: stringPtr("Monthly security update policy"),
2022+
TargetOsId: stringPtr("os-1234abcd"),
2023+
UpdatePackages: stringPtr("curl wget vim"),
2024+
UpdatePolicy: (*infra.UpdatePolicy)(stringPtr("UPDATE_POLICY_LATEST")),
2025+
UpdateSources: &[]string{"https://updates.example.com"},
2026+
UpdateKernelCommand: stringPtr("console=ttyS0"),
20272027
Timestamps: &infra.Timestamps{
20282028
CreatedAt: timestampPtr(timestamp),
20292029
UpdatedAt: timestampPtr(timestamp),

internal/cli/osupdatepolicy.go

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ var osUpdatePolicySchema = `
5050
"spec": {
5151
"type": "object",
5252
"properties": {
53-
"name": { "type": "string" },
54-
"description": { "type": "string" },
55-
"installPackages": { "type": "string" },
56-
"kernelCommand": { "type": "string" },
57-
"targetOs": { "type": "string" },
58-
"updateSources": { "type": ["array", "null"], "items": { "type": "string" } },
59-
"updatePolicy": { "type": "string" }
53+
"name": { "type": "string" },
54+
"description": { "type": "string" },
55+
"updatePackages": { "type": "string" },
56+
"updateKernelCommand": { "type": "string" },
57+
"targetOs": { "type": "string" },
58+
"updateSources": { "type": ["array", "null"], "items": { "type": "string" } },
59+
"updatePolicy": { "type": "string" }
6060
},
6161
"required": ["name", "description", "updatePolicy"]
6262
}
@@ -66,13 +66,13 @@ var osUpdatePolicySchema = `
6666
`
6767

6868
type OSUpdatePolicy struct {
69-
Name string `yaml:"name"`
70-
Description string `yaml:"description"`
71-
InstallPackages string `yaml:"installPackages"`
72-
KernelCommand string `yaml:"kernelCommand"`
73-
TargetOS string `yaml:"targetOs"`
74-
UpdateSources []string `yaml:"updateSources"`
75-
UpdatePolicy string `yaml:"updatePolicy"`
69+
Name string `yaml:"name"`
70+
Description string `yaml:"description"`
71+
UpdatePackages string `yaml:"updatePackages"`
72+
UpdateKernelCommand string `yaml:"updateKernelCommand"`
73+
TargetOS string `yaml:"targetOs"`
74+
UpdateSources []string `yaml:"updateSources"`
75+
UpdatePolicy string `yaml:"updatePolicy"`
7676
}
7777

7878
type UpdateNestedSpec struct {
@@ -110,7 +110,7 @@ func printOSUpdatePolicy(writer io.Writer, OSUpdatePolicy *infra.OSUpdatePolicy)
110110
_, _ = fmt.Fprintf(writer, "Resource ID:\t %s\n", *OSUpdatePolicy.ResourceId)
111111
_, _ = fmt.Fprintf(writer, "Target OS ID:\t %s\n", *OSUpdatePolicy.TargetOsId)
112112
_, _ = fmt.Fprintf(writer, "Description:\t %v\n", *OSUpdatePolicy.Description)
113-
_, _ = fmt.Fprintf(writer, "Install Packages:\t %s\n", *OSUpdatePolicy.InstallPackages)
113+
_, _ = fmt.Fprintf(writer, "Update Packages:\t %s\n", *OSUpdatePolicy.UpdatePackages)
114114
_, _ = fmt.Fprintf(writer, "Update Policy:\t %s\n", *OSUpdatePolicy.UpdatePolicy)
115115
_, _ = fmt.Fprintf(writer, "Create at:\t %v\n", *OSUpdatePolicy.Timestamps.CreatedAt)
116116
_, _ = fmt.Fprintf(writer, "Updated at:\t %v\n", *OSUpdatePolicy.Timestamps.CreatedAt)
@@ -355,12 +355,12 @@ func runCreateOSUpdatePolicyCommand(cmd *cobra.Command, args []string) error {
355355
updpol = infra.UpdatePolicy(spec.Spec.UpdatePolicy)
356356
}
357357

358-
if spec.Spec.InstallPackages != "" {
359-
packages = &spec.Spec.InstallPackages
358+
if spec.Spec.UpdatePackages != "" {
359+
packages = &spec.Spec.UpdatePackages
360360
}
361361

362-
if spec.Spec.KernelCommand != "" {
363-
kernel = &spec.Spec.KernelCommand
362+
if spec.Spec.UpdateKernelCommand != "" {
363+
kernel = &spec.Spec.UpdateKernelCommand
364364
}
365365

366366
if spec.Spec.UpdateSources != nil {
@@ -374,14 +374,13 @@ func runCreateOSUpdatePolicyCommand(cmd *cobra.Command, args []string) error {
374374
//Create policy
375375
resp, err := OSUPolicyClient.OSUpdatePolicyCreateOSUpdatePolicyWithResponse(ctx, projectName,
376376
infra.OSUpdatePolicyCreateOSUpdatePolicyJSONRequestBody{
377-
Name: spec.Spec.Name,
378-
Description: &spec.Spec.Description,
379-
InstallPackages: packages,
380-
KernelCommand: kernel,
381-
//TargetOs: profile,
382-
TargetOsId: profileID,
383-
UpdateSources: sources,
384-
UpdatePolicy: &updpol,
377+
Name: spec.Spec.Name,
378+
Description: &spec.Spec.Description,
379+
UpdatePackages: packages,
380+
UpdateKernelCommand: kernel,
381+
TargetOsId: profileID,
382+
UpdateSources: sources,
383+
UpdatePolicy: &updpol,
385384
}, auth.AddAuthHeader)
386385
if err != nil {
387386
return processError(err)

internal/cli/osupdatepolicy_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ func (s *CLITestSuite) TestOSUpdatePolicy() {
9090
parsedGetOutput := mapGetOutput(getOutput)
9191

9292
expectedOutput := map[string]string{
93-
"Name:": "security-policy-v1.2",
94-
"Resource ID:": id, // "osupdatepolicy-abc12345"
95-
"Target OS ID:": "os-1234abcd",
96-
"Description:": "Monthly security update policy",
97-
"Install Packages:": "curl wget vim",
98-
"Update Policy:": "UPDATE_POLICY_LATEST",
99-
"Create at:": "2025-01-15 10:30:00 +0000 UTC",
100-
"Updated at:": "2025-01-15 10:30:00 +0000 UTC",
93+
"Name:": "security-policy-v1.2",
94+
"Resource ID:": id, // "osupdatepolicy-abc12345"
95+
"Target OS ID:": "os-1234abcd",
96+
"Description:": "Monthly security update policy",
97+
"Update Packages:": "curl wget vim",
98+
"Update Policy:": "UPDATE_POLICY_LATEST",
99+
"Create at:": "2025-01-15 10:30:00 +0000 UTC",
100+
"Updated at:": "2025-01-15 10:30:00 +0000 UTC",
101101
}
102102
s.compareGetOutput(expectedOutput, parsedGetOutput)
103103

internal/cli/testdata/mutableosupdateprofile.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ spec:
66
name: myupdateubuntu
77
updatePolicy: "UPDATE_POLICY_TARGET"
88
description: "an update profile"
9-
installPackages: |
10-
curl
11-
vim
12-
htop
13-
net-tools
14-
kernelCommand: "hugepages=2"
9+
updatePackages: curl
10+
updateKernelCommand: "hugepages=2"
1511
# For mock purpose the EMT name is used as it already exists
1612
updateSources:
1713
- "source1"

pkg/rest/catalog/client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/rest/catalog/types.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/rest/catalogutilities/client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)