Skip to content

Commit 48e63cc

Browse files
authored
Update protovalidate and simplify permission generation (#78)
1 parent 6a87eda commit 48e63cc

File tree

13 files changed

+154
-145
lines changed

13 files changed

+154
-145
lines changed

generate/generate.go

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -143,48 +143,27 @@ func servicePermissions(root string) (*permissions.ServicePermissions, error) {
143143
}
144144
auditable[methodName] = true
145145
// Tenant
146-
switch *methodOpt.IdentifierValue {
147-
case v1.TenantRole_TENANT_ROLE_OWNER.String():
148-
roles.Tenant[v1.TenantRole_TENANT_ROLE_OWNER.String()] = append(roles.Tenant[v1.TenantRole_TENANT_ROLE_OWNER.String()], methodName)
149-
visibility.Tenant[methodName] = true
150-
case v1.TenantRole_TENANT_ROLE_EDITOR.String():
151-
roles.Tenant[v1.TenantRole_TENANT_ROLE_EDITOR.String()] = append(roles.Tenant[v1.TenantRole_TENANT_ROLE_EDITOR.String()], methodName)
152-
visibility.Tenant[methodName] = true
153-
case v1.TenantRole_TENANT_ROLE_VIEWER.String():
154-
roles.Tenant[v1.TenantRole_TENANT_ROLE_VIEWER.String()] = append(roles.Tenant[v1.TenantRole_TENANT_ROLE_VIEWER.String()], methodName)
155-
visibility.Tenant[methodName] = true
156-
case v1.TenantRole_TENANT_ROLE_GUEST.String():
157-
roles.Tenant[v1.TenantRole_TENANT_ROLE_GUEST.String()] = append(roles.Tenant[v1.TenantRole_TENANT_ROLE_GUEST.String()], methodName)
146+
switch role := *methodOpt.IdentifierValue; role {
147+
case v1.TenantRole_TENANT_ROLE_OWNER.String(), v1.TenantRole_TENANT_ROLE_EDITOR.String(), v1.TenantRole_TENANT_ROLE_VIEWER.String(), v1.TenantRole_TENANT_ROLE_GUEST.String():
148+
roles.Tenant[role] = append(roles.Tenant[role], methodName)
158149
visibility.Tenant[methodName] = true
159150
case v1.TenantRole_TENANT_ROLE_UNSPECIFIED.String():
160151
// noop
161152
// Project
162-
case v1.ProjectRole_PROJECT_ROLE_OWNER.String():
163-
roles.Project[v1.ProjectRole_PROJECT_ROLE_OWNER.String()] = append(roles.Project[v1.ProjectRole_PROJECT_ROLE_OWNER.String()], methodName)
164-
visibility.Project[methodName] = true
165-
case v1.ProjectRole_PROJECT_ROLE_EDITOR.String():
153+
case v1.ProjectRole_PROJECT_ROLE_OWNER.String(), v1.ProjectRole_PROJECT_ROLE_EDITOR.String(), v1.ProjectRole_PROJECT_ROLE_VIEWER.String():
154+
roles.Project[role] = append(roles.Project[role], methodName)
166155
visibility.Project[methodName] = true
167-
roles.Project[v1.ProjectRole_PROJECT_ROLE_EDITOR.String()] = append(roles.Project[v1.ProjectRole_PROJECT_ROLE_EDITOR.String()], methodName)
168-
case v1.ProjectRole_PROJECT_ROLE_VIEWER.String():
169-
visibility.Project[methodName] = true
170-
roles.Project[v1.ProjectRole_PROJECT_ROLE_VIEWER.String()] = append(roles.Project[v1.ProjectRole_PROJECT_ROLE_VIEWER.String()], methodName)
171156
case v1.ProjectRole_PROJECT_ROLE_UNSPECIFIED.String():
172157
// noop
173158
// Admin
174-
case v1.AdminRole_ADMIN_ROLE_EDITOR.String():
175-
roles.Admin[v1.AdminRole_ADMIN_ROLE_EDITOR.String()] = append(roles.Admin[v1.AdminRole_ADMIN_ROLE_EDITOR.String()], methodName)
176-
visibility.Admin[methodName] = true
177-
case v1.AdminRole_ADMIN_ROLE_VIEWER.String():
178-
roles.Admin[v1.AdminRole_ADMIN_ROLE_VIEWER.String()] = append(roles.Admin[v1.AdminRole_ADMIN_ROLE_VIEWER.String()], methodName)
159+
case v1.AdminRole_ADMIN_ROLE_EDITOR.String(), v1.AdminRole_ADMIN_ROLE_VIEWER.String():
160+
roles.Admin[role] = append(roles.Admin[role], methodName)
179161
visibility.Admin[methodName] = true
180162
case v1.AdminRole_ADMIN_ROLE_UNSPECIFIED.String():
181163
// noop
182164
// Infra
183-
case v1.InfraRole_INFRA_ROLE_EDITOR.String():
184-
roles.Infra[v1.InfraRole_INFRA_ROLE_EDITOR.String()] = append(roles.Infra[v1.InfraRole_INFRA_ROLE_EDITOR.String()], methodName)
185-
visibility.Infra[methodName] = true
186-
case v1.InfraRole_INFRA_ROLE_VIEWER.String():
187-
roles.Infra[v1.InfraRole_INFRA_ROLE_VIEWER.String()] = append(roles.Infra[v1.InfraRole_INFRA_ROLE_VIEWER.String()], methodName)
165+
case v1.InfraRole_INFRA_ROLE_EDITOR.String(), v1.InfraRole_INFRA_ROLE_VIEWER.String():
166+
roles.Infra[role] = append(roles.Infra[role], methodName)
188167
visibility.Infra[methodName] = true
189168
case v1.InfraRole_INFRA_ROLE_UNSPECIFIED.String():
190169
// noop

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/metal-stack/api
33
go 1.25
44

55
require (
6-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20250912141014-52f32327d4b0.1
7-
buf.build/go/protovalidate v1.0.1
6+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20251209175733-2a1774d88802.1
7+
buf.build/go/protovalidate v1.1.0
88
connectrpc.com/connect v1.19.1
99
github.com/bufbuild/protocompile v0.14.1
1010
github.com/go-task/slim-sprig/v3 v3.0.0
@@ -20,16 +20,16 @@ require (
2020
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
2121
github.com/davecgh/go-spew v1.1.1 // indirect
2222
github.com/google/cel-go v0.26.1 // indirect
23-
github.com/klauspost/compress v1.18.1 // indirect
23+
github.com/klauspost/compress v1.18.2 // indirect
2424
github.com/kr/pretty v0.3.1 // indirect
2525
github.com/minio/minlz v1.0.1 // indirect
2626
github.com/pmezard/go-difflib v1.0.0 // indirect
2727
github.com/stoewer/go-strcase v1.3.1 // indirect
2828
github.com/stretchr/objx v0.5.3 // indirect
29-
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6 // indirect
30-
golang.org/x/text v0.31.0 // indirect
31-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba // indirect
32-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirect
29+
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 // indirect
30+
golang.org/x/text v0.32.0 // indirect
31+
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
32+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
3333
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3434
gopkg.in/yaml.v3 v3.0.1 // indirect
3535
)

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20250912141014-52f32327d4b0.1 h1:31on4W/yPcV4nZHL4+UCiCvLPsMqe/vJcNg8Rci0scc=
2-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20250912141014-52f32327d4b0.1/go.mod h1:fUl8CEN/6ZAMk6bP8ahBJPUJw7rbp+j4x+wCcYi2IG4=
3-
buf.build/go/protovalidate v1.0.1 h1:Fwmf08OOUuKVeMvEnDmcKxQam4PJc/zFgvVX64BhTms=
4-
buf.build/go/protovalidate v1.0.1/go.mod h1:SoZmvk/3ZzOVg9YSkTdm4grMAByjf8zgZq4ZNaLZXoQ=
1+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20251209175733-2a1774d88802.1 h1:ZnX3qpF/pDiYrf+Q3p+/zCzZ5ELSpszy5hdVarDMSV4=
2+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20251209175733-2a1774d88802.1/go.mod h1:fUl8CEN/6ZAMk6bP8ahBJPUJw7rbp+j4x+wCcYi2IG4=
3+
buf.build/go/protovalidate v1.1.0 h1:pQqEQRpOo4SqS60qkvmhLTTQU9JwzEvdyiqAtXa5SeY=
4+
buf.build/go/protovalidate v1.1.0/go.mod h1:bGZcPiAQDC3ErCHK3t74jSoJDFOs2JH3d7LWuTEIdss=
55
cel.dev/expr v0.25.1 h1:1KrZg61W6TWSxuNZ37Xy49ps13NUovb66QLprthtwi4=
66
cel.dev/expr v0.25.1/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4=
77
connectrpc.com/connect v1.19.1 h1:R5M57z05+90EfEvCY1b7hBxDVOUl45PrtXtAV2fOC14=
@@ -24,8 +24,8 @@ github.com/google/cel-go v0.26.1 h1:iPbVVEdkhTX++hpe3lzSk7D3G3QSYqLGoHOcEio+UXQ=
2424
github.com/google/cel-go v0.26.1/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PUIaryMM=
2525
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
2626
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
27-
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
28-
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
27+
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
28+
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
2929
github.com/klauspost/connect-compress/v2 v2.1.0 h1:8fM8QrVeHT69e5VVSh4yjDaQASYIvOp2uMZq7nVLj2U=
3030
github.com/klauspost/connect-compress/v2 v2.1.0/go.mod h1:Ayurh2wscMMx3AwdGGVL+ylSR5316WfApREDgsqHyH8=
3131
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -56,14 +56,14 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
5656
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
5757
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
5858
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
59-
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6 h1:zfMcR1Cs4KNuomFFgGefv5N0czO2XZpUbxGUy8i8ug0=
60-
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0=
61-
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
62-
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
63-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba h1:B14OtaXuMaCQsl2deSvNkyPKIzq3BjfxQp8d00QyWx4=
64-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba/go.mod h1:G5IanEx8/PgI9w6CFcYQf7jMtHQhZruvfM1i3qOqk5U=
65-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba h1:UKgtfRM7Yh93Sya0Fo8ZzhDP4qBckrrxEr2oF5UIVb8=
66-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
59+
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 h1:MDfG8Cvcqlt9XXrmEiD4epKn7VJHZO84hejP9Jmp0MM=
60+
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU=
61+
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
62+
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
63+
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls=
64+
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto=
65+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
66+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
6767
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
6868
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
6969
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

go/tests/mocks/client/Adminv2.go

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

go/tests/validation/filesystem_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ func TestValidateFilesystem(t *testing.T) {
2525
Device: "/",
2626
},
2727
wantErr: true,
28-
wantErrorMessage: `validation error:
29-
- device: value length must be at least 2 characters [string.min_len]
30-
- format: value is required [required]`,
28+
wantErrorMessage: `validation errors:
29+
- device: value length must be at least 2 characters
30+
- format: value is required`,
3131
},
3232
{
3333
name: "Invalid Filesystem, device to short, format invalid",
3434
msg: &apiv2.Filesystem{
3535
Device: "/dev/sda3",
3636
Format: apiv2.Format(99),
3737
},
38-
wantErr: true,
39-
wantErrorMessage: `validation error:
40-
- format: value must be one of the defined enum values [enum.defined_only]`,
38+
wantErr: true,
39+
wantErrorMessage: `validation error: format: value must be one of the defined enum values`,
4140
},
4241
{
4342
name: "Valid FilesystemLayout minimal config",
@@ -62,9 +61,8 @@ func TestValidateFilesystem(t *testing.T) {
6261
Name: proto.String("c"),
6362
Description: proto.String("c1-large"),
6463
},
65-
wantErr: true,
66-
wantErrorMessage: `validation error:
67-
- name: must be within 2 and 128 characters [string.is_name]`},
64+
wantErr: true,
65+
wantErrorMessage: `validation error: name: must be within 2 and 128 characters`},
6866
}
6967

7068
validateProtos(t, tests)

go/tests/validation/firewall-rule_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ func TestValidateFirewallRules(t *testing.T) {
1717
Comment: "a rule",
1818
},
1919
wantErr: true,
20-
wantErrorMessage: `validation error:
21-
- protocol: value must be one of the defined enum values [enum.defined_only]
22-
- ports[0]: value must be less than or equal to 65532 [uint32.lte]
23-
- to: given prefixes must be valid [repeated.prefixes]`,
20+
wantErrorMessage: `validation errors:
21+
- protocol: value must be one of the defined enum values
22+
- ports[0]: value must be less than or equal to 65532
23+
- to: given prefixes must be valid`,
2424
},
2525
{
2626
name: "Invalid Rule with invalid comment",
@@ -31,7 +31,7 @@ func TestValidateFirewallRules(t *testing.T) {
3131
Comment: "a # invalid 3 rule",
3232
},
3333
wantErr: true,
34-
wantErrorMessage: "validation error:\n - comment: value does not match regex pattern `^[a-z_ -]*$` [string.pattern]",
34+
wantErrorMessage: "validation error: comment: value does not match regex pattern `^[a-z_ -]*$`",
3535
},
3636
}
3737

