From cfbf96bf3f9d4cd05f20caec89c4499b859319c1 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 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index 1721faf8cf..44c01f977a 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,23 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { return err } + if strings.Contains(repositoryURL.Hostname(), "git-codecommit") && strings.Contains(repositoryURL.Hostname(), "amazonaws.com") { + if repositoryURL.Scheme == git.SSH { + if repositoryURL.User == nil { + return fmt.Errorf("invalid AWS CodeCommit url: ssh username should be specified in the url") + } + if repositoryURL.User.Username() == git.DefaultPublicKeyAuthUser { + 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") + } + } + if repositoryURL.Scheme == git.HTTPS && !bootstrapArgs.tokenAuth { + return fmt.Errorf("--token-auth=true must be specified for using a HTTPS AWS CodeCommit url") + } + } + ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() @@ -154,7 +174,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { } clientOpts := []gogit.ClientOption{gogit.WithDiskStorage()} - if authOpts.Transport == git.HTTP { + if gitArgs.insecureHttpAllowed { clientOpts = append(clientOpts, gogit.WithInsecureCredentialsOverHTTP()) } gitClient, err := gogit.NewClient(tmpDir, authOpts, clientOpts...)