From ac860e658fa7255c54e7ca0a6a7ca3c1006d850c Mon Sep 17 00:00:00 2001 From: Sanskar Jaiswal Date: Mon, 14 Nov 2022 19:32:35 +0530 Subject: [PATCH] add aws codecommit example and validation Signed-off-by: Sanskar Jaiswal --- cmd/flux/bootstrap_git.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index d553bae2d5..97ef0a27de 100644 --- a/cmd/flux/bootstrap_git.go +++ b/cmd/flux/bootstrap_git.go @@ -60,6 +60,9 @@ command will perform an upgrade if needed.`, # Run bootstrap for a Git repository with a private key and password flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file= --password= + + # Run bootstrap for a Git repository on AWS CodeCommit + flux bootstrap git --url=ssh://@git-codecommit..amazonaws.com/v1/repos/ --private-key-file= --password= `, RunE: bootstrapGitCmdRun, } @@ -115,6 +118,19 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { return err } + if repositoryURL.Scheme == "ssh" && strings.Contains(repositoryURL.Hostname(), "git-codecommit") && + strings.Contains(repositoryURL.Hostname(), "amazonaws.com") { + if repositoryURL.User == nil { + return fmt.Errorf("invalid AWS CodeCommit url: ssh username should be specified in the url") + } + if repositoryURL.User.Username() == "git" { + return fmt.Errorf("invalid AWS CodeCommit url: ssh username should be the SSH key ID for the provided private key") + } + if bootstrapArgs.privateKeyFile == "" { + return fmt.Errorf("private key file is required for bootstrapping against AWS CodeCommit using ssh") + } + } + ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel()