camput: reenable -secret-keyring, use flag.StringVar

http://camlistore.org/issue/76

Change-Id: I37229a1082e5d955cadcc63521ea1b13dd63a33c
This commit is contained in:
mpl 2013-04-26 00:25:34 +02:00
parent 5b73925c2a
commit db9fdb7e6e
3 changed files with 15 additions and 22 deletions

View File

@ -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() {

View File

@ -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 != "" {

View File

@ -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) {