go/tests/validation/image_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ func TestValidateImage(t *testing.T) {
2727
Url: "not-a-uri",
2828
Features: []apiv2.ImageFeature{apiv2.ImageFeature_IMAGE_FEATURE_MACHINE},
2929
},
30-
wantErr: true,
31-
wantErrorMessage: `validation error:
32-
- url: given uri must be valid [string.uri]`,
30+
wantErr: true,
31+
wantErrorMessage: `validation error: url: given uri must be valid`,
3332
},
3433
{
3534
name: "Invalid Image, no features",
@@ -38,9 +37,8 @@ func TestValidateImage(t *testing.T) {
3837
Url: "http://download.org/debian:12.0",
3938
Features: []apiv2.ImageFeature{3},
4039
},
41-
wantErr: true,
42-
wantErrorMessage: `validation error:
43-
- features[0]: value must be one of the defined enum values [enum.defined_only]`,
40+
wantErr: true,
41+
wantErrorMessage: `validation error: features[0]: value must be one of the defined enum values`,
4442
},
4543
{
4644
name: "Valid ImageUpdate minimal config",
@@ -62,9 +60,8 @@ func TestValidateImage(t *testing.T) {
6260
Features: []apiv2.ImageFeature{apiv2.ImageFeature_IMAGE_FEATURE_MACHINE, apiv2.ImageFeature_IMAGE_FEATURE_MACHINE},
6361
Classification: apiv2.ImageClassification_IMAGE_CLASSIFICATION_PREVIEW,
6462
},
65-
wantErr: true,
66-
wantErrorMessage: `validation error:
67-
- features: repeated value must contain unique items [repeated.unique]`,
63+
wantErr: true,
64+
wantErrorMessage: `validation error: features: repeated value must contain unique items`,
6865
},
6966
{
7067
name: "InValid ImageUpdate invalid Features",
@@ -75,9 +72,8 @@ func TestValidateImage(t *testing.T) {
7572
Features: []apiv2.ImageFeature{apiv2.ImageFeature_IMAGE_FEATURE_MACHINE, 3},
7673
Classification: apiv2.ImageClassification_IMAGE_CLASSIFICATION_PREVIEW,
7774
},
78-
wantErr: true,
79-
wantErrorMessage: `validation error:
80-
- features[1]: value must be one of the defined enum values [enum.defined_only]`,
75+
wantErr: true,
76+
wantErrorMessage: `validation error: features[1]: value must be one of the defined enum values`,
8177
},
8278
}
8379

0 commit comments

Comments
 (0)