1
0
Fork 0
mirror of https://github.com/Luzifer/vault-openvpn.git synced 2024-11-08 16:20:05 +00:00
vault-openvpn/cmd/client.go
Knut Ahlers b5935b315f
Add version command
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-05-27 12:10:14 +02:00

34 lines
1.1 KiB
Go

package cmd
import (
"errors"
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// clientCmd represents the client command
var clientCmd = &cobra.Command{
Use: "client <fqdn>",
Short: "Generate certificate and output client config",
PreRunE: func(cmd *cobra.Command, args []string) error { return initVaultClient() },
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 || !validateFQDN(args[0]) {
return errors.New("You need to provide a valid FQDN")
}
return generateCertificateConfig("client.conf", args[0])
},
}
func init() {
RootCmd.AddCommand(clientCmd)
clientCmd.Flags().BoolVar(&cfg.AutoRevoke, "auto-revoke", true, "Automatically revoke older certificates for this FQDN")
clientCmd.Flags().DurationVar(&cfg.CertTTL, "ttl", 8760*time.Hour, "Set the TTL for this certificate")
clientCmd.Flags().StringVar(&cfg.OVPNKey, "ovpn-key", "", "Specify a secret name that holds an OpenVPN shared key")
clientCmd.Flags().StringVar(&cfg.TemplatePath, "template-path", ".", "Path to read the client.conf / server.conf template from")
viper.BindPFlags(clientCmd.Flags())
}