1 /* 2 Copyright 2014 The Perkeep Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package serverconfig provides types related to the server configuration file. 18 package serverconfig // import "perkeep.org/pkg/types/serverconfig" 19 20 import ( 21 "encoding/json" 22 ) 23 24 // Config holds the values from the JSON (high-level) server config 25 // file that is exposed to users (and is by default at 26 // osutil.UserServerConfigPath). From this simpler configuration, a 27 // complete, low-level one, is generated by 28 // serverinit.genLowLevelConfig, and used to configure the various 29 // Perkeep components. 30 type Config struct { 31 Auth string `json:"auth"` // auth scheme and values (ex: userpass:foo:bar). 32 BaseURL string `json:"baseURL,omitempty"` // Base URL the server advertises. For when behind a proxy. 33 Listen string `json:"listen"` // address (of the form host|ip:port) on which the server will listen on. 34 35 Identity string `json:"identity"` // GPG identity. 36 IdentitySecretRing string `json:"identitySecretRing"` // path to the secret ring file. 37 38 // alternative source tree, to override the embedded ui and/or closure resources. 39 // If non empty, the ui files will be expected at 40 // sourceRoot + "/server/perkeepd/ui" and the closure library at 41 // sourceRoot + "/clients/web/embed/closure/lib" 42 // Also used by the publish handler. 43 SourceRoot string `json:"sourceRoot,omitempty"` 44 45 // OwnerName is the full name of this Perkeep instance. Currently unused. 46 OwnerName string `json:"ownerName,omitempty"` 47 48 // Blob storage. 49 MemoryStorage bool `json:"memoryStorage,omitempty"` // do not store anything (blobs or queues) on localdisk, use memory instead. 50 BlobPath string `json:"blobPath,omitempty"` // path to the directory containing the blobs. 51 PackBlobs bool `json:"packBlobs,omitempty"` // use "diskpacked" instead of the default filestorage. (exclusive with PackRelated) 52 PackRelated bool `json:"packRelated,omitempty"` // use "blobpacked" instead of the default storage (exclusive with PackBlobs) 53 S3 string `json:"s3,omitempty"` // Amazon S3 credentials: access_key_id:secret_access_key:bucket[/optional/dir][:hostname]. 54 B2 string `json:"b2,omitempty"` // Backblaze B2 credentials: account_id:application_key:bucket[/optional/dir]. 55 GoogleCloudStorage string `json:"googlecloudstorage,omitempty"` // Google Cloud credentials: clientId:clientSecret:refreshToken:bucket[/optional/dir] or ":bucket[/optional/dir/]" for auto on GCE 56 GoogleDrive string `json:"googledrive,omitempty"` // Google Drive credentials: clientId:clientSecret:refreshToken:parentId. 57 ShareHandler bool `json:"shareHandler,omitempty"` // enable the share handler. If true, and shareHandlerPath is empty then shareHandlerPath will default to "/share/" when generating the low-level config. 58 ShareHandlerPath string `json:"shareHandlerPath,omitempty"` // URL prefix for the share handler. If set, overrides shareHandler. 59 60 // HTTPS. 61 HTTPS bool `json:"https,omitempty"` // enable HTTPS. 62 HTTPSCert string `json:"httpsCert,omitempty"` // path to the HTTPS certificate file. 63 HTTPSKey string `json:"httpsKey,omitempty"` // path to the HTTPS key file. 64 65 // Index. 66 RunIndex invertedBool `json:"runIndex,omitempty"` // if logically false: no search, no UI, etc. 67 CopyIndexToMemory invertedBool `json:"copyIndexToMemory,omitempty"` // copy disk-based index to memory on start-up. 68 MemoryIndex bool `json:"memoryIndex,omitempty"` // use memory-only indexer. 69 70 // DBName is the optional name of the index database for MySQL, PostgreSQL, MongoDB. 71 // If empty, DBUnique is used as part of the database name. 72 DBName string `json:"dbname,omitempty"` 73 74 // DBUnique optionally provides a unique value to differentiate databases on a 75 // DBMS shared by multiple Perkeep instances. It should not contain spaces or 76 // punctuation. If empty, Identity is used instead. If the latter is absent, the 77 // current username (provided by the operating system) is used instead. For the 78 // index database, DBName takes priority. 79 DBUnique string `json:"dbUnique,omitempty"` 80 LevelDB string `json:"levelDB,omitempty"` // path to the levelDB directory, for indexing with github.com/syndtr/goleveldb. 81 KVFile string `json:"kvIndexFile,omitempty"` // path to the kv file, for indexing with modernc.org/kv. 82 MySQL string `json:"mysql,omitempty"` // MySQL credentials (username@host:password), for indexing with MySQL. 83 Mongo string `json:"mongo,omitempty"` // MongoDB credentials ([username:password@]host), for indexing with MongoDB. 84 PostgreSQL string `json:"postgres,omitempty"` // PostgreSQL credentials (username@host:password), for indexing with PostgreSQL. 85 SQLite string `json:"sqlite,omitempty"` // path to the SQLite file, for indexing with SQLite. 86 87 ReplicateTo []interface{} `json:"replicateTo,omitempty"` // NOOP for now. 88 // Publish maps a URL prefix path used as a root for published paths (a.k.a. a camliRoot path), to the configuration of the publish handler that serves all the published paths under this root. 89 Publish map[string]*Publish `json:"publish,omitempty"` 90 ScanCab *ScanCab `json:"scancab,omitempty"` // Scanning cabinet app configuration. 91 92 // TODO(mpl): map of importers instead? 93 Flickr string `json:"flickr,omitempty"` // flicker importer. 94 Picasa string `json:"picasa,omitempty"` // picasa importer. 95 Instapaper string `json:"instapaper,omitempty"` // instapaper importer. 96 } 97 98 // App holds the common configuration values for apps and the app handler. 99 // See https://perkeep.org/doc/app-environment 100 type App struct { 101 // Listen is the address (of the form host|ip:port) on which the app 102 // will listen. It defines CAMLI_APP_LISTEN. 103 // If empty, the default is the concatenation of the Perkeep server's 104 // Listen host part, and a random port. 105 Listen string `json:"listen,omitempty"` 106 107 // BackendURL is the URL of the application's process, always ending in a 108 // trailing slash. It is the URL that the app handler will proxy to when 109 // getting requests for the concerned app. 110 // If empty, the default is the concatenation of the Perkeep server's BaseURL 111 // scheme, the Perkeep server's BaseURL host part, and the port of Listen. 112 BackendURL string `json:"backendURL,omitempty"` 113 114 // APIHost is URL prefix of the Perkeep server which the app should 115 // use to make API calls. It defines CAMLI_API_HOST. 116 // If empty, the default is the Perkeep server's BaseURL, with a 117 // trailing slash appended. 118 APIHost string `json:"apiHost,omitempty"` 119 120 // HTTPSCert is the path to the HTTPS certificate file. If not set, and 121 // Perkeep is using HTTPS, the app should try to use Perkeep's Let's 122 // Encrypt cache (assuming it runs on the same host). 123 HTTPSCert string `json:"httpsCert,omitempty"` 124 HTTPSKey string `json:"httpsKey,omitempty"` // path to the HTTPS key file. 125 } 126 127 // Publish holds the server configuration values specific to a publisher, i.e. to a publish prefix. 128 type Publish struct { 129 // Program is the server app program to run as the publisher. 130 // Defaults to "publisher". 131 Program string `json:"program"` 132 133 *App // Common apps and app handler configuration. 134 135 // CamliRoot value that defines our root permanode for this 136 // publisher. The root permanode is used as the root for all the 137 // paths served by this publisher. 138 CamliRoot string `json:"camliRoot"` 139 140 // GoTemplate is the name of the Go template file used by this 141 // publisher to represent the data. This file should live in 142 // app/publisher/. 143 GoTemplate string `json:"goTemplate"` 144 145 // CacheRoot is the path that will be used as the root for the 146 // caching blobserver (for images). No caching if empty. 147 // An example value is Config.BlobPath + "/cache". 148 CacheRoot string `json:"cacheRoot,omitempty"` 149 150 // SourceRoot optionally defines the directory where to look for some resources 151 // such as HTML templates, as well as javascript, and CSS files. The 152 // default is to use the resources embedded in the publisher binary, found 153 // in the publisher app source directory. 154 SourceRoot string `json:"sourceRoot,omitempty"` 155 } 156 157 // ScanCab holds the server configuration values specific to a scanning cabinet 158 // app. Please note that the scanning cabinet app is still experimental and is 159 // subject to change. 160 type ScanCab struct { 161 // Program is the server app program to run as the scanning cabinet. 162 // Defaults to "scanningcabinet". 163 Program string `json:"program"` 164 165 // Prefix is the URL path prefix where the scanning cabinet app handler is mounted 166 // on Perkeep. 167 // It always ends with a trailing slash. Examples: "/scancab/", "/scanning/". 168 Prefix string `json:"prefix"` 169 170 // TODO(mpl): maybe later move Auth to type App. For now just in ScanCab as 171 // publisher does not support any auth. Should be trivial to add though. 172 173 // Auth is the authentication scheme and values to access the app. 174 // It defaults to the server config auth. 175 // Common uses are HTTP basic auth: "userpass:foo:bar", or no authentication: 176 // "none". See https://perkeep.org/pkg/auth for other schemes. 177 Auth string `json:"auth"` 178 179 // App is for the common apps and app handler configuration. 180 *App 181 } 182 183 // invertedBool is a bool that marshals to and from JSON with the opposite of its in-memory value. 184 type invertedBool bool 185 186 func (ib invertedBool) MarshalJSON() ([]byte, error) { 187 return json.Marshal(!bool(ib)) 188 } 189 190 func (ib *invertedBool) UnmarshalJSON(b []byte) error { 191 var bo bool 192 if err := json.Unmarshal(b, &bo); err != nil { 193 return err 194 } 195 *ib = invertedBool(!bo) 196 return nil 197 } 198 199 // Get returns the logical value of ib. 200 func (ib invertedBool) Get() bool { 201 return !bool(ib) 202 } 203 204 // Owner holds the search handler's owner configuration. 205 type Owner struct { 206 // Identity is the GPG identifier of the user. 207 // It should be 16-characters hex (e.g. "2931A67C26F5ABDA") 208 Identity string `json:"identity"` 209 // SecringFile is the go4.org/wkfs path to the GPG secret ring file. 210 SecringFile string `json:"secring"` 211 }