-
Notifications
You must be signed in to change notification settings - Fork 171
/
naming.go
384 lines (342 loc) · 12.5 KB
/
naming.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
* Copyright (c) 2019-2021. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
package common
import (
"runtime"
"strconv"
"time"
hashiversion "github.com/hashicorp/go-version"
"go.uber.org/zap/zapcore"
)
// Various custom types internally used by Pydio.
type (
ServiceType string
ServiceTag string
ServiceName string
LogConfigType string
)
// Defines all constants for services names.
const (
ServiceNats = "nats"
ServiceLog = "log"
ServiceConfig = "config"
ServiceInstall = "install"
ServiceUpdate = "update"
ServiceHealthCheck = "healthcheck"
ServiceBroker = "broker"
ServiceRegistry = "registry"
ServiceTagBroker = "broker"
ServiceTagData = "data"
ServiceTagDatasource = "datasource"
ServiceTagDiscovery = "discovery"
ServiceTagFrontend = "frontend"
ServiceTagGateway = "gateway"
ServiceTagIdm = "idm"
ServiceTagScheduler = "scheduler"
ServiceAcl = "acl"
ServiceShare = "share"
ServiceRole = "role"
ServiceUser = "user"
ServiceAuth = "auth"
ServiceOAuth = "oauth"
ServiceToken = "token"
ServiceWorkspace = "workspace"
ServicePolicy = "policy"
ServiceGraph = "graph"
ServiceUserMeta = "user-meta"
ServiceUserKey = "user-key"
ServiceTree = "tree"
ServiceMeta = "meta"
ServiceEncKey = "data-key"
ServiceSearch = "search"
ServiceChanges = "changes"
ServiceSync = "sync"
ServiceTemplates = "templates"
ServiceActivity = "activity"
ServiceMailer = "mailer"
ServiceWebSocket = "websocket"
ServiceChat = "chat"
ServiceFrontend = "frontend"
ServiceFrontStatics = "statics"
ServiceTimer = "timer"
ServiceJobs = "jobs"
ServiceTasks = "tasks"
ServiceVersions = "versions"
ServiceDocStore = "docstore"
ServiceMetrics = "metrics"
ServicePprof = "pprof"
ServiceData_ = "data."
ServiceDataIndex = ServiceData_ + "index"
ServiceDataObjects = ServiceData_ + "objects"
ServiceDataObjectsPeer = ServiceData_ + "objects.peer"
ServiceDataSync = ServiceData_ + "sync"
ServiceDataIndex_ = ServiceDataIndex + "."
ServiceDataObjects_ = ServiceDataObjects + "."
ServiceDataSync_ = ServiceDataSync + "."
ServiceGrpcNamespace_ = "pydio.grpc."
ServiceWebNamespace_ = "pydio.web."
ServiceRestNamespace_ = "pydio.rest."
ServiceGatewayNamespace_ = "pydio.gateway."
ServiceTestNamespace_ = "pydio.test."
ServiceStorageNamespace_ = "pydio.storage."
ServiceGenericNamespace_ = "pydio.generic."
ServiceGatewayProxy = ServiceGatewayNamespace_ + "proxy"
ServiceGatewayData = ServiceGatewayNamespace_ + "data"
ServiceGatewayGrpc = ServiceGatewayNamespace_ + "grpc"
ServiceGatewayGrpcClear = ServiceGatewayNamespace_ + "grpc.clear"
ServiceGatewayDav = ServiceGatewayNamespace_ + "dav"
ServiceGatewayWopi = ServiceGatewayNamespace_ + "wopi"
ServiceMicroApi = ServiceGatewayNamespace_ + "rest"
)
// Define constants for Event Bus Topics
const (
TopicRegistryCommand = "topic.pydio.registry.command"
TopicServiceRegistration = "topic.pydio.service.registration"
TopicProxyRestarted = "topic.pydio.proxy.restarted"
TopicServiceStop = "topic.pydio.service.stop" // @todo This is used in "stop" command but probably out-of-date
EventTypeServiceRegistered = "registered"
EventTypeServiceUnregistered = "unregistered"
EventHeaderServiceRegisterService = "x-service-name"
EventHeaderServiceRegisterPeer = "x-service-peer"
EventTypeDebugPrintInternals = "debug"
TopicInstallSuccessEvent = "topic.pydio.install.success"
TopicReloadAssets = "topic.pydio.assets.reload"
TopicIndexChanges = "topic.pydio.index.nodes.changes"
TopicTreeChanges = "topic.pydio.tree.nodes.changes"
TopicMetaChanges = "topic.pydio.meta.nodes.changes"
TopicTimerEvent = "topic.pydio.meta.timer.event"
TopicJobConfigEvent = "topic.pydio.jobconfig.event"
TopicJobTaskEvent = "topic.pydio.tasks.event"
TopicIdmEvent = "topic.pydio.idm.event"
TopicIdmPolicies = "topic.pydio.idm.policies"
TopicActivityEvent = "topic.pydio.activity.event"
TopicChatEvent = "topic.pydio.chat.event"
TopicDatasourceEvent = "topic.pydio.datasource.event"
TopicIndexEvent = "topic.pydio.index.event"
TopicLogLevelEvent = "topic.pydio.log-level.event"
)
// Define constants for metadata and fixed datasources
const (
MetaNamespaceDatasourceName = "pydio:meta-data-source-name"
MetaNamespaceDatasourcePath = "pydio:meta-data-source-path"
MetaNamespaceDatasourceInternal = "pydio:meta-data-source-internal"
MetaNamespaceNodeTestLocalFolder = "pydio:test:local-folder-storage"
MetaNamespaceRecycleRestore = "pydio:recycle_restore"
MetaNamespaceNodeName = "name"
MetaNamespaceMime = "mime"
MetaNamespaceHash = "x-cells-hash"
MetaNamespaceVersionId = "versionId"
MetaNamespaceVersionDesc = "versionDescription"
MetaNamespaceGeoLocation = "GeoLocation"
MetaNamespaceContents = "Contents"
RecycleBinName = "recycle_bin"
PydioThumbstoreNamespace = "pydio-thumbstore"
PydioDocstoreBinariesNamespace = "pydio-binaries"
PydioVersionsNamespace = "versions-store"
)
// Additional constants for authentication/authorization aspects
const (
PydioContextUserKey = "X-Pydio-User"
PydioSystemUsername = "pydio.system.user"
PydioS3AnonUsername = "pydio.anon.user"
PydioSyncHiddenFile = ".pydio"
XAmzMetaClearSize = "X-Amz-Meta-Pydio-Clear-Size"
XAmzMetaClearSizeUnknown = "unknown"
XAmzMetaNodeUuid = "X-Amz-Meta-Pydio-Node-Uuid"
XAmzMetaContentMd5 = "X-Amz-Meta-Content-Md5"
XAmzMetaDirective = "X-Amz-Metadata-Directive"
XPydioClientUuid = "X-Pydio-Client-Uuid"
XPydioSessionUuid = "X-Pydio-Session"
XPydioIndexationSessionUuid = "X-Pydio-Indexation-Session"
XPydioFrontendSessionUuid = "X-Pydio-Frontend-Session"
XPydioMoveUuid = "X-Pydio-Move"
XContentType = "Content-Type"
SyncSessionClose_ = "close-"
SyncSessionPrefixCopy = "copy-"
SyncSessionPrefixMove = "move-"
PydioProfileAdmin = "admin"
PydioProfileStandard = "standard"
PydioProfileShared = "shared"
PydioProfileAnon = "anon"
KeyringMasterKey = "keyring.master"
MetaFlagReadonly = "node_readonly"
MetaFlagLevelReadonly = "level_readonly"
MetaFlagEncrypted = "datasource_encrypted"
MetaFlagVersioning = "datasource_versioning"
MetaFlagIndexed = "datasource_node_indexed"
MetaFlagHashingVersion = "hashing_version"
MetaFlagWorkspaceRoot = "ws_root"
MetaFlagWorkspaceScope = "ws_scope"
MetaFlagWorkspaceSyncable = "ws_syncable"
MetaFlagWorkspacePermissions = "ws_permissions"
MetaFlagWorkspaceLabel = "ws_label"
MetaFlagWorkspaceDescription = "ws_description"
MetaFlagWorkspaceSlug = "ws_slug"
MetaFlagWorkspaceUuid = "ws_uuid"
MetaFlagVirtualRoot = "virtual_root"
MetaFlagBucket = "ds_bucket"
NodeFlagEtagTemporary = "temporary"
MetaFlagCellNode = "CellNode"
MetaFlagChildrenCount = "ChildrenCount"
MetaFlagChildrenFolders = "ChildrenFolders"
MetaFlagChildrenFiles = "ChildrenFiles"
MetaFlagRecursiveCount = "RecursiveCount"
MetaFlagWorkspaceSkipRecycle = "ws_skip_recycle"
MetaFlagContentLock = "content_lock"
MetaFlagWorkspacesShares = "workspaces_shares"
MetaFlagUserSubscriptions = "user_subscriptions"
MetaFlagDocumentContentHit = "document_content_hit"
MetaFlagWorkspaceRepoId = "repository_id"
MetaFlagWorkspaceRepoDisplay = "repository_display"
MetaFlagWorkspaceEventId = "EventWorkspaceId"
IdmWsInternalHomepageID = "homepage"
IdmWsInternalSettingsID = "settings"
IdmWsInternalDirectoryID = "directory"
)
var (
S3GatewayRootUser = "gateway"
S3GatewayRootPassword = "gatewaysecret"
S3GatewayDefaultRegion = "us-east-1"
XSpecialPydioHeaders = []string{
XPydioClientUuid,
XPydioSessionUuid,
XPydioIndexationSessionUuid,
XPydioFrontendSessionUuid,
XPydioMoveUuid,
}
IdmWsInternalReservedSlugs = map[string]string{
IdmWsInternalSettingsID: "settings",
IdmWsInternalHomepageID: "welcome",
IdmWsInternalDirectoryID: "directory",
}
)
// DocStore constants for StoreID's
const (
DocStoreIdSelections = "selections"
DocStoreIdVirtualNodes = "virtualnodes"
DocStoreIdVersioningPolicies = "versioningPolicies"
DocStoreIdShares = "share"
DocStoreIdResetPassKeys = "resetPasswordKeys"
)
// Define constants for Loggging configuration
const (
LogConfigConsole LogConfigType = "console"
LogConfigProduction LogConfigType = "production"
)
// Main code information. Set by the go linker in the resulting binary when doing 'make main'
var (
BuildStamp string
BuildRevision string
version = "4.0.0"
)
// Package info. Initialised by main.
var (
PackageType string
PackageLabel string
)
// Update Server default values.
var (
UpdateDefaultChannel = "stable"
UpdateDefaultServerUrl = "https://updatecells.pydio.com/"
UpdateDefaultPublicKey = `-----BEGIN PUBLIC KEY-----\nMIIBCgKCAQEAwh/ofjZTITlQc4h/qDZMR3RquBxlG7UTunDKLG85JQwRtU7EL90v\nlWxamkpSQsaPeqho5Q6OGkhJvZkbWsLBJv6LZg+SBhk6ZSPxihD+Kfx8AwCcWZ46\nDTpKpw+mYnkNH1YEAedaSfJM8d1fyU1YZ+WM3P/j1wTnUGRgebK9y70dqZEo2dOK\nn98v3kBP7uEN9eP/wig63RdmChjCpPb5gK1/WKnY4NFLQ60rPAOBsXurxikc9N/3\nEvbIB/1vQNqm7yEwXk8LlOC6Fp8W/6A0DIxr2BnZAJntMuH2ulUfhJgw0yJalMNF\nDR0QNzGVktdLOEeSe8BSrASe9uZY2SDbTwIDAQAB\n-----END PUBLIC KEY-----`
)
// Let's Encrypt Default CA URLs
var (
DefaultCaUrl = "https://acme-v02.api.letsencrypt.org/directory"
DefaultCaStagingUrl = "https://acme-staging-v02.api.letsencrypt.org/directory"
)
// Logging Levels.
var (
LogConfig LogConfigType
LogLevel zapcore.Level
LogToFile bool
LogFileDefaultValue = "true"
)
var (
// PydioUserProfiles order reflects the level of authorizations
PydioUserProfiles = []string{
PydioProfileAnon,
PydioProfileShared,
PydioProfileStandard,
PydioProfileAdmin,
}
)
const (
DefaultRouteREST = "/a"
)
// Version returns the current code version as an object.
func Version() *hashiversion.Version {
v, _ := hashiversion.NewVersion(version)
return v
}
// MustLogFileDefaultValue parses associated variable to boolean.
func MustLogFileDefaultValue() bool {
if v, e := strconv.ParseBool(LogFileDefaultValue); e == nil {
return v
}
return true
}
// IsXSpecialPydioHeader checks if headerName is in XSpecialPydioHeaders slice.
func IsXSpecialPydioHeader(headerName string) bool {
for _, hh := range XSpecialPydioHeaders {
if hh == headerName {
return true
}
}
return false
}
// IsReservedIdmWorkspaceSlug checks if a slug is already reserved for usage
func IsReservedIdmWorkspaceSlug(slug string) bool {
for _, s := range IdmWsInternalReservedSlugs {
if s == slug {
return true
}
}
return false
}
// CellsVersion contains version information for the current running binary
type CellsVersion struct {
//Distribution string
PackageLabel string
Version string
BuildTime string
GitCommit string
OS string
Arch string
GoVersion string
}
// MakeCellsVersion builds a CellsVersion object filled with data
func MakeCellsVersion() *CellsVersion {
var t time.Time
if BuildStamp != "" {
t, _ = time.Parse("2006-01-02T15:04:05", BuildStamp)
} else {
t = time.Now()
}
return &CellsVersion{
PackageLabel: PackageLabel,
Version: Version().String(),
BuildTime: t.Format(time.RFC822Z),
GitCommit: BuildRevision,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
GoVersion: runtime.Version(),
}
}