Skip to content

Commit eb954f4

Browse files
authored
chore: migrate configs to protovalidate (#667)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 8e6f3a7 commit eb954f4

File tree

23 files changed

+351
-3180
lines changed

23 files changed

+351
-3180
lines changed

app/artifact-cas/cmd/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"time"
2222

23+
"github.com/bufbuild/protovalidate-go"
2324
"github.com/getsentry/sentry-go"
2425

2526
"github.com/chainloop-dev/chainloop/app/artifact-cas/internal/conf"
@@ -102,6 +103,16 @@ func main() {
102103
panic(err)
103104
}
104105

106+
// validate configuration
107+
validator, err := protovalidate.New()
108+
if err != nil {
109+
panic(err)
110+
}
111+
112+
if err := validator.Validate(&bc); err != nil {
113+
panic(err)
114+
}
115+
105116
logger, err := servicelogger.InitZapLogger(Version)
106117
if err != nil {
107118
panic(err)

app/artifact-cas/internal/conf/buf.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
version: v1
33
deps:
44
- remote: buf.build
5-
owner: envoyproxy
6-
repository: protoc-gen-validate
7-
commit: 45685e052c7e406b9fbd441fc7a568a5
5+
owner: bufbuild
6+
repository: protovalidate
7+
commit: b983156c5e994cc9892e0ce3e64e17e0
88
- remote: buf.build
99
owner: googleapis
1010
repository: googleapis
11-
commit: cc916c31859748a68fd229a3c8d7a2e8
11+
commit: 7a6bc1e3207144b38e9066861e1de0ff

app/artifact-cas/internal/conf/buf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ breaking:
44
- FILE
55
deps:
66
- buf.build/googleapis/googleapis
7-
- buf.build/envoyproxy/protoc-gen-validate:45685e052c7e406b9fbd441fc7a568a5
7+
- buf.build/bufbuild/protovalidate
88
lint:
99
use:
1010
- DEFAULT

app/artifact-cas/internal/conf/conf.pb.go

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

app/artifact-cas/internal/conf/conf.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -15,10 +15,10 @@
1515

1616
syntax = "proto3";
1717

18-
option go_package = "github.com/chainloop-dev/chainloop/app/artifact-cas/internal/conf;conf";
19-
20-
import "google/protobuf/duration.proto";
2118
import "credentials/v1/config.proto";
19+
import "google/protobuf/duration.proto";
20+
21+
option go_package = "github.com/chainloop-dev/chainloop/app/artifact-cas/internal/conf;conf";
2222

2323
message Bootstrap {
2424
Server server = 1;

app/controlplane/api/buf.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ deps:
88
- remote: buf.build
99
owner: googleapis
1010
repository: googleapis
11-
commit: cc916c31859748a68fd229a3c8d7a2e8
11+
commit: 7a6bc1e3207144b38e9066861e1de0ff
1212
- remote: buf.build
1313
owner: kratos-go
1414
repository: kratos

app/controlplane/cmd/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"time"
2222

23+
"github.com/bufbuild/protovalidate-go"
2324
"github.com/getsentry/sentry-go"
2425
flag "github.com/spf13/pflag"
2526

@@ -90,6 +91,16 @@ func main() {
9091
panic(err)
9192
}
9293

94+
// validate configuration
95+
validator, err := protovalidate.New()
96+
if err != nil {
97+
panic(err)
98+
}
99+
100+
if err := validator.Validate(&bc); err != nil {
101+
panic(err)
102+
}
103+
93104
logger, err := servicelogger.InitZapLogger(Version)
94105
if err != nil {
95106
panic(err)

app/controlplane/internal/biz/casclient.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"io"
2323

24+
"github.com/bufbuild/protovalidate-go"
25+
2426
"github.com/chainloop-dev/chainloop/app/controlplane/internal/conf"
2527
"github.com/chainloop-dev/chainloop/internal/casclient"
2628
"github.com/chainloop-dev/chainloop/internal/grpcconn"
@@ -152,8 +154,12 @@ func (uc *CASClientUseCase) IsReady(ctx context.Context) (bool, error) {
152154
return false, errors.New("missing CAS server configuration")
153155
}
154156

155-
err := uc.casServerConf.ValidateAll()
157+
v, err := protovalidate.New()
156158
if err != nil {
159+
return false, fmt.Errorf("failed to create validator: %w", err)
160+
}
161+
162+
if err := v.Validate(uc.casServerConf); err != nil {
157163
return false, fmt.Errorf("invalid CAS client configuration: %w", err)
158164
}
159165

app/controlplane/internal/conf/buf.gen.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ plugins:
33
- name: go
44
out: .
55
opt: paths=source_relative
6-
- name: validate
7-
out: .
8-
opt: paths=source_relative,lang=go

app/controlplane/internal/conf/buf.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
version: v1
33
deps:
44
- remote: buf.build
5-
owner: envoyproxy
6-
repository: protoc-gen-validate
7-
commit: 45685e052c7e406b9fbd441fc7a568a5
5+
owner: bufbuild
6+
repository: protovalidate
7+
commit: b983156c5e994cc9892e0ce3e64e17e0
88
- remote: buf.build
99
owner: googleapis
1010
repository: googleapis
11-
commit: 463926e7ee924d46ad0a726e1cf4eacd
11+
commit: 7a6bc1e3207144b38e9066861e1de0ff

0 commit comments

Comments
 (0)