2 Commits
Author SHA1 Message Date
jmug 1892fd9e8a feat: arr and map methods now output json to make the read, mutate, write loop easier.
release-clis / release (push) Successful in 43s
build-secretsserver / build (push) Successful in 59s
2026-10-30 13:50:55 -07:00
jmug aa3d497139 feat: Support setting the value of array/map secrets from a json file.
build-secretsserver / build (push) Successful in 39s
2026-10-30 13:32:35 -07:00
4 changed files with 62 additions and 6 deletions

No files matched your search

+6 -1
View File
@@ -1,6 +1,7 @@
package hmsecrets
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
@@ -20,7 +21,11 @@ var getArrCmd = &cobra.Command{
if err != nil {
return err
}
fmt.Println(secret)
secretJSON, err := json.MarshalIndent(secret, "", " ")
if err != nil {
return err
}
fmt.Println(string(secretJSON))
return nil
},
}
+6 -1
View File
@@ -1,6 +1,7 @@
package hmsecrets
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
@@ -20,7 +21,11 @@ var getMapCmd = &cobra.Command{
if err != nil {
return err
}
fmt.Println(secret)
secretJSON, err := json.MarshalIndent(secret, "", " ")
if err != nil {
return err
}
fmt.Println(string(secretJSON))
return nil
},
}
+25 -2
View File
@@ -1,22 +1,35 @@
package hmsecrets
import (
"encoding/json"
"fmt"
"os"
"github.com/spf13/cobra"
)
var arrValue []string
var arrFile string
func init() {
rootCmd.AddCommand(setArrCmd)
setArrCmd.Flags().StringArrayVarP(
&arrValue,
"array-value",
"value",
"v",
nil,
"array value to store in the secret",
)
setArrCmd.MarkFlagRequired("array-value")
setArrCmd.Flags().StringVarP(
&arrFile,
"value-file",
"f",
"",
"file that contains the secret value (in json) to set",
)
setArrCmd.MarkFlagsOneRequired("value-file", "value")
}
var setArrCmd = &cobra.Command{
@@ -25,6 +38,16 @@ var setArrCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient()
if arrFile != "" {
arrJSONBytes, err := os.ReadFile(arrFile)
if err != nil {
return fmt.Errorf("reading array value file: %w", err)
}
err = json.Unmarshal(arrJSONBytes, &arrValue)
if err != nil {
return fmt.Errorf("reading value from array file: %w", err)
}
}
err := cli.PutStringArr(args[0], arrValue)
if err != nil {
return err
+25 -2
View File
@@ -1,22 +1,35 @@
package hmsecrets
import (
"encoding/json"
"fmt"
"os"
"github.com/spf13/cobra"
)
var mapValue map[string]string
var mapFile string
func init() {
rootCmd.AddCommand(setMapCmd)
setMapCmd.Flags().StringToStringVarP(
&mapValue,
"map-value",
"value",
"v",
nil,
"map value to store in the secret",
)
setArrCmd.MarkFlagRequired("map-value")
setMapCmd.Flags().StringVarP(
&mapFile,
"value-file",
"f",
"",
"file that contains the secret value (in json) to set",
)
setMapCmd.MarkFlagsOneRequired("value-file", "value")
}
var setMapCmd = &cobra.Command{
@@ -25,6 +38,16 @@ var setMapCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient()
if mapFile != "" {
mapJSONBytes, err := os.ReadFile(mapFile)
if err != nil {
return fmt.Errorf("reading map value file: %w", err)
}
err = json.Unmarshal(mapJSONBytes, &mapValue)
if err != nil {
return fmt.Errorf("reading value from map file: %w", err)
}
}
err := cli.PutStringMap(args[0], mapValue)
if err != nil {
return err