diff --git a/cmd/camput/init.go b/cmd/camput/init.go index a98ddf994..b6deea015 100644 --- a/cmd/camput/init.go +++ b/cmd/camput/init.go @@ -14,10 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// TODO(mpl): Shouldn't we move this subcommand to camtool? e.g as 'camtool configinit' ? -// It does not feel like a good fit in camput since this does not send anything -// to a server. - package main import ( @@ -40,6 +36,7 @@ import ( type initCmd struct { newKey bool gpgkey string + noconfig bool } func init() { @@ -47,6 +44,7 @@ func init() { cmd := new(initCmd) flags.BoolVar(&cmd.newKey, "newkey", false, "Automatically generate a new identity in a new secret ring.") flags.StringVar(&cmd.gpgkey, "gpgkey", "", "GPG key to use for signing (overrides $GPGKEY environment)") + flags.BoolVar(&cmd.noconfig, "noconfig", false, "Stop after creating the public key blob, and do not try and create a config file.") return cmd }) } @@ -172,6 +170,10 @@ func (c *initCmd) RunCommand(args []string) error { log.Printf("Your Camlistore identity (your GPG public key's blobref) is: %s", bref.String()) + if c.noconfig { + return nil + } + configFilePath := osutil.UserClientConfigPath() _, err = os.Stat(configFilePath) if err == nil { diff --git a/config/dev-server-config.json b/config/dev-server-config.json index ebb14cd07..68dc0fe58 100644 --- a/config/dev-server-config.json +++ b/config/dev-server-config.json @@ -78,7 +78,7 @@ "handler": "jsonsign", "handlerArgs": { "secretRing": ["_env", "${CAMLI_SECRET_RING}"], - "keyId": "26F5ABDA", + "keyId": ["_env", "${CAMLI_KEYID}"], "publicKeyDest": "/bs/" } }, diff --git a/dev/devcam/camget.go b/dev/devcam/camget.go index 499de4215..bf6cf8d17 100644 --- a/dev/devcam/camget.go +++ b/dev/devcam/camget.go @@ -131,8 +131,8 @@ func (c *getCmd) build() error { func (c *getCmd) setEnvVars() error { setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir")) - setenv("CAMLI_SECRET_RING", filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg")) - setenv("CAMLI_KEYID", "26F5ABDA") + setenv("CAMLI_SECRET_RING", filepath.FromSlash(defaultSecring)) + setenv("CAMLI_KEYID", defaultKeyID) setenv("CAMLI_AUTH", "userpass:camlistore:pass3179") setenv("CAMLI_DEV_KEYBLOBS", filepath.FromSlash("config/dev-client-dir/keyblobs")) c.verbose, _ = strconv.ParseBool(os.Getenv("CAMLI_QUIET")) diff --git a/dev/devcam/camput.go b/dev/devcam/camput.go index 94d5e6f33..d66340b51 100644 --- a/dev/devcam/camput.go +++ b/dev/devcam/camput.go @@ -132,8 +132,8 @@ func (c *putCmd) build() error { func (c *putCmd) setEnvVars() error { setenv("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir")) - setenv("CAMLI_SECRET_RING", filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg")) - setenv("CAMLI_KEYID", "26F5ABDA") + setenv("CAMLI_SECRET_RING", filepath.FromSlash(defaultSecring)) + setenv("CAMLI_KEYID", defaultKeyID) setenv("CAMLI_AUTH", "userpass:camlistore:pass3179") setenv("CAMLI_DEV_KEYBLOBS", filepath.FromSlash("config/dev-client-dir/keyblobs")) if c.altkey { diff --git a/dev/devcam/server.go b/dev/devcam/server.go index c3f9e4b0b..82de159f6 100644 --- a/dev/devcam/server.go +++ b/dev/devcam/server.go @@ -33,6 +33,13 @@ import ( "camlistore.org/pkg/osutil" ) +const ( + // default secret ring used in tests and in devcam commands + defaultSecring = "pkg/jsonsign/testdata/test-secring.gpg" + // public ID of the GPG key in defaultSecring + defaultKeyID = "26F5ABDA" +) + type serverCmd struct { // start of flag vars all bool @@ -273,7 +280,8 @@ func (c *serverCmd) setEnvVars() error { } setenv("CAMLI_PORT", c.port) setenv("CAMLI_SECRET_RING", filepath.Join(camliSrcRoot, - filepath.FromSlash("pkg/jsonsign/testdata/test-secring.gpg"))) + filepath.FromSlash(defaultSecring))) + setenv("CAMLI_KEYID", defaultKeyID) return nil } diff --git a/dev/devcam/test.go b/dev/devcam/test.go index 548cf92c7..15634bec5 100644 --- a/dev/devcam/test.go +++ b/dev/devcam/test.go @@ -67,6 +67,9 @@ func (c *testCmd) RunCommand(args []string) error { if err := c.buildSelf(); err != nil { return err } + if err := c.genKeyBlob(); err != nil { + return err + } if err := c.runTests(); err != nil { return err } @@ -86,27 +89,6 @@ func (c *testCmd) syncSrc() error { return nil } -func (c *testCmd) runTests() error { - args := []string{"test"} - if !strings.HasSuffix(c.buildGoPath, "-nosqlite") { - args = append(args, "--tags=with_sqlite") - } - if c.short { - args = append(args, "-short") - } - args = append(args, []string{ - "./pkg/...", - "./server/camlistored", - "./server/appengine", - "./cmd/...", - }...) - env := append(cleanGoEnv(), - "SKIP_DEP_TESTS=1", - "GOPATH="+c.buildGoPath, - ) - return runExec("go", args, env) -} - // cleanGoEnv returns a copy of the current environment with GOPATH and // GOBIN removed. func cleanGoEnv() (clean []string) { @@ -143,3 +125,45 @@ func (c *testCmd) buildSelf() error { } return nil } + +func (c *testCmd) genKeyBlob() error { + cmdBin := filepath.FromSlash("./bin/devcam") + args := []string{ + "put", + "init", + "--gpgkey="+defaultKeyID, + "--noconfig", + } + cmd := exec.Command(cmdBin, args...) + cmd.Env = append(cleanGoEnv(), + "CAMLI_SECRET_RING="+filepath.FromSlash(defaultSecring), + "GOPATH="+c.buildGoPath, + ) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + return fmt.Errorf("Error generating keyblobs: %v", err) + } + return nil +} + +func (c *testCmd) runTests() error { + args := []string{"test"} + if !strings.HasSuffix(c.buildGoPath, "-nosqlite") { + args = append(args, "--tags=with_sqlite") + } + if c.short { + args = append(args, "-short") + } + args = append(args, []string{ + "./pkg/...", + "./server/camlistored", + "./server/appengine", + "./cmd/...", + }...) + env := append(cleanGoEnv(), + "SKIP_DEP_TESTS=1", + "GOPATH="+c.buildGoPath, + ) + return runExec("go", args, env) +} diff --git a/doc/environment-vars.txt b/doc/environment-vars.txt index a7e4a8b3e..e1b0c0d79 100644 --- a/doc/environment-vars.txt +++ b/doc/environment-vars.txt @@ -78,6 +78,11 @@ CAMLI_INCLUDE_PATH (string): directory. It should be in the OS path form, i.e. unix-like systems would be /path/1:/path/two:/some/other/path, and Windows would be C:\path\one;D:\path\2 +CAMLI_KEYID (string): + devcam commands only, used by config/dev-server-config.json, and + config/dev-client-dir/client-config.json: public ID of the GPG key + to use for signing. + CAMLI_MONGO_WIPE (bool): Wipe out mongo based index on startup. diff --git a/misc/buildbot/bot.go b/misc/buildbot/bot.go index d0efae199..64c255230 100644 --- a/misc/buildbot/bot.go +++ b/misc/buildbot/bot.go @@ -99,7 +99,7 @@ var NameToCmd = map[string]string{ "buildGoTip1": "./make.bash", "buildCamli1": "go run make.go -v", "buildCamli2": "go build -o devcam ./dev/devcam/", - "buildCamli3": "devcam test", + "buildCamli3": "./devcam test", "runCamli": "./devcam server --wipe --mysql", "hitCamliUi1": "http://localhost:3179/ui/", "camget": "./devcam get ",