Skip to content

Commit 5812676

Browse files
authored
Fix validation isssues found in apiserver (#59)
1 parent 7afe27d commit 5812676

File tree

20 files changed

+211
-190
lines changed

20 files changed

+211
-190
lines changed

doc/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10414,14 +10414,14 @@ <h3 id="metalstack.api.v2.Switch">Switch</h3>
1041410414
<tr>
1041510415
<td>management_user</td>
1041610416
<td><a href="#string">string</a></td>
10417-
<td></td>
10417+
<td>optional</td>
1041810418
<td><p>ManagementUser is the user name to use for management access. </p></td>
1041910419
</tr>
1042010420

1042110421
<tr>
1042210422
<td>console_command</td>
1042310423
<td><a href="#string">string</a></td>
10424-
<td></td>
10424+
<td>optional</td>
1042510425
<td><p>ConsoleCommand is the command for accessing the switch&#39;s console. </p></td>
1042610426
</tr>
1042710427

@@ -12972,7 +12972,8 @@ <h3 id="metalstack.api.v2.TokenServiceUpdateRequest">TokenServiceUpdateRequest</
1297212972
<td>update_meta</td>
1297312973
<td><a href="#metalstack.api.v2.UpdateMeta">UpdateMeta</a></td>
1297412974
<td></td>
12975-
<td><p>UpdateMeta contains the timestamp and strategy to be used in this update request </p></td>
12975+
<td><p>UpdateMeta contains the timestamp and strategy to be used in this update request
12976+
TokenUpdate is not guarded with optlock in the backend </p></td>
1297612977
</tr>
1297712978

1297812979
<tr>

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ require (
2525
github.com/pmezard/go-difflib v1.0.0 // indirect
2626
github.com/stoewer/go-strcase v1.3.1 // indirect
2727
github.com/stretchr/objx v0.5.3 // indirect
28-
golang.org/x/exp v0.0.0-20251002181428-27f1f14c8bb9 // indirect
29-
golang.org/x/text v0.29.0 // indirect
28+
golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b // indirect
29+
golang.org/x/text v0.30.0 // indirect
3030
google.golang.org/genproto/googleapis/api v0.0.0-20251007200510-49b9836ed3ff // indirect
3131
google.golang.org/genproto/googleapis/rpc v0.0.0-20251007200510-49b9836ed3ff // indirect
3232
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
5050
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
5151
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
5252
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
53-
golang.org/x/exp v0.0.0-20251002181428-27f1f14c8bb9 h1:TQwNpfvNkxAVlItJf6Cr5JTsVZoC/Sj7K3OZv2Pc14A=
54-
golang.org/x/exp v0.0.0-20251002181428-27f1f14c8bb9/go.mod h1:TwQYMMnGpvZyc+JpB/UAuTNIsVJifOlSkrZkhcvpVUk=
55-
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
56-
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
53+
golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b h1:18qgiDvlvH7kk8Ioa8Ov+K6xCi0GMvmGfGW0sgd/SYA=
54+
golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
55+
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
56+
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
5757
google.golang.org/genproto/googleapis/api v0.0.0-20251007200510-49b9836ed3ff h1:8Zg5TdmcbU8A7CXGjGXF1Slqu/nIFCRaR3S5gT2plIA=
5858
google.golang.org/genproto/googleapis/api v0.0.0-20251007200510-49b9836ed3ff/go.mod h1:dbWfpVPvW/RqafStmRWBUpMN14puDezDMHxNYiRfQu0=
5959
google.golang.org/genproto/googleapis/rpc v0.0.0-20251007200510-49b9836ed3ff h1:A90eA31Wq6HOMIQlLfzFwzqGKBTuaVztYu/g8sn+8Zc=

go/metalstack/api/v2/filesystem.pb.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.

go/metalstack/api/v2/ip.pb.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/metalstack/api/v2/network.pb.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/metalstack/api/v2/switch.pb.go

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/metalstack/api/v2/token.pb.go

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/tests/validation/switch_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func TestValidateSwitch(t *testing.T) {
4747
Id: "leaf01",
4848
Partition: "p1",
4949
ManagementIp: "1.2.3.4",
50-
ManagementUser: "admin",
51-
ConsoleCommand: "ssh",
50+
ManagementUser: proto.String("admin"),
51+
ConsoleCommand: proto.String("ssh"),
5252
},
5353
wantErr: false,
5454
},
@@ -58,8 +58,8 @@ func TestValidateSwitch(t *testing.T) {
5858
Id: "_1",
5959
Partition: "p1",
6060
ManagementIp: "1.2.3.4",
61-
ManagementUser: "admin",
62-
ConsoleCommand: "ssh",
61+
ManagementUser: proto.String("admin"),
62+
ConsoleCommand: proto.String("ssh"),
6363
},
6464
wantErr: true,
6565
wantErrorMessage: `validation error:

go/tests/validation/token_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ func TestValidateToken(t *testing.T) {
1313
msg: &apiv2.TokenServiceCreateRequest{
1414
Description: "A Token",
1515
ProjectRoles: map[string]apiv2.ProjectRole{
16-
"p12": apiv2.ProjectRole_PROJECT_ROLE_EDITOR,
17-
"p22": apiv2.ProjectRole_PROJECT_ROLE_VIEWER,
18-
"p32": apiv2.ProjectRole_PROJECT_ROLE_OWNER,
16+
"00000000-0000-0000-0000-000000000000": apiv2.ProjectRole_PROJECT_ROLE_EDITOR,
17+
"00000000-0000-0000-0000-000000000001": apiv2.ProjectRole_PROJECT_ROLE_VIEWER,
18+
"00000000-0000-0000-0000-000000000002": apiv2.ProjectRole_PROJECT_ROLE_OWNER,
1919
},
2020
TenantRoles: map[string]apiv2.TenantRole{
2121
"t12": apiv2.TenantRole_TENANT_ROLE_EDITOR,
@@ -33,8 +33,21 @@ func TestValidateToken(t *testing.T) {
3333
},
3434
wantErr: true,
3535
wantErrorMessage: `validation error:
36+
- project_roles["p42"]: value must be a valid UUID [string.uuid]
3637
- project_roles["p42"]: value must be one of the defined enum values [enum.defined_only]`,
3738
},
39+
{
40+
name: "InValid Token Create Request",
41+
msg: &apiv2.TokenServiceCreateRequest{
42+
Description: "B Token",
43+
ProjectRoles: map[string]apiv2.ProjectRole{
44+
"00000000-0000-0000-0000-000000000000": 5,
45+
},
46+
},
47+
wantErr: true,
48+
wantErrorMessage: `validation error:
49+
- project_roles["00000000-0000-0000-0000-000000000000"]: value must be one of the defined enum values [enum.defined_only]`,
50+
},
3851
}
3952

4053
validateProtos(t, tests)

0 commit comments

Comments
 (0)