Skip to content

Commit a735386

Browse files
authored
feat: add unique name to cas-backends (#662)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent a3d5456 commit a735386

40 files changed

+685
-236
lines changed

app/cli/cmd/casbackend.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -40,6 +40,9 @@ func newCASBackendAddCmd() *cobra.Command {
4040

4141
cmd.PersistentFlags().Bool("default", false, "set the backend as default in your organization")
4242
cmd.PersistentFlags().String("description", "", "descriptive information for this registration")
43+
cmd.PersistentFlags().String("name", "", "CAS backend name")
44+
err := cmd.MarkPersistentFlagRequired("name")
45+
cobra.CheckErr(err)
4346

4447
cmd.AddCommand(newCASBackendAddOCICmd(), newCASBackendAddAzureBlobStorageCmd(), newCASBackendAddAWSS3Cmd())
4548
return cmd
@@ -53,6 +56,7 @@ func newCASBackendUpdateCmd() *cobra.Command {
5356

5457
cmd.PersistentFlags().Bool("default", false, "set the backend as default in your organization")
5558
cmd.PersistentFlags().String("description", "", "descriptive information for this registration")
59+
cmd.PersistentFlags().String("name", "", "CAS backend name")
5660

5761
cmd.AddCommand(newCASBackendUpdateOCICmd(), newCASBackendUpdateInlineCmd(), newCASBackendUpdateAzureBlobCmd(), newCASBackendUpdateAWSS3Cmd())
5862
return cmd

app/cli/cmd/casbackend_add_azureblob.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -35,6 +35,9 @@ func newCASBackendAddAzureBlobStorageCmd() *cobra.Command {
3535
isDefault, err := cmd.Flags().GetBool("default")
3636
cobra.CheckErr(err)
3737

38+
name, err := cmd.Flags().GetString("name")
39+
cobra.CheckErr(err)
40+
3841
description, err := cmd.Flags().GetString("description")
3942
cobra.CheckErr(err)
4043

@@ -48,6 +51,7 @@ func newCASBackendAddAzureBlobStorageCmd() *cobra.Command {
4851
}
4952

5053
opts := &action.NewCASBackendAddOpts{
54+
Name: name,
5155
Location: fmt.Sprintf("%s/%s", storageAccountName, container),
5256
Provider: azureblob.ProviderID,
5357
Description: description,

app/cli/cmd/casbackend_add_oci.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -32,6 +32,9 @@ func newCASBackendAddOCICmd() *cobra.Command {
3232
isDefault, err := cmd.Flags().GetBool("default")
3333
cobra.CheckErr(err)
3434

35+
name, err := cmd.Flags().GetString("name")
36+
cobra.CheckErr(err)
37+
3538
description, err := cmd.Flags().GetString("description")
3639
cobra.CheckErr(err)
3740

@@ -45,6 +48,7 @@ func newCASBackendAddOCICmd() *cobra.Command {
4548
}
4649

4750
opts := &action.NewCASBackendAddOpts{
51+
Name: name,
4852
Location: repo, Description: description,
4953
Provider: "OCI",
5054
Credentials: map[string]any{

app/cli/cmd/casbackend_add_s3.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -31,6 +31,9 @@ func newCASBackendAddAWSS3Cmd() *cobra.Command {
3131
isDefault, err := cmd.Flags().GetBool("default")
3232
cobra.CheckErr(err)
3333

34+
name, err := cmd.Flags().GetString("name")
35+
cobra.CheckErr(err)
36+
3437
description, err := cmd.Flags().GetString("description")
3538
cobra.CheckErr(err)
3639

@@ -44,6 +47,7 @@ func newCASBackendAddAWSS3Cmd() *cobra.Command {
4447
}
4548

4649
opts := &action.NewCASBackendAddOpts{
50+
Name: name,
4751
Location: bucketName,
4852
Provider: s3.ProviderID,
4953
Description: description,

app/cli/cmd/casbackend_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func casBackendListTableOutput(backends []*action.CASBackendItem) error {
5252
}
5353

5454
t := newTableWriter()
55-
header := table.Row{"ID", "Location", "Provider", "Description", "Limits", "Default"}
55+
header := table.Row{"ID", "Name", "Location", "Provider", "Description", "Limits", "Default"}
5656
if full {
5757
header = append(header, "Validation Status", "Created At", "Validated At")
5858
}
@@ -64,7 +64,7 @@ func casBackendListTableOutput(backends []*action.CASBackendItem) error {
6464
limits = fmt.Sprintf("MaxSize: %s", bytefmt.ByteSize(uint64(b.Limits.MaxBytes)))
6565
}
6666

67-
r := table.Row{b.ID, wrap.String(b.Location, 35), b.Provider, wrap.String(b.Description, 35), limits, b.Default}
67+
r := table.Row{b.ID, b.Name, wrap.String(b.Location, 35), b.Provider, wrap.String(b.Description, 35), limits, b.Default}
6868
if full {
6969
r = append(r, b.ValidationStatus,
7070
b.CreatedAt.Format(time.RFC822),

app/cli/cmd/casbackend_update_azureblob.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -35,6 +35,9 @@ func newCASBackendUpdateAzureBlobCmd() *cobra.Command {
3535
description, err := cmd.Flags().GetString("description")
3636
cobra.CheckErr(err)
3737

38+
name, err := cmd.Flags().GetString("name")
39+
cobra.CheckErr(err)
40+
3841
// If we are overriding the default we ask for confirmation
3942
if isDefault {
4043
if confirmed, err := confirmDefaultCASBackendOverride(actionOpts, backendID); err != nil {
@@ -55,6 +58,7 @@ func newCASBackendUpdateAzureBlobCmd() *cobra.Command {
5558

5659
opts := &action.NewCASBackendUpdateOpts{
5760
ID: backendID,
61+
Name: name,
5862
Description: description,
5963
Credentials: map[string]any{
6064
"tenantID": tenantID,

app/cli/cmd/casbackend_update_inline.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -33,6 +33,9 @@ func newCASBackendUpdateInlineCmd() *cobra.Command {
3333
description, err := cmd.Flags().GetString("description")
3434
cobra.CheckErr(err)
3535

36+
name, err := cmd.Flags().GetString("name")
37+
cobra.CheckErr(err)
38+
3639
// If we are overriding the default we ask for confirmation
3740
if isDefault {
3841
if confirmed, err := confirmDefaultCASBackendOverride(actionOpts, backendID); err != nil {
@@ -52,6 +55,7 @@ func newCASBackendUpdateInlineCmd() *cobra.Command {
5255
}
5356

5457
opts := &action.NewCASBackendUpdateOpts{
58+
Name: name,
5559
ID: backendID,
5660
Description: description,
5761
Default: isDefault,

app/cli/cmd/casbackend_update_oci.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -35,6 +35,9 @@ func newCASBackendUpdateOCICmd() *cobra.Command {
3535
description, err := cmd.Flags().GetString("description")
3636
cobra.CheckErr(err)
3737

38+
name, err := cmd.Flags().GetString("name")
39+
cobra.CheckErr(err)
40+
3841
// If we are overriding the default we ask for confirmation
3942
if isDefault {
4043
if confirmed, err := confirmDefaultCASBackendOverride(actionOpts, backendID); err != nil {
@@ -55,6 +58,7 @@ func newCASBackendUpdateOCICmd() *cobra.Command {
5558

5659
opts := &action.NewCASBackendUpdateOpts{
5760
ID: backendID,
61+
Name: name,
5862
Description: description,
5963
Credentials: map[string]any{
6064
"username": username,

app/cli/cmd/casbackend_update_s3.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -35,6 +35,9 @@ func newCASBackendUpdateAWSS3Cmd() *cobra.Command {
3535
description, err := cmd.Flags().GetString("description")
3636
cobra.CheckErr(err)
3737

38+
name, err := cmd.Flags().GetString("name")
39+
cobra.CheckErr(err)
40+
3841
// If we are overriding the default we ask for confirmation
3942
if isDefault {
4043
if confirmed, err := confirmDefaultCASBackendOverride(actionOpts, backendID); err != nil {
@@ -55,6 +58,7 @@ func newCASBackendUpdateAWSS3Cmd() *cobra.Command {
5558

5659
opts := &action.NewCASBackendUpdateOpts{
5760
ID: backendID,
61+
Name: name,
5862
Description: description,
5963
Credentials: map[string]any{
6064
"accessKeyID": accessKeyID,

app/cli/internal/action/casbackend_add.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type CASBackendAdd struct {
2828
}
2929

3030
type NewCASBackendAddOpts struct {
31+
Name string
3132
Location string
3233
Provider string
3334
Description string
@@ -48,6 +49,7 @@ func (action *CASBackendAdd) Run(opts *NewCASBackendAddOpts) (*CASBackendItem, e
4849

4950
client := pb.NewCASBackendServiceClient(action.cfg.CPConnection)
5051
resp, err := client.Create(context.Background(), &pb.CASBackendServiceCreateRequest{
52+
Name: opts.Name,
5153
Location: opts.Location,
5254
Provider: opts.Provider,
5355
Description: opts.Description,

0 commit comments

Comments
 (0)