aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-05-28 22:30:42 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-05-29 13:13:05 +0100
commit4dfb29f2e07fe6fb90544ba66cf0a3df187072d9 (patch)
tree02b6277c49a2e37801f44191736ba35e32c5c075 /cmd
parentacb41bd824cc9dec47a9b28d87bc2adc8e39a21c (diff)
Use flags as defaults, allow them to override config file
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cashier/config.go9
-rw-r--r--cmd/cashier/main.go13
2 files changed, 14 insertions, 8 deletions
diff --git a/cmd/cashier/config.go b/cmd/cashier/config.go
index 1196cbd..eed98e1 100644
--- a/cmd/cashier/config.go
+++ b/cmd/cashier/config.go
@@ -1,6 +1,7 @@
package main
import (
+ "github.com/spf13/pflag"
"github.com/spf13/viper"
)
@@ -13,10 +14,10 @@ type config struct {
}
func setDefaults() {
- viper.SetDefault("ca", "http://localhost:10000")
- viper.SetDefault("key_type", "rsa")
- viper.SetDefault("key_size", 2048)
- viper.SetDefault("validity", "24h")
+ viper.BindPFlag("ca", pflag.Lookup("ca"))
+ viper.BindPFlag("key_type", pflag.Lookup("key_type"))
+ viper.BindPFlag("key_size", pflag.Lookup("key_size"))
+ viper.BindPFlag("validity", pflag.Lookup("validity"))
viper.SetDefault("validateTLSCertificate", true)
}
diff --git a/cmd/cashier/main.go b/cmd/cashier/main.go
index 564664c..768ebcd 100644
--- a/cmd/cashier/main.go
+++ b/cmd/cashier/main.go
@@ -4,7 +4,6 @@ import (
"bytes"
"crypto/tls"
"encoding/json"
- "flag"
"fmt"
"io/ioutil"
"log"
@@ -17,13 +16,18 @@ import (
"github.com/nsheridan/cashier/lib"
"github.com/pkg/browser"
+ "github.com/spf13/pflag"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)
var (
- u, _ = user.Current()
- cfg = flag.String("config", path.Join(u.HomeDir, ".cashier.cfg"), "Path to config file")
+ u, _ = user.Current()
+ cfg = pflag.String("config", path.Join(u.HomeDir, ".cashier.conf"), "Path to config file")
+ ca = pflag.String("ca", "http://localhost:10000", "CA server")
+ keysize = pflag.Int("key_size", 2048, "Key size. Ignored for ed25519 keys")
+ validity = pflag.Duration("validity", time.Hour*24, "Key validity")
+ keytype = pflag.String("key_type", "rsa", "Type of private key to generate - rsa, ecdsa or ed25519")
)
func installCert(a agent.Agent, cert *ssh.Certificate, key key) error {
@@ -102,7 +106,8 @@ func sign(pub ssh.PublicKey, token string, conf *config) (*ssh.Certificate, erro
}
func main() {
- flag.Parse()
+ pflag.Parse()
+
c, err := readConfig(*cfg)
if err != nil {
log.Fatalf("Error parsing config file: %v\n", err)