feat: Utility CLI to interact with the secrets service.

This commit is contained in:
jmug committed 2026-10-24 02:13:11 -07:00
1 parent 39ea9d708a
commit f65e0c7eaa
7 files changed
+150

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
package main
import "git.handmadecities.com/HMC/shhh/internal/clis/hmsecrets"
func main() {
hmsecrets.Execute()
}
+11
View File
@@ -0,0 +1,11 @@
package hmsecrets
import "git.handmadecities.com/HMC/shhh/pkg/secretsclient"
func getClient(base, ca, cert, certKey string) secretsclient.Client {
cli, err := secretsclient.New(base, ca, cert, certKey)
if err != nil {
panic(err)
}
return cli
}
+23
View File
@@ -0,0 +1,23 @@
package hmsecrets
import (
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(delCmd)
}
var delCmd = &cobra.Command{
Use: "del",
Short: "del [key]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient(apiBase, caFile, clientCert, clientKey)
err := cli.Delete(args[0])
if err != nil {
return err
}
return nil
},
}
+26
View File
@@ -0,0 +1,26 @@
package hmsecrets
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(getCmd)
}
var getCmd = &cobra.Command{
Use: "get",
Short: "get [key]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient(apiBase, caFile, clientCert, clientKey)
secret, err := cli.GetString(args[0])
if err != nil {
return err
}
fmt.Println(secret)
return nil
},
}
+59
View File
@@ -0,0 +1,59 @@
package hmsecrets
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var apiBase string
var caFile string
var clientCert string
var clientKey string
func init() {
rootCmd.PersistentFlags().StringVar(
&apiBase,
"api-base",
"",
"base url for the service",
)
rootCmd.MarkPersistentFlagRequired("api-base")
rootCmd.PersistentFlags().StringVar(
&caFile,
"ca-file",
"",
"CA cert file",
)
rootCmd.MarkPersistentFlagRequired("ca-file")
rootCmd.PersistentFlags().StringVar(
&clientCert,
"client-cert",
"",
"certificate to be used for client mTLS auth",
)
rootCmd.MarkPersistentFlagRequired("client-cert")
rootCmd.PersistentFlags().StringVar(
&clientKey,
"client-key",
"",
"private key for the certificate to be used for client mTLS auth",
)
rootCmd.MarkPersistentFlagRequired("client-key")
}
var rootCmd = &cobra.Command{
Use: "hmsecrets",
Short: "Interact with the HandMade secrets service",
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
+23
View File
@@ -0,0 +1,23 @@
package hmsecrets
import (
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(setCmd)
}
var setCmd = &cobra.Command{
Use: "set",
Short: "set [key] [value]",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient(apiBase, caFile, clientCert, clientKey)
err := cli.PutString(args[0], args[1])
if err != nil {
return err
}
return nil
},
}
+1
View File
@@ -33,6 +33,7 @@ func New(base, ca, cert, certKey string) (Client, error) {
}, nil }, nil
} }
// TODO: Propagate errors to the callers.
type client struct { type client struct {
base string base string
h *http.Client h *http.Client