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

Method Update

app/controlplane/pkg/data/casbackend.go:195–276  ·  view source on GitHub ↗
(ctx context.Context, opts *biz.CASBackendUpdateOpts)

Source from the content-addressed store, hash-verified

193}
194
195func (r *CASBackendRepo) Update(ctx context.Context, opts *biz.CASBackendUpdateOpts) (*biz.CASBackend, error) {
196 ctx, span := otelx.Start(ctx, casBackendRepoTracer, "CASBackendRepo.Update")
197 defer span.End()
198
199 var (
200 backend *ent.CASBackend
201 err error
202 )
203 if err = WithTx(ctx, r.data.DB, func(tx *ent.Tx) error {
204 // 1 - unset default backend for all the other backends in the org
205 if opts.Default != nil && *opts.Default {
206 if err := tx.CASBackend.Update().
207 Where(casbackend.HasOrganizationWith(organization.ID(opts.OrgID))).
208 Where(casbackend.Default(true)).
209 SetDefault(false).
210 Exec(ctx); err != nil {
211 return fmt.Errorf("failed to clear previous default backend: %w", err)
212 }
213 }
214
215 // 2 - unset fallback backend for all the other backends in the org
216 if opts.Fallback != nil && *opts.Fallback {
217 if err := tx.CASBackend.Update().
218 Where(casbackend.HasOrganizationWith(organization.ID(opts.OrgID))).
219 Where(casbackend.Fallback(true)).
220 SetFallback(false).
221 Exec(ctx); err != nil {
222 return fmt.Errorf("failed to clear previous fallback backend: %w", err)
223 }
224 }
225
226 // 3 - Chain the list of updates
227 // TODO: allow setting values as empty, currently it's not possible.
228 // We do it in other models by providing pointers to string + setNillableX methods
229 updateChain := tx.CASBackend.UpdateOneID(opts.ID).
230 SetNillableDescription(opts.Description).
231 SetUpdatedAt(time.Now())
232
233 // Make default and fallback mutually exclusive
234 if opts.Default != nil {
235 updateChain = updateChain.SetDefault(*opts.Default)
236 if *opts.Default {
237 updateChain = updateChain.SetFallback(false)
238 }
239 }
240
241 if opts.Fallback != nil {
242 updateChain = updateChain.SetFallback(*opts.Fallback)
243 if *opts.Fallback {
244 updateChain = updateChain.SetDefault(false)
245 }
246 }
247
248 // If secretName is provided we set it
249 if opts.SecretName != "" {
250 updateChain = updateChain.SetSecretName(opts.SecretName)
251 }
252

Callers

nothing calls this directly

Implementers 3

CASBackendRepoapp/controlplane/pkg/biz/mocks/CASBack
CASBackendRepo_Expecterapp/controlplane/pkg/biz/mocks/CASBack
CASBackendRepoapp/controlplane/pkg/data/casbackend.g

Calls 15

FindByIDMethod · 0.95
StartFunction · 0.92
HasOrganizationWithFunction · 0.92
IDFunction · 0.92
DefaultFunction · 0.92
FallbackFunction · 0.92
WithTxFunction · 0.85
ExecMethod · 0.65
UpdateMethod · 0.65
SaveMethod · 0.65
SetDefaultMethod · 0.45
WhereMethod · 0.45

Tested by

no test coverage detected