@@ -18,6 +18,7 @@ package action
18
18
import (
19
19
"context"
20
20
"errors"
21
+ "fmt"
21
22
22
23
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
23
24
"github.com/chainloop-dev/chainloop/internal/attestation/crafter"
@@ -63,7 +64,7 @@ func (action *AttestationAdd) Run(k, v string) error {
63
64
return err
64
65
}
65
66
66
- // Get upload creds for the current attestation and set up CAS client
67
+ // Get upload creds and CASbackend for the current attestation and set up CAS client
67
68
client := pb .NewAttestationServiceClient (action .CPConnection )
68
69
creds , err := client .GetUploadCreds (context .Background (),
69
70
& pb.AttestationServiceGetUploadCredsRequest {
@@ -73,31 +74,32 @@ func (action *AttestationAdd) Run(k, v string) error {
73
74
if err != nil {
74
75
return err
75
76
}
76
- artifactCASConn , err := grpcconn .New (action .casURI , creds .Result .Token , action .connectionInsecure )
77
- if err != nil {
78
- return err
79
- }
80
- defer artifactCASConn .Close ()
81
77
82
- cc := casclient .New (artifactCASConn , casclient .WithLogger (action .Logger ))
78
+ b := creds .GetResult ().GetBackend ()
79
+ if b == nil {
80
+ return fmt .Errorf ("no backend found in upload creds" )
81
+ }
83
82
84
- // // TODO: retrieve this information from backend
85
- backend := & casclient.CASBackend {
86
- Uploader : cc ,
87
- Name : "OCI" ,
88
- // 100MB max size
89
- MaxSize : 100 * 1024 * 1024 ,
83
+ // Define CASbackend information based on the API response
84
+ casBackend := & casclient.CASBackend {
85
+ Name : b .Provider ,
86
+ MaxSize : b .GetLimits ().MaxBytes ,
90
87
}
91
88
92
- // backend := &casclient.CASBackend{
93
- // Name: "INLINE",
94
- // // 500KB max size
95
- // MaxSize: 500 * 1024,
96
- // }
89
+ // Some CASBackends will actually upload information to the CAS server
90
+ // in such case we need to set up a connection
91
+ if ! b .IsInline && creds .Result .Token != "" {
92
+ artifactCASConn , err := grpcconn .New (action .casURI , creds .Result .Token , action .connectionInsecure )
93
+ if err != nil {
94
+ return err
95
+ }
96
+ defer artifactCASConn .Close ()
97
97
98
- if err := action .c .AddMaterial (k , v , backend ); err != nil {
99
- action .Logger .Err (err ).Msg ("adding material" )
100
- return err
98
+ casBackend .Uploader = casclient .New (artifactCASConn , casclient .WithLogger (action .Logger ))
99
+ }
100
+
101
+ if err := action .c .AddMaterial (k , v , casBackend ); err != nil {
102
+ return fmt .Errorf ("adding material: %w" , err )
101
103
}
102
104
103
105
return nil
0 commit comments