Skip to content

Commit

Permalink
Add requirement for ssh issue credentials command to include either o…
Browse files Browse the repository at this point in the history
…utFilePath or addToAgent flag
  • Loading branch information
dangtony98 committed Dec 19, 2024
1 parent f97f98b commit f5a0641
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cli/packages/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ func issueCredentials(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

addToAgent, err := cmd.Flags().GetBool("addToAgent")
if err != nil {
util.HandleError(err, "Unable to parse addToAgent flag")
}

if outFilePath == "" && addToAgent == false {
util.PrintErrorMessageAndExit("You must provide either --outFilePath or --addToAgent flag to use this command")
}

var (
outputDir string
privateKeyPath string
Expand Down Expand Up @@ -357,12 +366,7 @@ func issueCredentials(cmd *cobra.Command, args []string) {
fmt.Println("Successfully wrote SSH certificate to:", signedKeyPath)
}

// Check if we need to add the key to the SSH agent
addToAgent, err := cmd.Flags().GetBool("addToAgent")
if err != nil {
util.HandleError(err, "Unable to parse addToAgent flag")
}

// Add SSH credentials to the SSH agent if needed
if addToAgent {
// Call the helper function to handle add-to-agent flow
err := addCredentialsToAgent(creds.PrivateKey, creds.SignedKey)
Expand Down

0 comments on commit f5a0641

Please sign in to comment.