From db9fdb7e6e6ff9ced8139355d52555fcfb6e41f5 Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 26 Apr 2013 00:25:34 +0200 Subject: [PATCH] camput: reenable -secret-keyring, use flag.StringVar http://camlistore.org/issue/76 Change-Id: I37229a1082e5d955cadcc63521ea1b13dd63a33c --- cmd/camput/camput.go | 1 - pkg/client/config.go | 22 +++++++++++++--------- pkg/jsonsign/sign.go | 14 ++------------ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cmd/camput/camput.go b/cmd/camput/camput.go index 4151afdd5..ad544319d 100644 --- a/cmd/camput/camput.go +++ b/cmd/camput/camput.go @@ -46,7 +46,6 @@ func init() { flag.BoolVar(&flagProxyLocal, "proxy_local", false, "If true, the HTTP_PROXY environment is also used for localhost requests. This can be helpful during debugging.") } cmdmain.ExtraFlagRegistration = func() { - jsonsign.AddFlags() client.AddFlags() } cmdmain.PreExit = func() { diff --git a/pkg/client/config.go b/pkg/client/config.go index 69aed293e..04a63fd40 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -36,19 +36,20 @@ import ( // "server" and "password" keys. // // A main binary must call AddFlags to expose these. -var flagServer *string +var ( + flagServer string + flagSecretRing string +) func AddFlags() { defaultPath := ConfigFilePath() - flagServer = flag.String("server", "", "Camlistore server prefix. If blank, the default from the \"server\" field of "+defaultPath+" is used. Acceptable forms: https://you.example.com, example.com:1345 (https assumed), or http://you.example.com/alt-root") + flag.StringVar(&flagServer, "server", "", "Camlistore server prefix. If blank, the default from the \"server\" field of "+defaultPath+" is used. Acceptable forms: https://you.example.com, example.com:1345 (https assumed), or http://you.example.com/alt-root") + flag.StringVar(&flagSecretRing, "secret-keyring", "", "GnuPG secret keyring file to use.") } // ExplicitServer returns the blobserver given in the flags, if any. func ExplicitServer() string { - if flagServer != nil { - return *flagServer - } - return "" + return flagServer } func ConfigFilePath() string { @@ -86,8 +87,8 @@ func cleanServer(server string) string { } func serverOrDie() string { - if flagServer != nil && *flagServer != "" { - return cleanServer(*flagServer) + if flagServer != "" { + return cleanServer(flagServer) } configOnce.Do(parseConfig) value, ok := config["server"] @@ -103,7 +104,7 @@ func serverOrDie() string { } func (c *Client) SetupAuth() error { - if flagServer != nil && *flagServer != "" { + if flagServer != "" { // If using an explicit blobserver, don't use auth // configured from the config file, so we don't send // our password to a friend's blobserver. @@ -137,6 +138,9 @@ func (c *Client) SignerPublicKeyBlobref() *blobref.BlobRef { } func (c *Client) SecretRingFile() string { + if flagSecretRing != "" { + return flagSecretRing + } configOnce.Do(parseConfig) keyRing, ok := config["secretRing"].(string) if ok && keyRing != "" { diff --git a/pkg/jsonsign/sign.go b/pkg/jsonsign/sign.go index f53a4173a..6510d6b9f 100644 --- a/pkg/jsonsign/sign.go +++ b/pkg/jsonsign/sign.go @@ -20,12 +20,10 @@ import ( "bytes" "encoding/json" "errors" - "flag" "fmt" "io" "log" "os" - "path/filepath" "strings" "sync" "time" @@ -39,14 +37,6 @@ import ( var _ = log.Printf -var flagSecretRing = "" - -func AddFlags() { - defSecRing := filepath.Join(os.Getenv("HOME"), ".gnupg", "secring.gpg") - flag.StringVar(&flagSecretRing, "secret-keyring", defSecRing, - "GnuPG secret keyring file to use.") -} - type EntityFetcher interface { FetchEntity(keyId string) (*openpgp.Entity, error) } @@ -56,7 +46,7 @@ type FileEntityFetcher struct { } func FlagEntityFetcher() *FileEntityFetcher { - return &FileEntityFetcher{File: flagSecretRing} + return &FileEntityFetcher{File: DefaultSecRingPath()} } type CachingEntityFetcher struct { @@ -196,7 +186,7 @@ func (sr *SignRequest) secretRingPath() string { if sr.SecretKeyringPath != "" { return sr.SecretKeyringPath } - return flagSecretRing + return DefaultSecRingPath() } func (sr *SignRequest) Sign() (signedJSON string, err error) {