Simon Marsh
6117bcd7bf
All checks were successful
continuous-integration/drone/push Build is passing
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
//////////////////////////////////////////////////////////////////////////
|
|
|
|
package main
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
|
|
"os"
|
|
|
|
vault "git.burble.dn42/burble.dn42/libvault"
|
|
)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// everything starts here
|
|
|
|
func main() {
|
|
log.SetLevel(log.ErrorLevel)
|
|
|
|
cmdRoot := &cobra.Command{
|
|
Use: "mini-vault",
|
|
Short: "Hashicorp Vault helper proglet",
|
|
}
|
|
cmdRoot.PersistentFlags().StringVarP(&TokenFile, "token", "t", "", "Token file")
|
|
|
|
// configure subcommands
|
|
cmdToken := &cobra.Command{
|
|
Use: "token",
|
|
Short: "token manipulation",
|
|
}
|
|
|
|
cmdTokenRenew := &cobra.Command{
|
|
Use: "renew",
|
|
Short: "Renew Token",
|
|
Run: CmdTokenRenew,
|
|
}
|
|
cmdTokenRenew.Flags().StringVarP(&TokenTTL, "ttl", "l", "", "Renewal TTL")
|
|
|
|
cmdTLS := &cobra.Command{
|
|
Use: "tls",
|
|
Short: "TLS cert management",
|
|
}
|
|
|
|
cmdTLSRenew := &cobra.Command{
|
|
Use: "renew",
|
|
Short: "Renew TLS certificate",
|
|
Run: CmdTLSRenew,
|
|
}
|
|
cmdTLSRenew.Flags().StringVarP(&TLSCertPEM, "cert", "c", "", "Path to Certificate PEM")
|
|
cmdTLSRenew.MarkFlagRequired("cert")
|
|
cmdTLSRenew.Flags().StringVarP(&TLSKeyPEM, "key", "k", "", "Path to Key PEM")
|
|
cmdTLSRenew.MarkFlagRequired("key")
|
|
cmdTLSRenew.Flags().StringVarP(&TLSCAPEM, "ca", "a", "", "Path to CA PEM")
|
|
cmdTLSRenew.MarkFlagRequired("ca")
|
|
cmdTLSRenew.Flags().StringVarP(&TLSRequest, "request", "r", "", "Request Parameters")
|
|
cmdTLSRenew.MarkFlagRequired("request")
|
|
cmdTLSRenew.Flags().BoolVarP(&TLSRenewToken, "renew-token", "n", true, "Also renew the token")
|
|
|
|
cmdRoot.AddCommand(cmdToken, cmdTLS)
|
|
cmdToken.AddCommand(cmdTokenRenew)
|
|
cmdTLS.AddCommand(cmdTLSRenew)
|
|
|
|
// set vault address from environment
|
|
va := os.Getenv("VAULT_ADDR")
|
|
if va != "" {
|
|
vault.VAULT_ADDR = va
|
|
}
|
|
|
|
// do it
|
|
cmdRoot.Execute()
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// end of code
|