Skip to content

Commit 5d84403

Browse files
committed
store cas backend info in atttestation
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
1 parent b6bfb35 commit 5d84403

18 files changed

Lines changed: 457 additions & 98 deletions

app/cli/pkg/action/action.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
2626
"github.com/chainloop-dev/chainloop/pkg/attestation/crafter"
27+
clientAPI "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/api/attestation/v1"
2728
"github.com/chainloop-dev/chainloop/pkg/attestation/crafter/statemanager/filesystem"
2829
"github.com/chainloop-dev/chainloop/pkg/attestation/crafter/statemanager/remote"
2930
"github.com/chainloop-dev/chainloop/pkg/casclient"
@@ -100,7 +101,7 @@ func newCrafter(stateOpts *newCrafterStateOpts, conn *grpc.ClientConn, opts ...c
100101
}
101102

102103
// getCASBackend tries to get CAS upload credentials and set up a CAS client
103-
func getCASBackend(ctx context.Context, client pb.AttestationServiceClient, workflowRunID, casCAPath, casURI string, casConnectionInsecure bool, logger zerolog.Logger, casBackend *casclient.CASBackend) (func() error, error) {
104+
func getCASBackend(ctx context.Context, client pb.AttestationServiceClient, workflowRunID, casCAPath, casURI string, casConnectionInsecure bool, logger zerolog.Logger, casBackend *casclient.CASBackend, casBackendInfo **clientAPI.Attestation_CASBackend) (func() error, error) {
104105
credsResp, err := client.GetUploadCreds(ctx, &pb.AttestationServiceGetUploadCredsRequest{
105106
WorkflowRunId: workflowRunID,
106107
})
@@ -122,6 +123,14 @@ func getCASBackend(ctx context.Context, client pb.AttestationServiceClient, work
122123
return nil, fmt.Errorf("no backend found in upload creds")
123124
}
124125

126+
if casBackendInfo != nil {
127+
*casBackendInfo = &clientAPI.Attestation_CASBackend{
128+
CasBackendId: backend.Id,
129+
CasBackendName: backend.Name,
130+
Fallback: backend.Fallback,
131+
}
132+
}
133+
125134
casBackend.Name = backend.Provider
126135
if backend.GetLimits() != nil {
127136
casBackend.MaxSize = backend.GetLimits().MaxBytes

app/cli/pkg/action/attestation_add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (action *AttestationAdd) Run(ctx context.Context, attestationID, materialNa
9999
if !crafter.CraftingState.GetDryRun() {
100100
client := pb.NewAttestationServiceClient(action.CPConnection)
101101
workflowRunID := crafter.CraftingState.GetAttestation().GetWorkflow().GetWorkflowRunId()
102-
connectionCloserFn, getCASBackendErr := getCASBackend(ctx, client, workflowRunID, action.casCAPath, action.casURI, action.connectionInsecure, action.Logger, casBackend)
102+
connectionCloserFn, getCASBackendErr := getCASBackend(ctx, client, workflowRunID, action.casCAPath, action.casURI, action.connectionInsecure, action.Logger, casBackend, nil)
103103
if getCASBackendErr != nil {
104104
return nil, fmt.Errorf("failed to get CAS backend: %w", getCASBackendErr)
105105
}

app/cli/pkg/action/attestation_init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
231231

232232
// Get CAS credentials for PR metadata upload
233233
var casBackend = &casclient.CASBackend{Name: "not-set"}
234+
var casBackendInfo *clientAPI.Attestation_CASBackend
234235
if !action.dryRun && attestationID != "" {
235-
connectionCloserFn, err := getCASBackend(ctx, client, attestationID, action.casCAPath, action.casURI, action.connectionInsecure, action.Logger, casBackend)
236+
connectionCloserFn, err := getCASBackend(ctx, client, attestationID, action.casCAPath, action.casURI, action.connectionInsecure, action.Logger, casBackend, &casBackendInfo)
236237
if err != nil {
237238
// We don't want to fail the attestation initialization if CAS setup fails, it's a best-effort feature for PR/MR metadata
238239
action.Logger.Warn().Err(err).Msg("unexpected error getting CAS backend")
@@ -275,7 +276,8 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
275276
TimestampAuthorityURL: timestampAuthorityURL,
276277
SigningCAName: signingCAName,
277278
},
278-
Auth: authInfo,
279+
Auth: authInfo,
280+
CASBackend: casBackendInfo,
279281
}
280282

281283
if err := action.c.Init(ctx, initOpts); err != nil {

app/controlplane/api/controlplane/v1/response_messages.pb.go

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

app/controlplane/api/controlplane/v1/response_messages.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ message CASBackendItem {
312312
// Error message if validation failed
313313
optional string validation_error = 12;
314314
google.protobuf.Timestamp updated_at = 13;
315+
// Wether it's the fallback backend in the organization
316+
bool fallback = 14;
315317

316318
message Limits {
317319
// Max number of bytes allowed to be stored in this backend

app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts

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

app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts

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

app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.CASBackend.jsonschema.json

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

0 commit comments

Comments
 (0)