diff --git a/pkg/server/help.go b/pkg/server/help.go index dba975ac7..551194691 100644 --- a/pkg/server/help.go +++ b/pkg/server/help.go @@ -24,7 +24,6 @@ import ( "net/http" "strconv" "strings" - "sync" "camlistore.org/pkg/blobserver" "camlistore.org/pkg/httputil" @@ -45,16 +44,16 @@ const helpHTML string = `

Client tools

- You can download the Camlistore command line tools in one of the binary releases at: + You can download the Camlistore command line tools for Linux, Mac, and Windows at:

You will need to use the following client configuration in order to access this server using the command line tools.

-
{{ . }}
+
{{ .ClientConfigJSON }}
+ + {{ .SecringDownloadHint }}

Anything Else?

See the Camlistore online documentation and community contacts.

@@ -63,18 +62,18 @@ const helpHTML string = ` // HelpHandler publishes information related to accessing the server type HelpHandler struct { - clientConfig *clientconfig.Config // generated from serverConfig - serverConfig jsonconfig.Obj // low-level config - goTemplate *template.Template // for rendering + clientConfig *clientconfig.Config // generated from serverConfig + serverConfig jsonconfig.Obj // low-level config + goTemplate *template.Template // for rendering + serverSecRing string } -// setServerConfigOnce guards operation within SetServerConfig -var setServerConfigOnce sync.Once - // SetServerConfig enables the handler to receive the server config // before InitHandler, which generates a client config from the server config, is called. func (hh *HelpHandler) SetServerConfig(config jsonconfig.Obj) { - setServerConfigOnce.Do(func() { hh.serverConfig = config }) + if hh.serverConfig == nil { + hh.serverConfig = config + } } func init() { @@ -117,6 +116,9 @@ func (hh *HelpHandler) InitHandler(hl blobserver.FindHandlerByTyper) error { } hh.clientConfig = clientConfig + hh.serverSecRing = clientConfig.IdentitySecretRing + clientConfig.IdentitySecretRing = "/home/you/.config/camlistore/identity-secring.gpg" + tmpl, err := template.New("help").Parse(helpHTML) if err != nil { return fmt.Errorf("error creating template: %v", err) @@ -162,5 +164,19 @@ func (hh *HelpHandler) serveHelpHTML(cc *clientconfig.Config, rw http.ResponseWr return } - hh.goTemplate.Execute(rw, string(jsonBytes)) + var hint template.HTML + if strings.HasPrefix(hh.serverSecRing, "/gcs/") { + bucketdir := strings.TrimPrefix(hh.serverSecRing, "/gcs/") + bucketdir = strings.TrimSuffix(bucketdir, "/identity-secring.gpg") + hint = template.HTML(fmt.Sprintf("

Download your GnuPG secret ring from https://console.developers.google.com/storage/browser/%s/ and place it in your Camlistore client config directory. Keep it private. It's not encrypted or password-protected and anybody in possession of it can create Camlistore claims as your identity.

\n", + bucketdir, bucketdir)) + } + + hh.goTemplate.Execute(rw, struct { + ClientConfigJSON string + SecringDownloadHint template.HTML + }{ + ClientConfigJSON: string(jsonBytes), + SecringDownloadHint: hint, + }) } diff --git a/pkg/types/clientconfig/config.go b/pkg/types/clientconfig/config.go index ddd6345bd..dd3a8ec91 100644 --- a/pkg/types/clientconfig/config.go +++ b/pkg/types/clientconfig/config.go @@ -67,7 +67,7 @@ func (conf *Config) Alias(server string) string { // access a server defined by the provided low-level server configuration. func GenerateClientConfig(serverConfig jsonconfig.Obj) (*Config, error) { missingConfig := func(param string) (*Config, error) { - return nil, fmt.Errorf("required value for '%s' not found", param) + return nil, fmt.Errorf("required value for %q not found", param) } if serverConfig == nil { @@ -159,6 +159,6 @@ func GenerateClientConfig(serverConfig jsonconfig.Obj) (*Config, error) { }, Identity: keyId, IdentitySecretRing: secretRing, - IgnoredFiles: []string{".DS_Store"}, + IgnoredFiles: []string{".DS_Store", "*~"}, }, nil }