From 3ae568639e67420177a0e3bf70e2551113c01514 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Thu, 11 Apr 2024 15:31:08 -0600 Subject: [PATCH] add flag to specify alternative filepath to secret For the hyp client to be able to support multiple servers, each with their own secret, this capability is requried. --- hyp/cmd/knock.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hyp/cmd/knock.go b/hyp/cmd/knock.go index 36d7c47..a86bd61 100644 --- a/hyp/cmd/knock.go +++ b/hyp/cmd/knock.go @@ -31,8 +31,14 @@ Example usage: `, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { + // load secret and generate ports using secret and current time - secretBytes, err := os.ReadFile("hyp.secret") + secretFilePath, err := cmd.Flags().GetString("secret") + if err != nil { + panic(fmt.Errorf("failed to parse command flag 'secret': %w", err)) + } + + secretBytes, err := os.ReadFile(secretFilePath) if err != nil { log.Fatalf("failed to read file 'hyp.secret': %v", err) } @@ -56,4 +62,6 @@ Example usage: func init() { rootCmd.AddCommand(knockCmd) + + knockCmd.PersistentFlags().String("secret", "hyp.secret", "Path to the file containing the hyp secret.") }