From 9abba638a0ca2ada87ed5f629a743fa72a47254e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 20 Jan 2014 13:54:42 -0800 Subject: [PATCH] Add new environment variables for setting client identity for use with test.World. Testing clients should now use CAMLI_CLIENT_IDENTITY, CAMLI_DISABLE_CLIENT_CONFIG_FILE (both new) and existing CAMLI_SECRET_RING, set using the new test.World accessors. Change-Id: I9fc0571b008f033674466bbc98129ae1919a0640 --- doc/environment-vars.txt | 6 ++++++ pkg/client/config.go | 9 ++++++--- pkg/test/world.go | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/environment-vars.txt b/doc/environment-vars.txt index b89791e30..442d80d6a 100644 --- a/doc/environment-vars.txt +++ b/doc/environment-vars.txt @@ -105,10 +105,16 @@ CAMLI_FAST_DEV (bool): Used by dev/demo.sh for giving presentations with devcam server/put/etc for faster pre-built builds, without calling make.go. +CAMLI_CLIENT_IDENTITY (string): + Optional GPG identity to use, taking precedence over config files. + CAMLI_SECRET_RING (string): Path to the GPG secret keyring, which is otherwise set by identitySecretRing in the server config, and secretRing in the client config. +CAMLI_DISABLE_CLIENT_CONFIG_FILE (bool): + If set, the pkg/client code will never use the on-disk config file. + CAMLI_TRACK_FS_STATS (bool): Enable operation counts for fuse filesystem. diff --git a/pkg/client/config.go b/pkg/client/config.go index b2a13ce3a..dd916cf87 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -358,10 +358,13 @@ func (c *Client) SignerPublicKeyBlobref() blob.Ref { } func (c *Client) initSignerPublicKeyBlobref() { - configOnce.Do(parseConfig) - keyId := config.Identity + keyId := os.Getenv("CAMLI_CLIENT_IDENTITY") if keyId == "" { - log.Fatalf("No 'identity' key in JSON configuration file %q; have you run \"camput init\"?", osutil.UserClientConfigPath()) + configOnce.Do(parseConfig) + keyId = config.Identity + if keyId == "" { + log.Fatalf("No 'identity' key in JSON configuration file %q; have you run \"camput init\"?", osutil.UserClientConfigPath()) + } } keyRing := c.SecretRingFile() if !fileExists(keyRing) { diff --git a/pkg/test/world.go b/pkg/test/world.go index 41f12e824..a0b050f77 100644 --- a/pkg/test/world.go +++ b/pkg/test/world.go @@ -176,8 +176,8 @@ func (w *World) CmdWithEnv(binary string, env []string, args ...string) *exec.Cm "CAMLI_CONFIG_DIR=" + clientConfigDir, // Respected by env expansions in config/dev-client-dir/client-config.json: "CAMLI_SERVER=" + w.ServerBaseURL(), - "CAMLI_SECRET_RING=" + filepath.Join(w.camRoot, "pkg", "jsonsign", "testdata", "test-secring.gpg"), - "CAMLI_KEYID=26F5ABDA", + "CAMLI_SECRET_RING=" + w.SecretRingFile(), + "CAMLI_KEYID=" + w.ClientIdentity(), "CAMLI_AUTH=userpass:testuser:passTestWorld", }, env...) default: @@ -240,3 +240,15 @@ func MustRunCmd(t *testing.T, c *exec.Cmd) string { } return out } + +// ClientIdentity returns the GPG identity to use in World tests, suitable +// for setting in CAMLI_CLIENT_IDENTITY. +func (w *World) ClientIdentity() string { + return "26F5ABDA" +} + +// SecretRingFile returns the GnuPG secret ring, suitable for setting +// in CAMLI_SECRET_RING. +func (w *World) SecretRingFile() string { + return filepath.Join(w.camRoot, "pkg", "jsonsign", "testdata", "test-secring.gpg") +}