MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / getCASBackend

Function getCASBackend

app/cli/pkg/action/action.go:117–176  ·  view source on GitHub ↗

getCASBackend tries to get CAS upload credentials and set up a CAS client

(ctx context.Context, client pb.AttestationServiceClient, workflowRunID, casCAPath, casURI string, casConnectionInsecure bool, logger zerolog.Logger, casBackend *casclient.CASBackend, cliVersion string)

Source from the content-addressed store, hash-verified

115
116// getCASBackend tries to get CAS upload credentials and set up a CAS client
117func getCASBackend(ctx context.Context, client pb.AttestationServiceClient, workflowRunID, casCAPath, casURI string, casConnectionInsecure bool, logger zerolog.Logger, casBackend *casclient.CASBackend, cliVersion string) (*clientAPI.Attestation_CASBackend, func() error, error) {
118 credsResp, err := client.GetUploadCreds(ctx, &pb.AttestationServiceGetUploadCredsRequest{
119 WorkflowRunId: workflowRunID,
120 })
121 if err != nil {
122 // Log warning but don't fail - will fall back to inline storage
123 logger.Warn().Err(err).Msg("failed to get CAS credentials, will store inline")
124 return nil, nil, fmt.Errorf("getting upload creds: %w", err)
125 }
126
127 if credsResp == nil || credsResp.GetResult() == nil {
128 logger.Debug().Msg("no upload creds result, will store inline")
129 return nil, nil, fmt.Errorf("getting upload creds: %w", err)
130 }
131
132 result := credsResp.GetResult()
133 backend := result.GetBackend()
134 if backend == nil {
135 logger.Debug().Msg("no backend info in upload creds, will store inline")
136 return nil, nil, fmt.Errorf("no backend found in upload creds")
137 }
138
139 casBackendInfo := &clientAPI.Attestation_CASBackend{
140 CasBackendId: backend.Id,
141 CasBackendName: backend.Name,
142 Fallback: backend.Fallback,
143 }
144
145 casBackend.Name = backend.Provider
146 if backend.GetLimits() != nil {
147 casBackend.MaxSize = backend.GetLimits().MaxBytes
148 }
149
150 // Only attempt to create a CAS connection when not inline and token is present
151 if backend.IsInline || result.Token == "" {
152 return casBackendInfo, nil, nil
153 }
154
155 opts := []grpcconn.Option{
156 grpcconn.WithInsecure(casConnectionInsecure),
157 grpcconn.WithCLIVersion(cliVersion),
158 }
159 if casCAPath != "" {
160 // Check if it's a file path or content. If it's a file path, it should exist. If not, treat it as content.
161 if _, err := os.Stat(casCAPath); err == nil {
162 opts = append(opts, grpcconn.WithCAFile(casCAPath))
163 } else {
164 opts = append(opts, grpcconn.WithCAContent(casCAPath))
165 }
166 }
167
168 artifactCASConn, err := grpcconn.New(casURI, result.Token, opts...)
169 if err != nil {
170 logger.Warn().Err(err).Msg("failed to create CAS connection, will store inline")
171 return nil, nil, fmt.Errorf("creating CAS connection: %w", err)
172 }
173
174 casBackend.Uploader = casclient.New(artifactCASConn, casclient.WithLogger(logger))

Callers 3

RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85

Calls 12

WithInsecureFunction · 0.92
WithCLIVersionFunction · 0.92
WithCAFileFunction · 0.92
WithCAContentFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithLoggerFunction · 0.92
GetLimitsMethod · 0.80
GetUploadCredsMethod · 0.65
GetResultMethod · 0.45
DebugMethod · 0.45
GetBackendMethod · 0.45

Tested by

no test coverage detected