-
Notifications
You must be signed in to change notification settings - Fork 38
feat(CAS): AWS S3 blob storage support #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,86 @@ | |||
// | |||
// Copyright 2023 The Chainloop Authors. | |||
// | |||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
// | |||
// http://www.apache.org/licenses/LICENSE-2.0 | |||
// | |||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
package cmd | |||
|
|||
import ( | |||
"github.com/chainloop-dev/chainloop/app/cli/internal/action" | |||
"github.com/chainloop-dev/chainloop/internal/blobmanager/s3" | |||
"github.com/go-kratos/kratos/v2/log" | |||
"github.com/spf13/cobra" | |||
) | |||
|
|||
func newCASBackendAddAWSS3Cmd() *cobra.Command { | |||
var bucketName, accessKeyID, secretAccessKey, region string | |||
cmd := &cobra.Command{ | |||
Use: "aws-s3", | |||
Short: "Register a AWS S3 storage bucket", | |||
RunE: func(cmd *cobra.Command, args []string) error { | |||
isDefault, err := cmd.Flags().GetBool("default") | |||
cobra.CheckErr(err) | |||
|
|||
description, err := cmd.Flags().GetString("description") | |||
cobra.CheckErr(err) | |||
|
|||
if isDefault { | |||
if confirmed, err := confirmDefaultCASBackendOverride(actionOpts, ""); err != nil { | |||
return err | |||
} else if !confirmed { | |||
log.Info("Aborting...") | |||
return nil | |||
} | |||
} | |||
|
|||
opts := &action.NewCASBackendAddOpts{ | |||
Location: bucketName, | |||
Provider: s3.ProviderID, | |||
Description: description, | |||
Credentials: map[string]any{ | |||
"accessKeyID": accessKeyID, | |||
"secretAccessKey": secretAccessKey, | |||
"region": region, | |||
}, | |||
Default: isDefault, | |||
} | |||
|
|||
res, err := action.NewCASBackendAdd(actionOpts).Run(opts) | |||
if err != nil { | |||
return err | |||
} else if res == nil { | |||
return nil | |||
} | |||
|
|||
return encodeOutput([]*action.CASBackendItem{res}, casBackendListTableOutput) | |||
}, | |||
} | |||
|
|||
cmd.Flags().StringVar(&bucketName, "bucket", "", "S3 bucket name") | |||
err := cmd.MarkFlagRequired("bucket") | |||
cobra.CheckErr(err) | |||
|
|||
cmd.Flags().StringVar(&accessKeyID, "access-key-id", "", "AWS Access Key ID") | |||
err = cmd.MarkFlagRequired("access-key-id") | |||
cobra.CheckErr(err) | |||
|
|||
cmd.Flags().StringVar(&secretAccessKey, "secret-access-key", "", "AWS Secret Access Key") | |||
err = cmd.MarkFlagRequired("secret-access-key") | |||
cobra.CheckErr(err) | |||
|
|||
cmd.Flags().StringVar(®ion, "region", "", "AWS region for the bucket") | |||
err = cmd.MarkFlagRequired("region") | |||
cobra.CheckErr(err) | |||
|
|||
return cmd | |||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,92 @@ | |||
// | |||
// Copyright 2023 The Chainloop Authors. | |||
// | |||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
// | |||
// http://www.apache.org/licenses/LICENSE-2.0 | |||
// | |||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
package cmd | |||
|
|||
import ( | |||
"github.com/chainloop-dev/chainloop/app/cli/internal/action" | |||
"github.com/go-kratos/kratos/v2/log" | |||
"github.com/spf13/cobra" | |||
) | |||
|
|||
func newCASBackendUpdateAWSS3Cmd() *cobra.Command { | |||
var backendID, accessKeyID, secretAccessKey, region string | |||
cmd := &cobra.Command{ | |||
Use: "aws-s3", | |||
Short: "Update a AWS S3 CAS Backend description, credentials or default status", | |||
RunE: func(cmd *cobra.Command, args []string) error { | |||
// If we are setting the default, we list existing CAS backends | |||
// and ask the user to confirm the rewrite | |||
isDefault, err := cmd.Flags().GetBool("default") | |||
cobra.CheckErr(err) | |||
|
|||
description, err := cmd.Flags().GetString("description") | |||
cobra.CheckErr(err) | |||
|
|||
// If we are overriding the default we ask for confirmation | |||
if isDefault { | |||
if confirmed, err := confirmDefaultCASBackendOverride(actionOpts, backendID); err != nil { | |||
return err | |||
} else if !confirmed { | |||
log.Info("Aborting...") | |||
return nil | |||
} | |||
} else { | |||
// If we are removing the default we ask for confirmation too | |||
if confirmed, err := confirmDefaultCASBackendUnset(backendID, "You are setting the default CAS backend to false", actionOpts); err != nil { | |||
return err | |||
} else if !confirmed { | |||
log.Info("Aborting...") | |||
return nil | |||
} | |||
} | |||
|
|||
opts := &action.NewCASBackendUpdateOpts{ | |||
ID: backendID, | |||
Description: description, | |||
Credentials: map[string]any{ | |||
"accessKeyID": accessKeyID, | |||
"secretAccessKey": secretAccessKey, | |||
"region": region, | |||
}, | |||
Default: isDefault, | |||
} | |||
|
|||
// this means that we are not updating credentials | |||
if accessKeyID == "" && secretAccessKey == "" && region == "" { | |||
opts.Credentials = nil | |||
} | |||
|
|||
res, err := action.NewCASBackendUpdate(actionOpts).Run(opts) | |||
if err != nil { | |||
return err | |||
} else if res == nil { | |||
return nil | |||
} | |||
|
|||
return encodeOutput([]*action.CASBackendItem{res}, casBackendListTableOutput) | |||
}, | |||
} | |||
|
|||
cmd.Flags().StringVar(&backendID, "id", "", "CAS Backend ID") | |||
err := cmd.MarkFlagRequired("id") | |||
cobra.CheckErr(err) | |||
|
|||
cmd.Flags().StringVar(&accessKeyID, "access-key-id", "", "AWS Access Key ID") | |||
cmd.Flags().StringVar(&secretAccessKey, "secret-access-key", "", "AWS Secret Access Key") | |||
cmd.Flags().StringVar(®ion, "region", "", "AWS region for the bucket") | |||
|
|||
return cmd | |||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.