Skip to content

Commit a641311

Browse files
authored
feat(cas): add managed flag (#3092)
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
1 parent e37736a commit a641311

19 files changed

Lines changed: 268 additions & 8 deletions

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

Lines changed: 14 additions & 3 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
@@ -407,6 +407,8 @@ message CASBackendItem {
407407
google.protobuf.Timestamp updated_at = 13;
408408
// Wether it's the fallback backend in the organization
409409
bool fallback = 14;
410+
// Whether this backend is provisioned and operated by Chainloop using
411+
bool is_managed = 15;
410412

411413
message Limits {
412414
// Max number of bytes allowed to be stored in this backend

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/controlplane.v1.CASBackendItem.jsonschema.json

Lines changed: 8 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/controlplane.v1.CASBackendItem.schema.json

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

app/controlplane/internal/service/casbackend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func bizCASBackendToPb(in *biz.CASBackend) *pb.CASBackendItem {
203203
Default: in.Default,
204204
Fallback: in.Fallback,
205205
IsInline: in.Inline,
206+
IsManaged: in.Managed,
206207
}
207208

208209
if in.Limits != nil {

app/controlplane/pkg/biz/casbackend.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ type CASBackend struct {
7272
Inline bool
7373
// It's a fallback backend, used when the default backend is unreachable
7474
Fallback bool
75+
// Managed indicates this backend is provisioned and operated by Chainloop
76+
Managed bool
7577

7678
Limits *CASBackendLimits
7779
}
@@ -88,6 +90,7 @@ type CASBackendOpts struct {
8890
Provider CASBackendProvider
8991
Default *bool
9092
Fallback *bool
93+
Managed *bool
9194
ValidationStatus CASBackendValidationStatus
9295
ValidationError *string
9396
}
@@ -450,6 +453,11 @@ func (uc *CASBackendUseCase) Update(ctx context.Context, orgID, id string, descr
450453
return nil, NewErrValidationStr("inline backends cannot have their max_bytes updated")
451454
}
452455

456+
// Managed backends are owned and operated by Chainloop and cannot be modified by users.
457+
if before.Managed {
458+
return nil, NewErrValidationStr("managed CAS backends cannot be modified")
459+
}
460+
453461
// Validate max_bytes if provided
454462
if maxBytes != nil && *maxBytes < MinCASBackendMaxBytes {
455463
return nil, NewErrValidationStr(fmt.Sprintf("max_bytes must be at least %s", bytefmt.ByteSize(uint64(MinCASBackendMaxBytes))))
@@ -612,6 +620,11 @@ func (uc *CASBackendUseCase) SoftDelete(ctx context.Context, orgID, id string) e
612620
return NewErrValidation(errors.New("can't delete the inline CAS backend"))
613621
}
614622

623+
// Prevent deletion of managed backends - they are owned and operated by Chainloop
624+
if backend.Managed {
625+
return NewErrValidation(errors.New("can't delete a managed CAS backend"))
626+
}
627+
615628
if err := uc.repo.SoftDelete(ctx, backendUUID); err != nil {
616629
return err
617630
}

app/controlplane/pkg/data/casbackend.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (r *CASBackendRepo) Create(ctx context.Context, opts *biz.CASBackendCreateO
155155
SetNillableFallback(opts.Fallback).
156156
SetProvider(opts.Provider).
157157
SetNillableDefault(opts.Default).
158+
SetNillableManaged(opts.Managed).
158159
SetSecretName(opts.SecretName).
159160
SetMaxBlobSizeBytes(opts.MaxBytes).
160161
Save(ctx)
@@ -404,6 +405,7 @@ func entCASBackendToBiz(backend *ent.CASBackend) *biz.CASBackend {
404405
Inline: backend.Provider == biz.CASBackendInline,
405406
Limits: limits,
406407
Fallback: backend.Fallback,
408+
Managed: backend.Managed,
407409
}
408410

409411
if org := backend.Edges.Organization; org != nil {

app/controlplane/pkg/data/ent/casbackend.go

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

app/controlplane/pkg/data/ent/casbackend/casbackend.go

Lines changed: 10 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)