Skip to content

Commit

Permalink
add aws codecommit example and validation
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
  • Loading branch information
aryan9600 committed Nov 14, 2022
1 parent f2d2d00 commit ac860e6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/flux/bootstrap_git.go
Expand Up @@ -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=<path/to/private.key> --password=<password>
# Run bootstrap for a Git repository on AWS CodeCommit
flux bootstrap git --url=ssh://<SSH-Key-ID>@git-codecommit.<region>.amazonaws.com/v1/repos/<repository> --private-key-file=<path/to/private.key> --password=<SSH-passphrase>
`,
RunE: bootstrapGitCmdRun,
}
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit ac860e6

Please sign in to comment.