From 759be70c92e827a90c11e1ddf9a0cb386a8cd1a2 Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 16 Jul 2013 17:55:20 +0200 Subject: [PATCH] share: allow configuration of URL prefix http://camlistore.org/issue/160 Change-Id: I77998bbde21790f15a5c4b492307434290ef9421 --- pkg/serverconfig/genconfig.go | 44 +++++++++++-------- pkg/serverconfig/testdata/default.json | 2 +- pkg/serverconfig/testdata/justblobs.json | 2 +- pkg/serverconfig/testdata/s3_nolocaldisk.json | 2 +- pkg/serverconfig/testdata/with_blog.json | 2 +- pkg/serverconfig/testdata/with_gallery.json | 2 +- website/content/docs/server-config | 3 +- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/pkg/serverconfig/genconfig.go b/pkg/serverconfig/genconfig.go index d9ce21129..869c1eb0a 100644 --- a/pkg/serverconfig/genconfig.go +++ b/pkg/serverconfig/genconfig.go @@ -36,12 +36,12 @@ const ( // various parameters derived from the high-level user config // and needed to set up the low-level config. type configPrefixesParams struct { - secretRing string - keyId string - indexerPath string - blobPath string - searchOwner *blobref.BlobRef - shareHandler bool + secretRing string + keyId string + indexerPath string + blobPath string + searchOwner *blobref.BlobRef + shareHandlerPath string } var tempDir = os.TempDir @@ -338,8 +338,8 @@ func genLowLevelPrefixes(params *configPrefixesParams, ownerName string) (m json "handler": "status", } - if params.shareHandler { - m["/share/"] = map[string]interface{}{ + if params.shareHandlerPath != "" { + m[params.shareHandlerPath] = map[string]interface{}{ "handler": "share", "handlerArgs": map[string]interface{}{ "blobRoot": "/bs/", @@ -425,10 +425,14 @@ func genLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) { tlsKey = conf.OptionalString("HTTPSKeyFile", "") // Blob storage options - blobPath = conf.OptionalString("blobPath", "") - s3 = conf.OptionalString("s3", "") // "access_key_id:secret_access_key:bucket" - gstorage = conf.OptionalString("google", "") // "clientId:clientSecret:refreshToken:bucket" - shareHandler = conf.OptionalBool("shareHandler", true) // enable the share handler + blobPath = conf.OptionalString("blobPath", "") + s3 = conf.OptionalString("s3", "") // "access_key_id:secret_access_key:bucket" + gstorage = conf.OptionalString("google", "") // "clientId:clientSecret:refreshToken:bucket" + // Enable the share handler. If true, and shareHandlerPath is empty, + // then shareHandlerPath defaults to "/share/". + shareHandler = conf.OptionalBool("shareHandler", false) + // URL prefix for the share handler. If set, overrides shareHandler. + shareHandlerPath = conf.OptionalString("shareHandlerPath", "") // Index options runIndex = conf.OptionalBool("runIndex", true) // if false: no search, no UI, etc. @@ -523,13 +527,17 @@ func genLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) { return nil, errors.New("You need at least one of blobPath (for localdisk) or s3 or google configured for a blobserver.") } + if shareHandler && shareHandlerPath == "" { + shareHandlerPath = "/share/" + } + prefixesParams := &configPrefixesParams{ - secretRing: secretRing, - keyId: keyId, - indexerPath: indexerPath, - blobPath: blobPath, - searchOwner: blobref.SHA1FromString(armoredPublicKey), - shareHandler: shareHandler, + secretRing: secretRing, + keyId: keyId, + indexerPath: indexerPath, + blobPath: blobPath, + searchOwner: blobref.SHA1FromString(armoredPublicKey), + shareHandlerPath: shareHandlerPath, } prefixes := genLowLevelPrefixes(prefixesParams, ownerName) diff --git a/pkg/serverconfig/testdata/default.json b/pkg/serverconfig/testdata/default.json index 5730866ff..bdacdfea0 100644 --- a/pkg/serverconfig/testdata/default.json +++ b/pkg/serverconfig/testdata/default.json @@ -11,5 +11,5 @@ "replicateTo": [], "publish": {}, "ownerName": "Brad", - "shareHandler": true + "shareHandlerPath": "/share/" } diff --git a/pkg/serverconfig/testdata/justblobs.json b/pkg/serverconfig/testdata/justblobs.json index ef6208518..411073263 100644 --- a/pkg/serverconfig/testdata/justblobs.json +++ b/pkg/serverconfig/testdata/justblobs.json @@ -6,5 +6,5 @@ "identity": "26F5ABDA", "identitySecretRing": "/path/to/secring", "runIndex": false, - "shareHandler": true + "shareHandlerPath": "/share/" } diff --git a/pkg/serverconfig/testdata/s3_nolocaldisk.json b/pkg/serverconfig/testdata/s3_nolocaldisk.json index 5c2224d66..bb7f0b534 100644 --- a/pkg/serverconfig/testdata/s3_nolocaldisk.json +++ b/pkg/serverconfig/testdata/s3_nolocaldisk.json @@ -8,5 +8,5 @@ "s3": "key:secret:bucket", "replicateTo": [], "publish": {}, - "shareHandler": true + "shareHandlerPath": "/share/" } diff --git a/pkg/serverconfig/testdata/with_blog.json b/pkg/serverconfig/testdata/with_blog.json index f0f83ea6e..49e83cd8a 100644 --- a/pkg/serverconfig/testdata/with_blog.json +++ b/pkg/serverconfig/testdata/with_blog.json @@ -15,5 +15,5 @@ } }, "replicateTo": [], - "shareHandler": true + "shareHandlerPath": "/share/" } diff --git a/pkg/serverconfig/testdata/with_gallery.json b/pkg/serverconfig/testdata/with_gallery.json index 71cb1ea72..2e1b9dcd4 100644 --- a/pkg/serverconfig/testdata/with_gallery.json +++ b/pkg/serverconfig/testdata/with_gallery.json @@ -15,5 +15,5 @@ } }, "replicateTo": [], - "shareHandler": true + "shareHandlerPath": "/share/" } diff --git a/website/content/docs/server-config b/website/content/docs/server-config index 675cf4888..324312abd 100644 --- a/website/content/docs/server-config +++ b/website/content/docs/server-config @@ -33,7 +33,8 @@ web browser and restart the server.

  • identity: your GPG fingerprint. A keypair is created for new users on start, but this may be changed if you know what you're doing.
  • identitySecretRing: your GnuPG secret keyring file. A new keyring is created on start for new users, but may be changed if you know what you're doing.
  • listen: The port (like "80" or ":80") or IP & port (like "10.0.0.2:8080") to listen for HTTP(s) connections on.
  • -
  • shareHandler: if "true", the server's sharing functionality is enabled, letting your friends have access to any content you've specifically shared.
  • +
  • shareHandler: if true, the server's sharing functionality is enabled, letting your friends have access to any content you've specifically shared. Its URL prefix path defaults to "/share/".
  • +
  • shareHandlerPath: Optional. If non-empty, it specifies the URL prefix path to the share handler, and the shareHandler value is ignored (i.e the share handler is enabled). Example: "/public/".
  • runIndex: defaults to true. If "false", no search, no UI, no indexing. (These can be controlled at a more granular level by writing a low-level config file)
  • sourceRoot: Optional. If non-empty, it specifies the path to an alternative Camlistore source tree, in order to override the embedded UI and/or Closure resources. The UI files will be expected in <sourceRoot>/server/camlistored/ui and the Closure library in <sourceRoot>/third_party/closure/lib.