From f5a064167170c78bce75ba3ed752e33386b51814 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Thu, 19 Dec 2024 11:55:44 -0800 Subject: [PATCH] Add requirement for ssh issue credentials command to include either outFilePath or addToAgent flag --- cli/packages/cmd/ssh.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cli/packages/cmd/ssh.go b/cli/packages/cmd/ssh.go index 2b3c4f9a8..d7c1f1e26 100644 --- a/cli/packages/cmd/ssh.go +++ b/cli/packages/cmd/ssh.go @@ -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 @@ -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)