From 5a29959a0bfe26fa468101207c0343cd283f737f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 9 Nov 2021 10:06:08 +0000 Subject: [PATCH 01/84] add spaces registry, drop mount_path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- storage/pkg/command/gateway.go | 46 ++++++++++++++++++++++-- storage/pkg/command/storagehome.go | 1 - storage/pkg/command/storagemetadata.go | 1 - storage/pkg/command/storagepubliclink.go | 2 -- storage/pkg/command/storageusers.go | 1 - 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 63f158da1ec..07611acebd0 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -181,7 +181,11 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg "drivers": map[string]interface{}{ "static": map[string]interface{}{ "home_provider": cfg.Reva.StorageRegistry.HomeProvider, - "rules": rules(cfg, logger), + "rules": simpleRules(cfg, logger), + }, + "spaces": map[string]interface{}{ + "home_provider": cfg.Reva.StorageRegistry.HomeProvider, + "rules": spacesRules(cfg, logger), }, }, }, @@ -191,7 +195,7 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg return rcfg } -func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} { +func simpleRules(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} { // if a list of rules is given it overrides the generated rules from below if len(cfg.Reva.StorageRegistry.Rules) > 0 { @@ -233,6 +237,44 @@ func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interfac return ret } +func spacesRules(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} { + + // if a list of rules is given it overrides the generated rules from below + if len(cfg.Reva.StorageRegistry.Rules) > 0 { + rules := map[string]map[string]interface{}{} + for i := range cfg.Reva.StorageRegistry.Rules { + parts := strings.SplitN(cfg.Reva.StorageRegistry.Rules[i], "=", 2) + rules[parts[0]] = map[string]interface{}{"address": parts[1]} + } + return rules + } + + // check if the rules have to be read from a json file + if cfg.Reva.StorageRegistry.JSON != "" { + data, err := ioutil.ReadFile(cfg.Reva.StorageRegistry.JSON) + if err != nil { + logger.Error().Err(err).Msg("Failed to read storage registry rules from JSON file: " + cfg.Reva.StorageRegistry.JSON) + return nil + } + var rules map[string]map[string]interface{} + if err = json.Unmarshal(data, &rules); err != nil { + logger.Error().Err(err).Msg("Failed to unmarshal storage registry rules") + return nil + } + return rules + } + + // generate rules based on default config + return map[string]map[string]interface{}{ + "/personal": {"address": cfg.Reva.StorageUsers.Endpoint}, + // public link storage returns the mount id of the actual storage + "/public": {"address": cfg.Reva.StoragePublicLink.Endpoint}, + // TODO shares + //"/shares": {"address": cfg.Reva.StoragePublicLink.Endpoint}, + // medatada storage not part of the global namespace + } +} + func mimetypes(cfg *config.Config, logger log.Logger) []map[string]interface{} { type mimeTypeConfig struct { diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storagehome.go index bbeca4d7058..247bf8552f1 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -106,7 +106,6 @@ func storageHomeConfigFromStruct(c *cli.Context, cfg *config.Config) map[string] "storageprovider": map[string]interface{}{ "driver": cfg.Reva.StorageHome.Driver, "drivers": storagedrivers.HomeDrivers(cfg), - "mount_path": cfg.Reva.StorageHome.MountPath, "mount_id": cfg.Reva.StorageHome.MountID, "expose_data_server": cfg.Reva.StorageHome.ExposeDataServer, "data_server_url": cfg.Reva.StorageHome.DataServerURL, diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 1c84313a37e..f77d1eca32e 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -132,7 +132,6 @@ func storageMetadataFromStruct(c *cli.Context, cfg *config.Config) map[string]in }, "services": map[string]interface{}{ "storageprovider": map[string]interface{}{ - "mount_path": "/meta", "driver": cfg.Reva.StorageMetadata.Driver, "drivers": storagedrivers.MetadataDrivers(cfg), "data_server_url": cfg.Reva.StorageMetadata.DataServerURL, diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index edd73c9ad5d..22591f9b2e0 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -101,8 +101,6 @@ func storagePublicLinkConfigFromStruct(c *cli.Context, cfg *config.Config) map[s }, "services": map[string]interface{}{ "publicstorageprovider": map[string]interface{}{ - "mount_path": cfg.Reva.StoragePublicLink.MountPath, - "mount_id": cfg.Reva.StoragePublicLink.MountID, "gateway_addr": cfg.Reva.Gateway.Endpoint, }, "authprovider": map[string]interface{}{ diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 7bb7aa6c0ff..9d671949a23 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -106,7 +106,6 @@ func storageUsersConfigFromStruct(c *cli.Context, cfg *config.Config) map[string "storageprovider": map[string]interface{}{ "driver": cfg.Reva.StorageUsers.Driver, "drivers": storagedrivers.UserDrivers(cfg), - "mount_path": cfg.Reva.StorageUsers.MountPath, "mount_id": cfg.Reva.StorageUsers.MountID, "expose_data_server": cfg.Reva.StorageUsers.ExposeDataServer, "data_server_url": cfg.Reva.StorageUsers.DataServerURL, From b63b322b6f0abfd2cb4e6a7f3359b6517e56f723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 9 Nov 2021 10:06:58 +0000 Subject: [PATCH 02/84] drop /meta mount prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- accounts/pkg/storage/cs3.go | 10 +++++----- ocis-pkg/indexer/index/cs3/autoincrement.go | 8 ++++++-- ocis-pkg/indexer/index/cs3/helper.go | 2 +- ocis-pkg/indexer/index/cs3/non_unique.go | 10 +++++----- ocis-pkg/indexer/index/cs3/non_unique_test.go | 2 +- ocis-pkg/indexer/index/cs3/unique.go | 7 ++++++- ocis-pkg/indexer/index/cs3/unique_test.go | 4 ++-- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index f628f538f49..4acebf46209 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -102,7 +102,7 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err err res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join(storageMountPath, accountsFolder), + Path: path.Join("/", accountsFolder), }, }) if err != nil { @@ -142,7 +142,7 @@ func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) { resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: path.Join(storageMountPath, accountsFolder, id), + Path: path.Join("/", accountsFolder, id), }, }) @@ -197,7 +197,7 @@ func (r CS3Repo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error) res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join(storageMountPath, groupsFolder), + Path: path.Join("/", groupsFolder), }, }) if err != nil { @@ -237,7 +237,7 @@ func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) { resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: path.Join(storageMountPath, groupsFolder, id), + Path: path.Join("/", groupsFolder, id), }, }) @@ -295,7 +295,7 @@ func (r CS3Repo) makeRootDirIfNotExist(ctx context.Context, folder string) error // MakeDirIfNotExist will create a root node in the metadata storage. Requires an authenticated context. func MakeDirIfNotExist(ctx context.Context, sp provider.ProviderAPIClient, folder string) error { var rootPathRef = &provider.Reference{ - Path: path.Join(storageMountPath, folder), + Path: path.Join("/", folder), } resp, err := sp.Stat(ctx, &provider.StatRequest{ diff --git a/ocis-pkg/indexer/index/cs3/autoincrement.go b/ocis-pkg/indexer/index/cs3/autoincrement.go index 1b223a7ed0b..99a34242855 100644 --- a/ocis-pkg/indexer/index/cs3/autoincrement.go +++ b/ocis-pkg/indexer/index/cs3/autoincrement.go @@ -162,7 +162,7 @@ func (idx *Autoincrement) Remove(id string, v string) error { return err } - deletePath := path.Join("/meta", idx.indexRootDir, v) + deletePath := path.Join("/", idx.indexRootDir, v) resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ Path: deletePath, @@ -203,7 +203,7 @@ func (idx *Autoincrement) Search(pattern string) ([]string, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/meta", idx.indexRootDir), + Path: path.Join("/", idx.indexRootDir), }, }) @@ -301,7 +301,11 @@ func (idx *Autoincrement) next() (int, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ +<<<<<<< HEAD Path: path.Join("/meta", idx.indexRootDir), //TODO: +======= + Path: path.Join("/", idx.indexRootDir), +>>>>>>> 7a5fb4c2e (drop /meta mount prefix) }, }) diff --git a/ocis-pkg/indexer/index/cs3/helper.go b/ocis-pkg/indexer/index/cs3/helper.go index 4cf5109d332..127b839c155 100644 --- a/ocis-pkg/indexer/index/cs3/helper.go +++ b/ocis-pkg/indexer/index/cs3/helper.go @@ -12,7 +12,7 @@ import ( func deleteIndexRoot(ctx context.Context, storageProvider provider.ProviderAPIClient, indexRootDir string) error { res, err := storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: path.Join("/meta", indexRootDir), + Path: path.Join("/", indexRootDir), }, }) if err != nil { diff --git a/ocis-pkg/indexer/index/cs3/non_unique.go b/ocis-pkg/indexer/index/cs3/non_unique.go index 8976199fc53..7b8f566278c 100644 --- a/ocis-pkg/indexer/index/cs3/non_unique.go +++ b/ocis-pkg/indexer/index/cs3/non_unique.go @@ -119,7 +119,7 @@ func (idx *NonUnique) Lookup(v string) ([]string, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/meta", idx.indexRootDir, v), + Path: path.Join("/", idx.indexRootDir, v), }, }) @@ -172,7 +172,7 @@ func (idx *NonUnique) Remove(id string, v string) error { return err } - deletePath := path.Join("/meta", idx.indexRootDir, v, id) + deletePath := path.Join("/", idx.indexRootDir, v, id) resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ Path: deletePath, @@ -187,7 +187,7 @@ func (idx *NonUnique) Remove(id string, v string) error { return &idxerrs.NotFoundErr{TypeName: idx.typeName, Key: idx.indexBy, Value: v} } - toStat := path.Join("/meta", idx.indexRootDir, v) + toStat := path.Join("/", idx.indexRootDir, v) lcResp, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ Path: toStat, @@ -198,7 +198,7 @@ func (idx *NonUnique) Remove(id string, v string) error { } if len(lcResp.Infos) == 0 { - deletePath = path.Join("/meta", idx.indexRootDir, v) + deletePath = path.Join("/", idx.indexRootDir, v) _, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ Path: deletePath, @@ -245,7 +245,7 @@ func (idx *NonUnique) Search(pattern string) ([]string, error) { matches := make([]string, 0) res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/meta", idx.indexRootDir), + Path: path.Join("/", idx.indexRootDir), }, }) diff --git a/ocis-pkg/indexer/index/cs3/non_unique_test.go b/ocis-pkg/indexer/index/cs3/non_unique_test.go index c98a1574a10..3dd0527daff 100644 --- a/ocis-pkg/indexer/index/cs3/non_unique_test.go +++ b/ocis-pkg/indexer/index/cs3/non_unique_test.go @@ -32,7 +32,7 @@ package cs3 // sut := NewNonUniqueIndexWithOptions( // option.WithTypeName(GetTypeFQN(User{})), // option.WithIndexBy("UserName"), -// option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/meta")), +// option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/")), // option.WithDataDir(cfg.Repo.Disk.Path), // option.WithDataURL(cfg.Repo.CS3.DataURL), // option.WithDataPrefix(cfg.Repo.CS3.DataPrefix), diff --git a/ocis-pkg/indexer/index/cs3/unique.go b/ocis-pkg/indexer/index/cs3/unique.go index 7114d4fcf5c..2c92da64158 100644 --- a/ocis-pkg/indexer/index/cs3/unique.go +++ b/ocis-pkg/indexer/index/cs3/unique.go @@ -162,7 +162,12 @@ func (idx *Unique) Remove(id string, v string) error { return err } +<<<<<<< HEAD deletePath := path.Join("/meta", idx.indexRootDir, v) +======= + deletePath := path.Join("/", idx.indexRootDir, v) + ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t) +>>>>>>> 7a5fb4c2e (drop /meta mount prefix) resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ Path: deletePath, @@ -212,7 +217,7 @@ func (idx *Unique) Search(pattern string) ([]string, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/meta", idx.indexRootDir), + Path: path.Join("/", idx.indexRootDir), }, }) diff --git a/ocis-pkg/indexer/index/cs3/unique_test.go b/ocis-pkg/indexer/index/cs3/unique_test.go index a1a7edb7da0..6c282e9085f 100644 --- a/ocis-pkg/indexer/index/cs3/unique_test.go +++ b/ocis-pkg/indexer/index/cs3/unique_test.go @@ -32,7 +32,7 @@ package cs3 // sut := NewUniqueIndexWithOptions( // option.WithTypeName(GetTypeFQN(User{})), // option.WithIndexBy("UserName"), -// option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/meta")), +// option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/")), // option.WithDataDir(cfg.Repo.Disk.Path), // option.WithDataURL(cfg.Repo.CS3.DataURL), // option.WithDataPrefix(cfg.Repo.CS3.DataPrefix), @@ -82,7 +82,7 @@ package cs3 // sut := NewUniqueIndexWithOptions( // option.WithTypeName(GetTypeFQN(User{})), // option.WithIndexBy("UserName"), -// option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/meta")), +// option.WithFilesDir(path.Join(cfg.Repo.Disk.Path, "/")), // option.WithDataDir(cfg.Repo.Disk.Path), // option.WithDataURL(cfg.Repo.CS3.DataURL), // option.WithDataPrefix(cfg.Repo.CS3.DataPrefix), From c36e99895bbfd25b923455feb6b1c16f0f52e576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 16 Nov 2021 14:20:23 +0000 Subject: [PATCH 03/84] update to latest changes in reva PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../{storagehome.go => storageshares.go} | 13 +- ocis/pkg/runtime/service/service.go | 2 +- storage/pkg/command/frontend.go | 1 + storage/pkg/command/gateway.go | 70 +++------- storage/pkg/command/root.go | 2 +- storage/pkg/command/storagedrivers/home.go | 132 ------------------ storage/pkg/command/storagepubliclink.go | 1 + .../{storagehome.go => storageshares.go} | 77 ++++------ storage/pkg/config/config.go | 114 +++++---------- thumbnails/pkg/thumbnail/imgsource/cs3.go | 2 +- 10 files changed, 92 insertions(+), 322 deletions(-) rename ocis/pkg/command/{storagehome.go => storageshares.go} (56%) delete mode 100644 storage/pkg/command/storagedrivers/home.go rename storage/pkg/command/{storagehome.go => storageshares.go} (51%) diff --git a/ocis/pkg/command/storagehome.go b/ocis/pkg/command/storageshares.go similarity index 56% rename from ocis/pkg/command/storagehome.go rename to ocis/pkg/command/storageshares.go index bae5c1c674a..fe38a4bc36a 100644 --- a/ocis/pkg/command/storagehome.go +++ b/ocis/pkg/command/storageshares.go @@ -10,23 +10,22 @@ import ( "github.com/urfave/cli/v2" ) -// StorageHomeCommand is the entrypoint for the storage-home command. -func StorageHomeCommand(cfg *config.Config) *cli.Command { +// StorageSharesCommand is the entrypoint for the storage-shares command. +func StorageSharesCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "storage-home", - Usage: "Start storage and data provider for /home mount", + Name: "storage-shares", + Usage: "Start storage and data provider for /home/Shares mount", Category: "Extensions", - //Flags: flagset.StorageHomeWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, Action: func(c *cli.Context) error { - origCmd := command.StorageHome(cfg.Storage) + origCmd := command.StorageShares(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } func init() { - register.AddCommand(StorageHomeCommand) + register.AddCommand(StorageSharesCommand) } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 2def6c6f572..c66b07c3fd1 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -108,8 +108,8 @@ func NewService(options ...Option) (*Service, error) { s.ServicesRegistry["storage-authbasic"] = storage.NewAuthBasic s.ServicesRegistry["storage-authbearer"] = storage.NewAuthBearer s.ServicesRegistry["storage-authmachine"] = storage.NewAuthMachine - s.ServicesRegistry["storage-home"] = storage.NewStorageHome s.ServicesRegistry["storage-users"] = storage.NewStorageUsers + s.ServicesRegistry["storage-shares"] = storage.NewStorageShares s.ServicesRegistry["storage-public-link"] = storage.NewStoragePublicLink s.ServicesRegistry["storage-appprovider"] = storage.NewAppProvider diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 4161d35c9fc..5041a36fc06 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -199,6 +199,7 @@ func frontendConfigFromStruct(c *cli.Context, cfg *config.Config, filesCfg map[s "resource_info_cache_ttl": cfg.Reva.Frontend.OCSResourceInfoCacheTTL, "prefix": cfg.Reva.Frontend.OCSPrefix, "additional_info_attribute": cfg.Reva.Frontend.OCSAdditionalInfoAttribute, + "machine_auth_apikey": "change-me-please", // FIXME make configurable "cache_warmup_driver": cfg.Reva.Frontend.OCSCacheWarmupDriver, "cache_warmup_drivers": map[string]interface{}{ "cbox": map[string]interface{}{ diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 07611acebd0..89cf297747e 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -179,10 +179,6 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg "storageregistry": map[string]interface{}{ "driver": cfg.Reva.StorageRegistry.Driver, "drivers": map[string]interface{}{ - "static": map[string]interface{}{ - "home_provider": cfg.Reva.StorageRegistry.HomeProvider, - "rules": simpleRules(cfg, logger), - }, "spaces": map[string]interface{}{ "home_provider": cfg.Reva.StorageRegistry.HomeProvider, "rules": spacesRules(cfg, logger), @@ -195,48 +191,6 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg return rcfg } -func simpleRules(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} { - - // if a list of rules is given it overrides the generated rules from below - if len(cfg.Reva.StorageRegistry.Rules) > 0 { - rules := map[string]map[string]interface{}{} - for i := range cfg.Reva.StorageRegistry.Rules { - parts := strings.SplitN(cfg.Reva.StorageRegistry.Rules[i], "=", 2) - rules[parts[0]] = map[string]interface{}{"address": parts[1]} - } - return rules - } - - // check if the rules have to be read from a json file - if cfg.Reva.StorageRegistry.JSON != "" { - data, err := ioutil.ReadFile(cfg.Reva.StorageRegistry.JSON) - if err != nil { - logger.Error().Err(err).Msg("Failed to read storage registry rules from JSON file: " + cfg.Reva.StorageRegistry.JSON) - return nil - } - var rules map[string]map[string]interface{} - if err = json.Unmarshal(data, &rules); err != nil { - logger.Error().Err(err).Msg("Failed to unmarshal storage registry rules") - return nil - } - return rules - } - - // generate rules based on default config - ret := map[string]map[string]interface{}{ - cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint}, - cfg.Reva.StorageHome.AlternativeID: {"address": cfg.Reva.StorageHome.Endpoint}, - cfg.Reva.StorageUsers.MountPath: {"address": cfg.Reva.StorageUsers.Endpoint}, - cfg.Reva.StorageUsers.MountID + ".*": {"address": cfg.Reva.StorageUsers.Endpoint}, - cfg.Reva.StoragePublicLink.MountPath: {"address": cfg.Reva.StoragePublicLink.Endpoint}, - cfg.Reva.StoragePublicLink.MountID: {"address": cfg.Reva.StoragePublicLink.Endpoint}, - // public link storage returns the mount id of the actual storage - // medatada storage not part of the global namespace - } - - return ret -} - func spacesRules(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} { // if a list of rules is given it overrides the generated rules from below @@ -266,11 +220,27 @@ func spacesRules(cfg *config.Config, logger log.Logger) map[string]map[string]in // generate rules based on default config return map[string]map[string]interface{}{ - "/personal": {"address": cfg.Reva.StorageUsers.Endpoint}, + "/home": { + "address": cfg.Reva.StorageUsers.Endpoint, + "space_type": "personal", + "space_owner_self": true, + }, + "/home/Shares": { + "address": cfg.Reva.StorageShares.Endpoint, + "space_type": "share", + "path_template": "/home/Shares/{{.Name}}", + }, + "/users": { + "address": cfg.Reva.StorageUsers.Endpoint, + "space_type": "personal", + "path_template": "/users/{{.Owner.Id.OpaqueId}}", + }, // public link storage returns the mount id of the actual storage - "/public": {"address": cfg.Reva.StoragePublicLink.Endpoint}, - // TODO shares - //"/shares": {"address": cfg.Reva.StoragePublicLink.Endpoint}, + "/public": { + "address": cfg.Reva.StoragePublicLink.Endpoint, + "space_type": "public", + "path_template": "/public", + }, // medatada storage not part of the global namespace } } diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 4ac235e8cc2..7de4fc5aa56 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -36,8 +36,8 @@ func Execute(cfg *config.Config) error { AuthBasic(cfg), AuthBearer(cfg), Sharing(cfg), - StorageHome(cfg), StorageUsers(cfg), + StorageShares(cfg), StoragePublicLink(cfg), StorageMetadata(cfg), Health(cfg), diff --git a/storage/pkg/command/storagedrivers/home.go b/storage/pkg/command/storagedrivers/home.go deleted file mode 100644 index 1f41bdb1267..00000000000 --- a/storage/pkg/command/storagedrivers/home.go +++ /dev/null @@ -1,132 +0,0 @@ -package storagedrivers - -import ( - "github.com/owncloud/ocis/storage/pkg/config" -) - -func HomeDrivers(cfg *config.Config) map[string]interface{} { - return map[string]interface{}{ - "eos": map[string]interface{}{ - "namespace": cfg.Reva.UserStorage.EOS.Root, - "shadow_namespace": cfg.Reva.UserStorage.EOS.ShadowNamespace, - "uploads_namespace": cfg.Reva.UserStorage.EOS.UploadsNamespace, - "share_folder": cfg.Reva.UserStorage.EOS.ShareFolder, - "eos_binary": cfg.Reva.UserStorage.EOS.EosBinary, - "xrdcopy_binary": cfg.Reva.UserStorage.EOS.XrdcopyBinary, - "master_url": cfg.Reva.UserStorage.EOS.MasterURL, - "slave_url": cfg.Reva.UserStorage.EOS.SlaveURL, - "cache_directory": cfg.Reva.UserStorage.EOS.CacheDirectory, - "sec_protocol": cfg.Reva.UserStorage.EOS.SecProtocol, - "keytab": cfg.Reva.UserStorage.EOS.Keytab, - "single_username": cfg.Reva.UserStorage.EOS.SingleUsername, - "enable_logging": cfg.Reva.UserStorage.EOS.EnableLogging, - "show_hidden_sys_files": cfg.Reva.UserStorage.EOS.ShowHiddenSysFiles, - "force_single_user_mode": cfg.Reva.UserStorage.EOS.ForceSingleUserMode, - "use_keytab": cfg.Reva.UserStorage.EOS.UseKeytab, - "gatewaysvc": cfg.Reva.UserStorage.EOS.GatewaySVC, - }, - "eoshome": map[string]interface{}{ - "namespace": cfg.Reva.UserStorage.EOS.Root, - "shadow_namespace": cfg.Reva.UserStorage.EOS.ShadowNamespace, - "uploads_namespace": cfg.Reva.UserStorage.EOS.UploadsNamespace, - "share_folder": cfg.Reva.UserStorage.EOS.ShareFolder, - "eos_binary": cfg.Reva.UserStorage.EOS.EosBinary, - "xrdcopy_binary": cfg.Reva.UserStorage.EOS.XrdcopyBinary, - "master_url": cfg.Reva.UserStorage.EOS.MasterURL, - "slave_url": cfg.Reva.UserStorage.EOS.SlaveURL, - "cache_directory": cfg.Reva.UserStorage.EOS.CacheDirectory, - "sec_protocol": cfg.Reva.UserStorage.EOS.SecProtocol, - "keytab": cfg.Reva.UserStorage.EOS.Keytab, - "single_username": cfg.Reva.UserStorage.EOS.SingleUsername, - "user_layout": cfg.Reva.UserStorage.EOS.UserLayout, - "enable_logging": cfg.Reva.UserStorage.EOS.EnableLogging, - "show_hidden_sys_files": cfg.Reva.UserStorage.EOS.ShowHiddenSysFiles, - "force_single_user_mode": cfg.Reva.UserStorage.EOS.ForceSingleUserMode, - "use_keytab": cfg.Reva.UserStorage.EOS.UseKeytab, - "gatewaysvc": cfg.Reva.UserStorage.EOS.GatewaySVC, - }, - "eosgrpc": map[string]interface{}{ - "namespace": cfg.Reva.UserStorage.EOS.Root, - "shadow_namespace": cfg.Reva.UserStorage.EOS.ShadowNamespace, - "share_folder": cfg.Reva.UserStorage.EOS.ShareFolder, - "eos_binary": cfg.Reva.UserStorage.EOS.EosBinary, - "xrdcopy_binary": cfg.Reva.UserStorage.EOS.XrdcopyBinary, - "master_url": cfg.Reva.UserStorage.EOS.MasterURL, - "master_grpc_uri": cfg.Reva.UserStorage.EOS.GrpcURI, - "slave_url": cfg.Reva.UserStorage.EOS.SlaveURL, - "cache_directory": cfg.Reva.UserStorage.EOS.CacheDirectory, - "sec_protocol": cfg.Reva.UserStorage.EOS.SecProtocol, - "keytab": cfg.Reva.UserStorage.EOS.Keytab, - "single_username": cfg.Reva.UserStorage.EOS.SingleUsername, - "user_layout": cfg.Reva.UserStorage.EOS.UserLayout, - "enable_logging": cfg.Reva.UserStorage.EOS.EnableLogging, - "show_hidden_sys_files": cfg.Reva.UserStorage.EOS.ShowHiddenSysFiles, - "force_single_user_mode": cfg.Reva.UserStorage.EOS.ForceSingleUserMode, - "use_keytab": cfg.Reva.UserStorage.EOS.UseKeytab, - "enable_home": true, - "gatewaysvc": cfg.Reva.UserStorage.EOS.GatewaySVC, - }, - "local": map[string]interface{}{ - "root": cfg.Reva.UserStorage.Local.Root, - "share_folder": cfg.Reva.UserStorage.Local.ShareFolder, - }, - "localhome": map[string]interface{}{ - "root": cfg.Reva.UserStorage.Local.Root, - "share_folder": cfg.Reva.UserStorage.Local.ShareFolder, - "user_layout": cfg.Reva.UserStorage.Local.UserLayout, - }, - "owncloud": map[string]interface{}{ - "datadirectory": cfg.Reva.UserStorage.OwnCloud.Root, - "upload_info_dir": cfg.Reva.UserStorage.OwnCloud.UploadInfoDir, - "share_folder": cfg.Reva.UserStorage.OwnCloud.ShareFolder, - "user_layout": cfg.Reva.UserStorage.OwnCloud.UserLayout, - "redis": cfg.Reva.UserStorage.OwnCloud.Redis, - "enable_home": true, - "scan": cfg.Reva.UserStorage.OwnCloud.Scan, - "userprovidersvc": cfg.Reva.Users.Endpoint, - }, - "owncloudsql": map[string]interface{}{ - "datadirectory": cfg.Reva.UserStorage.OwnCloudSQL.Root, - "upload_info_dir": cfg.Reva.UserStorage.OwnCloudSQL.UploadInfoDir, - "share_folder": cfg.Reva.UserStorage.OwnCloudSQL.ShareFolder, - "user_layout": cfg.Reva.UserStorage.OwnCloudSQL.UserLayout, - "enable_home": true, - "dbusername": cfg.Reva.UserStorage.OwnCloudSQL.DBUsername, - "dbpassword": cfg.Reva.UserStorage.OwnCloudSQL.DBPassword, - "dbhost": cfg.Reva.UserStorage.OwnCloudSQL.DBHost, - "dbport": cfg.Reva.UserStorage.OwnCloudSQL.DBPort, - "dbname": cfg.Reva.UserStorage.OwnCloudSQL.DBName, - "userprovidersvc": cfg.Reva.Users.Endpoint, - }, - "ocis": map[string]interface{}{ - "root": cfg.Reva.UserStorage.OCIS.Root, - "enable_home": true, - "user_layout": cfg.Reva.UserStorage.OCIS.UserLayout, - "share_folder": cfg.Reva.UserStorage.OCIS.ShareFolder, - "treetime_accounting": true, - "treesize_accounting": true, - "owner": cfg.Reva.UserStorage.OCIS.ServiceUserUUID, // the accounts service system account uuid - }, - "s3": map[string]interface{}{ - "region": cfg.Reva.UserStorage.S3.Region, - "access_key": cfg.Reva.UserStorage.S3.AccessKey, - "secret_key": cfg.Reva.UserStorage.S3.SecretKey, - "endpoint": cfg.Reva.UserStorage.S3.Endpoint, - "bucket": cfg.Reva.UserStorage.S3.Bucket, - }, - "s3ng": map[string]interface{}{ - "root": cfg.Reva.UserStorage.S3NG.Root, - "enable_home": true, - "user_layout": cfg.Reva.UserStorage.S3NG.UserLayout, - "treetime_accounting": true, - "treesize_accounting": true, - "owner": cfg.Reva.UserStorage.S3NG.ServiceUserUUID, // the accounts service system account uuid - "share_folder": cfg.Reva.UserStorage.S3NG.ShareFolder, - "s3.region": cfg.Reva.UserStorage.S3NG.Region, - "s3.access_key": cfg.Reva.UserStorage.S3NG.AccessKey, - "s3.secret_key": cfg.Reva.UserStorage.S3NG.SecretKey, - "s3.endpoint": cfg.Reva.UserStorage.S3NG.Endpoint, - "s3.bucket": cfg.Reva.UserStorage.S3NG.Bucket, - }, - } -} diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index 22591f9b2e0..0e3966b7d1f 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -101,6 +101,7 @@ func storagePublicLinkConfigFromStruct(c *cli.Context, cfg *config.Config) map[s }, "services": map[string]interface{}{ "publicstorageprovider": map[string]interface{}{ + "mount_id": cfg.Reva.StoragePublicLink.MountID, "gateway_addr": cfg.Reva.Gateway.Endpoint, }, "authprovider": map[string]interface{}{ diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storageshares.go similarity index 51% rename from storage/pkg/command/storagehome.go rename to storage/pkg/command/storageshares.go index 247bf8552f1..a239170a21c 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storageshares.go @@ -12,7 +12,6 @@ import ( "github.com/gofrs/uuid" "github.com/oklog/run" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/storage/pkg/command/storagedrivers" "github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" @@ -20,13 +19,13 @@ import ( "github.com/urfave/cli/v2" ) -// StorageHome is the entrypoint for the storage-home command. -func StorageHome(cfg *config.Config) *cli.Command { +// StorageShares is the entrypoint for the storage-shares command. +func StorageShares(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "storage-home", - Usage: "Start storage-home service", + Name: "storage-shares", + Usage: "Start storage-shares service", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg, "storage-home") + return ParseConfig(c, cfg, "storage-shares") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -40,7 +39,7 @@ func StorageHome(cfg *config.Config) *cli.Command { uuid := uuid.Must(uuid.NewV4()) pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") - rcfg := storageHomeConfigFromStruct(c, cfg) + rcfg := storageSharesConfigFromStruct(c, cfg) gr.Add(func() error { runtime.RunWithOptions( @@ -59,7 +58,7 @@ func StorageHome(cfg *config.Config) *cli.Command { debugServer, err := debug.Server( debug.Name(c.Command.Name+"-debug"), - debug.Addr(cfg.Reva.StorageHome.DebugAddr), + debug.Addr(cfg.Reva.StorageShares.DebugAddr), debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -74,7 +73,7 @@ func StorageHome(cfg *config.Config) *cli.Command { cancel() }) - if !cfg.Reva.StorageHome.Supervised { + if !cfg.Reva.StorageShares.Supervised { sync.Trap(&gr, cancel) } @@ -83,11 +82,11 @@ func StorageHome(cfg *config.Config) *cli.Command { } } -// storageHomeConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service. -func storageHomeConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} { +// storageSharesConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service. +func storageSharesConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} { rcfg := map[string]interface{}{ "core": map[string]interface{}{ - "max_cpus": cfg.Reva.StorageHome.MaxCPUs, + "max_cpus": cfg.Reva.StorageShares.MaxCPUs, "tracing_enabled": cfg.Tracing.Enabled, "tracing_endpoint": cfg.Tracing.Endpoint, "tracing_collector": cfg.Tracing.Collector, @@ -99,37 +98,17 @@ func storageHomeConfigFromStruct(c *cli.Context, cfg *config.Config) map[string] "skip_user_groups_in_token": cfg.Reva.SkipUserGroupsInToken, }, "grpc": map[string]interface{}{ - "network": cfg.Reva.StorageHome.GRPCNetwork, - "address": cfg.Reva.StorageHome.GRPCAddr, - // TODO build services dynamically + "network": cfg.Reva.StorageShares.GRPCNetwork, + "address": cfg.Reva.StorageShares.GRPCAddr, "services": map[string]interface{}{ - "storageprovider": map[string]interface{}{ - "driver": cfg.Reva.StorageHome.Driver, - "drivers": storagedrivers.HomeDrivers(cfg), - "mount_id": cfg.Reva.StorageHome.MountID, - "expose_data_server": cfg.Reva.StorageHome.ExposeDataServer, - "data_server_url": cfg.Reva.StorageHome.DataServerURL, - "tmp_folder": cfg.Reva.StorageHome.TempFolder, - }, - }, - }, - "http": map[string]interface{}{ - "network": cfg.Reva.StorageHome.HTTPNetwork, - "address": cfg.Reva.StorageHome.HTTPAddr, - // TODO build services dynamically - "services": map[string]interface{}{ - "dataprovider": map[string]interface{}{ - "prefix": cfg.Reva.StorageHome.HTTPPrefix, - "driver": cfg.Reva.StorageHome.Driver, - "drivers": storagedrivers.HomeDrivers(cfg), - "timeout": 86400, - "insecure": cfg.Reva.StorageHome.DataProvider.Insecure, - "disable_tus": false, + "sharesstorageprovider": map[string]interface{}{ + "usershareprovidersvc": cfg.Reva.Sharing.Endpoint, + "gateway_addr": cfg.Reva.Gateway.Endpoint, }, }, }, } - if cfg.Reva.StorageHome.ReadOnly { + if cfg.Reva.StorageShares.ReadOnly { gcfg := rcfg["grpc"].(map[string]interface{}) gcfg["interceptors"] = map[string]interface{}{ "readonly": map[string]interface{}{}, @@ -138,35 +117,35 @@ func storageHomeConfigFromStruct(c *cli.Context, cfg *config.Config) map[string] return rcfg } -// StorageHomeSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree. -type StorageHomeSutureService struct { +// StorageSharesSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree. +type StorageSharesSutureService struct { cfg *config.Config } -// NewStorageHomeSutureService creates a new storage.StorageHomeSutureService -func NewStorageHome(cfg *ociscfg.Config) suture.Service { +// NewStorageShares creates a new storage.StorageSharesSutureService +func NewStorageShares(cfg *ociscfg.Config) suture.Service { cfg.Storage.Commons = cfg.Commons - return StorageHomeSutureService{ + return StorageSharesSutureService{ cfg: cfg.Storage, } } -func (s StorageHomeSutureService) Serve(ctx context.Context) error { - s.cfg.Reva.StorageHome.Context = ctx +func (s StorageSharesSutureService) Serve(ctx context.Context) error { + s.cfg.Reva.StorageShares.Context = ctx f := &flag.FlagSet{} - cmdFlags := StorageHome(s.cfg).Flags + cmdFlags := StorageShares(s.cfg).Flags for k := range cmdFlags { if err := cmdFlags[k].Apply(f); err != nil { return err } } cliCtx := cli.NewContext(nil, f, nil) - if StorageHome(s.cfg).Before != nil { - if err := StorageHome(s.cfg).Before(cliCtx); err != nil { + if StorageShares(s.cfg).Before != nil { + if err := StorageShares(s.cfg).Before(cliCtx); err != nil { return err } } - if err := StorageHome(s.cfg).Action(cliCtx); err != nil { + if err := StorageShares(s.cfg).Action(cliCtx); err != nil { return err } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 0687716b316..22b502110ff 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -194,7 +194,6 @@ type DataProvider struct { type StoragePort struct { Port Driver string `ocisConfig:"driver"` - MountPath string `ocisConfig:"mount_path"` MountID string `ocisConfig:"mount_id"` AlternativeID string `ocisConfig:"alternative_id"` ExposeDataServer bool `ocisConfig:"expose_data_server"` @@ -472,7 +471,7 @@ type Reva struct { AuthMachine Port `ocisConfig:"auth_machine"` AuthMachineConfig AuthMachineConfig `ocisConfig:"auth_machine_config"` Sharing Sharing `ocisConfig:"sharing"` - StorageHome StoragePort `ocisConfig:"storage_home"` + StorageShares StoragePort `ocisConfig:"storage_shares"` StorageUsers StoragePort `ocisConfig:"storage_users"` StoragePublicLink PublicStorage `ocisConfig:"storage_public_link"` StorageMetadata StoragePort `ocisConfig:"storage_metadata"` @@ -864,7 +863,7 @@ func DefaultConfig() *Config { PublicJanitorRunInterval: 60, UserStorageMountID: "", }, - StorageHome: StoragePort{ + StorageShares: StoragePort{ Port: Port{ Endpoint: "localhost:9154", DebugAddr: "127.0.0.1:9156", @@ -873,14 +872,9 @@ func DefaultConfig() *Config { HTTPNetwork: "tcp", HTTPAddr: "127.0.0.1:9155", }, - Driver: "ocis", ReadOnly: false, - MountPath: "/home", AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - DataServerURL: "http://localhost:9155/data", - HTTPPrefix: "data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "home"), }, StorageUsers: StoragePort{ Port: Port{ @@ -891,7 +885,6 @@ func DefaultConfig() *Config { HTTPNetwork: "tcp", HTTPAddr: "127.0.0.1:9158", }, - MountPath: "/users", MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", Driver: "ocis", DataServerURL: "http://localhost:9158/data", @@ -906,8 +899,7 @@ func DefaultConfig() *Config { GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9178", }, - MountPath: "/public", - MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", + MountID: "7993447f-687f-490d-875c-ac95e89a62a4", }, PublicShareProviderAddr: "", UserProviderAddr: "", @@ -991,10 +983,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"OCIS_INSECURE", "STORAGE_METADATA_DATAPROVIDER_INSECURE"}, Destination: &cfg.Reva.StorageMetadata.DataProvider.Insecure, }, - { - EnvVars: []string{"OCIS_INSECURE", "STORAGE_HOME_DATAPROVIDER_INSECURE"}, - Destination: &cfg.Reva.StorageHome.DataProvider.Insecure, - }, { EnvVars: []string{"OCIS_INSECURE", "STORAGE_FRONTEND_APPPROVIDER_INSECURE"}, Destination: &cfg.Reva.Frontend.AppProviderInsecure, @@ -1023,10 +1011,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"STORAGE_USERS_DRIVER"}, Destination: &cfg.Reva.StorageUsers.Driver, }, - { - EnvVars: []string{"STORAGE_HOME_DRIVER"}, - Destination: &cfg.Reva.StorageHome.Driver, - }, { EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_DATADIR"}, Destination: &cfg.Reva.UserStorage.OwnCloud.Root, @@ -1412,37 +1396,21 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"STORAGE_APPPROVIDER_ENDPOINT"}, Destination: &cfg.Reva.AppProvider.Endpoint, }, - { - EnvVars: []string{"STORAGE_HOME_ENDPOINT"}, - Destination: &cfg.Reva.StorageHome.Endpoint, - }, - { - EnvVars: []string{"STORAGE_HOME_MOUNT_PATH"}, - Destination: &cfg.Reva.StorageHome.MountPath, - }, - { - EnvVars: []string{"STORAGE_HOME_MOUNT_ID"}, - Destination: &cfg.Reva.StorageHome.MountID, - }, { EnvVars: []string{"STORAGE_USERS_ENDPOINT"}, Destination: &cfg.Reva.StorageUsers.Endpoint, }, - { - EnvVars: []string{"STORAGE_USERS_MOUNT_PATH"}, - Destination: &cfg.Reva.StorageUsers.MountPath, - }, { EnvVars: []string{"STORAGE_USERS_MOUNT_ID"}, Destination: &cfg.Reva.StorageUsers.MountID, }, { - EnvVars: []string{"STORAGE_PUBLIC_LINK_ENDPOINT"}, - Destination: &cfg.Reva.StoragePublicLink.Endpoint, + EnvVars: []string{"STORAGE_SHARES_ENDPOINT"}, + Destination: &cfg.Reva.StorageShares.Endpoint, }, { - EnvVars: []string{"STORAGE_PUBLIC_LINK_MOUNT_PATH"}, - Destination: &cfg.Reva.StoragePublicLink.MountPath, + EnvVars: []string{"STORAGE_PUBLIC_LINK_ENDPOINT"}, + Destination: &cfg.Reva.StoragePublicLink.Endpoint, }, // groups @@ -1689,48 +1657,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Reva.Sharing.UserSQLName, }, - // storage home - { - EnvVars: []string{"STORAGE_HOME_DEBUG_ADDR"}, - Destination: &cfg.Reva.StorageHome.DebugAddr, - }, - { - EnvVars: []string{"STORAGE_HOME_GRPC_NETWORK"}, - Destination: &cfg.Reva.StorageHome.GRPCNetwork, - }, - { - EnvVars: []string{"STORAGE_HOME_GRPC_ADDR"}, - Destination: &cfg.Reva.StorageHome.GRPCAddr, - }, - { - EnvVars: []string{"STORAGE_HOME_HTTP_NETWORK"}, - Destination: &cfg.Reva.StorageHome.HTTPNetwork, - }, - { - EnvVars: []string{"STORAGE_HOME_HTTP_ADDR"}, - Destination: &cfg.Reva.StorageHome.HTTPAddr, - }, - { - EnvVars: []string{"OCIS_STORAGE_READ_ONLY", "STORAGE_HOME_READ_ONLY"}, - Destination: &cfg.Reva.StorageHome.ReadOnly, - }, - { - EnvVars: []string{"STORAGE_HOME_EXPOSE_DATA_SERVER"}, - Destination: &cfg.Reva.StorageHome.ExposeDataServer, - }, - { - EnvVars: []string{"STORAGE_HOME_DATA_SERVER_URL"}, - Destination: &cfg.Reva.StorageHome.DataServerURL, - }, - { - EnvVars: []string{"STORAGE_HOME_HTTP_PREFIX"}, - Destination: &cfg.Reva.StorageHome.HTTPPrefix, - }, - { - EnvVars: []string{"STORAGE_HOME_TMP_FOLDER"}, - Destination: &cfg.Reva.StorageHome.TempFolder, - }, - // storage metadata { EnvVars: []string{"STORAGE_METADATA_DEBUG_ADDR"}, @@ -1821,6 +1747,32 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Reva.StorageUsers.TempFolder, }, + // storage shares + { + EnvVars: []string{"STORAGE_SHARES_DEBUG_ADDR"}, + Destination: &cfg.Reva.StorageShares.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_SHARES_GRPC_NETWORK"}, + Destination: &cfg.Reva.StorageShares.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_SHARES_GRPC_ADDR"}, + Destination: &cfg.Reva.StorageShares.GRPCAddr, + }, + { + EnvVars: []string{"STORAGE_SHARES_HTTP_NETWORK"}, + Destination: &cfg.Reva.StorageShares.HTTPNetwork, + }, + { + EnvVars: []string{"STORAGE_SHARES_HTTP_ADDR"}, + Destination: &cfg.Reva.StorageShares.HTTPAddr, + }, + { + EnvVars: []string{"OCIS_STORAGE_READ_ONLY", "STORAGE_SHARES_READ_ONLY"}, + Destination: &cfg.Reva.StorageShares.ReadOnly, + }, + // tracing { EnvVars: []string{"OCIS_TRACING_ENABLED", "STORAGE_TRACING_ENABLED"}, diff --git a/thumbnails/pkg/thumbnail/imgsource/cs3.go b/thumbnails/pkg/thumbnail/imgsource/cs3.go index 07271397885..9cf3db58abd 100644 --- a/thumbnails/pkg/thumbnail/imgsource/cs3.go +++ b/thumbnails/pkg/thumbnail/imgsource/cs3.go @@ -58,7 +58,7 @@ func (s CS3) Get(ctx context.Context, path string) (io.ReadCloser, error) { } var ep, tk string for _, p := range rsp.Protocols { - if p.Protocol == "simple" { + if p.Protocol == "spaces" { ep, tk = p.DownloadEndpoint, p.Token } } From de7620af98a2ec3fdd36bc90a83cd0597a3fb89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 16 Nov 2021 22:42:28 +0000 Subject: [PATCH 04/84] get rid of /home mount point MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- storage/pkg/command/gateway.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 89cf297747e..c4b6aa9fa87 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -220,20 +220,15 @@ func spacesRules(cfg *config.Config, logger log.Logger) map[string]map[string]in // generate rules based on default config return map[string]map[string]interface{}{ - "/home": { - "address": cfg.Reva.StorageUsers.Endpoint, - "space_type": "personal", - "space_owner_self": true, - }, - "/home/Shares": { - "address": cfg.Reva.StorageShares.Endpoint, - "space_type": "share", - "path_template": "/home/Shares/{{.Name}}", - }, "/users": { "address": cfg.Reva.StorageUsers.Endpoint, "space_type": "personal", - "path_template": "/users/{{.Owner.Id.OpaqueId}}", + "path_template": "/users/{{.Space.Owner.Id.OpaqueId}}", + }, + "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}": { + "address": cfg.Reva.StorageShares.Endpoint, + "space_type": "share", + "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", }, // public link storage returns the mount id of the actual storage "/public": { From 5ec72daaeb512efbc83c62e13fc098f4f49ed5a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 17 Nov 2021 14:09:09 +0000 Subject: [PATCH 05/84] adapt metadata storage to make use the spaces datatx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- accounts/pkg/storage/cs3.go | 75 ++++++++++++++++--- ocis-pkg/indexer/index/cs3/autoincrement.go | 26 ++++--- .../indexer/index/cs3/data_provider_client.go | 47 ++++++++++++ ocis-pkg/indexer/index/cs3/helper.go | 10 ++- ocis-pkg/indexer/index/cs3/non_unique.go | 39 ++++++++-- ocis-pkg/indexer/index/cs3/unique.go | 25 ++++--- ocis-pkg/metadata_storage/metadata_storage.go | 19 +++-- 7 files changed, 196 insertions(+), 45 deletions(-) create mode 100644 ocis-pkg/indexer/index/cs3/data_provider_client.go diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index 4acebf46209..f6cb9f84d7a 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -7,10 +7,13 @@ import ( "path/filepath" "github.com/cs3org/reva/pkg/auth/scope" + "github.com/cs3org/reva/pkg/errtypes" + "github.com/cs3org/reva/pkg/utils" user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" revactx "github.com/cs3org/reva/pkg/ctx" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/token" @@ -32,6 +35,7 @@ type CS3Repo struct { tm token.Manager storageProvider provider.ProviderAPIClient metadataStorage metadatastorage.MetadataStorage + space *provider.StorageSpace } // NewCS3Repo creates a new cs3 repo @@ -54,12 +58,60 @@ func NewCS3Repo(cfg *config.Config) (Repo, error) { return nil, err } - return CS3Repo{ + repo := CS3Repo{ cfg: cfg, tm: tokenManager, storageProvider: client, metadataStorage: ms, - }, nil + } + + if err := repo.Init(); err != nil { + return nil, err + } + + return &repo, nil +} + +// init creates the metadata space +func (r *CS3Repo) Init() (err error) { + ctx := context.Background() + ctx, err = r.getAuthenticatedContext(ctx) + if err != nil { + return err + } + // FIXME change CS3 api to allow sending a space id + cssr, err := r.storageProvider.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{ + Opaque: &typesv1beta1.Opaque{ + Map: map[string]*typesv1beta1.OpaqueEntry{ + "spaceid": { + Decoder: "plain", + Value: []byte(r.cfg.ServiceUser.UUID), + }, + }, + }, + Owner: &user.User{ + Id: &user.UserId{ + OpaqueId: r.cfg.ServiceUser.UUID, + }, + Groups: []string{}, + UidNumber: r.cfg.ServiceUser.UID, + GidNumber: r.cfg.ServiceUser.GID, + }, + Name: "Metadata", + Type: "metadata", + }) + switch { + case err != nil: + return err + case cssr.Status.Code == v1beta11.Code_CODE_OK: + // continue + case cssr.Status.Code != v1beta11.Code_CODE_ALREADY_EXISTS: + // continue + default: + return errtypes.NewErrtypeFromStatus(cssr.Status) + } + r.metadataStorage.SpaceRoot = cssr.StorageSpace.Root + return nil } // WriteAccount writes an account via cs3 and modifies the provided account (e.g. with a generated id). @@ -102,7 +154,8 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err err res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/", accountsFolder), + ResourceId: r.space.Root, + Path: utils.MakeRelativePath(accountsFolder), }, }) if err != nil { @@ -142,7 +195,8 @@ func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) { resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: path.Join("/", accountsFolder, id), + ResourceId: r.space.Root, + Path: utils.MakeRelativePath(filepath.Join("/", accountsFolder, id)), }, }) @@ -197,7 +251,8 @@ func (r CS3Repo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error) res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/", groupsFolder), + ResourceId: r.space.Root, + Path: utils.MakeRelativePath(groupsFolder), }, }) if err != nil { @@ -237,7 +292,8 @@ func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) { resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: path.Join("/", groupsFolder, id), + ResourceId: r.space.Root, + Path: utils.MakeRelativePath(filepath.Join(groupsFolder, id)), }, }) @@ -289,13 +345,14 @@ func (r CS3Repo) groupURL(id string) string { } func (r CS3Repo) makeRootDirIfNotExist(ctx context.Context, folder string) error { - return MakeDirIfNotExist(ctx, r.storageProvider, folder) + return MakeDirIfNotExist(ctx, r.storageProvider, r.space.Root, folder) } // MakeDirIfNotExist will create a root node in the metadata storage. Requires an authenticated context. -func MakeDirIfNotExist(ctx context.Context, sp provider.ProviderAPIClient, folder string) error { +func MakeDirIfNotExist(ctx context.Context, sp provider.ProviderAPIClient, root *provider.ResourceId, folder string) error { var rootPathRef = &provider.Reference{ - Path: path.Join("/", folder), + ResourceId: root, + Path: utils.MakeRelativePath(folder), } resp, err := sp.Stat(ctx, &provider.StatRequest{ diff --git a/ocis-pkg/indexer/index/cs3/autoincrement.go b/ocis-pkg/indexer/index/cs3/autoincrement.go index 99a34242855..263a24896a3 100644 --- a/ocis-pkg/indexer/index/cs3/autoincrement.go +++ b/ocis-pkg/indexer/index/cs3/autoincrement.go @@ -19,6 +19,7 @@ import ( "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/token" "github.com/cs3org/reva/pkg/token/manager/jwt" + "github.com/cs3org/reva/pkg/utils" "google.golang.org/grpc/metadata" "github.com/owncloud/ocis/ocis-pkg/indexer/index" @@ -165,7 +166,11 @@ func (idx *Autoincrement) Remove(id string, v string) error { deletePath := path.Join("/", idx.indexRootDir, v) resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: deletePath, + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(deletePath), }, }) @@ -203,7 +208,11 @@ func (idx *Autoincrement) Search(pattern string) ([]string, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/", idx.indexRootDir), + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(idx.indexRootDir), }, }) @@ -289,7 +298,6 @@ func (idx *Autoincrement) makeDirIfNotExists(folder string) error { if err != nil { return err } - return storage.MakeDirIfNotExist(ctx, idx.storageProvider, folder) } @@ -301,11 +309,11 @@ func (idx *Autoincrement) next() (int, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ -<<<<<<< HEAD - Path: path.Join("/meta", idx.indexRootDir), //TODO: -======= - Path: path.Join("/", idx.indexRootDir), ->>>>>>> 7a5fb4c2e (drop /meta mount prefix) + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(idx.indexRootDir), }, }) @@ -352,5 +360,5 @@ func (idx *Autoincrement) Delete() error { return err } - return deleteIndexRoot(ctx, idx.storageProvider, idx.indexRootDir) + return deleteIndexRoot(ctx, idx.storageProvider, idx.cs3conf.ServiceUser.UUID, idx.indexRootDir) } diff --git a/ocis-pkg/indexer/index/cs3/data_provider_client.go b/ocis-pkg/indexer/index/cs3/data_provider_client.go new file mode 100644 index 00000000000..baec5ddcb91 --- /dev/null +++ b/ocis-pkg/indexer/index/cs3/data_provider_client.go @@ -0,0 +1,47 @@ +package cs3 + +import ( + "io" + "net/http" + "path/filepath" + "strings" +) + +type dataProviderClient struct { + client http.Client + spaceid string + baseURL string +} + +func (d dataProviderClient) put(url string, body io.Reader, token string) (*http.Response, error) { + req, err := http.NewRequest(http.MethodPut, singleJoiningSlash(d.baseURL, filepath.Join("spaces", d.spaceid+"!"+d.spaceid, url)), body) + if err != nil { + return nil, err + } + + req.Header.Add("x-access-token", token) + return d.client.Do(req) +} + +func (d dataProviderClient) get(url string, token string) (*http.Response, error) { + req, err := http.NewRequest(http.MethodGet, singleJoiningSlash(d.baseURL, filepath.Join("spaces", d.spaceid+"!"+d.spaceid, url)), nil) + if err != nil { + return nil, err + } + + req.Header.Add("x-access-token", token) + return d.client.Do(req) +} + +// TODO: this is copied from proxy. Find a better solution or move it to ocis-pkg +func singleJoiningSlash(a, b string) string { + aslash := strings.HasSuffix(a, "/") + bslash := strings.HasPrefix(b, "/") + switch { + case aslash && bslash: + return a + b[1:] + case !aslash && !bslash: + return a + "/" + b + } + return a + b +} diff --git a/ocis-pkg/indexer/index/cs3/helper.go b/ocis-pkg/indexer/index/cs3/helper.go index 127b839c155..5024557e8cf 100644 --- a/ocis-pkg/indexer/index/cs3/helper.go +++ b/ocis-pkg/indexer/index/cs3/helper.go @@ -3,16 +3,20 @@ package cs3 import ( "context" "fmt" - "path" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/pkg/utils" ) -func deleteIndexRoot(ctx context.Context, storageProvider provider.ProviderAPIClient, indexRootDir string) error { +func deleteIndexRoot(ctx context.Context, storageProvider provider.ProviderAPIClient, spaceid, indexRootDir string) error { res, err := storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: path.Join("/", indexRootDir), + ResourceId: &provider.ResourceId{ + StorageId: spaceid, + OpaqueId: spaceid, + }, + Path: utils.MakeRelativePath(indexRootDir), }, }) if err != nil { diff --git a/ocis-pkg/indexer/index/cs3/non_unique.go b/ocis-pkg/indexer/index/cs3/non_unique.go index 7b8f566278c..a839d05a62d 100644 --- a/ocis-pkg/indexer/index/cs3/non_unique.go +++ b/ocis-pkg/indexer/index/cs3/non_unique.go @@ -15,6 +15,7 @@ import ( "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/token" "github.com/cs3org/reva/pkg/token/manager/jwt" + "github.com/cs3org/reva/pkg/utils" idxerrs "github.com/owncloud/ocis/ocis-pkg/indexer/errors" "github.com/owncloud/ocis/ocis-pkg/indexer/index" "github.com/owncloud/ocis/ocis-pkg/indexer/option" @@ -119,7 +120,11 @@ func (idx *NonUnique) Lookup(v string) ([]string, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/", idx.indexRootDir, v), + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(path.Join("/", idx.indexRootDir, v)), }, }) @@ -175,7 +180,11 @@ func (idx *NonUnique) Remove(id string, v string) error { deletePath := path.Join("/", idx.indexRootDir, v, id) resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: deletePath, + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(deletePath), }, }) @@ -190,7 +199,11 @@ func (idx *NonUnique) Remove(id string, v string) error { toStat := path.Join("/", idx.indexRootDir, v) lcResp, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: toStat, + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(toStat), }, }) if err != nil { @@ -201,7 +214,11 @@ func (idx *NonUnique) Remove(id string, v string) error { deletePath = path.Join("/", idx.indexRootDir, v) _, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: deletePath, + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(deletePath), }, }) if err != nil { @@ -245,7 +262,11 @@ func (idx *NonUnique) Search(pattern string) ([]string, error) { matches := make([]string, 0) res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/", idx.indexRootDir), + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(idx.indexRootDir), }, }) @@ -266,7 +287,11 @@ func (idx *NonUnique) Search(pattern string) ([]string, error) { for i := range foldersMatched { res, _ := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: foldersMatched[i], + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(foldersMatched[i]), }, }) @@ -356,5 +381,5 @@ func (idx *NonUnique) Delete() error { return err } - return deleteIndexRoot(ctx, idx.storageProvider, idx.indexRootDir) + return deleteIndexRoot(ctx, idx.storageProvider, idx.cs3conf.ServiceUser.UUID, idx.indexRootDir) } diff --git a/ocis-pkg/indexer/index/cs3/unique.go b/ocis-pkg/indexer/index/cs3/unique.go index 2c92da64158..0ba6760dd99 100644 --- a/ocis-pkg/indexer/index/cs3/unique.go +++ b/ocis-pkg/indexer/index/cs3/unique.go @@ -15,6 +15,7 @@ import ( "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/token" "github.com/cs3org/reva/pkg/token/manager/jwt" + "github.com/cs3org/reva/pkg/utils" idxerrs "github.com/owncloud/ocis/ocis-pkg/indexer/errors" "github.com/owncloud/ocis/ocis-pkg/indexer/index" "github.com/owncloud/ocis/ocis-pkg/indexer/option" @@ -162,15 +163,14 @@ func (idx *Unique) Remove(id string, v string) error { return err } -<<<<<<< HEAD - deletePath := path.Join("/meta", idx.indexRootDir, v) -======= deletePath := path.Join("/", idx.indexRootDir, v) - ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t) ->>>>>>> 7a5fb4c2e (drop /meta mount prefix) resp, err := idx.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - Path: deletePath, + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(deletePath), }, }) @@ -217,7 +217,11 @@ func (idx *Unique) Search(pattern string) ([]string, error) { res, err := idx.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - Path: path.Join("/", idx.indexRootDir), + ResourceId: &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, + Path: utils.MakeRelativePath(idx.indexRootDir), }, }) @@ -304,7 +308,10 @@ func (idx *Unique) makeDirIfNotExists(folder string) error { if err != nil { return err } - return storage.MakeDirIfNotExist(ctx, idx.storageProvider, folder) + return storage.MakeDirIfNotExist(ctx, idx.storageProvider, &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, folder) } func (idx *Unique) getAuthenticatedContext(ctx context.Context) (context.Context, error) { @@ -323,5 +330,5 @@ func (idx *Unique) Delete() error { return err } - return deleteIndexRoot(ctx, idx.storageProvider, idx.indexRootDir) + return deleteIndexRoot(ctx, idx.storageProvider, idx.cs3conf.ServiceUser.UUID, idx.indexRootDir) } diff --git a/ocis-pkg/metadata_storage/metadata_storage.go b/ocis-pkg/metadata_storage/metadata_storage.go index bb7527426ab..5a7a5dd4c2b 100644 --- a/ocis-pkg/metadata_storage/metadata_storage.go +++ b/ocis-pkg/metadata_storage/metadata_storage.go @@ -36,17 +36,19 @@ func NewMetadataStorage(providerAddr string) (s MetadataStorage, err error) { type MetadataStorage struct { storageProvider provider.ProviderAPIClient dataGatewayClient *http.Client + SpaceRoot *provider.ResourceId } -func (r MetadataStorage) SimpleUpload(ctx context.Context, uploadpath string, content []byte) error { +func (ms MetadataStorage) SimpleUpload(ctx context.Context, uploadpath string, content []byte) error { ref := provider.InitiateFileUploadRequest{ Ref: &provider.Reference{ - Path: path.Join(storageMountPath, uploadpath), + ResourceId: ms.SpaceRoot, + Path: path.Join(storageMountPath, uploadpath), }, } - res, err := r.storageProvider.InitiateFileUpload(ctx, &ref) + res, err := ms.storageProvider.InitiateFileUpload(ctx, &ref) if err != nil { return err } @@ -70,7 +72,7 @@ func (r MetadataStorage) SimpleUpload(ctx context.Context, uploadpath string, co md, _ := metadata.FromOutgoingContext(ctx) req.Header.Add(revactx.TokenHeader, md.Get(revactx.TokenHeader)[0]) - resp, err := r.dataGatewayClient.Do(req) + resp, err := ms.dataGatewayClient.Do(req) if err != nil { return err } @@ -80,14 +82,15 @@ func (r MetadataStorage) SimpleUpload(ctx context.Context, uploadpath string, co return nil } -func (r MetadataStorage) SimpleDownload(ctx context.Context, downloadpath string) (content []byte, err error) { +func (ms MetadataStorage) SimpleDownload(ctx context.Context, downloadpath string) (content []byte, err error) { ref := provider.InitiateFileDownloadRequest{ Ref: &provider.Reference{ - Path: path.Join(storageMountPath, downloadpath), + ResourceId: ms.SpaceRoot, + Path: path.Join(storageMountPath, downloadpath), }, } - res, err := r.storageProvider.InitiateFileDownload(ctx, &ref) + res, err := ms.storageProvider.InitiateFileDownload(ctx, &ref) if err != nil { return []byte{}, err } @@ -111,7 +114,7 @@ func (r MetadataStorage) SimpleDownload(ctx context.Context, downloadpath string md, _ := metadata.FromOutgoingContext(ctx) req.Header.Add(revactx.TokenHeader, md.Get(revactx.TokenHeader)[0]) - resp, err := r.dataGatewayClient.Do(req) + resp, err := ms.dataGatewayClient.Do(req) if err != nil { return []byte{}, err } From 31bf29cb26944b3841c5845ac1b6eef484c8081b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 3 Dec 2021 07:49:40 +0000 Subject: [PATCH 06/84] update spaces config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- storage/pkg/command/gateway.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index c4b6aa9fa87..b2af4bc44e5 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -180,8 +180,8 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg "driver": cfg.Reva.StorageRegistry.Driver, "drivers": map[string]interface{}{ "spaces": map[string]interface{}{ - "home_provider": cfg.Reva.StorageRegistry.HomeProvider, - "rules": spacesRules(cfg, logger), + "home_template": cfg.Reva.StorageRegistry.HomeProvider, + "providers": spacesProviders(cfg, logger), }, }, }, @@ -191,7 +191,7 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg return rcfg } -func spacesRules(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} { +func spacesProviders(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} { // if a list of rules is given it overrides the generated rules from below if len(cfg.Reva.StorageRegistry.Rules) > 0 { @@ -220,21 +220,24 @@ func spacesRules(cfg *config.Config, logger log.Logger) map[string]map[string]in // generate rules based on default config return map[string]map[string]interface{}{ - "/users": { - "address": cfg.Reva.StorageUsers.Endpoint, + cfg.Reva.StorageUsers.Endpoint: { + "mount_path": "/users", "space_type": "personal", "path_template": "/users/{{.Space.Owner.Id.OpaqueId}}", + "description": "Personal Spaces", }, - "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}": { - "address": cfg.Reva.StorageShares.Endpoint, + cfg.Reva.StorageShares.Endpoint: { + "mount_path": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", "space_type": "share", "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", + "description": "Shares", }, // public link storage returns the mount id of the actual storage - "/public": { - "address": cfg.Reva.StoragePublicLink.Endpoint, + cfg.Reva.StoragePublicLink.Endpoint: { + "mount_path": "/public", "space_type": "public", "path_template": "/public", + "description": "Public Links", }, // medatada storage not part of the global namespace } From 550b0bbfeaa2790fa90062fbf230b5e5b3a6b853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 3 Dec 2021 10:11:19 +0000 Subject: [PATCH 07/84] reuse existing metadata storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- accounts/pkg/storage/cs3.go | 19 +++++++++---------- storage/pkg/config/config.go | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index f6cb9f84d7a..7418b608276 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -35,7 +35,6 @@ type CS3Repo struct { tm token.Manager storageProvider provider.ProviderAPIClient metadataStorage metadatastorage.MetadataStorage - space *provider.StorageSpace } // NewCS3Repo creates a new cs3 repo @@ -104,13 +103,13 @@ func (r *CS3Repo) Init() (err error) { case err != nil: return err case cssr.Status.Code == v1beta11.Code_CODE_OK: - // continue - case cssr.Status.Code != v1beta11.Code_CODE_ALREADY_EXISTS: - // continue + r.metadataStorage.SpaceRoot = cssr.StorageSpace.Root + case cssr.Status.Code == v1beta11.Code_CODE_ALREADY_EXISTS: + // TODO make CreateStorageSpace return existing space? + r.metadataStorage.SpaceRoot = &provider.ResourceId{StorageId: r.cfg.ServiceUser.UUID, OpaqueId: r.cfg.ServiceUser.UUID} default: return errtypes.NewErrtypeFromStatus(cssr.Status) } - r.metadataStorage.SpaceRoot = cssr.StorageSpace.Root return nil } @@ -154,7 +153,7 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err err res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - ResourceId: r.space.Root, + ResourceId: r.metadataStorage.SpaceRoot, Path: utils.MakeRelativePath(accountsFolder), }, }) @@ -195,7 +194,7 @@ func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) { resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - ResourceId: r.space.Root, + ResourceId: r.metadataStorage.SpaceRoot, Path: utils.MakeRelativePath(filepath.Join("/", accountsFolder, id)), }, }) @@ -251,7 +250,7 @@ func (r CS3Repo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error) res, err := r.storageProvider.ListContainer(ctx, &provider.ListContainerRequest{ Ref: &provider.Reference{ - ResourceId: r.space.Root, + ResourceId: r.metadataStorage.SpaceRoot, Path: utils.MakeRelativePath(groupsFolder), }, }) @@ -292,7 +291,7 @@ func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) { resp, err := r.storageProvider.Delete(ctx, &provider.DeleteRequest{ Ref: &provider.Reference{ - ResourceId: r.space.Root, + ResourceId: r.metadataStorage.SpaceRoot, Path: utils.MakeRelativePath(filepath.Join(groupsFolder, id)), }, }) @@ -345,7 +344,7 @@ func (r CS3Repo) groupURL(id string) string { } func (r CS3Repo) makeRootDirIfNotExist(ctx context.Context, folder string) error { - return MakeDirIfNotExist(ctx, r.storageProvider, r.space.Root, folder) + return MakeDirIfNotExist(ctx, r.storageProvider, r.metadataStorage.SpaceRoot, folder) } // MakeDirIfNotExist will create a root node in the metadata storage. Requires an authenticated context. diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 22b502110ff..7c19cbc53e7 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -585,8 +585,8 @@ func DefaultConfig() *Config { EnableMedialSearch: false, }, OCDav: OCDav{ - WebdavNamespace: "/home/", - DavFilesNamespace: "/users/", + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + DavFilesNamespace: "/users", }, Archiver: Archiver{ MaxNumFiles: 10000, @@ -751,7 +751,7 @@ func DefaultConfig() *Config { ArchiverPrefix: "archiver", DatagatewayPrefix: "data", Favorites: false, - OCDavInsecure: false, + OCDavInsecure: true, OCDavPrefix: "", OCSPrefix: "ocs", OCSSharePrefix: "/Shares", @@ -782,7 +782,7 @@ func DefaultConfig() *Config { EtagCacheTTL: 0, }, StorageRegistry: StorageRegistry{ - Driver: "static", + Driver: "spaces", HomeProvider: "/home", JSON: "", }, From f9bfc27a82b9bcd068cb62966c96166772c442ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 3 Dec 2021 10:21:21 +0000 Subject: [PATCH 08/84] replace reva in go.mod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 5 ++++- go.sum | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 4d989478e77..642913101a5 100644 --- a/go.mod +++ b/go.mod @@ -215,7 +215,6 @@ require ( github.com/sony/gobreaker v0.4.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/steveyen/gtreap v0.1.0 // indirect - github.com/studio-b12/gowebdav v0.0.0-20210917133250-a3a86976a1df // indirect github.com/tus/tusd v1.6.0 // indirect github.com/wk8/go-ordered-map v0.2.0 // indirect github.com/xanzy/ssh-agent v0.3.1 // indirect @@ -241,3 +240,7 @@ require ( stash.kopano.io/kgol/kcc-go/v5 v5.0.1 // indirect stash.kopano.io/kgol/oidc-go v0.3.2 // indirect ) + +replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211202110423-9a39aa29c2ea + +//replace github.com/cs3org/reva => ../reva diff --git a/go.sum b/go.sum index 28a54a77ad6..cddd0122b1b 100644 --- a/go.sum +++ b/go.sum @@ -227,6 +227,8 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= +github.com/butonic/reva v0.0.0-20211202110423-9a39aa29c2ea h1:MpylJKtCaMjdZj72MY6fElNnlDi0yv5xkmRVolLoJFk= +github.com/butonic/reva v0.0.0-20211202110423-9a39aa29c2ea/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -299,8 +301,6 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20211203225713-939768a1af06 h1:NP+Zvli7+9USaDss/+Ywk4KJ0H7n82UHZiU4V+x25I0= -github.com/cs3org/reva v1.16.1-0.20211203225713-939768a1af06/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= @@ -1203,7 +1203,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/studio-b12/gowebdav v0.0.0-20210917133250-a3a86976a1df h1:C+J/LwTqP8gRPt1MdSzBNZP0OYuDm5wsmDKgwpLjYzo= github.com/studio-b12/gowebdav v0.0.0-20210917133250-a3a86976a1df/go.mod h1:gCcfDlA1Y7GqOaeEKw5l9dOGx1VLdc/HuQSlQAaZ30s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= From 321f5b8b46a0fca55ebea80b9cffe12d14637643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 6 Dec 2021 15:04:13 +0000 Subject: [PATCH 09/84] use edge branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 642913101a5..208c35b4dc8 100644 --- a/go.mod +++ b/go.mod @@ -241,6 +241,4 @@ require ( stash.kopano.io/kgol/oidc-go v0.3.2 // indirect ) -replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211202110423-9a39aa29c2ea - -//replace github.com/cs3org/reva => ../reva +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211206145907-b2a9a7e46694 diff --git a/go.sum b/go.sum index cddd0122b1b..8832e2bb94f 100644 --- a/go.sum +++ b/go.sum @@ -227,8 +227,6 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/butonic/reva v0.0.0-20211202110423-9a39aa29c2ea h1:MpylJKtCaMjdZj72MY6fElNnlDi0yv5xkmRVolLoJFk= -github.com/butonic/reva v0.0.0-20211202110423-9a39aa29c2ea/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -301,6 +299,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= +github.com/cs3org/reva v1.16.1-0.20211206145907-b2a9a7e46694 h1:5dqcyv2uQe0tdpZYpM7mEhsJ0spGvr5UwAQ3Fd4aN00= +github.com/cs3org/reva v1.16.1-0.20211206145907-b2a9a7e46694/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= From b527702572cce19699f7a7138f23a827ac6c6f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 6 Dec 2021 21:10:17 +0000 Subject: [PATCH 10/84] update reva to fix metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 208c35b4dc8..0d9c0157057 100644 --- a/go.mod +++ b/go.mod @@ -241,4 +241,4 @@ require ( stash.kopano.io/kgol/oidc-go v0.3.2 // indirect ) -replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211206145907-b2a9a7e46694 +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211206210805-7ac4043bf153 diff --git a/go.sum b/go.sum index 8832e2bb94f..98bd8ab5223 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20211206145907-b2a9a7e46694 h1:5dqcyv2uQe0tdpZYpM7mEhsJ0spGvr5UwAQ3Fd4aN00= -github.com/cs3org/reva v1.16.1-0.20211206145907-b2a9a7e46694/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= +github.com/cs3org/reva v1.16.1-0.20211206210805-7ac4043bf153 h1:rufN1AuhGA7C+5CZSMFEkesSkjvCotXCj78WJFkjD0M= +github.com/cs3org/reva v1.16.1-0.20211206210805-7ac4043bf153/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= From a3702f722da27e8a81526e0ac01f244ddfa6a0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 7 Dec 2021 14:48:56 +0000 Subject: [PATCH 11/84] fix metadata for spaces registry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- accounts/pkg/storage/cs3.go | 67 +++---------------- go.mod | 2 +- go.sum | 4 +- ocis-pkg/indexer/index/cs3/autoincrement.go | 13 +++- .../indexer/index/cs3/data_provider_client.go | 47 ------------- ocis-pkg/indexer/index/cs3/non_unique.go | 13 +++- ocis-pkg/indexer/index/cs3/unique.go | 8 +++ ocis-pkg/metadata_storage/metadata_storage.go | 57 +++++++++++++--- 8 files changed, 93 insertions(+), 118 deletions(-) delete mode 100644 ocis-pkg/indexer/index/cs3/data_provider_client.go diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index 7418b608276..c50f68be52d 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -6,18 +6,15 @@ import ( "path" "path/filepath" - "github.com/cs3org/reva/pkg/auth/scope" - "github.com/cs3org/reva/pkg/errtypes" - "github.com/cs3org/reva/pkg/utils" - user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" + "github.com/cs3org/reva/pkg/auth/scope" revactx "github.com/cs3org/reva/pkg/ctx" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/token" "github.com/cs3org/reva/pkg/token/manager/jwt" + "github.com/cs3org/reva/pkg/utils" "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/proto/v0" olog "github.com/owncloud/ocis/ocis-pkg/log" @@ -25,16 +22,12 @@ import ( "google.golang.org/grpc/metadata" ) -const ( - storageMountPath = "/meta" -) - // CS3Repo provides a cs3 implementation of the Repo interface type CS3Repo struct { cfg *config.Config tm token.Manager storageProvider provider.ProviderAPIClient - metadataStorage metadatastorage.MetadataStorage + metadataStorage *metadatastorage.MetadataStorage } // NewCS3Repo creates a new cs3 repo @@ -57,60 +50,22 @@ func NewCS3Repo(cfg *config.Config) (Repo, error) { return nil, err } - repo := CS3Repo{ + r := CS3Repo{ cfg: cfg, tm: tokenManager, storageProvider: client, - metadataStorage: ms, + metadataStorage: &ms, } - if err := repo.Init(); err != nil { - return nil, err - } - - return &repo, nil -} - -// init creates the metadata space -func (r *CS3Repo) Init() (err error) { - ctx := context.Background() - ctx, err = r.getAuthenticatedContext(ctx) + ctx, err := r.getAuthenticatedContext(context.Background()) if err != nil { - return err + return nil, err } - // FIXME change CS3 api to allow sending a space id - cssr, err := r.storageProvider.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{ - Opaque: &typesv1beta1.Opaque{ - Map: map[string]*typesv1beta1.OpaqueEntry{ - "spaceid": { - Decoder: "plain", - Value: []byte(r.cfg.ServiceUser.UUID), - }, - }, - }, - Owner: &user.User{ - Id: &user.UserId{ - OpaqueId: r.cfg.ServiceUser.UUID, - }, - Groups: []string{}, - UidNumber: r.cfg.ServiceUser.UID, - GidNumber: r.cfg.ServiceUser.GID, - }, - Name: "Metadata", - Type: "metadata", - }) - switch { - case err != nil: - return err - case cssr.Status.Code == v1beta11.Code_CODE_OK: - r.metadataStorage.SpaceRoot = cssr.StorageSpace.Root - case cssr.Status.Code == v1beta11.Code_CODE_ALREADY_EXISTS: - // TODO make CreateStorageSpace return existing space? - r.metadataStorage.SpaceRoot = &provider.ResourceId{StorageId: r.cfg.ServiceUser.UUID, OpaqueId: r.cfg.ServiceUser.UUID} - default: - return errtypes.NewErrtypeFromStatus(cssr.Status) + if err := ms.Init(ctx, cfg.ServiceUser); err != nil { + return nil, err } - return nil + + return r, nil } // WriteAccount writes an account via cs3 and modifies the provided account (e.g. with a generated id). diff --git a/go.mod b/go.mod index 0d9c0157057..2565df75e35 100644 --- a/go.mod +++ b/go.mod @@ -241,4 +241,4 @@ require ( stash.kopano.io/kgol/oidc-go v0.3.2 // indirect ) -replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211206210805-7ac4043bf153 +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211207113801-1fa1ac1d3349 diff --git a/go.sum b/go.sum index 98bd8ab5223..97bb56ab011 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20211206210805-7ac4043bf153 h1:rufN1AuhGA7C+5CZSMFEkesSkjvCotXCj78WJFkjD0M= -github.com/cs3org/reva v1.16.1-0.20211206210805-7ac4043bf153/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= +github.com/cs3org/reva v1.16.1-0.20211207113801-1fa1ac1d3349 h1:nqswCeR3uzHjMAwHdCLaf27+8niLI+nS8/u749Xh0cE= +github.com/cs3org/reva v1.16.1-0.20211207113801-1fa1ac1d3349/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= diff --git a/ocis-pkg/indexer/index/cs3/autoincrement.go b/ocis-pkg/indexer/index/cs3/autoincrement.go index 263a24896a3..1c988e9768f 100644 --- a/ocis-pkg/indexer/index/cs3/autoincrement.go +++ b/ocis-pkg/indexer/index/cs3/autoincrement.go @@ -94,6 +94,14 @@ func (idx *Autoincrement) Init() error { } idx.metadataStorage = &m + ctx, err := idx.getAuthenticatedContext(context.Background()) + if err != nil { + return err + } + if err := idx.metadataStorage.Init(ctx, idx.cs3conf.ServiceUser); err != nil { + return err + } + if err := idx.makeDirIfNotExists(idx.indexBaseDir); err != nil { return err } @@ -298,7 +306,10 @@ func (idx *Autoincrement) makeDirIfNotExists(folder string) error { if err != nil { return err } - return storage.MakeDirIfNotExist(ctx, idx.storageProvider, folder) + return storage.MakeDirIfNotExist(ctx, idx.storageProvider, &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, folder) } func (idx *Autoincrement) next() (int, error) { diff --git a/ocis-pkg/indexer/index/cs3/data_provider_client.go b/ocis-pkg/indexer/index/cs3/data_provider_client.go deleted file mode 100644 index baec5ddcb91..00000000000 --- a/ocis-pkg/indexer/index/cs3/data_provider_client.go +++ /dev/null @@ -1,47 +0,0 @@ -package cs3 - -import ( - "io" - "net/http" - "path/filepath" - "strings" -) - -type dataProviderClient struct { - client http.Client - spaceid string - baseURL string -} - -func (d dataProviderClient) put(url string, body io.Reader, token string) (*http.Response, error) { - req, err := http.NewRequest(http.MethodPut, singleJoiningSlash(d.baseURL, filepath.Join("spaces", d.spaceid+"!"+d.spaceid, url)), body) - if err != nil { - return nil, err - } - - req.Header.Add("x-access-token", token) - return d.client.Do(req) -} - -func (d dataProviderClient) get(url string, token string) (*http.Response, error) { - req, err := http.NewRequest(http.MethodGet, singleJoiningSlash(d.baseURL, filepath.Join("spaces", d.spaceid+"!"+d.spaceid, url)), nil) - if err != nil { - return nil, err - } - - req.Header.Add("x-access-token", token) - return d.client.Do(req) -} - -// TODO: this is copied from proxy. Find a better solution or move it to ocis-pkg -func singleJoiningSlash(a, b string) string { - aslash := strings.HasSuffix(a, "/") - bslash := strings.HasPrefix(b, "/") - switch { - case aslash && bslash: - return a + b[1:] - case !aslash && !bslash: - return a + "/" + b - } - return a + b -} diff --git a/ocis-pkg/indexer/index/cs3/non_unique.go b/ocis-pkg/indexer/index/cs3/non_unique.go index a839d05a62d..3e0f1a222dc 100644 --- a/ocis-pkg/indexer/index/cs3/non_unique.go +++ b/ocis-pkg/indexer/index/cs3/non_unique.go @@ -96,6 +96,14 @@ func (idx *NonUnique) Init() error { } idx.metadataStorage = &m + ctx, err := idx.getAuthenticatedContext(context.Background()) + if err != nil { + return err + } + if err := idx.metadataStorage.Init(ctx, idx.cs3conf.ServiceUser); err != nil { + return err + } + if err := idx.makeDirIfNotExists(idx.indexBaseDir); err != nil { return err } @@ -328,7 +336,10 @@ func (idx *NonUnique) makeDirIfNotExists(folder string) error { if err != nil { return err } - return storage.MakeDirIfNotExist(ctx, idx.storageProvider, folder) + return storage.MakeDirIfNotExist(ctx, idx.storageProvider, &provider.ResourceId{ + StorageId: idx.cs3conf.ServiceUser.UUID, + OpaqueId: idx.cs3conf.ServiceUser.UUID, + }, folder) } func (idx *NonUnique) createSymlink(oldname, newname string) error { diff --git a/ocis-pkg/indexer/index/cs3/unique.go b/ocis-pkg/indexer/index/cs3/unique.go index 0ba6760dd99..8bde7778f87 100644 --- a/ocis-pkg/indexer/index/cs3/unique.go +++ b/ocis-pkg/indexer/index/cs3/unique.go @@ -91,6 +91,14 @@ func (idx *Unique) Init() error { } idx.metadataStorage = &m + ctx, err := idx.getAuthenticatedContext(context.Background()) + if err != nil { + return err + } + if err := idx.metadataStorage.Init(ctx, idx.cs3conf.ServiceUser); err != nil { + return err + } + if err := idx.makeDirIfNotExists(idx.indexBaseDir); err != nil { return err } diff --git a/ocis-pkg/metadata_storage/metadata_storage.go b/ocis-pkg/metadata_storage/metadata_storage.go index 5a7a5dd4c2b..51c293ec67a 100644 --- a/ocis-pkg/metadata_storage/metadata_storage.go +++ b/ocis-pkg/metadata_storage/metadata_storage.go @@ -6,20 +6,20 @@ import ( "errors" "io/ioutil" "net/http" - "path" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" revactx "github.com/cs3org/reva/pkg/ctx" + "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" + "github.com/cs3org/reva/pkg/utils" + "github.com/owncloud/ocis/accounts/pkg/config" "google.golang.org/grpc/metadata" ) -const ( - storageMountPath = "/meta" -) - func NewMetadataStorage(providerAddr string) (s MetadataStorage, err error) { - p, err := pool.GetStorageProviderServiceClient(providerAddr) if err != nil { return MetadataStorage{}, err @@ -39,12 +39,49 @@ type MetadataStorage struct { SpaceRoot *provider.ResourceId } +// init creates the metadata space +func (ms *MetadataStorage) Init(ctx context.Context, serviceUser config.ServiceUser) (err error) { + // FIXME change CS3 api to allow sending a space id + cssr, err := ms.storageProvider.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{ + Opaque: &typesv1beta1.Opaque{ + Map: map[string]*typesv1beta1.OpaqueEntry{ + "spaceid": { + Decoder: "plain", + Value: []byte(serviceUser.UUID), + }, + }, + }, + Owner: &user.User{ + Id: &user.UserId{ + OpaqueId: serviceUser.UUID, + }, + Groups: []string{}, + UidNumber: serviceUser.UID, + GidNumber: serviceUser.GID, + }, + Name: "Metadata", + Type: "metadata", + }) + switch { + case err != nil: + return err + case cssr.Status.Code == v1beta11.Code_CODE_OK: + ms.SpaceRoot = cssr.StorageSpace.Root + case cssr.Status.Code == v1beta11.Code_CODE_ALREADY_EXISTS: + // TODO make CreateStorageSpace return existing space? + ms.SpaceRoot = &provider.ResourceId{StorageId: serviceUser.UUID, OpaqueId: serviceUser.UUID} + default: + return errtypes.NewErrtypeFromStatus(cssr.Status) + } + return nil +} + func (ms MetadataStorage) SimpleUpload(ctx context.Context, uploadpath string, content []byte) error { ref := provider.InitiateFileUploadRequest{ Ref: &provider.Reference{ ResourceId: ms.SpaceRoot, - Path: path.Join(storageMountPath, uploadpath), + Path: utils.MakeRelativePath(uploadpath), }, } @@ -86,7 +123,7 @@ func (ms MetadataStorage) SimpleDownload(ctx context.Context, downloadpath strin ref := provider.InitiateFileDownloadRequest{ Ref: &provider.Reference{ ResourceId: ms.SpaceRoot, - Path: path.Join(storageMountPath, downloadpath), + Path: utils.MakeRelativePath(downloadpath), }, } @@ -98,13 +135,13 @@ func (ms MetadataStorage) SimpleDownload(ctx context.Context, downloadpath strin var endpoint string for _, proto := range res.GetProtocols() { - if proto.Protocol == "simple" { + if proto.Protocol == "spaces" { endpoint = proto.GetDownloadEndpoint() break } } if endpoint == "" { - return []byte{}, errors.New("metadata storage doesn't support the simple download protocol") + return []byte{}, errors.New("metadata storage doesn't support the spaces download protocol") } req, err := http.NewRequest(http.MethodGet, endpoint, nil) From 505776b07bed8240b1fd3f7bd9aaa78965ce7812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 7 Dec 2021 15:47:09 +0000 Subject: [PATCH 12/84] fix user creation and deletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocs/pkg/service/v0/users.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ocs/pkg/service/v0/users.go b/ocs/pkg/service/v0/users.go index dd47b3d055d..99507f29ccf 100644 --- a/ocs/pkg/service/v0/users.go +++ b/ocs/pkg/service/v0/users.go @@ -19,6 +19,7 @@ import ( "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/token/manager/jwt" "github.com/go-chi/chi/v5" + "github.com/google/uuid" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/owncloud/ocis/ocs/pkg/service/v0/data" "github.com/owncloud/ocis/ocs/pkg/service/v0/response" @@ -197,7 +198,7 @@ func (o Ocs) AddUser(w http.ResponseWriter, r *http.Request) { } newAccount := &accounts.Account{ - Id: userid, + Id: uuid.New().String(), DisplayName: displayname, PreferredName: userid, OnPremisesSamAccountName: userid, @@ -463,7 +464,7 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) { return } - if purgeRecycleResponse.Status.Code != rpcv1beta1.Code_CODE_OK { + if purgeRecycleResponse.Status.Code != rpcv1beta1.Code_CODE_OK && purgeRecycleResponse.Status.Code != rpcv1beta1.Code_CODE_NOT_FOUND { o.logger.Error(). Str("stat_status_code", statResp.Status.Code.String()). Str("stat_message", statResp.Status.Message). From 35a11dda7e81f80834465d4d45e76eaab45beabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 7 Dec 2021 16:16:54 +0000 Subject: [PATCH 13/84] fix ocs unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocs/pkg/server/http/svc_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 0e432054bb2..ec50679b6ab 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -482,6 +482,22 @@ func assertUsersSame(t *testing.T, expected, actual User, quotaAvailable bool) { } } +func findAccount(t *testing.T, username string) (*accountsProto.Account, error) { + cl := accountsProto.NewAccountsService("com.owncloud.api.accounts", service.Client()) + + req := &accountsProto.ListAccountsRequest{ + Query: "preferred_name eq '" + username + "'", + } + res, err := cl.ListAccounts(context.Background(), req) + if err != nil { + return nil, err + } + if len(res.Accounts) == 0 { + return nil, fmt.Errorf("username %s not found", username) + } + return res.Accounts[0], err +} + func deleteAccount(t *testing.T, id string) (*empty.Empty, error) { cl := accountsProto.NewAccountsService("com.owncloud.api.accounts", service.Client()) @@ -1435,12 +1451,17 @@ func TestGetSingleUser(t *testing.T) { t.Fatal(err) } + a, err := findAccount(t, user.ID) + if err != nil { + t.Fatal(err) + } + formatpart := getFormatString(format) res, err := sendRequest( "GET", fmt.Sprintf("/%v/cloud/user%v", ocsVersion, formatpart), "", - &User{ID: user.ID}, + &User{ID: a.Id}, []string{ssvc.BundleUUIDRoleUser}, ) From 5e1bfb387c29825b42967a8d9e0330652b074c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 7 Dec 2021 21:24:32 +0000 Subject: [PATCH 14/84] fix config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- storage/pkg/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 7c19cbc53e7..e0dac971122 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -545,7 +545,7 @@ func DefaultConfig() *Config { UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", + UserGroupFilter: "(&(objectclass=posixGroup)(cn={{.}}*))", // FIXME (&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*)) in reva the template is executed with a string. IIRC rhaferkamp mentioned this GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", @@ -755,7 +755,7 @@ func DefaultConfig() *Config { OCDavPrefix: "", OCSPrefix: "ocs", OCSSharePrefix: "/Shares", - OCSHomeNamespace: "/home", + OCSHomeNamespace: "/users/{{.Id.OpaqueId}}", PublicURL: "https://localhost:9200", OCSCacheWarmupDriver: "", OCSAdditionalInfoAttribute: "{{.Mail}}", From 22834af1ea75b50fd90bab7e99523796aa53311e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 8 Dec 2021 16:47:16 +0000 Subject: [PATCH 15/84] adjust to multiple spaces config in latest reva MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 4 ++-- go.sum | 4 ++-- storage/pkg/command/gateway.go | 33 +++++++++++++++++++++------------ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 2565df75e35..6fb3758649a 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/gofrs/uuid v4.2.0+incompatible github.com/golang-jwt/jwt/v4 v4.1.0 github.com/golang/protobuf v1.5.2 + github.com/google/uuid v1.3.0 github.com/gookit/config/v2 v2.0.27 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.1 @@ -143,7 +144,6 @@ require ( github.com/gomodule/redigo v1.8.5 // indirect github.com/google/go-cmp v0.5.6 // indirect github.com/google/go-querystring v1.1.0 // indirect - github.com/google/uuid v1.3.0 // indirect github.com/gookit/goutil v0.3.15 // indirect github.com/gorilla/schema v1.2.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect @@ -241,4 +241,4 @@ require ( stash.kopano.io/kgol/oidc-go v0.3.2 // indirect ) -replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211207113801-1fa1ac1d3349 +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b diff --git a/go.sum b/go.sum index 97bb56ab011..06cdd7faf97 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20211207113801-1fa1ac1d3349 h1:nqswCeR3uzHjMAwHdCLaf27+8niLI+nS8/u749Xh0cE= -github.com/cs3org/reva v1.16.1-0.20211207113801-1fa1ac1d3349/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= +github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b h1:qF8a3q73QkxLdwYHUfxjCj0DE+VVy3tKwaUUfudUbIE= +github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index b2af4bc44e5..592acfcebaa 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -221,23 +221,32 @@ func spacesProviders(cfg *config.Config, logger log.Logger) map[string]map[strin // generate rules based on default config return map[string]map[string]interface{}{ cfg.Reva.StorageUsers.Endpoint: { - "mount_path": "/users", - "space_type": "personal", - "path_template": "/users/{{.Space.Owner.Id.OpaqueId}}", - "description": "Personal Spaces", + "spaces": map[string]interface{}{ + "personal": map[string]interface{}{ + "mount_point": "/users", + "path_template": "/users/{{.Space.Owner.Id.OpaqueId}}", + }, + "project": map[string]interface{}{ + "mount_point": "/projects", + "path_template": "/projects/{{.Space.Name}}", + }, + }, }, cfg.Reva.StorageShares.Endpoint: { - "mount_path": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", - "space_type": "share", - "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", - "description": "Shares", + "spaces": map[string]interface{}{ + "share": map[string]interface{}{ + "mount_point": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", + "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", + }, + }, }, // public link storage returns the mount id of the actual storage cfg.Reva.StoragePublicLink.Endpoint: { - "mount_path": "/public", - "space_type": "public", - "path_template": "/public", - "description": "Public Links", + "spaces": map[string]interface{}{ + "public": map[string]interface{}{ + "mount_point": "/public", + }, + }, }, // medatada storage not part of the global namespace } From 954bd657b6555f759b6a7821bc44663ec7128a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 9 Dec 2021 14:59:11 +0000 Subject: [PATCH 16/84] use list all spaces branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 4 +++- go.sum | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6fb3758649a..82fa02fd0c2 100644 --- a/go.mod +++ b/go.mod @@ -241,4 +241,6 @@ require ( stash.kopano.io/kgol/oidc-go v0.3.2 // indirect ) -replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b +//replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b +//replace github.com/cs3org/reva => ../reva +replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211209144624-f30ae65a9198 diff --git a/go.sum b/go.sum index 06cdd7faf97..6c1e390e5b5 100644 --- a/go.sum +++ b/go.sum @@ -227,6 +227,8 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= +github.com/butonic/reva v0.0.0-20211209144624-f30ae65a9198 h1:07/nBnJFLDsagwSGYUK05VJ34HpduPvbtwEoFkn3kd8= +github.com/butonic/reva v0.0.0-20211209144624-f30ae65a9198/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -299,8 +301,6 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b h1:qF8a3q73QkxLdwYHUfxjCj0DE+VVy3tKwaUUfudUbIE= -github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= From 7041549a163a9ca99bd139bbe95c903b6f520cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 9 Dec 2021 14:59:25 +0000 Subject: [PATCH 17/84] fix listing drives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- graph/pkg/service/v0/drives.go | 56 +++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index aa370cbdfda..76469977fd4 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -274,15 +274,20 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { return } + root := &provider.ResourceId{} + identifierParts := strings.Split(req.FirstSegment.Identifier.Get(), "!") - if len(identifierParts) != 2 { + switch len(identifierParts) { + case 1: + root.StorageId, root.OpaqueId = identifierParts[0], identifierParts[0] + case 2: + root.StorageId, root.OpaqueId = identifierParts[0], identifierParts[1] + default: errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", req.FirstSegment.Identifier.Get())) w.WriteHeader(http.StatusInternalServerError) return } - storageID, opaqueID := identifierParts[0], identifierParts[1] - client, err := g.GetClient() if err != nil { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) @@ -294,12 +299,9 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { // the original storage space. StorageSpace: &provider.StorageSpace{ Id: &storageprovider.StorageSpaceId{ - OpaqueId: req.FirstSegment.Identifier.Get(), - }, - Root: &provider.ResourceId{ - StorageId: storageID, - OpaqueId: opaqueID, + OpaqueId: root.StorageId + "!" + root.OpaqueId, }, + Root: root, }, } @@ -386,21 +388,20 @@ func formatDriveItems(mds []*storageprovider.ResourceInfo) ([]*msgraph.DriveItem func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpace) (*msgraph.Drive, error) { rootID := space.Root.StorageId + "!" + space.Root.OpaqueId + if space.Root.StorageId == space.Root.OpaqueId { + // omit opaqueid + rootID = space.Root.StorageId + } + drive := &msgraph.Drive{ BaseItem: msgraph.BaseItem{ Entity: msgraph.Entity{ - Id: &space.Id.OpaqueId, + Id: &rootID, }, Name: &space.Name, //"createdDateTime": "string (timestamp)", // TODO read from StorageSpace ... needs Opaque for now //"description": "string", // TODO read from StorageSpace ... needs Opaque for now }, - Owner: &msgraph.IdentitySet{ - User: &msgraph.Identity{ - Id: &space.Owner.Id.OpaqueId, - // DisplayName: , TODO read and cache from users provider - }, - }, DriveType: &space.SpaceType, Root: &msgraph.DriveItem{ @@ -420,6 +421,15 @@ func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpac drive.Root.WebDavUrl = &webDavURL } + // TODO The public space has no owner ... should we even show it? + if space.Owner != nil && space.Owner.Id != nil { + drive.Owner = &msgraph.IdentitySet{ + User: &msgraph.Identity{ + Id: &space.Owner.Id.OpaqueId, + // DisplayName: , TODO read and cache from users provider + }, + } + } if space.Mtime != nil { lastModified := cs3TimestampToTime(space.Mtime) drive.BaseItem.LastModifiedDateTime = &lastModified @@ -447,22 +457,21 @@ func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, mds []*storag if err != nil { return nil, err } - qta, err := g.getDriveQuota(ctx, mds[i]) + res.Quota, err = g.getDriveQuota(ctx, mds[i]) if err != nil { return nil, err } - res.Quota = &qta responses = append(responses, res) } return responses, nil } -func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.StorageSpace) (msgraph.Quota, error) { +func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.StorageSpace) (*msgraph.Quota, error) { client, err := g.GetClient() if err != nil { g.logger.Error().Err(err).Msg("error creating grpc client") - return msgraph.Quota{}, err + return nil, nil } req := &gateway.GetQuotaRequest{ @@ -478,17 +487,20 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage switch { case err != nil: g.logger.Error().Err(err).Msg("error sending get quota grpc request") - return msgraph.Quota{}, err + return nil, nil + case res.Status.Code == cs3rpc.Code_CODE_UNIMPLEMENTED: + // TODO well duh + return nil, nil case res.Status.Code != cs3rpc.Code_CODE_OK: g.logger.Error().Err(err).Msg("error sending sending get quota grpc request") - return msgraph.Quota{}, err + return nil, err } total := int64(res.TotalBytes) used := int64(res.UsedBytes) remaining := total - used - qta := msgraph.Quota{ + qta := &msgraph.Quota{ Remaining: &remaining, Total: &total, Used: &used, From 1eeb5fd7afa46815c06ef50fcd1b096f5d7fffe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 9 Dec 2021 15:46:39 +0000 Subject: [PATCH 18/84] look ma, all the fixes! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../expected-failures-API-on-OCIS-storage.md | 43 +------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index b548cdd78a2..9755d06f04c 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -332,21 +332,14 @@ File and sync features in a shared scenario - [apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature:48](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature#L48) #### [Shares received in different ways are not merged](https://github.com/owncloud/ocis/issues/2711) -- [apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature:553](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature#L553) -- [apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature:554](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature#L554) - [apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature:598](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature#L598) - [apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature:599](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature#L599) - [apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature:621](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature#L621) - [apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature:622](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareCreateSpecialToShares1/createShareReceivedInMultipleWays.feature#L622) #### [file_target of a auto-renamed file is not correct directly after sharing](https://github.com/owncloud/core/issues/32322) -- [apiShareManagementBasicToShares/deleteShareFromShares.feature:59](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/deleteShareFromShares.feature#L59) - [apiShareManagementToShares/mergeShare.feature:89](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/mergeShare.feature#L89) -#### [Listing shares via ocs API does not show path for parent folders](https://github.com/owncloud/ocis/issues/1231) -- [apiShareManagementBasicToShares/createShareToSharesFolder.feature:290](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/createShareToSharesFolder.feature#L290) -- [apiShareManagementBasicToShares/createShareToSharesFolder.feature:291](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/createShareToSharesFolder.feature#L291) - #### [Cannot move a file to a shared folder](https://github.com/owncloud/ocis/issues/2146) - [apiShareManagementBasicToShares/createShareToSharesFolder.feature:509](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/createShareToSharesFolder.feature#L515) @@ -408,18 +401,6 @@ cannot share a folder with create permission - [apiSharePublicLink1/changingPublicLinkShare.feature:51](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/changingPublicLinkShare.feature#L51) - [apiSharePublicLink1/changingPublicLinkShare.feature:90](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/changingPublicLinkShare.feature#L90) -#### [Public link enforce permissions](https://github.com/owncloud/ocis/issues/1269) - -- [apiSharePublicLink1/createPublicLinkShare.feature:141](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/createPublicLinkShare.feature#L141) -- [apiSharePublicLink1/createPublicLinkShare.feature:142](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/createPublicLinkShare.feature#L142) -- [apiSharePublicLink1/createPublicLinkShare.feature:218](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/createPublicLinkShare.feature#L218) -- [apiSharePublicLink1/createPublicLinkShare.feature:219](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/createPublicLinkShare.feature#L219) - -#### [Ability to return error messages in Webdav response bodies](https://github.com/owncloud/ocis/issues/1293) - -- [apiSharePublicLink1/createPublicLinkShare.feature:105](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/createPublicLinkShare.feature#L105) -- [apiSharePublicLink1/createPublicLinkShare.feature:106](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/createPublicLinkShare.feature#L106) - #### [various sharing settings cannot be set](https://github.com/owncloud/ocis/issues/1328) - [apiSharePublicLink1/createPublicLinkShare.feature:319](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink1/createPublicLinkShare.feature#L319) @@ -648,12 +629,9 @@ Scenario Outline: Moving a file into a shared folder as the sharee and as the sh - [apiWebdavMove2/moveFile.feature:290](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavMove2/moveFile.feature#L290) - [apiWebdavMove2/moveFile.feature:291](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavMove2/moveFile.feature#L291) -#### [User loses accepted share if owner changes the contents of the file](https://github.com/owncloud/ocis/issues/2706) -- [apiVersions/fileVersionsSharingToShares.feature:32](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature#L32) - #### [restoring an older version of a shared file deletes the share](https://github.com/owncloud/ocis/issues/765) - [apiShareManagementToShares/acceptShares.feature:587](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L587) -- [apiVersions/fileVersionsSharingToShares.feature:43](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature#L43) + #### [not possible to move file into a received folder](https://github.com/owncloud/ocis/issues/764) - [apiVersions/fileVersionsSharingToShares.feature:219](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature#L219) @@ -857,9 +835,6 @@ _ocs: api compatibility, return correct status code_ - [apiShareManagementBasicToShares/createShareToSharesFolder.feature:670](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/createShareToSharesFolder.feature#L670) - [apiShareManagementBasicToShares/createShareToSharesFolder.feature:671](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/createShareToSharesFolder.feature#L671) -#### [OCIS-storage overwriting a file as share receiver, does not create a new file version for the sharer](https://github.com/owncloud/ocis/issues/766) -- [apiVersions/fileVersionsSharingToShares.feature:294](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature#L294) - #### [deleting a share with wrong authentication returns OCS status 996 / HTTP 500](https://github.com/owncloud/ocis/issues/1229) - [apiShareManagementBasicToShares/deleteShareFromShares.feature:250](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/deleteShareFromShares.feature#L250) - [apiShareManagementBasicToShares/deleteShareFromShares.feature:251](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementBasicToShares/deleteShareFromShares.feature#L251) @@ -1049,9 +1024,6 @@ API, search, favorites, config, capabilities, not existing endpoints, CORS and o #### [Trying to access another user's file gives http 403 instead of 404](https://github.com/owncloud/ocis/issues/2175) _ocdav: api compatibility, return correct status code_ -- [apiAuthWebDav/webDavDELETEAuth.feature:38](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavDELETEAuth.feature#L38) Scenario: send DELETE requests to another user's webDav endpoints as normal user -- [apiAuthWebDav/webDavPROPFINDAuth.feature:39](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPROPFINDAuth.feature#L39) Scenario: send PROPFIND requests to another user's webDav endpoints as normal user -- [apiAuthWebDav/webDavPROPPATCHAuth.feature:40](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPROPPATCHAuth.feature#L40) Scenario: send PROPPATCH requests to another user's webDav endpoints as normal user - [apiAuthWebDav/webDavMKCOLAuth.feature:36](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavMKCOLAuth.feature#L36) Scenario: send MKCOL requests to another user's webDav endpoints as normal user #### [trying to lock file of another user gives http 200](https://github.com/owncloud/ocis/issues/2176) @@ -1121,12 +1093,6 @@ And other missing implementation of favorites - [apiFavorites/favorites.feature:149](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favorites.feature#L149) - [apiFavorites/favorites.feature:176](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favorites.feature#L176) - [apiFavorites/favorites.feature:177](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favorites.feature#L177) -- [apiFavorites/favoritesSharingToShares.feature:21](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L21) -- [apiFavorites/favoritesSharingToShares.feature:22](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L22) -- [apiFavorites/favoritesSharingToShares.feature:35](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L35) -- [apiFavorites/favoritesSharingToShares.feature:36](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L36) -- [apiFavorites/favoritesSharingToShares.feature:48](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L48) -- [apiFavorites/favoritesSharingToShares.feature:49](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L49) - [apiFavorites/favoritesSharingToShares.feature:62](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L62) - [apiFavorites/favoritesSharingToShares.feature:63](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiFavorites/favoritesSharingToShares.feature#L63) @@ -1334,10 +1300,6 @@ Scenario Outline: Unauthenticated call #### [Share inaccessible if folder with same name was deleted and recreated](https://github.com/owncloud/ocis/issues/1787) - [apiShareReshareToShares1/reShare.feature:269](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareReshareToShares1/reShare.feature#L269) - [apiShareReshareToShares1/reShare.feature:270](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareReshareToShares1/reShare.feature#L270) -- [apiShareReshareToShares1/reShare.feature:287](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareReshareToShares1/reShare.feature#L287) -- [apiShareReshareToShares1/reShare.feature:288](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareReshareToShares1/reShare.feature#L288) -- [apiShareReshareToShares1/reShare.feature:305](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareReshareToShares1/reShare.feature#L305) -- [apiShareReshareToShares1/reShare.feature:306](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareReshareToShares1/reShare.feature#L306) #### [Trying to accept a share with invalid ID gives incorrect OCS and HTTP status](https://github.com/owncloud/ocis/issues/2111) - [apiShareOperationsToShares2/shareAccessByID.feature:85](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L85) @@ -1444,9 +1406,6 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers - [apiWebdavUpload1/uploadFileToBlacklistedName.feature:66](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFileToBlacklistedName.feature#L66) - [apiWebdavUpload1/uploadFileToBlacklistedName.feature:67](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFileToBlacklistedName.feature#L67) -### [not possible to overwrite a received shared file](https://github.com/owncloud/ocis/issues/2267) -- [apiShareOperationsToShares1/changingFilesShare.feature:114](https://github.com/owncloud/web/blob/master/tests/acceptance/features/apiShareOperationsToShares1/changingFilesShare.feature#L114) - ### [Allow public link sharing only for certain groups feature not implemented] - [apiSharePublicLink2/allowGroupToCreatePublicLinks.feature:35](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink2/allowGroupToCreatePublicLinks.feature#L35) - [apiSharePublicLink2/allowGroupToCreatePublicLinks.feature:91](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink2/allowGroupToCreatePublicLinks.feature#L91) From 0ad542369a6de4087406f1f8312bb6d989511a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 9 Dec 2021 15:47:19 +0000 Subject: [PATCH 19/84] use fix-archive branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 82fa02fd0c2..1ec13c9db62 100644 --- a/go.mod +++ b/go.mod @@ -243,4 +243,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211209144624-f30ae65a9198 +replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211209153438-8cbbceb1207c diff --git a/go.sum b/go.sum index 6c1e390e5b5..7a4325d0427 100644 --- a/go.sum +++ b/go.sum @@ -227,8 +227,8 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/butonic/reva v0.0.0-20211209144624-f30ae65a9198 h1:07/nBnJFLDsagwSGYUK05VJ34HpduPvbtwEoFkn3kd8= -github.com/butonic/reva v0.0.0-20211209144624-f30ae65a9198/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= +github.com/butonic/reva v0.0.0-20211209153438-8cbbceb1207c h1:aqfWmKKW6iaVCkXfIoyfp1Aqd5fQPARBwu2KdtYZDec= +github.com/butonic/reva v0.0.0-20211209153438-8cbbceb1207c/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= From 70b8f3b949d2438b9ae372867912816f21c15eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 15 Dec 2021 16:27:16 +0000 Subject: [PATCH 20/84] wtf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 4 ++-- storage/pkg/command/gateway.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 1ec13c9db62..8d607e08a01 100644 --- a/go.mod +++ b/go.mod @@ -243,4 +243,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211209153438-8cbbceb1207c +replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211215162350-743e7a39805b diff --git a/go.sum b/go.sum index 7a4325d0427..21c68f2671a 100644 --- a/go.sum +++ b/go.sum @@ -227,8 +227,8 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/butonic/reva v0.0.0-20211209153438-8cbbceb1207c h1:aqfWmKKW6iaVCkXfIoyfp1Aqd5fQPARBwu2KdtYZDec= -github.com/butonic/reva v0.0.0-20211209153438-8cbbceb1207c/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= +github.com/butonic/reva v0.0.0-20211215162350-743e7a39805b h1:9zPqRLc119+yceSpJR9w8tTciasO9oDCHy7Dmdrd3lc= +github.com/butonic/reva v0.0.0-20211215162350-743e7a39805b/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 592acfcebaa..f3b20a17d9d 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -234,7 +234,7 @@ func spacesProviders(cfg *config.Config, logger log.Logger) map[string]map[strin }, cfg.Reva.StorageShares.Endpoint: { "spaces": map[string]interface{}{ - "share": map[string]interface{}{ + "reference": map[string]interface{}{ "mount_point": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", }, From 42f5ca07c96780ece4b88846828492a5b01eb9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 15 Dec 2021 19:31:01 +0000 Subject: [PATCH 21/84] fix graph MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- graph/pkg/service/v0/drives.go | 47 ++++++++++++++++------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index cdcd4f80a35..894e1044685 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -15,8 +15,6 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" - v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" - provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" ctxpkg "github.com/cs3org/reva/pkg/ctx" @@ -27,7 +25,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/service/grpc" sproto "github.com/owncloud/ocis/settings/pkg/proto/v0" settingsSvc "github.com/owncloud/ocis/settings/pkg/service/v0" - msgraph "github.com/yaegashi/msgraph.go/beta" merrors "go-micro.dev/v4/errors" ) @@ -214,7 +211,7 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { return } - csr := provider.CreateStorageSpaceRequest{ + csr := storageprovider.CreateStorageSpaceRequest{ Owner: us, Type: driveType, Name: spaceName, @@ -227,7 +224,7 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { return } - if resp.GetStatus().GetCode() != v1beta11.Code_CODE_OK { + if resp.GetStatus().GetCode() != cs3rpc.Code_CODE_OK { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "") return } @@ -267,16 +264,16 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { return } - root := &provider.ResourceId{} + root := &storageprovider.ResourceId{} - identifierParts := strings.Split(req.FirstSegment.Identifier.Get(), "!") + identifierParts := strings.Split(driveID, "!") switch len(identifierParts) { case 1: root.StorageId, root.OpaqueId = identifierParts[0], identifierParts[0] case 2: root.StorageId, root.OpaqueId = identifierParts[0], identifierParts[1] default: - errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", req.FirstSegment.Identifier.Get())) + errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", driveID)) w.WriteHeader(http.StatusInternalServerError) return } @@ -287,10 +284,10 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { return } - updateSpaceRequest := &provider.UpdateStorageSpaceRequest{ + updateSpaceRequest := &storageprovider.UpdateStorageSpaceRequest{ // Prepare the object to apply the diff from. The properties on StorageSpace will overwrite // the original storage space. - StorageSpace: &provider.StorageSpace{ + StorageSpace: &storageprovider.StorageSpace{ Id: &storageprovider.StorageSpaceId{ OpaqueId: root.StorageId + "!" + root.OpaqueId, }, @@ -324,9 +321,9 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { return } - if resp.GetStatus().GetCode() != v1beta11.Code_CODE_OK { + if resp.GetStatus().GetCode() != cs3rpc.Code_CODE_OK { switch resp.Status.GetCode() { - case v1beta11.Code_CODE_NOT_FOUND: + case cs3rpc.Code_CODE_NOT_FOUND: errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, resp.GetStatus().GetMessage()) return default: @@ -430,8 +427,8 @@ func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpac // TODO The public space has no owner ... should we even show it? if space.Owner != nil && space.Owner.Id != nil { - drive.Owner = &msgraph.IdentitySet{ - User: &msgraph.Identity{ + drive.Owner = &libregraph.IdentitySet{ + User: &libregraph.Identity{ Id: &space.Owner.Id.OpaqueId, // DisplayName: , TODO read and cache from users provider }, @@ -474,16 +471,16 @@ func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, mds []*storag return responses, nil } -func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.StorageSpace) (libregraph.Quota, error) { +func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.StorageSpace) (*libregraph.Quota, error) { client, err := g.GetClient() if err != nil { g.logger.Error().Err(err).Msg("error creating grpc client") - return libregraph.Quota{}, err + return nil, err } req := &gateway.GetQuotaRequest{ - Ref: &provider.Reference{ - ResourceId: &provider.ResourceId{ + Ref: &storageprovider.Reference{ + ResourceId: &storageprovider.ResourceId{ StorageId: space.Root.StorageId, OpaqueId: space.Root.OpaqueId, }, @@ -494,13 +491,13 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage switch { case err != nil: g.logger.Error().Err(err).Msg("error sending get quota grpc request") - return libregraph.Quota{}, nil + return nil, nil case res.Status.Code == cs3rpc.Code_CODE_UNIMPLEMENTED: // TODO well duh - return libregraph.Quota{}, nil + return nil, nil case res.Status.Code != cs3rpc.Code_CODE_OK: g.logger.Error().Err(err).Msg("error sending sending get quota grpc request") - return libregraph.Quota{}, err + return nil, err } total := int64(res.TotalBytes) @@ -515,7 +512,7 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage state := calculateQuotaState(total, used) qta.State = &state - return qta, nil + return &qta, nil } func calculateQuotaState(total int64, used int64) (state string) { @@ -533,16 +530,16 @@ func calculateQuotaState(total int64, used int64) (state string) { } } -func getQuota(quota *libregraph.Quota, defaultQuota string) *provider.Quota { +func getQuota(quota *libregraph.Quota, defaultQuota string) *storageprovider.Quota { switch { case quota != nil && quota.Total != nil: if q := *quota.Total; q >= 0 { - return &provider.Quota{QuotaMaxBytes: uint64(q)} + return &storageprovider.Quota{QuotaMaxBytes: uint64(q)} } fallthrough case defaultQuota != "": if q, err := strconv.ParseInt(defaultQuota, 10, 64); err == nil && q >= 0 { - return &provider.Quota{QuotaMaxBytes: uint64(q)} + return &storageprovider.Quota{QuotaMaxBytes: uint64(q)} } fallthrough default: From c0301fb46ed04a3143999b53002ba9ff4a333cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 15 Dec 2021 20:27:48 +0000 Subject: [PATCH 22/84] fix listing spaces without owners MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- graph/pkg/service/v0/drives.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index 894e1044685..12059dd0b7e 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -405,12 +405,6 @@ func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpac Name: &space.Name, //"createdDateTime": "string (timestamp)", // TODO read from StorageSpace ... needs Opaque for now //"description": "string", // TODO read from StorageSpace ... needs Opaque for now - Owner: &libregraph.IdentitySet{ - User: &libregraph.Identity{ - Id: &space.Owner.Id.OpaqueId, - // DisplayName: , TODO read and cache from users provider - }, - }, DriveType: &space.SpaceType, Root: &libregraph.DriveItem{ Id: &rootID, From bab74a02ff1b74679cf73f0baab118321914a476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 22 Dec 2021 12:31:21 +0000 Subject: [PATCH 23/84] use explicit grant and mountpoint types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- storage/pkg/command/gateway.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index f3b20a17d9d..0dff38512bb 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -234,7 +234,25 @@ func spacesProviders(cfg *config.Config, logger log.Logger) map[string]map[strin }, cfg.Reva.StorageShares.Endpoint: { "spaces": map[string]interface{}{ - "reference": map[string]interface{}{ + /* + "share": map[string]interface{}{ + // The jail needs to be filled with mount points + // .Space.Name is a path relative to the mount point + "mount_point": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", + "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", + }, + */ + "virtual": map[string]interface{}{ + // The root of the share jail is mounted here + "mount_point": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", + }, + "grant": map[string]interface{}{ + // Grants are relative to a space root that the gateway will determine with a stat + "mount_point": ".", + }, + "mountpoint": map[string]interface{}{ + // The jail needs to be filled with mount points + // .Space.Name is a path relative to the mount point "mount_point": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", }, From ae21ab95b5f9c78b01cbd9e08967d836c96509ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 4 Jan 2022 19:20:15 +0000 Subject: [PATCH 24/84] fix dav files default layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- storage/pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index ee1631851cf..2c8026a8354 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -587,7 +587,7 @@ func DefaultConfig() *Config { }, OCDav: OCDav{ WebdavNamespace: "/users/{{.Id.OpaqueId}}", - DavFilesNamespace: "/users", + DavFilesNamespace: "/users/{{.Id.OpaqueId}}", }, Archiver: Archiver{ MaxNumFiles: 10000, From ae6b9c6fce13288ae8d4e05153b9c174beed8a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 4 Jan 2022 19:25:21 +0000 Subject: [PATCH 25/84] update reva edge commit id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 6 ++++-- go.sum | 16 +++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 84f309678b0..623bb3226eb 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/asim/go-micro/plugins/wrapper/trace/opencensus/v4 v4.0.0-20211028090348-ed690ed838cc github.com/blevesearch/bleve/v2 v2.2.2 github.com/coreos/go-oidc/v3 v3.1.0 - github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 + github.com/cs3org/go-cs3apis v0.0.0-20211213090556-12c0d565f51d github.com/cs3org/reva v1.17.1-0.20211215132908-5cde0187454b github.com/disintegration/imaging v1.6.2 github.com/glauth/glauth/v2 v2.0.0-20211021011345-ef3151c28733 @@ -78,6 +78,7 @@ require ( require ( contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect + github.com/BurntSushi/toml v0.4.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/sprig v2.22.0+incompatible // indirect @@ -242,4 +243,5 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20211215162350-743e7a39805b + +replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20220104162327-7cb3906d2729 diff --git a/go.sum b/go.sum index 83356a9a7ac..64f60de6fa0 100644 --- a/go.sum +++ b/go.sum @@ -74,6 +74,7 @@ github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbt github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c h1:/IBSNwUN8+eKzUzbJPqhK839ygXJ82sde8x3ogr6R28= github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CiscoM31/godata v1.0.5 h1:AITXpa/5ybXEq59A0nqUGiS7ZXVJnQtFw5o09tyN/UA= @@ -103,7 +104,6 @@ github.com/ProtonMail/go-crypto v0.0.0-20210920160938-87db9fbc61c7/go.mod h1:z4/ github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/ReneKroon/ttlcache/v2 v2.9.0/go.mod h1:mBxvsNY+BT8qLLd6CuAJubbKo6r0jh3nb5et22bbfGY= github.com/ReneKroon/ttlcache/v2 v2.10.0 h1:y4g2gs2fSqAugSseq7vUB1jClqzT/e0CjSrMJywoWa8= github.com/ReneKroon/ttlcache/v2 v2.10.0/go.mod h1:mBxvsNY+BT8qLLd6CuAJubbKo6r0jh3nb5et22bbfGY= github.com/RoaringBitmap/roaring v0.9.4 h1:ckvZSX5gwCRaJYBNe7syNawCU5oruY9gQmjXlp4riwo= @@ -178,7 +178,6 @@ github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/ github.com/aws/aws-sdk-go v1.37.27/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.38.35/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.40.11/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= -github.com/aws/aws-sdk-go v1.42.9/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/aws/aws-sdk-go v1.42.19 h1:L/aM1QwsqVia9qIqexTHwYN+lgLYuOtf11VDgz0YIyw= github.com/aws/aws-sdk-go v1.42.19/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= @@ -237,8 +236,8 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/butonic/reva v0.0.0-20211215162350-743e7a39805b h1:9zPqRLc119+yceSpJR9w8tTciasO9oDCHy7Dmdrd3lc= -github.com/butonic/reva v0.0.0-20211215162350-743e7a39805b/go.mod h1:3n/zVKsKTCL10Mwn2Nhtvn50gP5mA+933lQ2IYNAJso= +github.com/butonic/reva v0.0.0-20220104162327-7cb3906d2729 h1:27hHmGuOnli7iSqc3LB5tmZg5IyWAYyXuaqWCJiH10A= +github.com/butonic/reva v0.0.0-20220104162327-7cb3906d2729/go.mod h1:fYX5U23gbJ66NhQ3UN/fs5ypzNFfLeOBJmQ8VGHFyho= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -314,8 +313,8 @@ github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3p github.com/crewjam/saml v0.4.5 h1:H9u+6CZAESUKHxMyxUbVn0IawYvKZn4nt3d4ccV4O/M= github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S68bk= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= -github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= -github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= +github.com/cs3org/go-cs3apis v0.0.0-20211213090556-12c0d565f51d h1:gnb2ciU4N+RwUug/nwe54wenWi7vSp5bAAjXINlgHZ8= +github.com/cs3org/go-cs3apis v0.0.0-20211213090556-12c0d565f51d/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= @@ -625,7 +624,6 @@ github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y= -github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/gomodule/redigo v1.8.6 h1:h7kHSqUl2kxeaQtVslsfUCPJ1oz2pxcyzLy4zezIzPw= github.com/gomodule/redigo v1.8.6/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -939,7 +937,6 @@ github.com/mileusna/useragent v1.0.2/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4 github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= -github.com/minio/minio-go/v7 v7.0.16/go.mod h1:pUV0Pc+hPd1nccgmzQF/EXh48l/Z/yps6QPF1aaie4g= github.com/minio/minio-go/v7 v7.0.18 h1:fncn6iacnK+i2uYfNc5aVPG7bEqQH0nU4yAGMSunY0w= github.com/minio/minio-go/v7 v7.0.18/go.mod h1:SyQ1IFeJuaa+eV5yEDxW7hYE1s5VVq5sgImDe27R+zg= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= @@ -970,7 +967,6 @@ github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= @@ -1374,10 +1370,8 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.2 go.opentelemetry.io/otel v1.2.0/go.mod h1:aT17Fk0Z1Nor9e0uisf98LrntPGMnk4frBO9+dkf69I= go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y= go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= -go.opentelemetry.io/otel/exporters/jaeger v1.2.0/go.mod h1:KJLFbEMKTNPIfOxcg/WikIozEoKcPgJRz3Ce1vLlM8E= go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0= go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc= -go.opentelemetry.io/otel/sdk v1.2.0/go.mod h1:jNN8QtpvbsKhgaC6V5lHiejMoKD+V8uadoSafgHPx1U= go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJreAI= go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs= go.opentelemetry.io/otel/trace v1.2.0/go.mod h1:N5FLswTubnxKxOJHM7XZC074qpeEdLy3CgAVsdMucK0= From 349987115d0355eafae0980e15b8474ce59de7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 4 Jan 2022 20:36:39 +0000 Subject: [PATCH 26/84] use locking branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d5714a81afe..17c9adbbd6e 100644 --- a/go.mod +++ b/go.mod @@ -246,4 +246,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20220104162327-7cb3906d2729 +replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20220104203102-5d4baf298e94 diff --git a/go.sum b/go.sum index 8d725011994..26dd084549b 100644 --- a/go.sum +++ b/go.sum @@ -239,8 +239,8 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/butonic/reva v0.0.0-20220104162327-7cb3906d2729 h1:27hHmGuOnli7iSqc3LB5tmZg5IyWAYyXuaqWCJiH10A= -github.com/butonic/reva v0.0.0-20220104162327-7cb3906d2729/go.mod h1:fYX5U23gbJ66NhQ3UN/fs5ypzNFfLeOBJmQ8VGHFyho= +github.com/butonic/reva v0.0.0-20220104203102-5d4baf298e94 h1:roPbPqjOqD5v8E2kRRv7fj6fSKaatTIQEu5d1uqshaw= +github.com/butonic/reva v0.0.0-20220104203102-5d4baf298e94/go.mod h1:MMqwHzWdFh9r61QTeDtUQZCeeBrm/P8UNiZGfKQEMfw= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -316,7 +316,6 @@ github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3p github.com/crewjam/saml v0.4.5 h1:H9u+6CZAESUKHxMyxUbVn0IawYvKZn4nt3d4ccV4O/M= github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S68bk= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= -github.com/cs3org/go-cs3apis v0.0.0-20211213090556-12c0d565f51d/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8 h1:PqOprF37OvwCbAN5W23znknGk6N/LMayqLAeP904FHE= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= From 196f2ab818aef3ac3d797bbc8356e708f378cd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 5 Jan 2022 10:03:11 +0000 Subject: [PATCH 27/84] use list spaces when deleting users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocs/pkg/service/v0/users.go | 96 ++++++++++++++----------------------- 1 file changed, 35 insertions(+), 61 deletions(-) diff --git a/ocs/pkg/service/v0/users.go b/ocs/pkg/service/v0/users.go index 99507f29ccf..84cf9df2bd2 100644 --- a/ocs/pkg/service/v0/users.go +++ b/ocs/pkg/service/v0/users.go @@ -399,77 +399,51 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) { o.logger.Error().Err(err).Msg("error securing a connection to Reva gateway") } - homeResp, err := gwc.GetHome(ctx, &provider.GetHomeRequest{}) - if err != nil { - o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not get home").Error())) - return - } - - if homeResp.Status.Code != rpcv1beta1.Code_CODE_OK { - o.logger.Error(). - Str("stat_status_code", homeResp.Status.Code.String()). - Str("stat_message", homeResp.Status.Message). - Msg("DeleteUser: could not get user home: get failed") - return - } - - statResp, err := gwc.Stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Path: homeResp.Path, + lsRes, err := gwc.ListStorageSpaces(ctx, &provider.ListStorageSpacesRequest{ + Filters: []*provider.ListStorageSpacesRequest_Filter{ + { + Type: provider.ListStorageSpacesRequest_Filter_TYPE_OWNER, + Term: &provider.ListStorageSpacesRequest_Filter_Owner{ + Owner: &revauser.UserId{ + Idp: o.config.IdentityManagement.Address, + OpaqueId: account.Id, + }, + }, + }, + { + Type: provider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE, + Term: &provider.ListStorageSpacesRequest_Filter_SpaceType{ + SpaceType: "personal", + }, + }, }, }) - if err != nil { - o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not stat home").Error())) + o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not list owned personal spaces").Error())) return } - if statResp.Status.Code != rpcv1beta1.Code_CODE_OK { + if lsRes.Status.Code != rpcv1beta1.Code_CODE_OK { o.logger.Error(). - Str("stat_status_code", statResp.Status.Code.String()). - Str("stat_message", statResp.Status.Message). - Msg("DeleteUser: could not delete user home: stat failed") - return - } - - delReq := &provider.DeleteRequest{ - Ref: &provider.Reference{ - ResourceId: statResp.Info.Id, - }, - } - - delResp, err := gwc.Delete(ctx, delReq) - if err != nil { - o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not delete home").Error())) + Interface("status", lsRes.Status). + Msg("DeleteUser: could not list personal spaces") return } - if delResp.Status.Code != rpcv1beta1.Code_CODE_OK { - o.logger.Error(). - Str("stat_status_code", statResp.Status.Code.String()). - Str("stat_message", statResp.Status.Message). - Msg("DeleteUser: could not delete user home: delete failed") - return - } - - req := &provider.PurgeRecycleRequest{ - Ref: &provider.Reference{ - Path: homeResp.Path, - }, - } - - purgeRecycleResponse, err := gwc.PurgeRecycle(ctx, req) - if err != nil { - o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not delete trash").Error())) - return - } - - if purgeRecycleResponse.Status.Code != rpcv1beta1.Code_CODE_OK && purgeRecycleResponse.Status.Code != rpcv1beta1.Code_CODE_NOT_FOUND { - o.logger.Error(). - Str("stat_status_code", statResp.Status.Code.String()). - Str("stat_message", statResp.Status.Message). - Msg("DeleteUser: could not delete user trash: delete failed") - return + for _, space := range lsRes.StorageSpaces { + dsRes, err := gwc.DeleteStorageSpace(ctx, &provider.DeleteStorageSpaceRequest{ + Id: space.Id, + }) + if err != nil { + o.logger.Error().Err(err).Msg("DeleteUser: could not make delete space request") + continue + } + if dsRes.Status.Code != rpcv1beta1.Code_CODE_OK && dsRes.Status.Code != rpcv1beta1.Code_CODE_NOT_FOUND { + o.logger.Error(). + Interface("status", dsRes.Status). + Msg("DeleteUser: could not delete space") + continue + } } } From 2cf22bf979633879eaa0c6d44a3ae76fc1a2031b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 6 Jan 2022 10:49:01 +0000 Subject: [PATCH 28/84] use latest reva branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 17c9adbbd6e..67841c72696 100644 --- a/go.mod +++ b/go.mod @@ -246,4 +246,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20220104203102-5d4baf298e94 +replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20220105230906-cecb8683f044 diff --git a/go.sum b/go.sum index 26dd084549b..2329f702071 100644 --- a/go.sum +++ b/go.sum @@ -239,8 +239,8 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/butonic/reva v0.0.0-20220104203102-5d4baf298e94 h1:roPbPqjOqD5v8E2kRRv7fj6fSKaatTIQEu5d1uqshaw= -github.com/butonic/reva v0.0.0-20220104203102-5d4baf298e94/go.mod h1:MMqwHzWdFh9r61QTeDtUQZCeeBrm/P8UNiZGfKQEMfw= +github.com/butonic/reva v0.0.0-20220105230906-cecb8683f044 h1:xFnn2q07PANTeawRbudVkuWxzIH9DAJqgBNkhmRyG9E= +github.com/butonic/reva v0.0.0-20220105230906-cecb8683f044/go.mod h1:MMqwHzWdFh9r61QTeDtUQZCeeBrm/P8UNiZGfKQEMfw= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= From fb7a93a46d2756552ea2a9df14ef8f540a75aa29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Jan 2022 15:24:58 +0000 Subject: [PATCH 29/84] expect type project instead of share MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- tests/acceptance/features/apiSpaces/shareSpaces.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/shareSpaces.feature b/tests/acceptance/features/apiSpaces/shareSpaces.feature index c65eac05d97..3d4dd7b693f 100644 --- a/tests/acceptance/features/apiSpaces/shareSpaces.feature +++ b/tests/acceptance/features/apiSpaces/shareSpaces.feature @@ -26,7 +26,7 @@ Feature: Share spaces When user "Brian" lists all available spaces via the GraphApi Then the json responded should contain a space "Share space to Brian" with these key and value pairs: | key | value | - | driveType | share | + | driveType | project | | id | %space_id% | | name | Share space to Brian | | quota@@@state | normal | @@ -55,7 +55,7 @@ Feature: Share spaces When user "Brian" lists all available spaces via the GraphApi Then the json responded should contain a space "Unshare space" with these key and value pairs: | key | value | - | driveType | share | + | driveType | project | | id | %space_id% | | name | Unshare space | When user "Alice" unshares a space "Unshare space" to user "Brian" From 76592e21d87799dbac67748363c21a345dec79fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Jan 2022 15:27:48 +0000 Subject: [PATCH 30/84] update to latest edge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 37e98a687a1..11d4291d949 100644 --- a/go.mod +++ b/go.mod @@ -246,4 +246,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/butonic/reva v0.0.0-20220105230906-cecb8683f044 +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20220107152324-c05e07489406 diff --git a/go.sum b/go.sum index 196c4f3a85f..9e230717d1e 100644 --- a/go.sum +++ b/go.sum @@ -114,7 +114,6 @@ github.com/ProtonMail/go-crypto v0.0.0-20211112122917-428f8eabeeb3/go.mod h1:z4/ github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/ReneKroon/ttlcache/v2 v2.10.0/go.mod h1:mBxvsNY+BT8qLLd6CuAJubbKo6r0jh3nb5et22bbfGY= github.com/ReneKroon/ttlcache/v2 v2.11.0 h1:OvlcYFYi941SBN3v9dsDcC2N8vRxyHcCmJb3Vl4QMoM= github.com/ReneKroon/ttlcache/v2 v2.11.0/go.mod h1:mBxvsNY+BT8qLLd6CuAJubbKo6r0jh3nb5et22bbfGY= github.com/RoaringBitmap/roaring v0.9.4 h1:ckvZSX5gwCRaJYBNe7syNawCU5oruY9gQmjXlp4riwo= @@ -190,7 +189,6 @@ github.com/aws/aws-sdk-go v1.37.27/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2z github.com/aws/aws-sdk-go v1.38.35/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.40.11/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/aws/aws-sdk-go v1.41.13/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= -github.com/aws/aws-sdk-go v1.42.19/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/aws/aws-sdk-go v1.42.27 h1:kxsBXQg3ee6LLbqjp5/oUeDgG7TENFrWYDmEVnd7spU= github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc= github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= @@ -249,8 +247,6 @@ github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f/go.mod h1:8rLXio+Wji github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/butonic/reva v0.0.0-20220105230906-cecb8683f044 h1:xFnn2q07PANTeawRbudVkuWxzIH9DAJqgBNkhmRyG9E= -github.com/butonic/reva v0.0.0-20220105230906-cecb8683f044/go.mod h1:MMqwHzWdFh9r61QTeDtUQZCeeBrm/P8UNiZGfKQEMfw= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -328,6 +324,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8 h1:PqOprF37OvwCbAN5W23znknGk6N/LMayqLAeP904FHE= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= +github.com/cs3org/reva v1.16.1-0.20220107152324-c05e07489406 h1:pmt68Syo7St30SztB5ce761x5P6/XNX7CXL+rnOPLrI= +github.com/cs3org/reva v1.16.1-0.20220107152324-c05e07489406/go.mod h1:WqO2/NkAmx1qes09G92lGPxxyroQgnZetJrCPItCcDo= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= @@ -935,7 +933,6 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk= github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= @@ -958,7 +955,6 @@ github.com/mileusna/useragent v1.0.2/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4 github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= -github.com/minio/minio-go/v7 v7.0.18/go.mod h1:SyQ1IFeJuaa+eV5yEDxW7hYE1s5VVq5sgImDe27R+zg= github.com/minio/minio-go/v7 v7.0.20 h1:0+Xt1SkCKDgcx5cmo3UxXcJ37u5Gy+/2i/+eQYqmYJw= github.com/minio/minio-go/v7 v7.0.20/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2DAn1ou4+Do= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= @@ -1186,7 +1182,6 @@ github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo= -github.com/rs/zerolog v1.26.0/go.mod h1:yBiM87lvSqX8h0Ww4sdzNSkVYZ8dL2xjZJG1lAuGZEo= github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc= github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc= github.com/russellhaering/goxmldsig v1.1.0/go.mod h1:QK8GhXPB3+AfuCrfo0oRISa9NfzeCpWmxeGnqEpDF9o= @@ -1294,7 +1289,6 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip/v6 v6.2.0/go.mod h1:pQZ36hWWRahCUXkFWlx9Hs711gLd8J4qdgLdRzmtY+g= github.com/tus/tusd v1.1.0/go.mod h1:3DWPOdeCnjBwKtv98y5dSws3itPqfce5TVa0s59LRiA= -github.com/tus/tusd v1.6.0/go.mod h1:ygrT4B9ZSb27dx3uTnobX5nOFDnutBL6iWKLH4+KpA0= github.com/tus/tusd v1.8.0 h1:QODQ5uMhL2tFX3Ouk7rUHHqPqeDBvi2+gYIoyUO0n8Q= github.com/tus/tusd v1.8.0/go.mod h1:stZzKpol4qz7lX2HXy/1H526dn5mRnkIICTW2lrh9NM= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= @@ -1396,17 +1390,14 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.27.0/go.mod h1:T/zQwBldOpoAEpE3HMbLnI8ydESZVz4ggw6Is4FF9LI= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0 h1:Ky1MObd188aGbgb5OgNnwGuEEwI9MVIcc7rBW6zk5Ak= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0/go.mod h1:vEhqr0m4eTc+DWxfsXoXue2GBgV2uUwVznkGIHW/e5w= -go.opentelemetry.io/otel v1.2.0/go.mod h1:aT17Fk0Z1Nor9e0uisf98LrntPGMnk4frBO9+dkf69I= go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y= go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0= go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc= go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJreAI= go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs= -go.opentelemetry.io/otel/trace v1.2.0/go.mod h1:N5FLswTubnxKxOJHM7XZC074qpeEdLy3CgAVsdMucK0= go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY= go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= @@ -1464,7 +1455,6 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5 golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e h1:1SzTfNOXwIS2oWiMF+6qu0OUDKb0dauo6MoDUQyu+yU= golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= @@ -1720,7 +1710,6 @@ golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210921065528-437939a70204/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From f602c50ff92d8257b1a5589f07f2dcd6704040b5 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Fri, 7 Jan 2022 16:32:45 +0100 Subject: [PATCH 31/84] fix thumbnailer for the new spaces approach --- thumbnails/pkg/config/config.go | 2 -- thumbnails/pkg/config/mappings.go | 4 ---- thumbnails/pkg/service/v0/service.go | 21 +++++++++------- webdav/pkg/config/config.go | 4 +++- webdav/pkg/config/mappings.go | 4 ++++ webdav/pkg/dav/requests/thumbnail.go | 15 +++++++----- webdav/pkg/server/http/server.go | 5 +++- webdav/pkg/service/v0/service.go | 36 ++++++++++++++++++++++++---- 8 files changed, 64 insertions(+), 27 deletions(-) diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 5126a2d60d7..0e92f4ce668 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -65,7 +65,6 @@ type Thumbnail struct { WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure"` CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure"` RevaGateway string `ocisConfig:"reva_gateway"` - WebdavNamespace string `ocisConfig:"webdav_namespace"` FontMapFile string `ocisConfig:"font_map_file"` } @@ -101,7 +100,6 @@ func DefaultConfig() *Config { }, WebdavAllowInsecure: true, RevaGateway: "127.0.0.1:9142", - WebdavNamespace: "/home", CS3AllowInsecure: false, }, } diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go index 6f6ef0d2fa1..a826dd76920 100644 --- a/thumbnails/pkg/config/mappings.go +++ b/thumbnails/pkg/config/mappings.go @@ -111,9 +111,5 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"OCIS_INSECURE", "THUMBNAILS_CS3SOURCE_INSECURE"}, Destination: &cfg.Thumbnail.CS3AllowInsecure, }, - { - EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, - Destination: &cfg.Thumbnail.WebdavNamespace, - }, } } diff --git a/thumbnails/pkg/service/v0/service.go b/thumbnails/pkg/service/v0/service.go index 8914aebbceb..f15211fe28d 100644 --- a/thumbnails/pkg/service/v0/service.go +++ b/thumbnails/pkg/service/v0/service.go @@ -8,6 +8,7 @@ import ( "strings" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" revactx "github.com/cs3org/reva/pkg/ctx" @@ -30,8 +31,7 @@ func NewService(opts ...Option) v0proto.ThumbnailServiceHandler { logger.Fatal().Err(err).Msg("resolutions not configured correctly") } svc := Thumbnail{ - serviceID: options.Config.Server.Namespace + "." + options.Config.Server.Name, - webdavNamespace: options.Config.Thumbnail.WebdavNamespace, + serviceID: options.Config.Server.Namespace + "." + options.Config.Server.Name, manager: thumbnail.NewSimpleManager( resolutions, options.ThumbnailStorage, @@ -52,7 +52,6 @@ func NewService(opts ...Option) v0proto.ThumbnailServiceHandler { // Thumbnail implements the GRPC handler. type Thumbnail struct { serviceID string - webdavNamespace string manager thumbnail.Manager webdavSource imgsource.Source cs3Source imgsource.Source @@ -100,7 +99,7 @@ func (g Thumbnail) GetThumbnail(ctx context.Context, req *v0proto.GetThumbnailRe func (g Thumbnail) handleCS3Source(ctx context.Context, req *v0proto.GetThumbnailRequest, encoder thumbnail.Encoder) ([]byte, error) { src := req.GetCs3Source() - sRes, err := g.stat(src.Path, src.Authorization) + sRes, err := g.stat(src.Path, src.Authorization, nil) if err != nil { return nil, err } @@ -144,7 +143,11 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *v0proto.GetThumb return nil, errors.Wrap(err, "source url is invalid") } - var auth, statPath string + var ( + auth, statPath string + user *userv1beta1.User + ) + if src.IsPublicLink { q := imgURL.Query() var rsp *gateway.AuthenticateResponse @@ -171,12 +174,14 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *v0proto.GetThumb return nil, merrors.InternalServerError(g.serviceID, "could not authenticate: %s", err.Error()) } auth = rsp.Token + user = rsp.User statPath = path.Join("/public", src.PublicLinkToken, req.Filepath) } else { auth = src.RevaAuthorization - statPath = path.Join(g.webdavNamespace, req.Filepath) + statPath = req.Filepath + user = revactx.ContextMustGetUser(ctx) } - sRes, err := g.stat(statPath, auth) + sRes, err := g.stat(statPath, auth, user) if err != nil { return nil, err } @@ -214,7 +219,7 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *v0proto.GetThumb return thumb, nil } -func (g Thumbnail) stat(path, auth string) (*provider.StatResponse, error) { +func (g Thumbnail) stat(path, auth string, user *userv1beta1.User) (*provider.StatResponse, error) { ctx := metadata.AppendToOutgoingContext(context.Background(), revactx.TokenHeader, auth) req := &provider.StatRequest{ diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index c08c8ea0f9e..722c8ed2f1e 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -57,6 +57,7 @@ type Config struct { Service Service `ocisConfig:"service"` OcisPublicURL string `ocisConfig:"ocis_public_url"` WebdavNamespace string `ocisConfig:"webdav_namespace"` + RevaGateway string `ocisConfig:"reva_gateway"` Context context.Context Supervised bool @@ -97,6 +98,7 @@ func DefaultConfig() *Config { Namespace: "com.owncloud.web", }, OcisPublicURL: "https://127.0.0.1:9200", - WebdavNamespace: "/home", + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + RevaGateway: "127.0.0.1:9142", } } diff --git a/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go index 7fa86211ef7..df4abfde080 100644 --- a/webdav/pkg/config/mappings.go +++ b/webdav/pkg/config/mappings.go @@ -103,5 +103,9 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, Destination: &cfg.WebdavNamespace, }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.RevaGateway, + }, } } diff --git a/webdav/pkg/dav/requests/thumbnail.go b/webdav/pkg/dav/requests/thumbnail.go index 6ce7b3d38a6..be1e7d43c4e 100644 --- a/webdav/pkg/dav/requests/thumbnail.go +++ b/webdav/pkg/dav/requests/thumbnail.go @@ -33,11 +33,13 @@ type ThumbnailRequest struct { Height int32 // In case of a public share the public link token. PublicLinkToken string + // The username from the requested URL + Username string } // ParseThumbnailRequest extracts all required parameters from a http request. func ParseThumbnailRequest(r *http.Request) (*ThumbnailRequest, error) { - fp, err := extractFilePath(r) + fp, username, err := extractFilePath(r) if err != nil { return nil, err } @@ -55,6 +57,7 @@ func ParseThumbnailRequest(r *http.Request) (*ThumbnailRequest, error) { Width: int32(width), Height: int32(height), PublicLinkToken: chi.URLParam(r, "token"), + Username: username, }, nil } @@ -64,23 +67,23 @@ func ParseThumbnailRequest(r *http.Request) (*ThumbnailRequest, error) { // // User and filepath are dynamic and filepath can contain slashes // So using the URLParam function is not possible. -func extractFilePath(r *http.Request) (string, error) { +func extractFilePath(r *http.Request) (string, string, error) { user := chi.URLParam(r, "user") user, err := url.QueryUnescape(user) if err != nil { - return "", errors.New("could not unescape user") + return "", "", errors.New("could not unescape user") } if user != "" { parts := strings.SplitN(r.URL.Path, user, 2) - return parts[1], nil + return parts[1], user, nil } token := chi.URLParam(r, "token") if token != "" { parts := strings.SplitN(r.URL.Path, token, 2) - return parts[1], nil + return parts[1], "", nil } - return "", errors.New("could not extract file path") + return "", "", errors.New("could not extract file path") } func parseDimensions(q url.Values) (int64, int64, error) { diff --git a/webdav/pkg/server/http/server.go b/webdav/pkg/server/http/server.go index 1b183af5ed0..8d8344c87d8 100644 --- a/webdav/pkg/server/http/server.go +++ b/webdav/pkg/server/http/server.go @@ -23,7 +23,7 @@ func Server(opts ...Option) (http.Service, error) { http.Flags(options.Flags...), ) - handle := svc.NewService( + handle, err := svc.NewService( svc.Logger(options.Logger), svc.Config(options.Config), svc.Middleware( @@ -47,6 +47,9 @@ func Server(opts ...Option) (http.Service, error) { ), ), ) + if err != nil { + return http.Service{}, err + } { handle = svc.NewInstrument(handle, options.Metrics) diff --git a/webdav/pkg/service/v0/service.go b/webdav/pkg/service/v0/service.go index 962942e6e9f..64ed700d4e9 100644 --- a/webdav/pkg/service/v0/service.go +++ b/webdav/pkg/service/v0/service.go @@ -3,11 +3,17 @@ package svc import ( "encoding/xml" "net/http" - "path" + "path/filepath" "strings" + gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" + "github.com/cs3org/reva/pkg/rgrpc/todo/pool" + "github.com/cs3org/reva/pkg/storage/utils/templates" "github.com/go-chi/render" merrors "go-micro.dev/v4/errors" + "google.golang.org/grpc/metadata" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/service/grpc" @@ -38,17 +44,24 @@ type Service interface { } // NewService returns a service implementation for Service. -func NewService(opts ...Option) Service { +func NewService(opts ...Option) (Service, error) { options := newOptions(opts...) + conf := options.Config m := chi.NewMux() m.Use(options.Middleware...) + gwc, err := pool.GetGatewayServiceClient(conf.RevaGateway) + if err != nil { + return nil, err + } + svc := Webdav{ - config: options.Config, + config: conf, log: options.Logger, mux: m, thumbnailsClient: thumbnails.NewThumbnailService("com.owncloud.api.thumbnails", grpc.DefaultClient), + revaClient: gwc, } m.Route(options.Config.HTTP.Root, func(r chi.Router) { @@ -57,7 +70,7 @@ func NewService(opts ...Option) Service { r.Head("/remote.php/dav/public-files/{token}/*", svc.PublicThumbnailHead) }) - return svc + return svc, nil } // Webdav defines implements the business logic for Service. @@ -66,6 +79,7 @@ type Webdav struct { log log.Logger mux *chi.Mux thumbnailsClient thumbnails.ThumbnailService + revaClient gatewayv1beta1.GatewayAPIClient } // ServeHTTP implements the Service interface. @@ -83,6 +97,18 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { } t := r.Header.Get(TokenHeader) + ctx := metadata.AppendToOutgoingContext(r.Context(), TokenHeader, t) + userRes, err := g.revaClient.GetUserByClaim(ctx, &userv1beta1.GetUserByClaimRequest{ + Claim: "username", + Value: tr.Username, + }) + if err != nil || userRes.Status.Code != rpcv1beta1.Code_CODE_OK { + g.log.Error().Err(err).Msg("could not get user") + renderError(w, r, errInternalError("could not get user")) + return + } + + fullPath := filepath.Join(templates.WithUser(userRes.User, g.config.WebdavNamespace), tr.Filepath) rsp, err := g.thumbnailsClient.GetThumbnail(r.Context(), &thumbnails.GetThumbnailRequest{ Filepath: strings.TrimLeft(tr.Filepath, "/"), ThumbnailType: extensionToThumbnailType(strings.TrimLeft(tr.Extension, ".")), @@ -90,7 +116,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { Height: tr.Height, Source: &thumbnails.GetThumbnailRequest_Cs3Source{ Cs3Source: &thumbnails.CS3Source{ - Path: path.Join(g.config.WebdavNamespace, tr.Filepath), + Path: fullPath, Authorization: t, }, }, From ee6fb0d1a5eeeda59336950913172ede5dba6f52 Mon Sep 17 00:00:00 2001 From: pwengerter Date: Tue, 4 Jan 2022 10:14:28 +0100 Subject: [PATCH 32/84] Add docs for locally running accounts&settings ui tests --- docs/extensions/accounts/tests.md | 83 +++++++++++++++++++++++++++++++ docs/extensions/settings/tests.md | 83 +++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 docs/extensions/accounts/tests.md create mode 100644 docs/extensions/settings/tests.md diff --git a/docs/extensions/accounts/tests.md b/docs/extensions/accounts/tests.md new file mode 100644 index 00000000000..07de8e5dc37 --- /dev/null +++ b/docs/extensions/accounts/tests.md @@ -0,0 +1,83 @@ +--- +title: "Tests" +weight: 80 +geekdocRepo: https://github.com/owncloud/ocis +geekdocEditPath: edit/master/docs/extensions/accounts +geekdocFilePath: tests.md +--- + +{{< toc >}} + +## Requirements + +You need a working installation of [the Go programming language](https://golang.org/), [the Node runtime](https://nodejs.org/) and [the Yarn package manager](https://yarnpkg.com/) installed to run the acceptance tests. You may also want to use [Docker](https://www.docker.com/) to start the necessary services in their respective containers. + +## Acceptance Tests + +Make sure you've cloned the [web frontend repo](https://github.com/owncloud/web/) and the [infinite scale repo](https://github.com/owncloud/ocis/) next to each other. If your file/folder structure is different, you'll have to change the paths below accordingly. + +{{< hint info >}} +For now, an IDP configuration file gets generated once and will fail upon changing the oCIS url as done below. To avoid any clashes, remove this file before starting the tests: + +``` +rm ~/.ocis/idp/identifier-registration.yaml +``` +{{< /hint >}} + +### In the web repo + +#### **Optional:** Build web to test local changes + +Install dependencies and bundle the frontend with a watcher by running + +``` +yarn && yarn build:w +``` + +If you skip the step above, the currently bundled frontend from the oCIS binary will be used. + +#### Dockerized acceptance test services + +Start the necessary acceptance test services by using Docker (Compose): + +``` +docker compose up selenium middleware-ocis vnc +``` + +### In the oCIS repo + +#### **Optional:** Build accounts UI to test local changes + +Navigate into the accounts service via `cd ../accounts/` and install dependencies and build the bundled accounts UI with a watcher by running + +``` +yarn && yarn watch +``` + +#### Start oCIS from binary + +Navigate into the oCIS directory inside the oCIS repository and build the oCIS binary by running + +``` +make clean build +``` + +Then, start oCIS from the binary via + +``` +OCIS_URL=https://host.docker.internal:9200 OCIS_INSECURE=true PROXY_ENABLE_BASIC_AUTH=true WEB_UI_CONFIG=../../web/dev/docker/ocis.web.config.json ./bin/ocis server +``` + +If you've built the web bundle locally in its repository, you also need to reference the bundle output in the above command: `WEB_ASSET_PATH=../../web/dist` + +If you've built the accounts UI bundle locally, you also need to reference the bundle output in the above command: `ACCOUNTS_ASSET_PATH=../accounts/assets/` + +#### Run accounts acceptance tests + +If you want visual feedback on the test run, visit http://host.docker.internal:6080/ in your browser and connect to the VNC client. + +Navigate into the accounts service via `cd ../accounts/` and start the acceptance tests by running + +``` +SERVER_HOST=https://host.docker.internal:9200 BACKEND_HOST=https://host.docker.internal:9200 RUN_ON_OCIS=true NODE_TLS_REJECT_UNAUTHORIZED=0 WEB_PATH=../../web WEB_UI_CONFIG=../../web/tests/drone/config-ocis.json MIDDLEWARE_HOST=http://host.docker.internal:3000 ./ui/tests/run-acceptance-test.sh ./ui/tests/acceptance/features/ +``` diff --git a/docs/extensions/settings/tests.md b/docs/extensions/settings/tests.md new file mode 100644 index 00000000000..06a4b3fb5f5 --- /dev/null +++ b/docs/extensions/settings/tests.md @@ -0,0 +1,83 @@ +--- +title: "Tests" +weight: 90 +geekdocRepo: https://github.com/owncloud/ocis +geekdocEditPath: edit/master/docs/extensions/settings +geekdocFilePath: tests.md +--- + +{{< toc >}} + +## Requirements + +You need a working installation of [the Go programming language](https://golang.org/), [the Node runtime](https://nodejs.org/) and [the Yarn package manager](https://yarnpkg.com/) installed to run the acceptance tests. You may also want to use [Docker](https://www.docker.com/) to start the necessary services in their respective containers. + +## Acceptance Tests + +Make sure you've cloned the [web frontend repo](https://github.com/owncloud/web/) and the [infinite scale repo](https://github.com/owncloud/ocis/) next to each other. If your file/folder structure is different, you'll have to change the paths below accordingly. + +{{< hint info >}} +For now, an IDP configuration file gets generated once and will fail upon changing the oCIS url as done below. To avoid any clashes, remove this file before starting the tests: + +``` +rm ~/.ocis/idp/identifier-registration.yaml +``` +{{< /hint >}} + +### In the web repo + +#### **Optional:** Build web to test local changes + +Install dependencies and bundle the frontend with a watcher by running + +``` +yarn && yarn build:w +``` + +If you skip the step above, the currently bundled frontend from the oCIS binary will be used. + +#### Dockerized acceptance test services + +Start the necessary acceptance test services by using Docker (Compose): + +``` +docker compose up selenium middleware-ocis vnc +``` + +### In the oCIS repo + +#### **Optional:** Build settings UI to test local changes + +Navigate into the settings service via `cd ../settings/` and install dependencies and build the bundled settings UI with a watcher by running + +``` +yarn && yarn watch +``` + +#### Start oCIS from binary + +Navigate into the oCIS directory inside the oCIS repository and build the oCIS binary by running + +``` +make clean build +``` + +Then, start oCIS from the binary via + +``` +OCIS_URL=https://host.docker.internal:9200 OCIS_INSECURE=true PROXY_ENABLE_BASIC_AUTH=true WEB_UI_CONFIG=../../web/dev/docker/ocis.web.config.json ./bin/ocis server +``` + +If you've built the web bundle locally in its repository, you also need to reference the bundle output in the above command: `WEB_ASSET_PATH=../../web/dist` + +If you've built the settings UI bundle locally, you also need to reference the bundle output in the above command: `SETTINGS_ASSET_PATH=../settings/assets/` + +#### Run settings acceptance tests + +If you want visual feedback on the test run, visit http://host.docker.internal:6080/ in your browser and connect to the VNC client. + +Navigate into the settings service via `cd ../settings/` and start the acceptance tests by running + +``` +SERVER_HOST=https://host.docker.internal:9200 BACKEND_HOST=https://host.docker.internal:9200 RUN_ON_OCIS=true NODE_TLS_REJECT_UNAUTHORIZED=0 WEB_PATH=../../web WEB_UI_CONFIG=../../web/tests/drone/config-ocis.json MIDDLEWARE_HOST=http://host.docker.internal:3000 ./ui/tests/run-acceptance-test.sh ./ui/tests/acceptance/features/ +``` From 6621ac2ef6095a44e476d2e86e93b11c1d1512cd Mon Sep 17 00:00:00 2001 From: PKiran <39373750+kiranparajuli589@users.noreply.github.com> Date: Thu, 6 Jan 2022 17:34:33 +0545 Subject: [PATCH 33/84] update core commit id for tests --- .drone.env | 2 +- tests/acceptance/expected-failures-API-on-OCIS-storage.md | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.drone.env b/.drone.env index 35d1a715497..895c99c0615 100644 --- a/.drone.env +++ b/.drone.env @@ -1,5 +1,5 @@ # The test runner source for API tests -CORE_COMMITID=a37efb60db92923398de7efef1abb173d13a9afb +CORE_COMMITID=09d584745d6cbd6aebc557d9b78f6130e9b99e2b CORE_BRANCH=master # The test runner source for UI tests diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index 34476fb9c48..389456b7c7e 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -27,7 +27,13 @@ _ocdav: double check the webdav property parsing when custom namespaces are used - [apiVersions/fileVersionsSharingToShares.feature:305](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature#L305) #### [file versions do not report the version author](https://github.com/owncloud/ocis/issues/2914) -- [apiVersions/fileVersions.feature:474](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersions.feature#L474) +- [apiVersions/fileVersionAuthor.feature:14](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionAuthor.feature:#L14) +- [apiVersions/fileVersionAuthor.feature:36](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionAuthor.feature:#L36) +- [apiVersions/fileVersionAuthor.feature:56](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionAuthor.feature:#L56) +- [apiVersions/fileVersionAuthor.feature:75](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionAuthor.feature:#L75) +- [apiVersions/fileVersionAuthor.feature:101](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionAuthor.feature:#L101) +- [apiVersions/fileVersionAuthor.feature:128](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionAuthor.feature:#L128) +- [apiVersions/fileVersionAuthor.feature:155](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionAuthor.feature:#L155) ### Sync Synchronization features like etag propagation, setting mtime and locking files From 3b5a33590e5e86e0565d3dc747c8adc3561d4fde Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 24 Nov 2021 18:30:20 +0100 Subject: [PATCH 34/84] add missing commands and unify service / namespace options --- accounts/pkg/command/add_account.go | 2 +- accounts/pkg/command/inspect_account.go | 2 +- accounts/pkg/command/list_accounts.go | 2 +- accounts/pkg/command/remove_account.go | 2 +- accounts/pkg/command/root.go | 2 +- accounts/pkg/command/server.go | 6 +-- accounts/pkg/command/update_account.go | 2 +- accounts/pkg/command/version.go | 2 +- accounts/pkg/config/config.go | 42 ++++++++--------- accounts/pkg/config/mappings.go | 8 ++-- accounts/pkg/flagset/flagset.go | 20 ++++---- .../pkg/proto/v0/accounts.pb.micro_test.go | 2 +- accounts/pkg/server/grpc/server.go | 4 +- accounts/pkg/server/http/server.go | 2 +- accounts/pkg/service/v0/accounts.go | 4 +- .../service/v0/accounts_permission_test.go | 2 +- accounts/pkg/service/v0/service.go | 6 +-- glauth/pkg/command/root.go | 2 +- glauth/pkg/command/server.go | 4 -- glauth/pkg/command/version.go | 47 +++++++++++++++++++ glauth/pkg/config/config.go | 43 +++++++++-------- graph-explorer/pkg/command/root.go | 2 +- graph-explorer/pkg/command/server.go | 2 +- graph-explorer/pkg/command/version.go | 47 +++++++++++++++++++ graph-explorer/pkg/config/config.go | 12 +++-- graph/pkg/command/root.go | 2 +- graph/pkg/command/server.go | 2 +- graph/pkg/command/version.go | 47 +++++++++++++++++++ graph/pkg/config/config.go | 14 +++--- idp/pkg/command/version.go | 2 +- idp/pkg/config/config.go | 42 ++++++++--------- idp/pkg/config/mappings.go | 4 +- idp/pkg/server/http/server.go | 2 +- ocis/pkg/command/graph.go | 42 +++++++++++++++++ ocis/pkg/command/graphexplorer.go | 42 +++++++++++++++++ ocis/pkg/command/storageauthmachine.go | 2 +- ocs/pkg/command/version.go | 2 +- ocs/pkg/config/config.go | 24 +++++----- ocs/pkg/config/mappings.go | 6 +-- ocs/pkg/server/http/server.go | 2 +- proxy/pkg/command/version.go | 2 +- proxy/pkg/config/config.go | 30 ++++++------ proxy/pkg/config/mappings.go | 18 +++---- proxy/pkg/server/http/server.go | 4 +- settings/pkg/config/config.go | 2 +- settings/pkg/config/mappings.go | 2 +- storage/pkg/command/root.go | 1 + store/pkg/command/version.go | 2 +- store/pkg/config/config.go | 20 ++++---- store/pkg/config/mappings.go | 4 +- store/pkg/server/grpc/server.go | 2 +- store/pkg/service/v0/service.go | 2 +- thumbnails/pkg/command/root.go | 2 +- thumbnails/pkg/command/server.go | 8 ++-- thumbnails/pkg/command/version.go | 2 +- thumbnails/pkg/config/config.go | 25 ++++++---- thumbnails/pkg/config/mappings.go | 8 ++-- thumbnails/pkg/server/debug/server.go | 4 +- thumbnails/pkg/server/grpc/server.go | 2 +- thumbnails/pkg/service/v0/service.go | 3 +- web/pkg/command/version.go | 47 +++++++++++++++++++ web/pkg/config/config.go | 10 ++++ webdav/pkg/command/version.go | 2 +- webdav/pkg/config/config.go | 24 +++++----- webdav/pkg/config/mappings.go | 2 +- webdav/pkg/server/http/server.go | 2 +- 66 files changed, 516 insertions(+), 218 deletions(-) create mode 100644 glauth/pkg/command/version.go create mode 100644 graph-explorer/pkg/command/version.go create mode 100644 graph/pkg/command/version.go create mode 100644 ocis/pkg/command/graph.go create mode 100644 ocis/pkg/command/graphexplorer.go create mode 100644 web/pkg/command/version.go diff --git a/accounts/pkg/command/add_account.go b/accounts/pkg/command/add_account.go index 4003c46eed5..07d18f1a824 100644 --- a/accounts/pkg/command/add_account.go +++ b/accounts/pkg/command/add_account.go @@ -41,7 +41,7 @@ func AddAccount(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { - accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name + accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) _, err := accSvc.CreateAccount(c.Context, &accounts.CreateAccountRequest{ Account: a, diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index 1ea262c31d0..7124b0da4a8 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -22,7 +22,7 @@ func InspectAccount(cfg *config.Config) *cli.Command { ArgsUsage: "id", Flags: flagset.InspectAccountWithConfig(cfg), Action: func(c *cli.Context) error { - accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name + accServiceID := cfg.GRPC.Namespace + "." + cfg.Service.Name if c.NArg() != 1 { fmt.Println("Please provide a user-id") os.Exit(1) diff --git a/accounts/pkg/command/list_accounts.go b/accounts/pkg/command/list_accounts.go index 87727b5762f..bf35626b1a2 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -22,7 +22,7 @@ func ListAccounts(cfg *config.Config) *cli.Command { Aliases: []string{"ls"}, Flags: flagset.ListAccountsWithConfig(cfg), Action: func(c *cli.Context) error { - accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name + accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) resp, err := accSvc.ListAccounts(c.Context, &accounts.ListAccountsRequest{}) diff --git a/accounts/pkg/command/remove_account.go b/accounts/pkg/command/remove_account.go index dfb723db9c0..c51c1abe318 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -21,7 +21,7 @@ func RemoveAccount(cfg *config.Config) *cli.Command { Aliases: []string{"rm"}, Flags: flagset.RemoveAccountWithConfig(cfg), Action: func(c *cli.Context) error { - accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name + accServiceID := cfg.GRPC.Namespace + "." + cfg.Service.Name if c.NArg() != 1 { fmt.Println("Please provide a user-id") os.Exit(1) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 19eae93b2f4..948ff2e4a1c 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -27,7 +27,7 @@ func Execute(cfg *config.Config) error { }, }, Before: func(c *cli.Context) error { - cfg.Server.Version = version.String + cfg.Service.Version = version.String return ParseConfig(c, cfg) }, diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index e4e6f92e689..3475532434c 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -47,7 +47,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - mtrcs.BuildInfo.WithLabelValues(cfg.Server.Version).Set(1) + mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) handler, err := svc.New(svc.Logger(logger), svc.Config(cfg)) if err != nil { @@ -58,7 +58,7 @@ func Server(cfg *config.Config) *cli.Command { httpServer := http.Server( http.Config(cfg), http.Logger(logger), - http.Name(cfg.Server.Name), + http.Name(cfg.Service.Name), http.Context(ctx), http.Metrics(mtrcs), http.Handler(handler), @@ -72,7 +72,7 @@ func Server(cfg *config.Config) *cli.Command { grpcServer := grpc.Server( grpc.Config(cfg), grpc.Logger(logger), - grpc.Name(cfg.Server.Name), + grpc.Name(cfg.Service.Name), grpc.Context(ctx), grpc.Metrics(mtrcs), grpc.Handler(handler), diff --git a/accounts/pkg/command/update_account.go b/accounts/pkg/command/update_account.go index 71f8c2c661e..1b9b91ca485 100644 --- a/accounts/pkg/command/update_account.go +++ b/accounts/pkg/command/update_account.go @@ -40,7 +40,7 @@ func UpdateAccount(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { a.Id = c.Args().First() - accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name + accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) _, err := accSvc.UpdateAccount(c.Context, &accounts.UpdateAccountRequest{ Account: a, diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index e61530d16b8..7e7fc0f571d 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -18,7 +18,7 @@ func PrintVersion(cfg *config.Config) *cli.Command { Usage: "Print the versions of the running instances", Action: func(c *cli.Context) error { reg := registry.GetRegistry() - services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Server.Name) + services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { fmt.Println(fmt.Errorf("could not get accounts services from the registry: %v", err)) return err diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 21bcd3dc254..63844a2cccd 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -56,12 +56,10 @@ type GRPC struct { Namespace string `ocisConfig:"namespace"` } -// Server configures a server. -type Server struct { - Version string `ocisConfig:"version"` - Name string `ocisConfig:"name"` - HashDifficulty int `ocisConfig:"hash_difficulty"` - DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups"` +// Service defines the available service configuration. +type Service struct { + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Asset defines the available asset configuration. @@ -125,17 +123,19 @@ type Tracing struct { type Config struct { *shared.Commons - LDAP LDAP `ocisConfig:"ldap"` - HTTP HTTP `ocisConfig:"http"` - GRPC GRPC `ocisConfig:"grpc"` - Server Server `ocisConfig:"server"` - Asset Asset `ocisConfig:"asset"` - Log *shared.Log `ocisConfig:"log"` - TokenManager TokenManager `ocisConfig:"token_manager"` - Repo Repo `ocisConfig:"repo"` - Index Index `ocisConfig:"index"` - ServiceUser ServiceUser `ocisConfig:"service_user"` - Tracing Tracing `ocisConfig:"tracing"` + LDAP LDAP `ocisConfig:"ldap"` + HTTP HTTP `ocisConfig:"http"` + GRPC GRPC `ocisConfig:"grpc"` + Service Service `ocisConfig:"service"` + Asset Asset `ocisConfig:"asset"` + Log *shared.Log `ocisConfig:"log"` + TokenManager TokenManager `ocisConfig:"token_manager"` + Repo Repo `ocisConfig:"repo"` + Index Index `ocisConfig:"index"` + ServiceUser ServiceUser `ocisConfig:"service_user"` + HashDifficulty int `ocisConfig:"hash_difficulty"` + DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups"` + Tracing Tracing `ocisConfig:"tracing"` Context context.Context Supervised bool @@ -167,15 +167,15 @@ func DefaultConfig() *Config { Addr: "127.0.0.1:9180", Namespace: "com.owncloud.api", }, - Server: Server{ - Name: "accounts", - HashDifficulty: 11, - DemoUsersAndGroups: true, + Service: Service{ + Name: "accounts", }, Asset: Asset{}, TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, + HashDifficulty: 11, + DemoUsersAndGroups: true, Repo: Repo{ Backend: "CS3", Disk: Disk{ diff --git a/accounts/pkg/config/mappings.go b/accounts/pkg/config/mappings.go index 00b13818b4e..b61d93bc279 100644 --- a/accounts/pkg/config/mappings.go +++ b/accounts/pkg/config/mappings.go @@ -69,16 +69,16 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.GRPC.Addr, }, { - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, + EnvVars: []string{"ACCOUNTS_SERVICE_NAME"}, + Destination: &cfg.Service.Name, }, { EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"}, - Destination: &cfg.Server.HashDifficulty, + Destination: &cfg.HashDifficulty, }, { EnvVars: []string{"ACCOUNTS_DEMO_USERS_AND_GROUPS"}, - Destination: &cfg.Server.DemoUsersAndGroups, + Destination: &cfg.DemoUsersAndGroups, }, { EnvVars: []string{"ACCOUNTS_ASSET_PATH"}, diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 3815f0784ae..d661508e2d1 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -23,10 +23,10 @@ func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag }, &cli.StringFlag{ Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"), Usage: "service name", EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, + Destination: &cfg.Service.Name, }, &cli.BoolFlag{ Name: "enabled", @@ -107,10 +107,10 @@ func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { }, &cli.StringFlag{ Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"), Usage: "service name", EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, + Destination: &cfg.Service.Name, }, &cli.BoolFlag{ Name: "enabled", @@ -191,10 +191,10 @@ func ListAccountsWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"), Usage: "service name", EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, + Destination: &cfg.Service.Name, }, } } @@ -211,10 +211,10 @@ func RemoveAccountWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"), Usage: "service name", EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, + Destination: &cfg.Service.Name, }, } } @@ -231,10 +231,10 @@ func InspectAccountWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"), Usage: "service name", EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, + Destination: &cfg.Service.Name, }, } } diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index 89cf6c346bc..562fad5894e 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -81,7 +81,7 @@ func init() { cfg := config.New() cfg.Repo.Backend = "disk" cfg.Repo.Disk.Path = dataPath - cfg.Server.DemoUsersAndGroups = true + cfg.DemoUsersAndGroups = true var hdlr *svc.Service var err error diff --git a/accounts/pkg/server/grpc/server.go b/accounts/pkg/server/grpc/server.go index 216b13e2e9d..d063eda4743 100644 --- a/accounts/pkg/server/grpc/server.go +++ b/accounts/pkg/server/grpc/server.go @@ -11,13 +11,13 @@ func Server(opts ...Option) grpc.Service { handler := options.Handler service := grpc.NewService( - grpc.Name(options.Config.Server.Name), + grpc.Name(options.Config.Service.Name), grpc.Context(options.Context), grpc.Address(options.Config.GRPC.Addr), grpc.Namespace(options.Config.GRPC.Namespace), grpc.Logger(options.Logger), grpc.Flags(options.Flags...), - grpc.Version(options.Config.Server.Version), + grpc.Version(options.Config.Service.Version), ) if err := proto.RegisterAccountsServiceHandler(service.Server(), handler); err != nil { diff --git a/accounts/pkg/server/http/server.go b/accounts/pkg/server/http/server.go index 21487a2d61d..306fa9347ff 100644 --- a/accounts/pkg/server/http/server.go +++ b/accounts/pkg/server/http/server.go @@ -21,7 +21,7 @@ func Server(opts ...Option) http.Service { service := http.NewService( http.Logger(options.Logger), http.Name(options.Name), - http.Version(options.Config.Server.Version), + http.Version(options.Config.Service.Version), http.Address(options.Config.HTTP.Addr), http.Namespace(options.Config.HTTP.Namespace), http.Context(options.Context), diff --git a/accounts/pkg/service/v0/accounts.go b/accounts/pkg/service/v0/accounts.go index 805f06c3768..d7425dce370 100644 --- a/accounts/pkg/service/v0/accounts.go +++ b/accounts/pkg/service/v0/accounts.go @@ -381,7 +381,7 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque if out.PasswordProfile != nil { if out.PasswordProfile.Password != "" { // encrypt password - hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.Server.HashDifficulty) + hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.HashDifficulty) if err != nil { s.log.Error().Err(err).Str("id", id).Msg("could not hash password") return merrors.InternalServerError(s.id, "could not hash password: %v", err.Error()) @@ -572,7 +572,7 @@ func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountReque } if in.Account.PasswordProfile.Password != "" { // encrypt password - hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.Server.HashDifficulty) + hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.HashDifficulty) if err != nil { in.Account.PasswordProfile.Password = "" s.log.Error().Err(err).Str("id", id).Msg("could not hash password") diff --git a/accounts/pkg/service/v0/accounts_permission_test.go b/accounts/pkg/service/v0/accounts_permission_test.go index 477369b6630..f339855f32f 100644 --- a/accounts/pkg/service/v0/accounts_permission_test.go +++ b/accounts/pkg/service/v0/accounts_permission_test.go @@ -32,7 +32,7 @@ var ( func init() { cfg := config.New() - cfg.Server.Name = "accounts" + cfg.Service.Name = "accounts" cfg.Repo.Backend = "disk" cfg.Repo.Disk.Path = dataPath logger := olog.NewLogger(olog.Color(true), olog.Pretty(true)) diff --git a/accounts/pkg/service/v0/service.go b/accounts/pkg/service/v0/service.go index cfea0f22093..d9118ad42a9 100644 --- a/accounts/pkg/service/v0/service.go +++ b/accounts/pkg/service/v0/service.go @@ -57,7 +57,7 @@ func New(opts ...Option) (s *Service, err error) { } s = &Service{ - id: cfg.GRPC.Namespace + "." + cfg.Server.Name, + id: cfg.GRPC.Namespace + "." + cfg.Service.Name, log: logger, Config: cfg, RoleService: roleService, @@ -81,11 +81,11 @@ func New(opts ...Option) (s *Service, err error) { return nil, err } - if err = s.createDefaultAccounts(cfg.Server.DemoUsersAndGroups); err != nil { + if err = s.createDefaultAccounts(cfg.DemoUsersAndGroups); err != nil { return nil, err } - if err = s.createDefaultGroups(cfg.Server.DemoUsersAndGroups); err != nil { + if err = s.createDefaultGroups(cfg.DemoUsersAndGroups); err != nil { return nil, err } return diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index e6017cfef5c..77270bf417a 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -28,7 +28,7 @@ func Execute(cfg *config.Config) error { }, }, Before: func(c *cli.Context) error { - cfg.Version = version.String + cfg.Service.Version = version.String return nil }, Commands: []*cli.Command{ diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index d9cbb5f1c0b..6dcad7f036e 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -2,7 +2,6 @@ package command import ( "context" - "strings" glauthcfg "github.com/glauth/glauth/v2/pkg/config" "github.com/oklog/run" @@ -23,9 +22,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } if err := ParseConfig(ctx, cfg); err != nil { return err diff --git a/glauth/pkg/command/version.go b/glauth/pkg/command/version.go new file mode 100644 index 00000000000..b9be475ab49 --- /dev/null +++ b/glauth/pkg/command/version.go @@ -0,0 +1,47 @@ +package command + +import ( + "fmt" + "os" + + "github.com/owncloud/ocis/ocis-pkg/registry" + + tw "github.com/olekukonko/tablewriter" + "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/urfave/cli/v2" +) + +// PrintVersion prints the service versions of all running instances. +func PrintVersion(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "version", + Usage: "Print the versions of the running instances", + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, + Action: func(c *cli.Context) error { + reg := registry.GetRegistry() + services, err := reg.GetService(cfg.Ldaps.Namespace + "." + cfg.Service.Name) + if err != nil { + fmt.Println(fmt.Errorf("could not get glauth services from the registry: %v", err)) + return err + } + + if len(services) == 0 { + fmt.Println("No running glauth service found.") + return nil + } + + table := tw.NewWriter(os.Stdout) + table.SetHeader([]string{"Version", "Address", "Id"}) + table.SetAutoFormatHeaders(false) + for _, s := range services { + for _, n := range s.Nodes { + table.Append([]string{s.Version, n.Address, n.Id}) + } + } + table.Render() + return nil + }, + } +} diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index d547180d7ca..c3b55c77206 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -17,11 +17,10 @@ type Debug struct { Zpages bool `ocisConfig:"zpages"` } -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` - Root string `ocisConfig:"root"` +// Service defines the available service configuration. +type Service struct { + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -35,16 +34,18 @@ type Tracing struct { // Ldap defined the available LDAP configuration. type Ldap struct { - Enabled bool `ocisConfig:"enabled"` - Addr string `ocisConfig:"addr"` + Enabled bool `ocisConfig:"enabled"` + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` } // Ldaps defined the available LDAPS configuration. type Ldaps struct { - Addr string `ocisConfig:"addr"` - Enabled bool `ocisConfig:"enabled"` - Cert string `ocisConfig:"cert"` - Key string `ocisConfig:"key"` + Enabled bool `ocisConfig:"enabled"` + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` + Cert string `ocisConfig:"cert"` + Key string `ocisConfig:"key"` } // Backend defined the available backend configuration. @@ -66,7 +67,7 @@ type Config struct { File string `ocisConfig:"file"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` + Service Service `ocisConfig:"service"` Tracing Tracing `ocisConfig:"tracing"` Ldap Ldap `ocisConfig:"ldap"` Ldaps Ldaps `ocisConfig:"ldaps"` @@ -89,20 +90,24 @@ func DefaultConfig() *Config { Debug: Debug{ Addr: "127.0.0.1:9129", }, - HTTP: HTTP{}, Tracing: Tracing{ Type: "jaeger", Service: "glauth", }, + Service: Service{ + Name: "glauth", + }, Ldap: Ldap{ - Enabled: true, - Addr: "127.0.0.1:9125", + Enabled: true, + Addr: "127.0.0.1:9125", + Namespace: "com.owncloud.ldap", }, Ldaps: Ldaps{ - Addr: "127.0.0.1:9126", - Enabled: true, - Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), - Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), + Enabled: true, + Addr: "127.0.0.1:9126", + Namespace: "com.owncloud.ldaps", + Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), }, Backend: Backend{ Datastore: "accounts", diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 2f5f679a4cb..d1c0e0ff683 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -26,7 +26,7 @@ func Execute(cfg *config.Config) error { }, }, Before: func(c *cli.Context) error { - cfg.Server.Version = version.String + cfg.Service.Version = version.String return ParseConfig(c, cfg) }, Commands: []*cli.Command{ diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index 86dabfe32ff..c606f1d7cd8 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -42,7 +42,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - mtrcs.BuildInfo.WithLabelValues(cfg.Server.Version).Set(1) + mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) { server, err := http.Server( diff --git a/graph-explorer/pkg/command/version.go b/graph-explorer/pkg/command/version.go new file mode 100644 index 00000000000..2fde4e337ea --- /dev/null +++ b/graph-explorer/pkg/command/version.go @@ -0,0 +1,47 @@ +package command + +import ( + "fmt" + "os" + + "github.com/owncloud/ocis/ocis-pkg/registry" + + tw "github.com/olekukonko/tablewriter" + "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/urfave/cli/v2" +) + +// PrintVersion prints the service versions of all running instances. +func PrintVersion(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "version", + Usage: "Print the versions of the running instances", + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, + Action: func(c *cli.Context) error { + reg := registry.GetRegistry() + services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) + if err != nil { + fmt.Println(fmt.Errorf("could not get graph services from the registry: %v", err)) + return err + } + + if len(services) == 0 { + fmt.Println("No running graph service found.") + return nil + } + + table := tw.NewWriter(os.Stdout) + table.SetHeader([]string{"Version", "Address", "Id"}) + table.SetAutoFormatHeaders(false) + for _, s := range services { + for _, n := range s.Nodes { + table.Append([]string{s.Version, n.Address, n.Id}) + } + } + table.Render() + return nil + }, + } +} diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index c25d415de51..1acf398e870 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -21,10 +21,10 @@ type HTTP struct { Namespace string `ocisConfig:"namespace"` } -// Server configures a server. -type Server struct { - Version string `ocisConfig:"version"` +// Service defines the available service configuration. +type Service struct { Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -50,7 +50,7 @@ type Config struct { Log shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` - Server Server `ocisConfig:"server"` + Service Service `ocisConfig:"service"` Tracing Tracing `ocisConfig:"tracing"` GraphExplorer GraphExplorer `ocisConfig:"graph_explorer"` @@ -78,7 +78,9 @@ func DefaultConfig() *Config { Root: "/graph-explorer", Namespace: "com.owncloud.web", }, - Server: Server{}, + Service: Service{ + Name: "graph", + }, Tracing: Tracing{ Type: "jaeger", Endpoint: "", diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 20d07c88ea2..3e61b387a9d 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -29,7 +29,7 @@ func Execute(cfg *config.Config) error { }, }, Before: func(c *cli.Context) error { - cfg.Server.Version = version.String + cfg.Service.Version = version.String return ParseConfig(c, cfg) }, Commands: []*cli.Command{ diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index 32cd2a4abaf..bcb9f3dcfbf 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -47,7 +47,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - mtrcs.BuildInfo.WithLabelValues(cfg.Server.Version).Set(1) + mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) { server, err := http.Server( diff --git a/graph/pkg/command/version.go b/graph/pkg/command/version.go new file mode 100644 index 00000000000..3eeaff740cf --- /dev/null +++ b/graph/pkg/command/version.go @@ -0,0 +1,47 @@ +package command + +import ( + "fmt" + "os" + + "github.com/owncloud/ocis/ocis-pkg/registry" + + tw "github.com/olekukonko/tablewriter" + "github.com/owncloud/ocis/graph/pkg/config" + "github.com/urfave/cli/v2" +) + +// PrintVersion prints the service versions of all running instances. +func PrintVersion(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "version", + Usage: "Print the versions of the running instances", + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, + Action: func(c *cli.Context) error { + reg := registry.GetRegistry() + services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) + if err != nil { + fmt.Println(fmt.Errorf("could not get graph services from the registry: %v", err)) + return err + } + + if len(services) == 0 { + fmt.Println("No running graph service found.") + return nil + } + + table := tw.NewWriter(os.Stdout) + table.SetHeader([]string{"Version", "Address", "Id"}) + table.SetAutoFormatHeaders(false) + for _, s := range services { + for _, n := range s.Nodes { + table.Append([]string{s.Version, n.Address, n.Id}) + } + } + table.Render() + return nil + }, + } +} diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 0cf4a473599..1cba3b4a24c 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -21,10 +21,10 @@ type HTTP struct { Root string `ocisConfig:"root"` } -// Server configures a server. -type Server struct { - Version string `ocisConfig:"version"` +// Service defines the available service configuration. +type Service struct { Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -85,7 +85,7 @@ type Config struct { Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` - Server Server `ocisConfig:"server"` + Service Service `ocisConfig:"service"` Tracing Tracing `ocisConfig:"tracing"` Reva Reva `ocisConfig:"reva"` TokenManager TokenManager `ocisConfig:"token_manager"` @@ -109,10 +109,12 @@ func DefaultConfig() *Config { }, HTTP: HTTP{ Addr: "127.0.0.1:9120", - Namespace: "com.owncloud.web", + Namespace: "com.owncloud.graph", Root: "/graph", }, - Server: Server{}, + Service: Service{ + Name: "graph", + }, Tracing: Tracing{ Enabled: false, Type: "jaeger", diff --git a/idp/pkg/command/version.go b/idp/pkg/command/version.go index 7408d59f617..30a54513947 100644 --- a/idp/pkg/command/version.go +++ b/idp/pkg/command/version.go @@ -21,7 +21,7 @@ func PrintVersion(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) + services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { fmt.Println(fmt.Errorf("could not get idp services from the registry: %v", err)) return err diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index ffb7e781e4d..54f1ff1d9a4 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -19,11 +19,18 @@ type Debug struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` - TLSCert string `ocisConfig:"tls_cert"` - TLSKey string `ocisConfig:"tls_key"` - TLS bool `ocisConfig:"tls"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` + TLSCert string `ocisConfig:"tls_cert"` + TLSKey string `ocisConfig:"tls_key"` + TLS bool `ocisConfig:"tls"` +} + +// Service defines the available service configuration. +type Service struct { + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Ldap defines the available LDAP configuration. @@ -41,13 +48,6 @@ type Ldap struct { Filter string `ocisConfig:"filter"` } -// Service defines the available service configuration. -type Service struct { - Name string `ocisConfig:"name"` - Namespace string `ocisConfig:"namespace"` - Version string `ocisConfig:"version"` -} - // Tracing defines the available tracing configuration. type Tracing struct { Enabled bool `ocisConfig:"enabled"` @@ -125,11 +125,15 @@ func DefaultConfig() *Config { Addr: "127.0.0.1:9134", }, HTTP: HTTP{ - Addr: "127.0.0.1:9130", - Root: "/", - TLSCert: path.Join(defaults.BaseDataPath(), "idp", "server.crt"), - TLSKey: path.Join(defaults.BaseDataPath(), "idp", "server.key"), - TLS: false, + Addr: "127.0.0.1:9130", + Root: "/", + Namespace: "com.owncloud.web", + TLSCert: path.Join(defaults.BaseDataPath(), "idp", "server.crt"), + TLSKey: path.Join(defaults.BaseDataPath(), "idp", "server.key"), + TLS: false, + }, + Service: Service{ + Name: "idp", }, Tracing: Tracing{ Type: "jaeger", @@ -184,9 +188,5 @@ func DefaultConfig() *Config { UUIDAttributeType: "text", Filter: "(objectClass=posixaccount)", }, - Service: Service{ - Name: "idp", - Namespace: "com.owncloud.web", - }, } } diff --git a/idp/pkg/config/mappings.go b/idp/pkg/config/mappings.go index 68383fe5c78..6e316eaba81 100644 --- a/idp/pkg/config/mappings.go +++ b/idp/pkg/config/mappings.go @@ -89,10 +89,10 @@ func structMappings(cfg *Config) []shared.EnvBinding { }, { EnvVars: []string{"IDP_HTTP_NAMESPACE"}, - Destination: &cfg.Service.Namespace, + Destination: &cfg.HTTP.Namespace, }, { - EnvVars: []string{"IDP_NAME"}, + EnvVars: []string{"IDP_SERVICE_NAME"}, Destination: &cfg.Service.Name, }, { diff --git a/idp/pkg/server/http/server.go b/idp/pkg/server/http/server.go index cab4554b3da..107643e3364 100644 --- a/idp/pkg/server/http/server.go +++ b/idp/pkg/server/http/server.go @@ -40,7 +40,7 @@ func Server(opts ...Option) (http.Service, error) { service := http.NewService( http.Logger(options.Logger), - http.Namespace(options.Config.Service.Namespace), + http.Namespace(options.Config.HTTP.Namespace), http.Name(options.Config.Service.Name), http.Version(options.Config.Service.Version), http.Address(options.Config.HTTP.Addr), diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go new file mode 100644 index 00000000000..1b1ae5553dc --- /dev/null +++ b/ocis/pkg/command/graph.go @@ -0,0 +1,42 @@ +//go:build !simple +// +build !simple + +package command + +import ( + "github.com/owncloud/ocis/graph/pkg/command" + "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis/pkg/register" + "github.com/urfave/cli/v2" +) + +// GraphCommand is the entrypoint for the graph command. +func GraphCommand(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "graph", + Usage: "Start graph server", + Category: "Extensions", + Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.Graph.Commons = cfg.Commons + } + + return nil + }, + Action: func(c *cli.Context) error { + origCmd := command.Server(cfg.Graph) + return handleOriginalAction(c, origCmd) + }, + Subcommands: []*cli.Command{ + command.PrintVersion(cfg.Graph), + }, + } +} + +func init() { + register.AddCommand(GraphCommand) +} diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go new file mode 100644 index 00000000000..e4dc82e0247 --- /dev/null +++ b/ocis/pkg/command/graphexplorer.go @@ -0,0 +1,42 @@ +//go:build !simple +// +build !simple + +package command + +import ( + "github.com/owncloud/ocis/graph-explorer/pkg/command" + "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis/pkg/register" + "github.com/urfave/cli/v2" +) + +// GraphExplorerCommand is the entrypoint for the graph-explorer command. +func GraphExplorerCommand(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "graph-explorer", + Usage: "Start graph-explorer server", + Category: "Extensions", + Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.Graph.Commons = cfg.Commons + } + + return nil + }, + Action: func(c *cli.Context) error { + origCmd := command.Server(cfg.GraphExplorer) + return handleOriginalAction(c, origCmd) + }, + Subcommands: []*cli.Command{ + command.PrintVersion(cfg.GraphExplorer), + }, + } +} + +func init() { + register.AddCommand(GraphExplorerCommand) +} diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 573266ca9d0..9498c7a017a 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -16,7 +16,7 @@ func StorageAuthMachineCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-machine", Usage: "Start storage auth-machine service", Category: "Extensions", - //Flags: flagset.AuthBearerWithConfig(cfg.Storage), + //Flags: flagset.AuthMachineWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocs/pkg/command/version.go b/ocs/pkg/command/version.go index 2c1b64e0e7a..dac137c15cd 100644 --- a/ocs/pkg/command/version.go +++ b/ocs/pkg/command/version.go @@ -21,7 +21,7 @@ func PrintVersion(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) + services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { fmt.Println(fmt.Errorf("could not get ocs services from the registry: %v", err)) return err diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 01f2d65bbd1..882c6364ee3 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -24,16 +24,16 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` - CORS CORS `ocisConfig:"cors"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Namespace string `ocisConfig:"namespace"` - Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -98,8 +98,9 @@ func DefaultConfig() *Config { Zpages: false, }, HTTP: HTTP{ - Addr: "127.0.0.1:9110", - Root: "/ocs", + Addr: "127.0.0.1:9110", + Root: "/ocs", + Namespace: "com.owncloud.web", CORS: CORS{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, @@ -107,6 +108,9 @@ func DefaultConfig() *Config { AllowCredentials: true, }, }, + Service: Service{ + Name: "ocs", + }, Tracing: Tracing{ Enabled: false, Type: "jaeger", @@ -117,10 +121,6 @@ func DefaultConfig() *Config { TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, - Service: Service{ - Name: "ocs", - Namespace: "com.owncloud.web", - }, AccountBackend: "accounts", Reva: Reva{Address: "127.0.0.1:9142"}, StorageUsersDriver: "ocis", diff --git a/ocs/pkg/config/mappings.go b/ocs/pkg/config/mappings.go index 2aab7b910ce..7fe449dd54c 100644 --- a/ocs/pkg/config/mappings.go +++ b/ocs/pkg/config/mappings.go @@ -84,11 +84,11 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.Addr, }, { - EnvVars: []string{"OCS_NAMESPACE"}, - Destination: &cfg.Service.Namespace, + EnvVars: []string{"OCS_HTTP_NAMESPACE"}, + Destination: &cfg.HTTP.Namespace, }, { - EnvVars: []string{"OCS_NAME"}, + EnvVars: []string{"OCS_SERVICE_NAME"}, Destination: &cfg.Service.Name, }, { diff --git a/ocs/pkg/server/http/server.go b/ocs/pkg/server/http/server.go index 4df5fbbddb4..27c4e7e7fb8 100644 --- a/ocs/pkg/server/http/server.go +++ b/ocs/pkg/server/http/server.go @@ -18,7 +18,7 @@ func Server(opts ...Option) (http.Service, error) { http.Logger(options.Logger), http.Name(options.Config.Service.Name), http.Version(options.Config.Service.Version), - http.Namespace(options.Config.Service.Namespace), + http.Namespace(options.Config.HTTP.Namespace), http.Address(options.Config.HTTP.Addr), http.Context(options.Context), http.Flags(options.Flags...), diff --git a/proxy/pkg/command/version.go b/proxy/pkg/command/version.go index 469abc6efe7..bd9cd671792 100644 --- a/proxy/pkg/command/version.go +++ b/proxy/pkg/command/version.go @@ -21,7 +21,7 @@ func PrintVersion(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) + services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { fmt.Println(fmt.Errorf("could not get proxy services from the registry: %v", err)) return err diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index bd21ee1e320..5193d5a653e 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -26,18 +26,18 @@ type Debug struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` - TLSCert string `ocisConfig:"tls_cert"` - TLSKey string `ocisConfig:"tls_key"` - TLS bool `ocisConfig:"tls"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` + TLSCert string `ocisConfig:"tls_cert"` + TLSKey string `ocisConfig:"tls_key"` + TLS bool `ocisConfig:"tls"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Namespace string `ocisConfig:"namespace"` - Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -207,15 +207,15 @@ func DefaultConfig() *Config { Token: "", }, HTTP: HTTP{ - Addr: "0.0.0.0:9200", - Root: "/", - TLSCert: path.Join(defaults.BaseDataPath(), "proxy", "server.crt"), - TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"), - TLS: true, + Addr: "0.0.0.0:9200", + Root: "/", + Namespace: "com.owncloud.web", + TLSCert: path.Join(defaults.BaseDataPath(), "proxy", "server.crt"), + TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"), + TLS: true, }, Service: Service{ - Name: "proxy", - Namespace: "com.owncloud.web", + Name: "proxy", }, Tracing: Tracing{ Type: "jaeger", diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index 582e391b4e5..1bb038a2635 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -101,15 +101,9 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"PROXY_HTTP_ROOT"}, Destination: &cfg.HTTP.Root, }, - - // Service { - EnvVars: []string{"PROXY_SERVICE_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - { - EnvVars: []string{"PROXY_SERVICE_NAME"}, - Destination: &cfg.Service.Name, + EnvVars: []string{"PROXY_HTTP_NAMESPACE"}, + Destination: &cfg.HTTP.Namespace, }, { EnvVars: []string{"PROXY_TRANSPORT_TLS_CERT"}, @@ -123,6 +117,14 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"PROXY_TLS"}, Destination: &cfg.HTTP.TLS, }, + + // Service + { + EnvVars: []string{"PROXY_SERVICE_NAME"}, + Destination: &cfg.Service.Name, + }, + + // Other { EnvVars: []string{"OCIS_JWT_SECRET", "PROXY_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, diff --git a/proxy/pkg/server/http/server.go b/proxy/pkg/server/http/server.go index a403f630d29..4ae43d82460 100644 --- a/proxy/pkg/server/http/server.go +++ b/proxy/pkg/server/http/server.go @@ -43,11 +43,11 @@ func Server(opts ...Option) (svc.Service, error) { service := svc.NewService( svc.Name(options.Config.Service.Name), + svc.Version(options.Config.Service.Version), svc.TLSConfig(tlsConfig), svc.Logger(options.Logger), - svc.Namespace(options.Config.Service.Namespace), - svc.Version(options.Config.Service.Version), svc.Address(options.Config.HTTP.Addr), + svc.Namespace(options.Config.HTTP.Namespace), svc.Context(options.Context), svc.Flags(options.Flags...), ) diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 4d91088b965..113beb8cb11 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -36,7 +36,7 @@ type HTTP struct { // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `ocisConfig:"grpc"` + Addr string `ocisConfig:"addr"` Namespace string `ocisConfig:"namespace"` } diff --git a/settings/pkg/config/mappings.go b/settings/pkg/config/mappings.go index 0fd5a9f2d6b..da12fcfa6db 100644 --- a/settings/pkg/config/mappings.go +++ b/settings/pkg/config/mappings.go @@ -104,7 +104,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.GRPC.Namespace, }, { - EnvVars: []string{"SETTINGS_NAME"}, + EnvVars: []string{"SETTINGS_SERVICE_NAME"}, Destination: &cfg.Service.Name, }, { diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 7de4fc5aa56..80e16d0719e 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -35,6 +35,7 @@ func Execute(cfg *config.Config) error { AppProvider(cfg), AuthBasic(cfg), AuthBearer(cfg), + AuthMachine(cfg), Sharing(cfg), StorageUsers(cfg), StorageShares(cfg), diff --git a/store/pkg/command/version.go b/store/pkg/command/version.go index b5bfef3b266..588e45b6465 100644 --- a/store/pkg/command/version.go +++ b/store/pkg/command/version.go @@ -21,7 +21,7 @@ func PrintVersion(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) + services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { fmt.Println(fmt.Errorf("could not get store services from the registry: %v", err)) return err diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index a39cae29b54..3131492b615 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -18,15 +18,15 @@ type Debug struct { // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Namespace string `ocisConfig:"namespace"` - Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -67,7 +67,11 @@ func DefaultConfig() *Config { Zpages: false, }, GRPC: GRPC{ - Addr: "127.0.0.1:9460", + Addr: "127.0.0.1:9460", + Namespace: "com.owncloud.api", + }, + Service: Service{ + Name: "store", }, Tracing: Tracing{ Enabled: false, @@ -77,10 +81,6 @@ func DefaultConfig() *Config { Service: "store", }, Datapath: path.Join(defaults.BaseDataPath(), "store"), - Service: Service{ - Name: "store", - Namespace: "com.owncloud.api", - }, } } diff --git a/store/pkg/config/mappings.go b/store/pkg/config/mappings.go index 62eea4e71e5..189f293ec5f 100644 --- a/store/pkg/config/mappings.go +++ b/store/pkg/config/mappings.go @@ -66,14 +66,14 @@ func structMappings(cfg *Config) []shared.EnvBinding { }, { EnvVars: []string{"STORE_GRPC_NAMESPACE"}, - Destination: &cfg.Service.Namespace, + Destination: &cfg.GRPC.Namespace, }, { EnvVars: []string{"STORE_GRPC_ADDR"}, Destination: &cfg.GRPC.Addr, }, { - EnvVars: []string{"STORE_NAME"}, + EnvVars: []string{"STORE_SERVICE_NAME"}, Destination: &cfg.Service.Name, }, { diff --git a/store/pkg/server/grpc/server.go b/store/pkg/server/grpc/server.go index 148de47ad8b..46ba11de8f0 100644 --- a/store/pkg/server/grpc/server.go +++ b/store/pkg/server/grpc/server.go @@ -11,7 +11,7 @@ func Server(opts ...Option) grpc.Service { options := newOptions(opts...) service := grpc.NewService( - grpc.Namespace(options.Config.Service.Namespace), + grpc.Namespace(options.Config.GRPC.Namespace), grpc.Name(options.Config.Service.Name), grpc.Version(options.Config.Service.Version), grpc.Context(options.Context), diff --git a/store/pkg/service/v0/service.go b/store/pkg/service/v0/service.go index c1a5cc98d99..b86033f1d3f 100644 --- a/store/pkg/service/v0/service.go +++ b/store/pkg/service/v0/service.go @@ -49,7 +49,7 @@ func New(opts ...Option) (s *Service, err error) { indexMapping.DefaultAnalyzer = keyword.Name s = &Service{ - id: cfg.Service.Namespace + "." + cfg.Service.Name, + id: cfg.GRPC.Namespace + "." + cfg.Service.Name, log: logger, Config: cfg, } diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 5136f0df0ca..30dc5c53ba6 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -30,7 +30,7 @@ func Execute(cfg *config.Config) error { }, Before: func(c *cli.Context) error { - cfg.Server.Version = version.String + cfg.Service.Version = version.String return nil }, diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index fc7ec10a625..f76645ba860 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -43,15 +43,15 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Server.Version).Set(1) + metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) service := grpc.NewService( grpc.Logger(logger), grpc.Context(ctx), grpc.Config(cfg), - grpc.Name(cfg.Server.Name), - grpc.Namespace(cfg.Server.Namespace), - grpc.Address(cfg.Server.Address), + grpc.Name(cfg.Service.Name), + grpc.Namespace(cfg.GRPC.Namespace), + grpc.Address(cfg.GRPC.Addr), grpc.Metrics(metrics), ) diff --git a/thumbnails/pkg/command/version.go b/thumbnails/pkg/command/version.go index df3c0230f02..d3dfb245916 100644 --- a/thumbnails/pkg/command/version.go +++ b/thumbnails/pkg/command/version.go @@ -21,7 +21,7 @@ func PrintVersion(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Server.Namespace + "." + cfg.Server.Name) + services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { fmt.Println(fmt.Errorf("could not get thumbnails services from the registry: %v", err)) return err diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 0e92f4ce668..2a9bf6582dd 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -16,12 +16,16 @@ type Debug struct { Zpages bool `ocisConfig:"zpages"` } -// Server defines the available server configuration. -type Server struct { - Name string `ocisConfig:"name"` +// GRPC defines the available grpc configuration. +type GRPC struct { + Addr string `ocisConfig:"addr"` Namespace string `ocisConfig:"namespace"` - Address string `ocisConfig:"address"` - Version string `ocisConfig:"version"` +} + +// Service provides configuration options for the service +type Service struct { + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -40,7 +44,8 @@ type Config struct { File string `ocisConfig:"file"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` - Server Server `ocisConfig:"server"` + GRPC GRPC `ocisConfig:"grpc"` + Service Service `ocisConfig:"service"` Tracing Tracing `ocisConfig:"tracing"` Thumbnail Thumbnail `ocisConfig:"thumbnail"` @@ -81,10 +86,12 @@ func DefaultConfig() *Config { Pprof: false, Zpages: false, }, - Server: Server{ - Name: "thumbnails", + GRPC: GRPC{ + Addr: "127.0.0.1:9185", Namespace: "com.owncloud.api", - Address: "127.0.0.1:9185", + }, + Service: Service{ + Name: "thumbnails", }, Tracing: Tracing{ Enabled: false, diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go index a826dd76920..9238a84666e 100644 --- a/thumbnails/pkg/config/mappings.go +++ b/thumbnails/pkg/config/mappings.go @@ -80,16 +80,16 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Debug.Zpages, }, { - EnvVars: []string{"THUMBNAILS_GRPC_NAME"}, - Destination: &cfg.Server.Name, + EnvVars: []string{"THUMBNAILS_SERVICE_NAME"}, + Destination: &cfg.Service.Name, }, { EnvVars: []string{"THUMBNAILS_GRPC_ADDR"}, - Destination: &cfg.Server.Address, + Destination: &cfg.GRPC.Addr, }, { EnvVars: []string{"THUMBNAILS_GRPC_NAMESPACE"}, - Destination: &cfg.Server.Namespace, + Destination: &cfg.GRPC.Namespace, }, { EnvVars: []string{"THUMBNAILS_TXT_FONTMAP_FILE"}, diff --git a/thumbnails/pkg/server/debug/server.go b/thumbnails/pkg/server/debug/server.go index 4db1f72367b..b78261d5fe2 100644 --- a/thumbnails/pkg/server/debug/server.go +++ b/thumbnails/pkg/server/debug/server.go @@ -14,8 +14,8 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name(options.Config.Server.Name), - debug.Version(options.Config.Server.Version), + debug.Name(options.Config.Service.Name), + debug.Version(options.Config.Service.Version), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), diff --git a/thumbnails/pkg/server/grpc/server.go b/thumbnails/pkg/server/grpc/server.go index 0c905c06e56..efa6ed85a32 100644 --- a/thumbnails/pkg/server/grpc/server.go +++ b/thumbnails/pkg/server/grpc/server.go @@ -22,7 +22,7 @@ func NewService(opts ...Option) grpc.Service { grpc.Address(options.Address), grpc.Context(options.Context), grpc.Flags(options.Flags...), - grpc.Version(options.Config.Server.Version), + grpc.Version(options.Config.Service.Version), ) tconf := options.Config.Thumbnail gc, err := pool.GetGatewayServiceClient(tconf.RevaGateway) diff --git a/thumbnails/pkg/service/v0/service.go b/thumbnails/pkg/service/v0/service.go index f15211fe28d..5d9fac80409 100644 --- a/thumbnails/pkg/service/v0/service.go +++ b/thumbnails/pkg/service/v0/service.go @@ -31,7 +31,8 @@ func NewService(opts ...Option) v0proto.ThumbnailServiceHandler { logger.Fatal().Err(err).Msg("resolutions not configured correctly") } svc := Thumbnail{ - serviceID: options.Config.Server.Namespace + "." + options.Config.Server.Name, + serviceID: options.Config.GRPC.Namespace + "." + options.Config.Service.Name, + webdavNamespace: options.Config.Thumbnail.WebdavNamespace, manager: thumbnail.NewSimpleManager( resolutions, options.ThumbnailStorage, diff --git a/web/pkg/command/version.go b/web/pkg/command/version.go new file mode 100644 index 00000000000..94a87b49665 --- /dev/null +++ b/web/pkg/command/version.go @@ -0,0 +1,47 @@ +package command + +import ( + "fmt" + "os" + + "github.com/owncloud/ocis/ocis-pkg/registry" + + tw "github.com/olekukonko/tablewriter" + "github.com/owncloud/ocis/web/pkg/config" + "github.com/urfave/cli/v2" +) + +// PrintVersion prints the service versions of all running instances. +func PrintVersion(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "version", + Usage: "Print the versions of the running instances", + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, + Action: func(c *cli.Context) error { + reg := registry.GetRegistry() + services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) + if err != nil { + fmt.Println(fmt.Errorf("could not get web services from the registry: %v", err)) + return err + } + + if len(services) == 0 { + fmt.Println("No running web service found.") + return nil + } + + table := tw.NewWriter(os.Stdout) + table.SetHeader([]string{"Version", "Address", "Id"}) + table.SetAutoFormatHeaders(false) + for _, s := range services { + for _, n := range s.Nodes { + table.Append([]string{s.Version, n.Address, n.Id}) + } + } + table.Render() + return nil + }, + } +} diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 0054c9331ac..210b52918d7 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -22,6 +22,12 @@ type HTTP struct { CacheTTL int `ocisConfig:"cache_ttl"` } +// Service defines the available service configuration. +type Service struct { + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` +} + // Tracing defines the available tracing configuration. type Tracing struct { Enabled bool `ocisConfig:"enabled"` @@ -92,6 +98,7 @@ type Config struct { Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` + Service Service `ocisConfig:"service"` Tracing Tracing `ocisConfig:"tracing"` Asset Asset `ocisConfig:"asset"` Web Web `ocisConfig:"web"` @@ -119,6 +126,9 @@ func DefaultConfig() *Config { Namespace: "com.owncloud.web", CacheTTL: 604800, // 7 days }, + Service: Service{ + Name: "web", + }, Tracing: Tracing{ Enabled: false, Type: "jaeger", diff --git a/webdav/pkg/command/version.go b/webdav/pkg/command/version.go index 813cc1c08c2..a0ab763f591 100644 --- a/webdav/pkg/command/version.go +++ b/webdav/pkg/command/version.go @@ -21,7 +21,7 @@ func PrintVersion(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) + services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { fmt.Println(fmt.Errorf("could not get webdav services from the registry: %v", err)) return err diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 722c8ed2f1e..bb65faa962a 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -24,16 +24,16 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` - CORS CORS `ocisConfig:"cors"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Namespace string `ocisConfig:"namespace"` - Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. @@ -77,8 +77,9 @@ func DefaultConfig() *Config { Zpages: false, }, HTTP: HTTP{ - Addr: "127.0.0.1:9115", - Root: "/", + Addr: "127.0.0.1:9115", + Root: "/", + Namespace: "com.owncloud.web", CORS: CORS{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, @@ -86,6 +87,9 @@ func DefaultConfig() *Config { AllowCredentials: true, }, }, + Service: Service{ + Name: "webdav", + }, Tracing: Tracing{ Enabled: false, Type: "jaeger", @@ -93,10 +97,6 @@ func DefaultConfig() *Config { Collector: "", Service: "webdav", }, - Service: Service{ - Name: "webdav", - Namespace: "com.owncloud.web", - }, OcisPublicURL: "https://127.0.0.1:9200", WebdavNamespace: "/users/{{.Id.OpaqueId}}", RevaGateway: "127.0.0.1:9142", diff --git a/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go index df4abfde080..f14c97d46ee 100644 --- a/webdav/pkg/config/mappings.go +++ b/webdav/pkg/config/mappings.go @@ -85,7 +85,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { }, { EnvVars: []string{"WEBDAV_HTTP_NAMESPACE"}, - Destination: &cfg.Service.Namespace, + Destination: &cfg.HTTP.Namespace, }, { EnvVars: []string{"WEBDAV_SERVICE_NAME"}, diff --git a/webdav/pkg/server/http/server.go b/webdav/pkg/server/http/server.go index 8d8344c87d8..e3217294971 100644 --- a/webdav/pkg/server/http/server.go +++ b/webdav/pkg/server/http/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (http.Service, error) { service := http.NewService( http.Logger(options.Logger), - http.Namespace(options.Config.Service.Namespace), + http.Namespace(options.Config.HTTP.Namespace), http.Name(options.Config.Service.Name), http.Version(options.Config.Service.Version), http.Address(options.Config.HTTP.Addr), From 7b61460fac6be474d0f60c08884fea4fb585bdfa Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 10:56:28 +0100 Subject: [PATCH 35/84] add accounts log level --- accounts/pkg/config/mappings.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/accounts/pkg/config/mappings.go b/accounts/pkg/config/mappings.go index b61d93bc279..d50464d1e95 100644 --- a/accounts/pkg/config/mappings.go +++ b/accounts/pkg/config/mappings.go @@ -16,6 +16,10 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"OCIS_LOG_FILE", "ACCOUNTS_LOG_FILE"}, Destination: &cfg.Log.File, }, + { + EnvVars: []string{"OCIS_LOG_LEVEL", "ACCOUNTS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, { EnvVars: []string{"OCIS_LOG_COLOR", "ACCOUNTS_LOG_COLOR"}, Destination: &cfg.Log.Color, From 106ba59dec1ade1cb9f4cf78dd0b56482ccd1d78 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 10:56:37 +0100 Subject: [PATCH 36/84] fix traefik basic auth defaul --- deployments/examples/oc10_ocis_parallel/docker-compose.yml | 2 +- deployments/examples/ocis_hello/docker-compose.yml | 2 +- deployments/examples/ocis_keycloak/docker-compose.yml | 2 +- deployments/examples/ocis_ldap/docker-compose.yml | 2 +- deployments/examples/ocis_s3/docker-compose.yml | 2 +- deployments/examples/ocis_traefik/docker-compose.yml | 2 +- deployments/examples/ocis_wopi/docker-compose.yml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/deployments/examples/oc10_ocis_parallel/docker-compose.yml b/deployments/examples/oc10_ocis_parallel/docker-compose.yml index 3469715c0fb..ec5185b86fc 100644 --- a/deployments/examples/oc10_ocis_parallel/docker-compose.yml +++ b/deployments/examples/oc10_ocis_parallel/docker-compose.yml @@ -33,7 +33,7 @@ services: - "certs:/certs" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$apr1$4vqie50r$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin + - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.owncloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" diff --git a/deployments/examples/ocis_hello/docker-compose.yml b/deployments/examples/ocis_hello/docker-compose.yml index 19aac699193..c539ed817f4 100644 --- a/deployments/examples/ocis_hello/docker-compose.yml +++ b/deployments/examples/ocis_hello/docker-compose.yml @@ -32,7 +32,7 @@ services: - "certs:/certs" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$apr1$4vqie50r$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin + - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.owncloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" diff --git a/deployments/examples/ocis_keycloak/docker-compose.yml b/deployments/examples/ocis_keycloak/docker-compose.yml index dd2be4da706..ec11d218f90 100644 --- a/deployments/examples/ocis_keycloak/docker-compose.yml +++ b/deployments/examples/ocis_keycloak/docker-compose.yml @@ -33,7 +33,7 @@ services: - "certs:/certs" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$apr1$4vqie50r$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin + - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.owncloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" diff --git a/deployments/examples/ocis_ldap/docker-compose.yml b/deployments/examples/ocis_ldap/docker-compose.yml index 4386238ec69..e8cd83e6219 100644 --- a/deployments/examples/ocis_ldap/docker-compose.yml +++ b/deployments/examples/ocis_ldap/docker-compose.yml @@ -32,7 +32,7 @@ services: - "certs:/certs" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$apr1$4vqie50r$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin + - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.owncloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" diff --git a/deployments/examples/ocis_s3/docker-compose.yml b/deployments/examples/ocis_s3/docker-compose.yml index 996262072ab..aed2b45f4a4 100644 --- a/deployments/examples/ocis_s3/docker-compose.yml +++ b/deployments/examples/ocis_s3/docker-compose.yml @@ -32,7 +32,7 @@ services: - "certs:/certs" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$apr1$4vqie50r$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin + - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.owncloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" diff --git a/deployments/examples/ocis_traefik/docker-compose.yml b/deployments/examples/ocis_traefik/docker-compose.yml index 53b8ca154c1..06a5e7a45df 100644 --- a/deployments/examples/ocis_traefik/docker-compose.yml +++ b/deployments/examples/ocis_traefik/docker-compose.yml @@ -32,7 +32,7 @@ services: - "certs:/certs" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$apr1$4vqie50r$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin + - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.owncloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" diff --git a/deployments/examples/ocis_wopi/docker-compose.yml b/deployments/examples/ocis_wopi/docker-compose.yml index 1cb1cf0a209..e9d0b4f6e33 100644 --- a/deployments/examples/ocis_wopi/docker-compose.yml +++ b/deployments/examples/ocis_wopi/docker-compose.yml @@ -36,7 +36,7 @@ services: - "certs:/certs" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$apr1$4vqie50r$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin + - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" # defaults to admin:admin - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.owncloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" From 0360b58587a94828d17ab1856884507091df1ff4 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 11:18:59 +0100 Subject: [PATCH 37/84] fix ocs test --- ocs/pkg/server/http/svc_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index ec50679b6ab..d763a1d2255 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -558,9 +558,7 @@ func init() { ) c := &accountsCfg.Config{ - Server: accountsCfg.Server{ - DemoUsersAndGroups: true, - }, + DemoUsersAndGroups: true, Repo: accountsCfg.Repo{ Backend: "disk", Disk: accountsCfg.Disk{ From ebfe8f069cfc3e8c113b40d14757b16fbf8f6483 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 14:59:55 +0100 Subject: [PATCH 38/84] remove service names --- accounts/pkg/config/mappings.go | 4 ---- idp/pkg/config/mappings.go | 4 ---- ocs/pkg/config/mappings.go | 4 ---- proxy/pkg/config/mappings.go | 6 ------ settings/pkg/config/mappings.go | 4 ---- store/pkg/config/mappings.go | 4 ---- thumbnails/pkg/config/mappings.go | 4 ---- webdav/pkg/config/mappings.go | 4 ---- 8 files changed, 34 deletions(-) diff --git a/accounts/pkg/config/mappings.go b/accounts/pkg/config/mappings.go index d50464d1e95..fdcdbcecd14 100644 --- a/accounts/pkg/config/mappings.go +++ b/accounts/pkg/config/mappings.go @@ -72,10 +72,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"ACCOUNTS_GRPC_ADDR"}, Destination: &cfg.GRPC.Addr, }, - { - EnvVars: []string{"ACCOUNTS_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, { EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"}, Destination: &cfg.HashDifficulty, diff --git a/idp/pkg/config/mappings.go b/idp/pkg/config/mappings.go index 6e316eaba81..c5b01cf74fa 100644 --- a/idp/pkg/config/mappings.go +++ b/idp/pkg/config/mappings.go @@ -91,10 +91,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"IDP_HTTP_NAMESPACE"}, Destination: &cfg.HTTP.Namespace, }, - { - EnvVars: []string{"IDP_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, { EnvVars: []string{"IDP_IDENTITY_MANAGER"}, Destination: &cfg.IDP.IdentityManager, diff --git a/ocs/pkg/config/mappings.go b/ocs/pkg/config/mappings.go index 7fe449dd54c..b32177739c0 100644 --- a/ocs/pkg/config/mappings.go +++ b/ocs/pkg/config/mappings.go @@ -87,10 +87,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"OCS_HTTP_NAMESPACE"}, Destination: &cfg.HTTP.Namespace, }, - { - EnvVars: []string{"OCS_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, { EnvVars: []string{"OCS_HTTP_ROOT"}, Destination: &cfg.HTTP.Root, diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index 1bb038a2635..101d9a70d27 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -118,12 +118,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.TLS, }, - // Service - { - EnvVars: []string{"PROXY_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, - // Other { EnvVars: []string{"OCIS_JWT_SECRET", "PROXY_JWT_SECRET"}, diff --git a/settings/pkg/config/mappings.go b/settings/pkg/config/mappings.go index da12fcfa6db..d4910269c91 100644 --- a/settings/pkg/config/mappings.go +++ b/settings/pkg/config/mappings.go @@ -103,10 +103,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"SETTINGS_GRPC_NAMESPACE"}, Destination: &cfg.GRPC.Namespace, }, - { - EnvVars: []string{"SETTINGS_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, { EnvVars: []string{"SETTINGS_DATA_PATH"}, Destination: &cfg.Service.DataPath, diff --git a/store/pkg/config/mappings.go b/store/pkg/config/mappings.go index 189f293ec5f..9d883ca2325 100644 --- a/store/pkg/config/mappings.go +++ b/store/pkg/config/mappings.go @@ -72,10 +72,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"STORE_GRPC_ADDR"}, Destination: &cfg.GRPC.Addr, }, - { - EnvVars: []string{"STORE_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, { EnvVars: []string{"STORE_DATA_PATH"}, Destination: &cfg.Datapath, diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go index 9238a84666e..fdd30b5019a 100644 --- a/thumbnails/pkg/config/mappings.go +++ b/thumbnails/pkg/config/mappings.go @@ -79,10 +79,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"THUMBNAILS_DEBUG_ZPAGES"}, Destination: &cfg.Debug.Zpages, }, - { - EnvVars: []string{"THUMBNAILS_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, { EnvVars: []string{"THUMBNAILS_GRPC_ADDR"}, Destination: &cfg.GRPC.Addr, diff --git a/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go index f14c97d46ee..350ab25fd63 100644 --- a/webdav/pkg/config/mappings.go +++ b/webdav/pkg/config/mappings.go @@ -87,10 +87,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"WEBDAV_HTTP_NAMESPACE"}, Destination: &cfg.HTTP.Namespace, }, - { - EnvVars: []string{"WEBDAV_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, { EnvVars: []string{"WEBDAV_HTTP_ROOT"}, Destination: &cfg.HTTP.Root, From d2befd9257d925139c0e64d34fb727222cd0df1a Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 16:51:18 +0100 Subject: [PATCH 39/84] switch accounts to struct tag based env config --- accounts/pkg/command/root.go | 41 +++++---- accounts/pkg/command/server.go | 14 ++- accounts/pkg/config/config.go | 127 +++++++++++--------------- accounts/pkg/config/mappings.go | 140 ----------------------------- accounts/pkg/service/v0/service.go | 8 +- go.mod | 3 +- go.sum | 2 + ocis-pkg/config/helpers.go | 2 +- ocis/pkg/command/accounts.go | 6 +- 9 files changed, 99 insertions(+), 244 deletions(-) delete mode 100644 accounts/pkg/config/mappings.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 948ff2e4a1c..6b646b4f24a 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -4,13 +4,13 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" "github.com/owncloud/ocis/accounts/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-accounts command. @@ -58,28 +58,35 @@ func Execute(cfg *config.Config) error { // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("accounts", cfg) + _, err := ociscfg.BindSourcesToStructs("accounts", cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} - } + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(cfg), false) + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil { + return err + } - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree. @@ -89,7 +96,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Accounts.Commons = cfg.Commons + //cfg.Accounts.Commons = cfg.Commons return SutureService{ cfg: cfg.Accounts, } diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 3475532434c..e28e8373c99 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -16,6 +16,18 @@ import ( "github.com/urfave/cli/v2" ) +// TODO: don't redeclare from ocis-pkg/log/log.go +// LoggerFromConfig initializes a service-specific logger instance. +func LoggerFromConfig(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} + // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ @@ -36,7 +48,7 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := log.LoggerFromConfig("accounts", *cfg.Log) + logger := LoggerFromConfig("accounts", cfg.Log) err := tracing.Configure(cfg) if err != nil { return err diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 63844a2cccd..bc49960810b 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -5,34 +5,9 @@ import ( "context" "path" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// LDAP defines the available ldap configuration. -type LDAP struct { - Hostname string `ocisConfig:"hostname"` - Port int `ocisConfig:"port"` - BaseDN string `ocisConfig:"base_dn"` - UserFilter string `ocisConfig:"user_filter"` - GroupFilter string `ocisConfig:"group_filter"` - BindDN string `ocisConfig:"bind_dn"` - BindPassword string `ocisConfig:"bind_password"` - IDP string `ocisConfig:"idp"` - Schema LDAPSchema `ocisConfig:"schema"` -} - -// LDAPSchema defines the available ldap schema configuration. -type LDAPSchema struct { - AccountID string `ocisConfig:"account_id"` - Identities string `ocisConfig:"identities"` - Username string `ocisConfig:"username"` - DisplayName string `ocisConfig:"display_name"` - Mail string `ocisConfig:"mail"` - Groups string `ocisConfig:"groups"` -} - // CORS defines the available cors configuration. type CORS struct { AllowedOrigins []string `ocisConfig:"allowed_origins"` @@ -43,98 +18,111 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` - Root string `ocisConfig:"root"` - CacheTTL int `ocisConfig:"cache_ttl"` + Addr string `ocisConfig:"addr" env:"ACCOUNTS_HTTP_ADDR"` + Namespace string + Root string `ocisConfig:"root" env:"ACCOUNTS_HTTP_ROOT"` + CacheTTL int `ocisConfig:"cache_ttl" env:"ACCOUNTS_CACHE_TTL"` CORS CORS `ocisConfig:"cors"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` + Addr string `ocisConfig:"addr" env:"ACCOUNTS_GRPC_ADDR"` + Namespace string } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Asset defines the available asset configuration. type Asset struct { - Path string `ocisConfig:"path"` + Path string `ocisConfig:"path" env:"ACCOUNTS_ASSET_PATH"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;ACCOUNTS_JWT_SECRET"` } // Repo defines which storage implementation is to be used. type Repo struct { - Backend string `ocisConfig:"backend"` + Backend string `ocisConfig:"backend" env:"ACCOUNTS_STORAGE_BACKEND"` Disk Disk `ocisConfig:"disk"` CS3 CS3 `ocisConfig:"cs3"` } // Disk is the local disk implementation of the storage. type Disk struct { - Path string `ocisConfig:"path"` + Path string `ocisConfig:"path" env:"ACCOUNTS_STORAGE_DISK_PATH"` } // CS3 is the cs3 implementation of the storage. type CS3 struct { - ProviderAddr string `ocisConfig:"provider_addr"` - JWTSecret string `ocisConfig:"jwt_secret"` + ProviderAddr string `ocisConfig:"provider_addr" env:"ACCOUNTS_STORAGE_CS3_PROVIDER_ADDR"` + JWTSecret string `ocisConfig:"jwt_secret" env:"ACCOUNTS_STORAGE_CS3_JWT_SECRET"` } // ServiceUser defines the user required for EOS. type ServiceUser struct { - UUID string `ocisConfig:"uuid"` - Username string `ocisConfig:"username"` - UID int64 `ocisConfig:"uid"` - GID int64 `ocisConfig:"gid"` + UUID string `ocisConfig:"uuid" env:"ACCOUNTS_SERVICE_USER_UUID"` + Username string `ocisConfig:"username" env:"ACCOUNTS_SERVICE_USER_USERNAME"` + UID int64 `ocisConfig:"uid" env:"ACCOUNTS_SERVICE_USER_UID"` + GID int64 `ocisConfig:"gid" env:"ACCOUNTS_SERVICE_USER_GID"` } // Index defines config for indexes. type Index struct { - UID Bound `ocisConfig:"uid"` - GID Bound `ocisConfig:"gid"` + UID UIDBound `ocisConfig:"uid"` + GID GIDBound `ocisConfig:"gid"` } -// Bound defines a lower and upper bound. -type Bound struct { - Lower int64 `ocisConfig:"lower"` - Upper int64 `ocisConfig:"upper"` +// GIDBound defines a lower and upper bound. +type GIDBound struct { + Lower int64 `ocisConfig:"lower" env:"ACCOUNTS_GID_INDEX_LOWER_BOUND"` + Upper int64 `ocisConfig:"upper" env:"ACCOUNTS_GID_INDEX_UPPER_BOUND"` +} + +// UIDBound defines a lower and upper bound. +type UIDBound struct { + Lower int64 `ocisConfig:"lower" env:"ACCOUNTS_UID_INDEX_LOWER_BOUND"` + Upper int64 `ocisConfig:"upper" env:"ACCOUNTS_UID_INDEX_UPPER_BOUND"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;ACCOUNTS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;ACCOUNTS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;ACCOUNTS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;ACCOUNTS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"ACCOUNTS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;ACCOUNTS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;ACCOUNTS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;ACCOUNTS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;ACCOUNTS_LOG_FILE"` } // Config merges all Account config parameters. type Config struct { - *shared.Commons + //*shared.Commons - LDAP LDAP `ocisConfig:"ldap"` HTTP HTTP `ocisConfig:"http"` GRPC GRPC `ocisConfig:"grpc"` Service Service `ocisConfig:"service"` Asset Asset `ocisConfig:"asset"` - Log *shared.Log `ocisConfig:"log"` + Log Log `ocisConfig:"log"` TokenManager TokenManager `ocisConfig:"token_manager"` Repo Repo `ocisConfig:"repo"` Index Index `ocisConfig:"index"` ServiceUser ServiceUser `ocisConfig:"service_user"` - HashDifficulty int `ocisConfig:"hash_difficulty"` - DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups"` + HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"` + DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"` Tracing Tracing `ocisConfig:"tracing"` Context context.Context @@ -143,14 +131,12 @@ type Config struct { // New returns a new config. func New() *Config { - return &Config{ - Log: &shared.Log{}, - } + return &Config{} } func DefaultConfig() *Config { return &Config{ - LDAP: LDAP{}, + HTTP: HTTP{ Addr: "127.0.0.1:9181", Namespace: "com.owncloud.web", @@ -187,11 +173,11 @@ func DefaultConfig() *Config { }, }, Index: Index{ - UID: Bound{ + UID: UIDBound{ Lower: 0, Upper: 1000, }, - GID: Bound{ + GID: GIDBound{ Lower: 0, Upper: 1000, }, @@ -208,14 +194,3 @@ func DefaultConfig() *Config { }, } } - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} diff --git a/accounts/pkg/config/mappings.go b/accounts/pkg/config/mappings.go deleted file mode 100644 index fdcdbcecd14..00000000000 --- a/accounts/pkg/config/mappings.go +++ /dev/null @@ -1,140 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_FILE", "ACCOUNTS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_LOG_LEVEL", "ACCOUNTS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "ACCOUNTS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "ACCOUNTS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "ACCOUNTS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "ACCOUNTS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "ACCOUNTS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "ACCOUNTS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"ACCOUNTS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"ACCOUNTS_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"ACCOUNTS_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"ACCOUNTS_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"ACCOUNTS_CACHE_TTL"}, - Destination: &cfg.HTTP.CacheTTL, - }, - { - EnvVars: []string{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - { - EnvVars: []string{"ACCOUNTS_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - { - EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"}, - Destination: &cfg.HashDifficulty, - }, - { - EnvVars: []string{"ACCOUNTS_DEMO_USERS_AND_GROUPS"}, - Destination: &cfg.DemoUsersAndGroups, - }, - { - EnvVars: []string{"ACCOUNTS_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - { - EnvVars: []string{"OCIS_JWT_SECRET", "ACCOUNTS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - { - EnvVars: []string{"ACCOUNTS_STORAGE_BACKEND"}, - Destination: &cfg.Repo.Backend, - }, - { - EnvVars: []string{"ACCOUNTS_STORAGE_DISK_PATH"}, - Destination: &cfg.Repo.Disk.Path, - }, - { - EnvVars: []string{"ACCOUNTS_STORAGE_CS3_PROVIDER_ADDR"}, - Destination: &cfg.Repo.CS3.ProviderAddr, - }, - { - EnvVars: []string{"OCIS_JWT_SECRET", "ACCOUNTS_STORAGE_CS3_JWT_SECRET"}, - Destination: &cfg.Repo.CS3.JWTSecret, - }, - { - EnvVars: []string{"ACCOUNTS_SERVICE_USER_UUID"}, - Destination: &cfg.ServiceUser.UUID, - }, - { - EnvVars: []string{"ACCOUNTS_SERVICE_USER_USERNAME"}, - Destination: &cfg.ServiceUser.Username, - }, - { - EnvVars: []string{"ACCOUNTS_SERVICE_USER_UID"}, - Destination: &cfg.ServiceUser.UID, - }, - { - EnvVars: []string{"ACCOUNTS_SERVICE_USER_GID"}, - Destination: &cfg.ServiceUser.GID, - }, - { - EnvVars: []string{"ACCOUNTS_UID_INDEX_LOWER_BOUND"}, - Destination: &cfg.Index.UID.Lower, - }, - { - EnvVars: []string{"ACCOUNTS_GID_INDEX_LOWER_BOUND"}, - Destination: &cfg.Index.GID.Lower, - }, - { - EnvVars: []string{"ACCOUNTS_UID_INDEX_UPPER_BOUND"}, - Destination: &cfg.Index.UID.Upper, - }, - { - EnvVars: []string{"ACCOUNTS_GID_INDEX_UPPER_BOUND"}, - Destination: &cfg.Index.GID.Upper, - }, - } -} diff --git a/accounts/pkg/service/v0/service.go b/accounts/pkg/service/v0/service.go index d9118ad42a9..957f5a50cf1 100644 --- a/accounts/pkg/service/v0/service.go +++ b/accounts/pkg/service/v0/service.go @@ -8,8 +8,6 @@ import ( "strings" "time" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/pkg/errors" "github.com/owncloud/ocis/ocis-pkg/service/grpc" @@ -111,9 +109,9 @@ func (s Service) buildIndex() (*indexer.Indexer, error) { func configFromSvc(cfg *config.Config) (*idxcfg.Config, error) { c := idxcfg.New() - if cfg.Log == nil { - cfg.Log = &shared.Log{} - } + //if cfg.Log == nil { + // cfg.Log = &shared.Log{} + //} defer func(cfg *config.Config) { l := log.NewLogger(log.Color(cfg.Log.Color), log.Pretty(cfg.Log.Pretty), log.Level(cfg.Log.Level)) diff --git a/go.mod b/go.mod index 11d4291d949..4461af23bb9 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.2 github.com/iancoleman/strcase v0.2.0 + github.com/imdario/mergo v0.3.12 github.com/justinas/alice v1.2.0 github.com/libregraph/lico v0.53.1 github.com/mennanov/fieldmask-utils v0.5.0 @@ -56,6 +57,7 @@ require ( github.com/stretchr/testify v1.7.0 github.com/thejerf/suture/v4 v4.0.1 github.com/urfave/cli/v2 v2.3.0 + github.com/wkloucek/envdecode v0.0.0-20211216135343-360f0d3c2679 go-micro.dev/v4 v4.5.0 go.opencensus.io v0.23.0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0 @@ -150,7 +152,6 @@ require ( github.com/hashicorp/go-plugin v1.4.3 // indirect github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect github.com/huandu/xstrings v1.3.2 // indirect - github.com/imdario/mergo v0.3.12 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect diff --git a/go.sum b/go.sum index 9e230717d1e..c5a01f9029c 100644 --- a/go.sum +++ b/go.sum @@ -1316,6 +1316,8 @@ github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgq github.com/vultr/govultr/v2 v2.0.0/go.mod h1:2PsEeg+gs3p/Fo5Pw8F9mv+DUBEOlrNZ8GmCTGmhOhs= github.com/wk8/go-ordered-map v0.2.0 h1:KlvGyHstD1kkGZkPtHCyCfRYS0cz84uk6rrW/Dnhdtk= github.com/wk8/go-ordered-map v0.2.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= +github.com/wkloucek/envdecode v0.0.0-20211216135343-360f0d3c2679 h1:aFJVdr5Lo6QrfgW4nlmguvATkSp+iOfIg6rcdTfu9eM= +github.com/wkloucek/envdecode v0.0.0-20211216135343-360f0d3c2679/go.mod h1:lEir1NV8XGJ16mCsne3GrW6MbiQyhf5WUk55kvu9rYs= github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= github.com/xanzy/ssh-agent v0.3.1 h1:AmzO1SSWxw73zxFZPRwaMN1MohDw8UyHnmuxyceTEGo= github.com/xanzy/ssh-agent v0.3.1/go.mod h1:QIE4lCeL7nkC25x+yA3LBIYfwCc1TFziCtG7cBAac6w= diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index f89cdc5ddc3..7da572a35f2 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -68,7 +68,7 @@ func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) [] // is to solely modify `dst`, not dealing with the config structs; and do so in a thread safe manner. func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, error) { sources := DefaultConfigSources(extension, supportedExtensions) - cnf := gofig.NewWithOptions(extension, gofig.ParseEnv) + cnf := gofig.NewWithOptions(extension) cnf.WithOptions(func(options *gofig.Options) { options.DecoderConfig.TagName = "ocisConfig" }) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 1cacd70d0a7..40acb44ef2c 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -29,9 +29,9 @@ func AccountsCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.Accounts.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.Accounts.Commons = cfg.Commons + //} return nil }, From cb27090cea3b1cd806ad86f6502de3af5c5a273f Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 17:39:00 +0100 Subject: [PATCH 40/84] fix accounts test --- accounts/pkg/proto/v0/accounts.pb.micro_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index 562fad5894e..85bb16a5d3c 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -12,10 +12,10 @@ import ( mgrpcc "github.com/asim/go-micro/plugins/client/grpc/v4" empty "github.com/golang/protobuf/ptypes/empty" + "github.com/owncloud/ocis/accounts/pkg/command" "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/proto/v0" svc "github.com/owncloud/ocis/accounts/pkg/service/v0" - oclog "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/service/grpc" settings "github.com/owncloud/ocis/settings/pkg/proto/v0" "github.com/stretchr/testify/assert" @@ -85,7 +85,7 @@ func init() { var hdlr *svc.Service var err error - if hdlr, err = svc.New(svc.Logger(oclog.LoggerFromConfig("accounts", *cfg.Log)), svc.Config(cfg), svc.RoleService(buildRoleServiceMock())); err != nil { + if hdlr, err = svc.New(svc.Logger(command.LoggerFromConfig("accounts", cfg.Log)), svc.Config(cfg), svc.RoleService(buildRoleServiceMock())); err != nil { log.Fatalf("Could not create new service") } From 161dd949fc273814a9033f49093c73e82c94ed23 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 18:53:06 +0100 Subject: [PATCH 41/84] switch ocs to struct tag based env config --- accounts/pkg/command/root.go | 2 +- accounts/pkg/command/server.go | 17 +-- accounts/pkg/logging/logging.go | 17 +++ .../pkg/proto/v0/accounts.pb.micro_test.go | 5 +- glauth/pkg/config/config.go | 1 - graph-explorer/pkg/config/config.go | 1 - graph/pkg/config/config.go | 1 - idp/pkg/config/config.go | 1 - ocs/pkg/command/root.go | 39 +++--- ocs/pkg/command/server.go | 7 +- ocs/pkg/config/config.go | 53 ++++---- ocs/pkg/config/mappings.go | 119 ------------------ ocs/pkg/logging/logging.go | 17 +++ ocs/pkg/server/http/svc_test.go | 10 +- settings/pkg/config/config.go | 1 - storage/pkg/config/config.go | 1 - store/pkg/config/config.go | 1 - web/pkg/config/config.go | 1 - 18 files changed, 101 insertions(+), 193 deletions(-) create mode 100644 accounts/pkg/logging/logging.go delete mode 100644 ocs/pkg/config/mappings.go create mode 100644 ocs/pkg/logging/logging.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 6b646b4f24a..502ddb74a8d 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -82,7 +82,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index e28e8373c99..2f68df37c32 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -4,10 +4,9 @@ import ( "context" "strings" - "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/oklog/run" "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/logging" "github.com/owncloud/ocis/accounts/pkg/metrics" "github.com/owncloud/ocis/accounts/pkg/server/grpc" "github.com/owncloud/ocis/accounts/pkg/server/http" @@ -16,18 +15,6 @@ import ( "github.com/urfave/cli/v2" ) -// TODO: don't redeclare from ocis-pkg/log/log.go -// LoggerFromConfig initializes a service-specific logger instance. -func LoggerFromConfig(name string, cfg config.Log) log.Logger { - return log.NewLogger( - log.Name(name), - log.Level(cfg.Level), - log.Pretty(cfg.Pretty), - log.Color(cfg.Color), - log.File(cfg.File), - ) -} - // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ @@ -48,7 +35,7 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := LoggerFromConfig("accounts", cfg.Log) + logger := logging.Configure(cfg.Service.Name, cfg.Log) err := tracing.Configure(cfg) if err != nil { return err diff --git a/accounts/pkg/logging/logging.go b/accounts/pkg/logging/logging.go new file mode 100644 index 00000000000..9b09b128ed8 --- /dev/null +++ b/accounts/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index 85bb16a5d3c..d15b0ab2d2a 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -12,11 +12,12 @@ import ( mgrpcc "github.com/asim/go-micro/plugins/client/grpc/v4" empty "github.com/golang/protobuf/ptypes/empty" - "github.com/owncloud/ocis/accounts/pkg/command" "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/proto/v0" svc "github.com/owncloud/ocis/accounts/pkg/service/v0" + oclog "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/service/grpc" + "github.com/owncloud/ocis/ocis-pkg/shared" settings "github.com/owncloud/ocis/settings/pkg/proto/v0" "github.com/stretchr/testify/assert" "go-micro.dev/v4/client" @@ -85,7 +86,7 @@ func init() { var hdlr *svc.Service var err error - if hdlr, err = svc.New(svc.Logger(command.LoggerFromConfig("accounts", cfg.Log)), svc.Config(cfg), svc.RoleService(buildRoleServiceMock())); err != nil { + if hdlr, err = svc.New(svc.Logger(oclog.LoggerFromConfig("accounts", shared.Log(cfg.Log))), svc.Config(cfg), svc.RoleService(buildRoleServiceMock())); err != nil { log.Fatalf("Could not create new service") } diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index c3b55c77206..f5dd3940119 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -64,7 +64,6 @@ type Backend struct { type Config struct { *shared.Commons - File string `ocisConfig:"file"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` Service Service `ocisConfig:"service"` diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 1acf398e870..0fcacecf42a 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -46,7 +46,6 @@ type GraphExplorer struct { // Config combines all available configuration parts. type Config struct { - File string `ocisConfig:"file"` Log shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 1cba3b4a24c..5a113d20d1e 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -81,7 +81,6 @@ type Identity struct { type Config struct { *shared.Commons - File string `ocisConfig:"file"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 54f1ff1d9a4..510f06e6bf5 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -100,7 +100,6 @@ type Settings struct { type Config struct { *shared.Commons - File string `ocisConfig:"file"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 19c53801c6f..a74c904a789 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -4,14 +4,14 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-ocs command. @@ -67,28 +67,35 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("ocs", cfg) + _, err := ociscfg.BindSourcesToStructs("ocs", cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} - } + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(cfg), false) + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil { + return err + } - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } + + return nil } // SutureService allows for the ocs command to be embedded and supervised by a suture supervisor tree. diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index d72e96216f0..406e0221cc1 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -4,6 +4,7 @@ import ( "context" "strings" + "github.com/owncloud/ocis/ocs/pkg/logging" "github.com/owncloud/ocis/ocs/pkg/tracing" "github.com/oklog/run" @@ -31,9 +32,9 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 882c6364ee3..6c25c301756 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -8,10 +8,10 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"OCS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"OCS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"OCS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"OCS_DEBUG_ZPAGES"` } // CORS defines the available cors configuration. @@ -24,60 +24,67 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` - Namespace string `ocisConfig:"namespace"` - CORS CORS `ocisConfig:"cors"` + Addr string `ocisConfig:"addr" env:"OCS_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"OCS_HTTP_ROOT"` + Namespace string + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;OCS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;OCS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;OCS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;OCS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"OCS_TRACING_SERVICE"` +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;OCS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;OCS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;OCS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;OCS_LOG_FILE"` } // Reva defines all available REVA configuration. type Reva struct { - Address string `ocisConfig:"address"` + Address string `ocisConfig:"address" env:"REVA_GATEWAY"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;OCS_JWT_SECRET"` } // IdentityManagement keeps track of the OIDC address. This is because Reva requisite of uniqueness for users // is based in the combination of IDP hostname + UserID. For more information see: // https://github.com/cs3org/reva/blob/4fd0229f13fae5bc9684556a82dbbd0eced65ef9/pkg/storage/utils/decomposedfs/node/node.go#L856-L865 type IdentityManagement struct { - Address string `ocisConfig:"address"` + Address string `ocisConfig:"address" env:"OCIS_URL;OCS_IDM_ADDRESS"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - File string `ocisConfig:"file"` - Log *shared.Log `ocisConfig:"log"` + Log Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` Tracing Tracing `ocisConfig:"tracing"` TokenManager TokenManager `ocisConfig:"token_manager"` Service Service `ocisConfig:"service"` - AccountBackend string `ocisConfig:"account_backend"` Reva Reva `ocisConfig:"reva"` - StorageUsersDriver string `ocisConfig:"storage_users_driver"` - MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key"` IdentityManagement IdentityManagement `ocisConfig:"identity_management"` + AccountBackend string `ocisConfig:"account_backend" env:"OCS_ACCOUNT_BACKEND_TYPE"` + StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"` + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"` Context context.Context Supervised bool diff --git a/ocs/pkg/config/mappings.go b/ocs/pkg/config/mappings.go deleted file mode 100644 index b32177739c0..00000000000 --- a/ocs/pkg/config/mappings.go +++ /dev/null @@ -1,119 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_FILE", "OCS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_LOG_LEVEL", "OCS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "OCS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "OCS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCS_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "OCS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "OCS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "OCS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "OCS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"OCS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"OCS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"OCS_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"OCS_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"OCS_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"OCS_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"OCS_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"OCS_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"OCIS_JWT_SECRET", "OCS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - { - EnvVars: []string{"OCS_ACCOUNT_BACKEND_TYPE"}, - Destination: &cfg.AccountBackend, - }, - { - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Address, - }, - { - EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "OCS_MACHINE_AUTH_API_KEY"}, - Destination: &cfg.MachineAuthAPIKey, - }, - { - EnvVars: []string{"OCIS_URL", "OCS_IDM_ADDRESS"}, - Destination: &cfg.IdentityManagement.Address, - }, - { - EnvVars: []string{"STORAGE_USERS_DRIVER", "OCS_STORAGE_USERS_DRIVER"}, - Destination: &cfg.StorageUsersDriver, - }, - } -} diff --git a/ocs/pkg/logging/logging.go b/ocs/pkg/logging/logging.go new file mode 100644 index 00000000000..355ab6c0dd9 --- /dev/null +++ b/ocs/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/ocs/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index d763a1d2255..70ee85ff258 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -14,8 +14,6 @@ import ( "strings" "testing" - "github.com/owncloud/ocis/ocis-pkg/shared" - user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/auth/scope" @@ -23,10 +21,10 @@ import ( "github.com/cs3org/reva/pkg/token/manager/jwt" "github.com/golang/protobuf/ptypes/empty" accountsCfg "github.com/owncloud/ocis/accounts/pkg/config" + accountsLogging "github.com/owncloud/ocis/accounts/pkg/logging" accountsProto "github.com/owncloud/ocis/accounts/pkg/proto/v0" accountsSvc "github.com/owncloud/ocis/accounts/pkg/service/v0" ocisLog "github.com/owncloud/ocis/ocis-pkg/log" - oclog "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/service/grpc" "github.com/owncloud/ocis/ocs/pkg/config" svc "github.com/owncloud/ocis/ocs/pkg/service/v0" @@ -565,7 +563,7 @@ func init() { Path: dataPath, }, }, - Log: &shared.Log{ + Log: accountsCfg.Log{ Level: "info", Pretty: true, Color: true, @@ -576,7 +574,7 @@ func init() { var err error if hdlr, err = accountsSvc.New( - accountsSvc.Logger(oclog.LoggerFromConfig("accounts", *c.Log)), + accountsSvc.Logger(accountsLogging.Configure("accounts", c.Log)), accountsSvc.Config(c), accountsSvc.RoleService(buildRoleServiceMock()), ); err != nil { @@ -712,7 +710,7 @@ func getService() svc.Service { TokenManager: config.TokenManager{ JWTSecret: jwtSecret, }, - Log: &shared.Log{ + Log: config.Log{ Level: "debug", }, } diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 113beb8cb11..4b46a8da843 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -70,7 +70,6 @@ type TokenManager struct { type Config struct { *shared.Commons - File string `ocisConfig:"file"` Service Service `ocisConfig:"service"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 2c8026a8354..09adc2e980c 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -507,7 +507,6 @@ type Asset struct { type Config struct { *shared.Commons - File string `ocisConfig:"file"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` Reva Reva `ocisConfig:"reva"` diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index 3131492b615..cdb9d23be9a 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -40,7 +40,6 @@ type Tracing struct { // Config combines all available configuration parts. type Config struct { - File string `ocisConfig:"file"` Log shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` GRPC GRPC `ocisConfig:"grpc"` diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 210b52918d7..222c93cd235 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -94,7 +94,6 @@ type Web struct { type Config struct { *shared.Commons - File string `ocisConfig:"file"` Log *shared.Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` From 788a3900169504c26d31d6393fb125b18a650cce Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 19:24:07 +0100 Subject: [PATCH 42/84] switch glauth to struct tag based env config --- accounts/pkg/command/root.go | 4 +- glauth/pkg/command/health.go | 3 +- glauth/pkg/command/root.go | 46 ++++---- glauth/pkg/command/server.go | 9 +- glauth/pkg/config/config.go | 95 +++++++++------- glauth/pkg/config/mappings.go | 167 ---------------------------- glauth/pkg/logging/logging.go | 17 +++ graph-explorer/pkg/config/config.go | 2 +- graph/pkg/config/config.go | 2 +- ocs/pkg/command/root.go | 4 +- proxy/pkg/config/config.go | 2 +- settings/pkg/config/config.go | 4 +- store/pkg/config/config.go | 2 +- thumbnails/pkg/config/config.go | 2 +- web/pkg/config/config.go | 4 +- webdav/pkg/config/config.go | 4 +- 16 files changed, 120 insertions(+), 247 deletions(-) delete mode 100644 glauth/pkg/config/mappings.go create mode 100644 glauth/pkg/logging/logging.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 502ddb74a8d..298aa399ada 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -77,12 +77,12 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil { + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil && err.Error() != "none of the target fields were set from environment variables" { + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { return err } diff --git a/glauth/pkg/command/health.go b/glauth/pkg/command/health.go index 1ee1362ecdb..1cd0eac23cd 100644 --- a/glauth/pkg/command/health.go +++ b/glauth/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 77270bf417a..7fdf54a1f0e 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -4,14 +4,13 @@ import ( "context" "os" + "github.com/imdario/mergo" "github.com/owncloud/ocis/glauth/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" - oclog "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-glauth command. @@ -50,34 +49,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return oclog.LoggerFromConfig("glauth", *cfg.Log) -} - // ParseConfig loads glauth configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("glauth", cfg) + _, err := ociscfg.BindSourcesToStructs("accounts", cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} - } + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(cfg), false) - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } + + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the glauth command to be embedded and supervised by a suture supervisor tree. diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index 6dcad7f036e..e5f88b39486 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -7,6 +7,7 @@ import ( "github.com/oklog/run" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/logging" "github.com/owncloud/ocis/glauth/pkg/metrics" "github.com/owncloud/ocis/glauth/pkg/server/debug" "github.com/owncloud/ocis/glauth/pkg/server/glauth" @@ -30,9 +31,9 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } @@ -47,7 +48,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Version).Set(1) + metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) { diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index f5dd3940119..19850fdc36d 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -11,69 +11,88 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"GLAUTH_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"GLAUTH_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"GLAUTH_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"GLAUTH_DEBUG_ZPAGES"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GLAUTH_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GLAUTH_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GLAUTH_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GLAUTH_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"GLAUTH_TRACING_SERVICE"` // TODO: +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GLAUTH_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GLAUTH_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GLAUTH_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;GLAUTH_LOG_FILE"` } // Ldap defined the available LDAP configuration. type Ldap struct { - Enabled bool `ocisConfig:"enabled"` - Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` + Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAP_ENABLED"` + Addr string `ocisConfig:"addr" env:"GLAUTH_LDAP_ADDR"` + Namespace string } // Ldaps defined the available LDAPS configuration. type Ldaps struct { - Enabled bool `ocisConfig:"enabled"` - Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` - Cert string `ocisConfig:"cert"` - Key string `ocisConfig:"key"` + Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAPS_ENABLED"` + Addr string `ocisConfig:"addr" env:"GLAUTH_LDAPS_ADDR"` + Namespace string + Cert string `ocisConfig:"cert" env:"GLAUTH_LDAPS_CERT"` + Key string `ocisConfig:"key" env:"GLAUTH_LDAPS_KEY"` } // Backend defined the available backend configuration. type Backend struct { - Datastore string `ocisConfig:"datastore"` - BaseDN string `ocisConfig:"base_dn"` - Insecure bool `ocisConfig:"insecure"` - NameFormat string `ocisConfig:"name_format"` - GroupFormat string `ocisConfig:"group_format"` - Servers []string `ocisConfig:"servers"` - SSHKeyAttr string `ocisConfig:"ssh_key_attr"` - UseGraphAPI bool `ocisConfig:"use_graph_api"` + Datastore string `ocisConfig:"datastore" env:"GLAUTH_BACKEND_DATASTORE"` + BaseDN string `ocisConfig:"base_dn" env:"GLAUTH_BACKEND_BASEDN"` + Insecure bool `ocisConfig:"insecure" env:"GLAUTH_BACKEND_INSECURE"` + NameFormat string `ocisConfig:"name_format" env:"GLAUTH_BACKEND_NAME_FORMAT"` + GroupFormat string `ocisConfig:"group_format" env:"GLAUTH_BACKEND_GROUP_FORMAT"` + Servers []string `ocisConfig:"servers"` //TODO: how to configure this via env? + SSHKeyAttr string `ocisConfig:"ssh_key_attr" env:"GLAUTH_BACKEND_SSH_KEY_ATTR"` + UseGraphAPI bool `ocisConfig:"use_graph_api" env:"GLAUTH_BACKEND_USE_GRAPHAPI"` +} + +// FallbackBackend defined the available fallback backend configuration. +type FallbackBackend struct { + Datastore string `ocisConfig:"datastore" env:"GLAUTH_FALLBACK_DATASTORE"` + BaseDN string `ocisConfig:"base_dn" env:"GLAUTH_FALLBACK_BASEDN"` + Insecure bool `ocisConfig:"insecure" env:"GLAUTH_FALLBACK_INSECURE"` + NameFormat string `ocisConfig:"name_format" env:"GLAUTH_FALLBACK_NAME_FORMAT"` + GroupFormat string `ocisConfig:"group_format" env:"GLAUTH_FALLBACK_GROUP_FORMAT"` + Servers []string `ocisConfig:"servers"` //TODO: how to configure this via env? + SSHKeyAttr string `ocisConfig:"ssh_key_attr" env:"GLAUTH_FALLBACK_SSH_KEY_ATTR"` + UseGraphAPI bool `ocisConfig:"use_graph_api" env:"GLAUTH_FALLBACK_USE_GRAPHAPI"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - Service Service `ocisConfig:"service"` - Tracing Tracing `ocisConfig:"tracing"` - Ldap Ldap `ocisConfig:"ldap"` - Ldaps Ldaps `ocisConfig:"ldaps"` - Backend Backend `ocisConfig:"backend"` - Fallback Backend `ocisConfig:"fallback"` - Version string `ocisConfig:"version"` - RoleBundleUUID string `ocisConfig:"role_bundle_uuid"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + Service Service `ocisConfig:"service"` + Tracing Tracing `ocisConfig:"tracing"` + Ldap Ldap `ocisConfig:"ldap"` + Ldaps Ldaps `ocisConfig:"ldaps"` + Backend Backend `ocisConfig:"backend"` + Fallback FallbackBackend `ocisConfig:"fallback"` + RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` Context context.Context Supervised bool @@ -118,7 +137,7 @@ func DefaultConfig() *Config { SSHKeyAttr: "sshPublicKey", UseGraphAPI: true, }, - Fallback: Backend{ + Fallback: FallbackBackend{ Datastore: "", BaseDN: "dc=ocis,dc=test", Insecure: false, diff --git a/glauth/pkg/config/mappings.go b/glauth/pkg/config/mappings.go deleted file mode 100644 index 4867fc9ea2a..00000000000 --- a/glauth/pkg/config/mappings.go +++ /dev/null @@ -1,167 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_LEVEL", "GLAUTH_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "GLAUTH_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "GLAUTH_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_FILE", "GLAUTH_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"GLAUTH_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "GLAUTH_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "GLAUTH_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GLAUTH_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GLAUTH_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"GLAUTH_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"GLAUTH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"GLAUTH_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"GLAUTH_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"GLAUTH_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"GLAUTH_ROLE_BUNDLE_ID"}, - Destination: &cfg.RoleBundleUUID, - }, - { - EnvVars: []string{"GLAUTH_LDAP_ADDR"}, - Destination: &cfg.Ldap.Addr, - }, - { - EnvVars: []string{"GLAUTH_LDAP_ENABLED"}, - Destination: &cfg.Ldap.Enabled, - }, - { - EnvVars: []string{"GLAUTH_LDAPS_ADDR"}, - Destination: &cfg.Ldaps.Addr, - }, - { - EnvVars: []string{"GLAUTH_LDAPS_ENABLED"}, - Destination: &cfg.Ldaps.Enabled, - }, - { - EnvVars: []string{"GLAUTH_LDAPS_CERT"}, - Destination: &cfg.Ldaps.Cert, - }, - { - EnvVars: []string{"GLAUTH_LDAPS_KEY"}, - Destination: &cfg.Ldaps.Key, - }, - { - EnvVars: []string{"GLAUTH_BACKEND_BASEDN"}, - Destination: &cfg.Backend.BaseDN, - }, - { - EnvVars: []string{"GLAUTH_BACKEND_NAME_FORMAT"}, - Destination: &cfg.Backend.NameFormat, - }, - { - EnvVars: []string{"GLAUTH_BACKEND_GROUP_FORMAT"}, - Destination: &cfg.Backend.GroupFormat, - }, - { - EnvVars: []string{"GLAUTH_BACKEND_SSH_KEY_ATTR"}, - Destination: &cfg.Backend.SSHKeyAttr, - }, - { - EnvVars: []string{"GLAUTH_BACKEND_DATASTORE"}, - Destination: &cfg.Backend.Datastore, - }, - { - EnvVars: []string{"GLAUTH_BACKEND_INSECURE"}, - Destination: &cfg.Backend.Insecure, - }, - { - EnvVars: []string{"GLAUTH_BACKEND_USE_GRAPHAPI"}, - Destination: &cfg.Backend.UseGraphAPI, - }, - { - EnvVars: []string{"GLAUTH_FALLBACK_BASEDN"}, - Destination: &cfg.Fallback.BaseDN, - }, - { - EnvVars: []string{"GLAUTH_FALLBACK_NAME_FORMAT"}, - Destination: &cfg.Fallback.NameFormat, - }, - { - EnvVars: []string{"GLAUTH_FALLBACK_GROUP_FORMAT"}, - Destination: &cfg.Fallback.GroupFormat, - }, - { - EnvVars: []string{"GLAUTH_FALLBACK_SSH_KEY_ATTR"}, - Destination: &cfg.Fallback.SSHKeyAttr, - }, - { - EnvVars: []string{"GLAUTH_FALLBACK_DATASTORE"}, - Destination: &cfg.Fallback.Datastore, - }, - { - EnvVars: []string{"GLAUTH_FALLBACK_INSECURE"}, - Destination: &cfg.Fallback.Insecure, - }, - { - EnvVars: []string{"GLAUTH_FALLBACK_USE_GRAPHAPI"}, - Destination: &cfg.Fallback.UseGraphAPI, - }, - } -} diff --git a/glauth/pkg/logging/logging.go b/glauth/pkg/logging/logging.go new file mode 100644 index 00000000000..2dd2f1cd4cd --- /dev/null +++ b/glauth/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 0fcacecf42a..f03e4f83e09 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -18,7 +18,7 @@ type Debug struct { type HTTP struct { Addr string `ocisConfig:"addr"` Root string `ocisConfig:"root"` - Namespace string `ocisConfig:"namespace"` + Namespace string } // Service defines the available service configuration. diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 5a113d20d1e..d7b233f5263 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -17,7 +17,7 @@ type Debug struct { // HTTP defines the available http configuration. type HTTP struct { Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` + Namespace string Root string `ocisConfig:"root"` } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index a74c904a789..be8d34ea14d 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -86,12 +86,12 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil { + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil && err.Error() != "none of the target fields were set from environment variables" { + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { return err } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 5193d5a653e..f9f93cc02bd 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -28,7 +28,7 @@ type Debug struct { type HTTP struct { Addr string `ocisConfig:"addr"` Root string `ocisConfig:"root"` - Namespace string `ocisConfig:"namespace"` + Namespace string TLSCert string `ocisConfig:"tls_cert"` TLSKey string `ocisConfig:"tls_key"` TLS bool `ocisConfig:"tls"` diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 4b46a8da843..d07229723ca 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -28,7 +28,7 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` + Namespace string Root string `ocisConfig:"root"` CacheTTL int `ocisConfig:"cache_ttl"` CORS CORS `ocisConfig:"cors"` @@ -37,7 +37,7 @@ type HTTP struct { // GRPC defines the available grpc configuration. type GRPC struct { Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` + Namespace string } // Service provides configuration options for the service diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index cdb9d23be9a..a804e7faf32 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -20,7 +20,7 @@ type Debug struct { type GRPC struct { Addr string `ocisConfig:"addr"` Root string `ocisConfig:"root"` - Namespace string `ocisConfig:"namespace"` + Namespace string } // Service defines the available service configuration. diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 2a9bf6582dd..466c0085ca2 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -19,7 +19,7 @@ type Debug struct { // GRPC defines the available grpc configuration. type GRPC struct { Addr string `ocisConfig:"addr"` - Namespace string `ocisConfig:"namespace"` + Namespace string } // Service provides configuration options for the service diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 222c93cd235..0cfd317fc39 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -18,8 +18,8 @@ type Debug struct { type HTTP struct { Addr string `ocisConfig:"addr"` Root string `ocisConfig:"root"` - Namespace string `ocisConfig:"namespace"` - CacheTTL int `ocisConfig:"cache_ttl"` + Namespace string + CacheTTL int `ocisConfig:"cache_ttl"` } // Service defines the available service configuration. diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index bb65faa962a..22964b3f95b 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -26,8 +26,8 @@ type CORS struct { type HTTP struct { Addr string `ocisConfig:"addr"` Root string `ocisConfig:"root"` - Namespace string `ocisConfig:"namespace"` - CORS CORS `ocisConfig:"cors"` + Namespace string + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. From 288d6c469ea65e81b02961bfa7d9c00a9fb4469b Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 19:40:23 +0100 Subject: [PATCH 43/84] switch graph to struct tag based env config --- accounts/pkg/command/root.go | 2 +- glauth/pkg/command/root.go | 2 +- graph/pkg/command/root.go | 39 +++++--- graph/pkg/command/server.go | 7 +- graph/pkg/config/config.go | 83 ++++++++-------- graph/pkg/config/mappings.go | 179 ----------------------------------- graph/pkg/logging/logging.go | 17 ++++ ocs/pkg/command/root.go | 2 +- 8 files changed, 94 insertions(+), 237 deletions(-) delete mode 100644 graph/pkg/config/mappings.go create mode 100644 graph/pkg/logging/logging.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 298aa399ada..4b0eb6a43d1 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -58,7 +58,7 @@ func Execute(cfg *config.Config) error { // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs("accounts", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 7fdf54a1f0e..c90a6c85064 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -51,7 +51,7 @@ func Execute(cfg *config.Config) error { // ParseConfig loads glauth configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs("accounts", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 3e61b387a9d..04906877ae7 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -4,9 +4,9 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" "github.com/thejerf/suture/v4" + "github.com/wkloucek/envdecode" "github.com/owncloud/ocis/graph/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -62,26 +62,35 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("graph", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} + + // load all env variables relevant to the config in the current context. + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err } - conf.LoadOSEnv(config.GetEnv(cfg), false) - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the graph command to be embedded and supervised by a suture supervisor tree. diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index bcb9f3dcfbf..6a62b1daceb 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/logging" "github.com/owncloud/ocis/graph/pkg/metrics" "github.com/owncloud/ocis/graph/pkg/server/debug" "github.com/owncloud/ocis/graph/pkg/server/http" @@ -30,9 +31,9 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index d7b233f5263..5185a6fed54 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -8,72 +8,81 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"GRAPH_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"GRAPH_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"GRAPH_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"GRAPH_DEBUG_ZPAGES"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` + Addr string `ocisConfig:"addr" env:"GRAPH_HTTP_ADDR"` Namespace string - Root string `ocisConfig:"root"` + Root string `ocisConfig:"root" env:"GRAPH_HTTP_ROOT"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"GRAPH_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GRAPH_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GRAPH_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GRAPH_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;GRAPH_LOG_FILE"` } // Reva defines all available REVA configuration. type Reva struct { - Address string `ocisConfig:"address"` + Address string `ocisConfig:"address" env:"REVA_GATEWAY"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;GRAPH_JWT_SECRET"` } type Spaces struct { - WebDavBase string `ocisConfig:"webdav_base"` - WebDavPath string `ocisConfig:"webdav_path"` - DefaultQuota string `ocisConfig:"default_quota"` + WebDavBase string `ocisConfig:"webdav_base" env:"GRAPH_SPACES_WEBDAV_BASE"` + WebDavPath string `ocisConfig:"webdav_path" env:"GRAPH_SPACES_WEBDAV_PATH"` + DefaultQuota string `ocisConfig:"default_quota" env:"GRAPH_SPACES_DEFAULT_QUOTA"` } +// TODO: do we really need a ldap backend if CS3 also does LDAP!? type LDAP struct { - URI string `ocisConfig:"uri"` - BindDN string `ocisConfig:"bind_dn"` - BindPassword string `ocisConfig:"bind_password"` - - UserBaseDN string `ocisConfig:"user_base_dn"` - UserSearchScope string `ocisConfig:"user_search_scope"` - UserFilter string `ocisConfig:"user_filter"` - UserEmailAttribute string `ocisConfig:"user_mail_attribute"` - UserDisplayNameAttribute string `ocisConfig:"user_displayname_attribute"` - UserNameAttribute string `ocisConfig:"user_name_attribute"` - UserIDAttribute string `ocisConfig:"user_id_attribute"` - - GroupBaseDN string `ocisConfig:"group_base_dn"` - GroupSearchScope string `ocisConfig:"group_search_scope"` - GroupFilter string `ocisConfig:"group_filter"` - GroupNameAttribute string `ocisConfig:"group_name_attribute"` - GroupIDAttribute string `ocisConfig:"group_id_attribute"` + URI string `ocisConfig:"uri" env:"GRAPH_LDAP_URI"` + BindDN string `ocisConfig:"bind_dn" env:"GRAPH_LDAP_BIND_DN"` + BindPassword string `ocisConfig:"bind_password" env:"GRAPH_LDAP_BIND_PASSWORD"` + + UserBaseDN string `ocisConfig:"user_base_dn" env:"GRAPH_LDAP_USER_BASE_DN"` + UserSearchScope string `ocisConfig:"user_search_scope" env:"GRAPH_LDAP_USER_SCOPE"` + UserFilter string `ocisConfig:"user_filter" env:"GRAPH_LDAP_USER_FILTER"` + UserEmailAttribute string `ocisConfig:"user_mail_attribute" env:"GRAPH_LDAP_USER_EMAIL_ATTRIBUTE"` + UserDisplayNameAttribute string `ocisConfig:"user_displayname_attribute" env:"GRAPH_LDAP_USER_DISPLAYNAME_ATTRIBUTE"` + UserNameAttribute string `ocisConfig:"user_name_attribute" env:"GRAPH_LDAP_USER_NAME_ATTRIBUTE"` + UserIDAttribute string `ocisConfig:"user_id_attribute" env:"GRAPH_LDAP_USER_UID_ATTRIBUTE"` + + GroupBaseDN string `ocisConfig:"group_base_dn" env:"GRAPH_LDAP_GROUP_BASE_DN"` + GroupSearchScope string `ocisConfig:"group_search_scope" env:"GRAPH_LDAP_GROUP_SEARCH_SCOPE"` + GroupFilter string `ocisConfig:"group_filter" env:"GRAPH_LDAP_GROUP_FILTER"` + GroupNameAttribute string `ocisConfig:"group_name_attribute" env:"GRAPH_LDAP_GROUP_NAME_ATTRIBUTE"` + GroupIDAttribute string `ocisConfig:"group_id_attribute" env:"GRAPH_LDAP_GROUP_ID_ATTRIBUTE"` } type Identity struct { - Backend string `ocisConfig:"backend"` + Backend string `ocisConfig:"backend" env:"GRAPH_IDENTITY_BACKEND"` LDAP LDAP `ocisConfig:"ldap"` } @@ -81,7 +90,7 @@ type Identity struct { type Config struct { *shared.Commons - Log *shared.Log `ocisConfig:"log"` + Log Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` Service Service `ocisConfig:"service"` diff --git a/graph/pkg/config/mappings.go b/graph/pkg/config/mappings.go deleted file mode 100644 index 6798e80687b..00000000000 --- a/graph/pkg/config/mappings.go +++ /dev/null @@ -1,179 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"GRAPH_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_LOG_LEVEL", "GRAPH_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "GRAPH_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "GRAPH_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_FILE", "GRAPH_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "GRAPH_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "GRAPH_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GRAPH_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GRAPH_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"GRAPH_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"GRAPH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"GRAPH_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"GRAPH_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"GRAPH_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"GRAPH_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"GRAPH_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"GRAPH_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"OCIS_URL", "GRAPH_SPACES_WEBDAV_BASE"}, - Destination: &cfg.Spaces.WebDavBase, - }, - { - EnvVars: []string{"GRAPH_SPACES_WEBDAV_PATH"}, - Destination: &cfg.Spaces.WebDavPath, - }, - { - EnvVars: []string{"GRAPH_SPACES_DEFAULT_QUOTA"}, - Destination: &cfg.Spaces.DefaultQuota, - }, - { - EnvVars: []string{"OCIS_JWT_SECRET", "GRAPH_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - { - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Address, - }, - { - EnvVars: []string{"GRAPH_IDENTITY_BACKEND"}, - Destination: &cfg.Identity.Backend, - }, - { - EnvVars: []string{"GRAPH_LDAP_URI"}, - Destination: &cfg.Identity.LDAP.URI, - }, - { - EnvVars: []string{"GRAPH_LDAP_BIND_DN"}, - Destination: &cfg.Identity.LDAP.BindDN, - }, - { - EnvVars: []string{"GRAPH_LDAP_BIND_PASSWORD"}, - Destination: &cfg.Identity.LDAP.BindPassword, - }, - { - EnvVars: []string{"GRAPH_LDAP_USER_BASE_DN"}, - Destination: &cfg.Identity.LDAP.UserBaseDN, - }, - { - EnvVars: []string{"GRAPH_LDAP_USER_EMAIL_ATTRIBUTE"}, - Destination: &cfg.Identity.LDAP.UserEmailAttribute, - }, - { - EnvVars: []string{"GRAPH_LDAP_USER_DISPLAYNAME_ATTRIBUTE"}, - Destination: &cfg.Identity.LDAP.UserDisplayNameAttribute, - }, - { - EnvVars: []string{"GRAPH_LDAP_USER_NAME_ATTRIBUTE"}, - Destination: &cfg.Identity.LDAP.UserNameAttribute, - }, - { - EnvVars: []string{"GRAPH_LDAP_USER_UID_ATTRIBUTE"}, - Destination: &cfg.Identity.LDAP.UserIDAttribute, - }, - { - EnvVars: []string{"GRAPH_LDAP_USER_FILTER"}, - Destination: &cfg.Identity.LDAP.UserFilter, - }, - { - EnvVars: []string{"GRAPH_LDAP_USER_SCOPE"}, - Destination: &cfg.Identity.LDAP.UserSearchScope, - }, - { - EnvVars: []string{"GRAPH_LDAP_GROUP_BASE_DN"}, - Destination: &cfg.Identity.LDAP.GroupBaseDN, - }, - { - EnvVars: []string{"GRAPH_LDAP_GROUP_SEARCH_SCOPE"}, - Destination: &cfg.Identity.LDAP.GroupSearchScope, - }, - { - EnvVars: []string{"GRAPH_LDAP_GROUP_FILTER"}, - Destination: &cfg.Identity.LDAP.GroupFilter, - }, - { - EnvVars: []string{"GRAPH_LDAP_GROUP_NAME_ATTRIBUTE"}, - Destination: &cfg.Identity.LDAP.GroupNameAttribute, - }, - { - EnvVars: []string{"GRAPH_LDAP_GROUP_ID_ATTRIBUTE"}, - Destination: &cfg.Identity.LDAP.GroupIDAttribute, - }, - } -} diff --git a/graph/pkg/logging/logging.go b/graph/pkg/logging/logging.go new file mode 100644 index 00000000000..07f8b44502c --- /dev/null +++ b/graph/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index be8d34ea14d..26c27151b73 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -67,7 +67,7 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs("ocs", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } From 6990e7d6602eb89ffc9c7ae6af0cd27527e22b17 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 10:44:57 +0100 Subject: [PATCH 44/84] switch all other services to struct tag based env config --- accounts/pkg/command/root.go | 1 + accounts/pkg/command/server.go | 4 +- accounts/pkg/config/config.go | 43 ++-- .../pkg/proto/v0/accounts.pb.micro_test.go | 2 +- .../service/v0/accounts_permission_test.go | 3 +- glauth/cmd/glauth/main.go | 2 +- glauth/pkg/command/root.go | 6 +- glauth/pkg/config/config.go | 27 +- graph-explorer/pkg/command/health.go | 3 +- graph-explorer/pkg/command/root.go | 47 ++-- graph-explorer/pkg/command/server.go | 9 +- graph-explorer/pkg/config/config.go | 76 +++--- graph-explorer/pkg/config/mappings.go | 96 ------- graph-explorer/pkg/logging/logging.go | 17 ++ graph/cmd/graph/main.go | 2 +- graph/pkg/command/health.go | 3 +- graph/pkg/command/root.go | 16 +- graph/pkg/config/config.go | 23 +- idp/pkg/command/health.go | 3 +- idp/pkg/command/root.go | 56 ++-- idp/pkg/command/server.go | 10 +- idp/pkg/config/config.go | 172 +++++++------ idp/pkg/config/mappings.go | 239 ------------------ idp/pkg/logging/logging.go | 17 ++ idp/pkg/{log => logging}/logrus_wrapper.go | 5 +- idp/pkg/server/http/server.go | 2 +- idp/pkg/service/v0/logging.go | 8 +- idp/pkg/service/v0/service.go | 4 +- ocis-pkg/config/config.go | 50 ++-- ocis/pkg/command/accounts.go | 3 - ocis/pkg/command/graph.go | 3 - ocis/pkg/command/graphexplorer.go | 3 - ocis/pkg/command/ocs.go | 3 - ocis/pkg/command/proxy.go | 3 - ocis/pkg/command/root.go | 17 +- ocis/pkg/command/server.go | 11 +- ocis/pkg/command/settings.go | 3 - ocis/pkg/command/storageappprovider.go | 3 - ocis/pkg/command/storageauthbasic.go | 3 - ocis/pkg/command/storageauthbearer.go | 3 - ocis/pkg/command/storageauthmachine.go | 3 - ocis/pkg/command/storagefrontend.go | 3 - ocis/pkg/command/storagegateway.go | 3 - ocis/pkg/command/storagegroupprovider.go | 3 - ocis/pkg/command/storagepubliclink.go | 3 - ocis/pkg/command/storageshares.go | 3 - ocis/pkg/command/storagesharing.go | 3 - ocis/pkg/command/storageuserprovider.go | 3 - ocis/pkg/command/storageusers.go | 3 - ocis/pkg/command/store.go | 16 +- ocis/pkg/command/thumbnails.go | 9 +- ocis/pkg/command/util.go | 21 +- ocis/pkg/command/web.go | 6 +- ocis/pkg/command/webdav.go | 3 - ocis/pkg/runtime/service/service.go | 6 +- ocs/pkg/command/health.go | 3 +- ocs/pkg/command/root.go | 16 +- ocs/pkg/config/config.go | 30 +-- proxy/pkg/command/health.go | 3 +- proxy/pkg/command/root.go | 63 ++--- proxy/pkg/command/server.go | 7 +- proxy/pkg/config/config.go | 118 +++++---- proxy/pkg/config/mappings.go | 182 ------------- proxy/pkg/cs3/client.go | 3 +- proxy/pkg/logging/logging.go | 17 ++ settings/pkg/command/health.go | 3 +- settings/pkg/command/root.go | 55 ++-- settings/pkg/command/server.go | 4 +- settings/pkg/config/config.go | 72 +++--- settings/pkg/config/mappings.go | 115 --------- settings/pkg/logging/logging.go | 17 ++ .../pkg/proto/v0/settings.pb.micro_test.go | 4 +- settings/pkg/store/filesystem/store.go | 10 +- storage/pkg/command/appprovider.go | 3 +- storage/pkg/command/authbasic.go | 3 +- storage/pkg/command/authbearer.go | 3 +- storage/pkg/command/authmachine.go | 3 +- storage/pkg/command/frontend.go | 3 +- storage/pkg/command/gateway.go | 24 +- storage/pkg/command/groups.go | 3 +- storage/pkg/command/health.go | 3 +- storage/pkg/command/root.go | 16 +- storage/pkg/command/sharing.go | 3 +- storage/pkg/command/storagemetadata.go | 3 +- storage/pkg/command/storagepubliclink.go | 3 +- storage/pkg/command/storageshares.go | 3 +- storage/pkg/command/storageusers.go | 3 +- storage/pkg/command/users.go | 3 +- storage/pkg/config/config.go | 23 +- storage/pkg/logging/logging.go | 17 ++ store/pkg/command/health.go | 3 +- store/pkg/command/root.go | 43 ++-- store/pkg/command/server.go | 26 +- store/pkg/config/config.go | 66 +++-- store/pkg/config/mappings.go | 80 ------ store/pkg/logging/logging.go | 17 ++ thumbnails/pkg/command/health.go | 3 +- thumbnails/pkg/command/root.go | 58 ++--- thumbnails/pkg/command/server.go | 6 +- thumbnails/pkg/config/config.go | 68 ++--- thumbnails/pkg/config/mappings.go | 111 -------- thumbnails/pkg/logging/logging.go | 17 ++ .../pkg/proto/v0/thumbnails.pb.micro_test.go | 14 +- thumbnails/pkg/service/v0/service.go | 3 +- web/pkg/command/health.go | 3 +- web/pkg/command/root.go | 61 ++--- web/pkg/command/server.go | 7 +- web/pkg/config/config.go | 87 ++++--- web/pkg/config/mappings.go | 143 ----------- web/pkg/logging/logging.go | 17 ++ webdav/pkg/command/health.go | 3 +- webdav/pkg/command/root.go | 55 ++-- webdav/pkg/command/server.go | 7 +- webdav/pkg/config/config.go | 61 +++-- webdav/pkg/config/mappings.go | 107 -------- webdav/pkg/logging/logging.go | 17 ++ 116 files changed, 1023 insertions(+), 1990 deletions(-) delete mode 100644 graph-explorer/pkg/config/mappings.go create mode 100644 graph-explorer/pkg/logging/logging.go delete mode 100644 idp/pkg/config/mappings.go create mode 100644 idp/pkg/logging/logging.go rename idp/pkg/{log => logging}/logrus_wrapper.go (98%) delete mode 100644 proxy/pkg/config/mappings.go create mode 100644 proxy/pkg/logging/logging.go delete mode 100644 settings/pkg/config/mappings.go create mode 100644 settings/pkg/logging/logging.go create mode 100644 storage/pkg/logging/logging.go delete mode 100644 store/pkg/config/mappings.go create mode 100644 store/pkg/logging/logging.go delete mode 100644 thumbnails/pkg/config/mappings.go create mode 100644 thumbnails/pkg/logging/logging.go delete mode 100644 web/pkg/config/mappings.go create mode 100644 web/pkg/logging/logging.go delete mode 100644 webdav/pkg/config/mappings.go create mode 100644 webdav/pkg/logging/logging.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 4b0eb6a43d1..97088ea2057 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -26,6 +26,7 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 2f68df37c32..aa2c1b0c310 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -26,12 +26,12 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) - if err := ParseConfig(ctx, cfg); err != nil { return err } + cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) + return nil }, Action: func(c *cli.Context) error { diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index bc49960810b..5c138ad7845 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -8,6 +8,15 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) +//TODO: use debug config +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"ACCOUNTS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"ACCOUNTS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"ACCOUNTS_DEBUG_ZPAGES"` +} + // CORS defines the available cors configuration. type CORS struct { AllowedOrigins []string `ocisConfig:"allowed_origins"` @@ -112,28 +121,28 @@ type Log struct { type Config struct { //*shared.Commons - HTTP HTTP `ocisConfig:"http"` - GRPC GRPC `ocisConfig:"grpc"` - Service Service `ocisConfig:"service"` - Asset Asset `ocisConfig:"asset"` - Log Log `ocisConfig:"log"` - TokenManager TokenManager `ocisConfig:"token_manager"` - Repo Repo `ocisConfig:"repo"` - Index Index `ocisConfig:"index"` - ServiceUser ServiceUser `ocisConfig:"service_user"` - HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"` - DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"` - Tracing Tracing `ocisConfig:"tracing"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + GRPC GRPC `ocisConfig:"grpc"` + + TokenManager TokenManager `ocisConfig:"token_manager"` + + Asset Asset `ocisConfig:"asset"` + Repo Repo `ocisConfig:"repo"` + Index Index `ocisConfig:"index"` + ServiceUser ServiceUser `ocisConfig:"service_user"` + HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"` + DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"` Context context.Context Supervised bool } -// New returns a new config. -func New() *Config { - return &Config{} -} - func DefaultConfig() *Config { return &Config{ diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index d15b0ab2d2a..b8e3eeb4d8a 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -79,7 +79,7 @@ func init() { grpc.Address("localhost:9180"), ) - cfg := config.New() + cfg := config.DefaultConfig() cfg.Repo.Backend = "disk" cfg.Repo.Disk.Path = dataPath cfg.DemoUsersAndGroups = true diff --git a/accounts/pkg/service/v0/accounts_permission_test.go b/accounts/pkg/service/v0/accounts_permission_test.go index f339855f32f..0cb47746801 100644 --- a/accounts/pkg/service/v0/accounts_permission_test.go +++ b/accounts/pkg/service/v0/accounts_permission_test.go @@ -31,8 +31,7 @@ var ( ) func init() { - cfg := config.New() - cfg.Service.Name = "accounts" + cfg := config.DefaultConfig() cfg.Repo.Backend = "disk" cfg.Repo.Disk.Path = dataPath logger := olog.NewLogger(olog.Color(true), olog.Pretty(true)) diff --git a/glauth/cmd/glauth/main.go b/glauth/cmd/glauth/main.go index f2abd5e20aa..6a2a83249d4 100644 --- a/glauth/cmd/glauth/main.go +++ b/glauth/cmd/glauth/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index c90a6c85064..b7b5fef7c94 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -26,10 +26,12 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + Before: func(c *cli.Context) error { cfg.Service.Version = version.String - return nil + return ParseConfig(c, cfg) }, + Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -89,7 +91,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.GLAuth.Commons = cfg.Commons + //cfg.GLAuth.Commons = cfg.Commons return SutureService{ cfg: cfg.GLAuth, } diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 19850fdc36d..4876413f6b2 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -84,25 +84,24 @@ type FallbackBackend struct { type Config struct { *shared.Commons - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - Service Service `ocisConfig:"service"` - Tracing Tracing `ocisConfig:"tracing"` - Ldap Ldap `ocisConfig:"ldap"` - Ldaps Ldaps `ocisConfig:"ldaps"` - Backend Backend `ocisConfig:"backend"` - Fallback FallbackBackend `ocisConfig:"fallback"` - RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + Ldap Ldap `ocisConfig:"ldap"` + Ldaps Ldaps `ocisConfig:"ldaps"` + + Backend Backend `ocisConfig:"backend"` + Fallback FallbackBackend `ocisConfig:"fallback"` + + RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - func DefaultConfig() *Config { return &Config{ Debug: Debug{ diff --git a/graph-explorer/pkg/command/health.go b/graph-explorer/pkg/command/health.go index 60f4cc925b8..54ad47fe99c 100644 --- a/graph-explorer/pkg/command/health.go +++ b/graph-explorer/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index d1c0e0ff683..621958d0091 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -4,12 +4,13 @@ import ( "context" "os" + "github.com/imdario/mergo" "github.com/owncloud/ocis/graph-explorer/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the graph-explorer command. @@ -25,10 +26,12 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, + Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -46,27 +49,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("graph-explorer"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - // ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("graph-explorer", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } - conf.LoadOSEnv(config.GetEnv(), false) - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} + + // load all env variables relevant to the config in the current context. + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } + + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the graph-explorer command to be embedded and supervised by a suture supervisor tree. @@ -76,7 +89,7 @@ type SutureService struct { // NewSutureService creates a new graph-explorer.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.GraphExplorer.Log = cfg.Log + //cfg.GraphExplorer.Log = cfg.Log return SutureService{ cfg: cfg.GraphExplorer, } diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index c606f1d7cd8..6b9f80129bd 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/logging" "github.com/owncloud/ocis/graph-explorer/pkg/metrics" "github.com/owncloud/ocis/graph-explorer/pkg/server/debug" "github.com/owncloud/ocis/graph-explorer/pkg/server/http" @@ -26,9 +27,11 @@ func Server(cfg *config.Config) *cli.Command { return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - tracing.Configure(cfg) - + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { + return err + } var ( gr = run.Group{} ctx, cancel = func() (context.Context, context.CancelFunc) { diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index f03e4f83e09..9a76da1019e 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -2,70 +2,73 @@ package config import ( "context" - - "github.com/owncloud/ocis/ocis-pkg/shared" ) // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"GRAPH_EXPLORER_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"GRAPH_EXPLORER_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"GRAPH_EXPLORER_DEBUG_ZPAGES"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` + Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"GRAPH_EXPLORER_HTTP_ROOT"` Namespace string } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_EXPLORER_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_EXPLORER_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_EXPLORER_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_EXPLORER_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"GRAPH_EXPLORER_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GRAPH_EXPLORER_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GRAPH_EXPLORER_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GRAPH_EXPLORER_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;GRAPH_EXPLORER_LOG_FILE"` } // GraphExplorer defines the available graph-explorer configuration. type GraphExplorer struct { - ClientID string `ocisConfig:"client_id"` - Issuer string `ocisConfig:"issuer"` - GraphURLBase string `ocisConfig:"graph_url_base"` - GraphURLPath string `ocisConfig:"graph_url_path"` + ClientID string `ocisConfig:"client_id" env:"GRAPH_EXPLORER_CLIENT_ID"` + Issuer string `ocisConfig:"issuer" env:"OCIS_URL;GRAPH_EXPLORER_ISSUER"` + GraphURLBase string `ocisConfig:"graph_url_base" env:"OCIS_URL;GRAPH_EXPLORER_GRAPH_URL_BASE"` + GraphURLPath string `ocisConfig:"graph_url_path" env:"GRAPH_EXPLORER_GRAPH_URL_PATH"` } // Config combines all available configuration parts. type Config struct { - Log shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - Service Service `ocisConfig:"service"` - Tracing Tracing `ocisConfig:"tracing"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + GraphExplorer GraphExplorer `ocisConfig:"graph_explorer"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - // DefaultConfig provides with a working version of a config. func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9136", Token: "", @@ -78,7 +81,7 @@ func DefaultConfig() *Config { Namespace: "com.owncloud.web", }, Service: Service{ - Name: "graph", + Name: "graph-explorer", }, Tracing: Tracing{ Type: "jaeger", @@ -94,14 +97,3 @@ func DefaultConfig() *Config { }, } } - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv() []string { - var r = make([]string, len(structMappings(&Config{}))) - for i := range structMappings(&Config{}) { - r = append(r, structMappings(&Config{})[i].EnvVars...) - } - - return r -} diff --git a/graph-explorer/pkg/config/mappings.go b/graph-explorer/pkg/config/mappings.go deleted file mode 100644 index 85014e61b6e..00000000000 --- a/graph-explorer/pkg/config/mappings.go +++ /dev/null @@ -1,96 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_LEVEL", "GRAPH_EXPLORER_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "GRAPH_EXPLORER_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "GRAPH_EXPLORER_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_FILE", "GRAPH_EXPLORER_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "GRAPH_EXPLORER_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "GRAPH_EXPLORER_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GRAPH_EXPLORER_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GRAPH_EXPLORER_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_ISSUER"}, - Destination: &cfg.GraphExplorer.Issuer, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_CLIENT_ID"}, - Destination: &cfg.GraphExplorer.ClientID, - }, - { - EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_GRAPH_URL_BASE"}, - Destination: &cfg.GraphExplorer.GraphURLBase, - }, - { - EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL_PATH"}, - Destination: &cfg.GraphExplorer.GraphURLPath, - }, - } -} diff --git a/graph-explorer/pkg/logging/logging.go b/graph-explorer/pkg/logging/logging.go new file mode 100644 index 00000000000..8d3175cbf61 --- /dev/null +++ b/graph-explorer/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/graph/cmd/graph/main.go b/graph/cmd/graph/main.go index c43db09932a..ec85f23718e 100644 --- a/graph/cmd/graph/main.go +++ b/graph/cmd/graph/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/graph/pkg/command/health.go b/graph/pkg/command/health.go index 509146e3fa6..18cc12baef9 100644 --- a/graph/pkg/command/health.go +++ b/graph/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 04906877ae7..7168eb16aa4 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -10,7 +10,6 @@ import ( "github.com/owncloud/ocis/graph/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/urfave/cli/v2" ) @@ -28,10 +27,12 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, + Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -49,17 +50,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("graph"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - // ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) @@ -100,7 +90,7 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Graph.Commons = cfg.Commons + //cfg.Graph.Commons = cfg.Commons return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 5185a6fed54..c3d22789a46 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -90,25 +90,24 @@ type Identity struct { type Config struct { *shared.Commons - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - Service Service `ocisConfig:"service"` - Tracing Tracing `ocisConfig:"tracing"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + Reva Reva `ocisConfig:"reva"` TokenManager TokenManager `ocisConfig:"token_manager"` - Spaces Spaces `ocisConfig:"spaces"` - Identity Identity `ocisConfig:"identity"` + + Spaces Spaces `ocisConfig:"spaces"` + Identity Identity `ocisConfig:"identity"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - func DefaultConfig() *Config { return &Config{ Debug: Debug{ diff --git a/idp/pkg/command/health.go b/idp/pkg/command/health.go index 813470bd483..fcb337253bc 100644 --- a/idp/pkg/command/health.go +++ b/idp/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/idp/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index e0d5ba775f7..77c740592b8 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -4,14 +4,13 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" "github.com/owncloud/ocis/idp/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-idp command. @@ -27,9 +26,10 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + Before: func(c *cli.Context) error { cfg.Service.Version = version.String - return nil + return ParseConfig(c, cfg) }, Commands: []*cli.Command{ @@ -52,41 +52,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("idp"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - // ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("idp", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} - } + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(cfg), false) + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the idp command to be embedded and supervised by a suture supervisor tree. @@ -96,7 +92,7 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.IDP.Commons = cfg.Commons + //cfg.IDP.Commons = cfg.Commons return SutureService{ cfg: cfg.IDP, } diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index d3b62034f58..0c91b4b5b22 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/idp/pkg/logging" "github.com/owncloud/ocis/idp/pkg/metrics" "github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/http" @@ -30,10 +31,11 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - tracing.Configure(cfg) - + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { + return err + } var ( gr = run.Group{} ctx, cancel = func() (context.Context, context.CancelFunc) { diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 510f06e6bf5..6793294e6ba 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -11,113 +11,139 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"IDP_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"IDP_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"IDP_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"IDP_DEBUG_ZPAGES"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` - Namespace string `ocisConfig:"namespace"` - TLSCert string `ocisConfig:"tls_cert"` - TLSKey string `ocisConfig:"tls_key"` - TLS bool `ocisConfig:"tls"` + Addr string `ocisConfig:"addr" env:"IDP_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"IDP_HTTP_ROOT"` + Namespace string + TLSCert string `ocisConfig:"tls_cert" env:"IDP_TRANSPORT_TLS_CERT"` + TLSKey string `ocisConfig:"tls_key" env:"IDP_TRANSPORT_TLS_KEY"` + TLS bool `ocisConfig:"tls" env:"IDP_TLS"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Ldap defines the available LDAP configuration. type Ldap struct { - URI string `ocisConfig:"uri"` - BindDN string `ocisConfig:"bind_dn"` - BindPassword string `ocisConfig:"bind_password"` - BaseDN string `ocisConfig:"base_dn"` - Scope string `ocisConfig:"scope"` - LoginAttribute string `ocisConfig:"login_attribute"` - EmailAttribute string `ocisConfig:"email_attribute"` - NameAttribute string `ocisConfig:"name_attribute"` - UUIDAttribute string `ocisConfig:"uuid_attribute"` - UUIDAttributeType string `ocisConfig:"uuid_attribute_type"` - Filter string `ocisConfig:"filter"` + URI string `ocisConfig:"uri" env:"IDP_LDAP_URI"` + + BindDN string `ocisConfig:"bind_dn" env:"IDP_LDAP_BIND_DN"` + BindPassword string `ocisConfig:"bind_password" env:"IDP_LDAP_BIND_PASSWORD"` + + BaseDN string `ocisConfig:"base_dn" env:"IDP_LDAP_BASE_DN"` + Scope string `ocisConfig:"scope" env:"IDP_LDAP_SCOPE"` + + LoginAttribute string `ocisConfig:"login_attribute" env:"IDP_LDAP_LOGIN_ATTRIBUTE"` + EmailAttribute string `ocisConfig:"email_attribute" env:"IDP_LDAP_EMAIL_ATTRIBUTE"` + NameAttribute string `ocisConfig:"name_attribute" env:"IDP_LDAP_NAME_ATTRIBUTE"` + UUIDAttribute string `ocisConfig:"uuid_attribute" env:"IDP_LDAP_UUID_ATTRIBUTE"` + UUIDAttributeType string `ocisConfig:"uuid_attribute_type" env:"IDP_LDAP_UUID_ATTRIBUTE_TYPE"` + + Filter string `ocisConfig:"filter" env:"IDP_LDAP_FILTER"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;IDP_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;IDP_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;IDP_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;IDP_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"IDP_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;IDP_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;IDP_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;IDP_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;IDP_LOG_FILE"` } // Asset defines the available asset configuration. type Asset struct { - Path string `ocisConfig:"asset"` + Path string `ocisConfig:"asset" env:"IDP_ASSET_PATH"` } type Settings struct { - Iss string `ocisConfig:"iss"` - IdentityManager string `ocisConfig:"identity_manager"` - URIBasePath string `ocisConfig:"uri_base_path"` - SignInURI string `ocisConfig:"sign_in_uri"` - SignedOutURI string `ocisConfig:"signed_out_uri"` - AuthorizationEndpointURI string `ocisConfig:"authorization_endpoint_uri"` - EndsessionEndpointURI string `ocisConfig:"end_session_endpoint_uri"` - Insecure bool `ocisConfig:"insecure"` - TrustedProxy []string `ocisConfig:"trusted_proxy"` - AllowScope []string `ocisConfig:"allow_scope"` - AllowClientGuests bool `ocisConfig:"allow_client_guests"` - AllowDynamicClientRegistration bool `ocisConfig:"allow_dynamic_client_registration"` - EncryptionSecretFile string `ocisConfig:"encrypt_secret_file"` - Listen string `ocisConfig:"listen"` - IdentifierClientDisabled bool `ocisConfig:"identifier_client_disabled"` - IdentifierClientPath string `ocisConfig:"identifier_client_path"` - IdentifierRegistrationConf string `ocisConfig:"identifier_registration_conf"` - IdentifierScopesConf string `ocisConfig:"identifier_scopes_conf"` - IdentifierDefaultBannerLogo string `ocisConfig:"identifier_default_banner_logo"` - IdentifierDefaultSignInPageText string `ocisConfig:"identifier_default_sign_in_page_text"` - IdentifierDefaultUsernameHintText string `ocisConfig:"identifier_default_username_hint_text"` - SigningKid string `ocisConfig:"sign_in_kid"` - SigningMethod string `ocisConfig:"sign_in_method"` - SigningPrivateKeyFiles []string `ocisConfig:"sign_in_private_key_files"` - ValidationKeysPath string `ocisConfig:"validation_keys_path"` - CookieBackendURI string `ocisConfig:"cookie_backend_uri"` - CookieNames []string `ocisConfig:"cookie_names"` - AccessTokenDurationSeconds uint64 `ocisConfig:"access_token_duration_seconds"` - IDTokenDurationSeconds uint64 `ocisConfig:"id_token_duration_seconds"` - RefreshTokenDurationSeconds uint64 `ocisConfig:"refresh_token_duration_seconds"` - DyamicClientSecretDurationSeconds uint64 `ocisConfig:"dynamic_client_secret_duration_seconds"` + // don't change the order of elements in this struct + // it needs to match github.com/libregraph/lico/bootstrap.Settings + + Iss string `ocisConfig:"iss" env:"OCIS_URL;IDP_ISS"` + + IdentityManager string `ocisConfig:"identity_manager" env:"IDP_IDENTITY_MANAGER"` + + URIBasePath string `ocisConfig:"uri_base_path" env:"IDP_URI_BASE_PATH"` + + SignInURI string `ocisConfig:"sign_in_uri" env:"IDP_SIGN_IN_URI"` + SignedOutURI string `ocisConfig:"signed_out_uri" env:"IDP_SIGN_OUT_URI"` + + AuthorizationEndpointURI string `ocisConfig:"authorization_endpoint_uri" env:"IDP_ENDPOINT_URI"` + EndsessionEndpointURI string `ocisConfig:"end_session_endpoint_uri" env:"IDP_ENDSESSION_ENDPOINT_URI"` + + Insecure bool `ocisConfig:"insecure" env:"IDP_INSECURE"` + + TrustedProxy []string `ocisConfig:"trusted_proxy"` //TODO: how to configure this via env? + + AllowScope []string `ocisConfig:"allow_scope"` // TODO: is this even needed? + AllowClientGuests bool `ocisConfig:"allow_client_guests" env:"IDP_ALLOW_CLIENT_GUESTS"` + AllowDynamicClientRegistration bool `ocisConfig:"allow_dynamic_client_registration" env:"IDP_ALLOW_DYNAMIC_CLIENT_REGISTRATION"` + + EncryptionSecretFile string `ocisConfig:"encrypt_secret_file" env:"IDP_ENCRYPTION_SECRET"` + + Listen string `ocisConfig:"listen"` //TODO: is this even needed? + + IdentifierClientDisabled bool `ocisConfig:"identifier_client_disabled" env:"IDP_DISABLE_IDENTIFIER_WEBAPP"` + IdentifierClientPath string `ocisConfig:"identifier_client_path" env:"IDP_IDENTIFIER_CLIENT_PATH"` + IdentifierRegistrationConf string `ocisConfig:"identifier_registration_conf" env:"IDP_IDENTIFIER_REGISTRATION_CONF"` + IdentifierScopesConf string `ocisConfig:"identifier_scopes_conf" env:"IDP_IDENTIFIER_SCOPES_CONF"` + IdentifierDefaultBannerLogo string `ocisConfig:"identifier_default_banner_logo"` // TODO: is this even needed? + IdentifierDefaultSignInPageText string `ocisConfig:"identifier_default_sign_in_page_text"` // TODO: is this even needed? + IdentifierDefaultUsernameHintText string `ocisConfig:"identifier_default_username_hint_text"` // TODO: is this even needed? + + SigningKid string `ocisConfig:"sign_in_kid" env:"IDP_SIGNING_KID"` + SigningMethod string `ocisConfig:"sign_in_method" env:"IDP_SIGNING_METHOD"` + SigningPrivateKeyFiles []string `ocisConfig:"sign_in_private_key_files"` // TODO: is this even needed? + ValidationKeysPath string `ocisConfig:"validation_keys_path" env:"IDP_VALIDATION_KEYS_PATH"` + + CookieBackendURI string `ocisConfig:"cookie_backend_uri"` // TODO: is this even needed? + CookieNames []string `ocisConfig:"cookie_names"` // TODO: is this even needed? + + AccessTokenDurationSeconds uint64 `ocisConfig:"access_token_duration_seconds" env:"IDP_ACCESS_TOKEN_EXPIRATION"` + IDTokenDurationSeconds uint64 `ocisConfig:"id_token_duration_seconds" env:"IDP_ID_TOKEN_EXPIRATION"` + RefreshTokenDurationSeconds uint64 `ocisConfig:"refresh_token_duration_seconds" env:"IDP_REFRESH_TOKEN_EXPIRATION"` + DyamicClientSecretDurationSeconds uint64 `ocisConfig:"dynamic_client_secret_duration_seconds" env:""` } // Config combines all available configuration parts. type Config struct { *shared.Commons - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - Tracing Tracing `ocisConfig:"tracing"` - Asset Asset `ocisConfig:"asset"` - IDP Settings `ocisConfig:"idp"` - Ldap Ldap `ocisConfig:"ldap"` - Service Service `ocisConfig:"service"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + + Asset Asset `ocisConfig:"asset"` + IDP Settings `ocisConfig:"idp"` + Ldap Ldap `ocisConfig:"ldap"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - func DefaultConfig() *Config { return &Config{ Debug: Debug{ diff --git a/idp/pkg/config/mappings.go b/idp/pkg/config/mappings.go deleted file mode 100644 index c5b01cf74fa..00000000000 --- a/idp/pkg/config/mappings.go +++ /dev/null @@ -1,239 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_LEVEL", "IDP_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "IDP_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "IDP_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_FILE", "IDP_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"IDP_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "IDP_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "IDP_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "IDP_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "IDP_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"IDP_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"IDP_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"IDP_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"IDP_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"IDP_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"IDP_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"IDP_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"IDP_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"IDP_IDENTITY_MANAGER"}, - Destination: &cfg.IDP.IdentityManager, - }, - { - EnvVars: []string{"IDP_LDAP_URI"}, - Destination: &cfg.Ldap.URI, - }, - { - EnvVars: []string{"IDP_LDAP_BIND_DN"}, - Destination: &cfg.Ldap.BindDN, - }, - { - EnvVars: []string{"IDP_LDAP_BIND_PASSWORD"}, - Destination: &cfg.Ldap.BindPassword, - }, - { - EnvVars: []string{"IDP_LDAP_BASE_DN"}, - Destination: &cfg.Ldap.BaseDN, - }, - { - EnvVars: []string{"IDP_LDAP_SCOPE"}, - Destination: &cfg.Ldap.Scope, - }, - { - EnvVars: []string{"IDP_LDAP_LOGIN_ATTRIBUTE"}, - Destination: &cfg.Ldap.LoginAttribute, - }, - { - EnvVars: []string{"IDP_LDAP_EMAIL_ATTRIBUTE"}, - Destination: &cfg.Ldap.EmailAttribute, - }, - { - EnvVars: []string{"IDP_LDAP_NAME_ATTRIBUTE"}, - Destination: &cfg.Ldap.NameAttribute, - }, - { - EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE"}, - Destination: &cfg.Ldap.UUIDAttribute, - }, - { - EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE_TYPE"}, - Destination: &cfg.Ldap.UUIDAttributeType, - }, - { - EnvVars: []string{"IDP_LDAP_FILTER"}, - Destination: &cfg.Ldap.Filter, - }, - { - EnvVars: []string{"IDP_TRANSPORT_TLS_CERT"}, - Destination: &cfg.HTTP.TLSCert, - }, - { - EnvVars: []string{"IDP_TRANSPORT_TLS_KEY"}, - Destination: &cfg.HTTP.TLSKey, - }, - { - EnvVars: []string{"OCIS_URL", "IDP_ISS"}, // IDP_ISS takes precedence over OCIS_URL - Destination: &cfg.IDP.Iss, - }, - { - EnvVars: []string{"IDP_SIGNING_KID"}, - Destination: &cfg.IDP.SigningKid, - }, - { - EnvVars: []string{"IDP_VALIDATION_KEYS_PATH"}, - Destination: &cfg.IDP.ValidationKeysPath, - }, - { - EnvVars: []string{"IDP_ENCRYPTION_SECRET"}, - Destination: &cfg.IDP.EncryptionSecretFile, - }, - { - EnvVars: []string{"IDP_SIGNING_METHOD"}, - Destination: &cfg.IDP.SigningMethod, - }, - { - EnvVars: []string{"IDP_URI_BASE_PATH"}, - Destination: &cfg.IDP.URIBasePath, - }, - { - EnvVars: []string{"IDP_SIGN_IN_URI"}, - Destination: &cfg.IDP.SignInURI, - }, - { - EnvVars: []string{"IDP_SIGN_OUT_URI"}, - Destination: &cfg.IDP.SignedOutURI, - }, - { - EnvVars: []string{"IDP_ENDPOINT_URI"}, - Destination: &cfg.IDP.AuthorizationEndpointURI, - }, - { - EnvVars: []string{"IDP_ENDSESSION_ENDPOINT_URI"}, - Destination: &cfg.IDP.EndsessionEndpointURI, - }, - { - EnvVars: []string{"IDP_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - { - EnvVars: []string{"IDP_IDENTIFIER_CLIENT_PATH"}, - Destination: &cfg.IDP.IdentifierClientPath, - }, - { - EnvVars: []string{"IDP_IDENTIFIER_REGISTRATION_CONF"}, - Destination: &cfg.IDP.IdentifierRegistrationConf, - }, - { - EnvVars: []string{"IDP_IDENTIFIER_SCOPES_CONF"}, - Destination: &cfg.IDP.IdentifierScopesConf, - }, - { - EnvVars: []string{"IDP_INSECURE"}, - Destination: &cfg.IDP.Insecure, - }, - { - EnvVars: []string{"IDP_TLS"}, - Destination: &cfg.HTTP.TLS, - }, - { - EnvVars: []string{"IDP_ALLOW_CLIENT_GUESTS"}, - Destination: &cfg.IDP.AllowClientGuests, - }, - { - EnvVars: []string{"IDP_ALLOW_DYNAMIC_CLIENT_REGISTRATION"}, - Destination: &cfg.IDP.AllowDynamicClientRegistration, - }, - { - EnvVars: []string{"IDP_DISABLE_IDENTIFIER_WEBAPP"}, - Destination: &cfg.IDP.IdentifierClientDisabled, - }, - { - EnvVars: []string{"IDP_ACCESS_TOKEN_EXPIRATION"}, - Destination: &cfg.IDP.AccessTokenDurationSeconds, - }, - { - EnvVars: []string{"IDP_ID_TOKEN_EXPIRATION"}, - Destination: &cfg.IDP.IDTokenDurationSeconds, - }, - { - EnvVars: []string{"IDP_REFRESH_TOKEN_EXPIRATION"}, - Destination: &cfg.IDP.RefreshTokenDurationSeconds, - }, - } -} diff --git a/idp/pkg/logging/logging.go b/idp/pkg/logging/logging.go new file mode 100644 index 00000000000..cbcc6483367 --- /dev/null +++ b/idp/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/idp/pkg/log/logrus_wrapper.go b/idp/pkg/logging/logrus_wrapper.go similarity index 98% rename from idp/pkg/log/logrus_wrapper.go rename to idp/pkg/logging/logrus_wrapper.go index 71f29be2c88..38e302005df 100644 --- a/idp/pkg/log/logrus_wrapper.go +++ b/idp/pkg/logging/logrus_wrapper.go @@ -1,9 +1,10 @@ -package log +package logging import ( + "io/ioutil" + "github.com/rs/zerolog" "github.com/sirupsen/logrus" - "io/ioutil" ) type levelMap map[logrus.Level]zerolog.Level diff --git a/idp/pkg/server/http/server.go b/idp/pkg/server/http/server.go index 107643e3364..0d9cf8b2f5e 100644 --- a/idp/pkg/server/http/server.go +++ b/idp/pkg/server/http/server.go @@ -70,7 +70,7 @@ func Server(opts ...Option) (http.Service, error) { { handle = svc.NewInstrument(handle, options.Metrics) - handle = svc.NewLogging(handle, options.Logger) + handle = svc.NewLoggingHandler(handle, options.Logger) } if err := micro.RegisterHandler(service.Server(), handle); err != nil { diff --git a/idp/pkg/service/v0/logging.go b/idp/pkg/service/v0/logging.go index d5098e2fe20..f3dfab793e9 100644 --- a/idp/pkg/service/v0/logging.go +++ b/idp/pkg/service/v0/logging.go @@ -7,19 +7,19 @@ import ( ) // NewLogging returns a service that logs messages. -func NewLogging(next Service, logger log.Logger) Service { - return logging{ +func NewLoggingHandler(next Service, logger log.Logger) Service { + return loggingHandler{ next: next, logger: logger, } } -type logging struct { +type loggingHandler struct { next Service logger log.Logger } // ServeHTTP implements the Service interface. -func (l logging) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func (l loggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { l.next.ServeHTTP(w, r) } diff --git a/idp/pkg/service/v0/service.go b/idp/pkg/service/v0/service.go index 0f949a91a1b..24fb3132d3a 100644 --- a/idp/pkg/service/v0/service.go +++ b/idp/pkg/service/v0/service.go @@ -21,7 +21,7 @@ import ( "github.com/libregraph/lico/server" "github.com/owncloud/ocis/idp/pkg/assets" "github.com/owncloud/ocis/idp/pkg/config" - logw "github.com/owncloud/ocis/idp/pkg/log" + "github.com/owncloud/ocis/idp/pkg/logging" "github.com/owncloud/ocis/idp/pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/log" "stash.kopano.io/kgol/rndm" @@ -59,7 +59,7 @@ func NewService(opts ...Option) Service { idpSettings := bootstrap.Settings(options.Config.IDP) bs, err := bootstrap.Boot(ctx, &idpSettings, &licoconfig.Config{ - Logger: logw.Wrap(logger), + Logger: logging.Wrap(logger), }) if err != nil { diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index e73c9d07e61..40436f6faa8 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -42,6 +42,28 @@ const ( type Mode int +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"ACCOUNTS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"ACCOUNTS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"ACCOUNTS_DEBUG_ZPAGES"` +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE"` +} + // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { Port string `ocisConfig:"port"` @@ -53,13 +75,17 @@ type Runtime struct { type Config struct { *shared.Commons `ocisConfig:"shared"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + Mode Mode // DEPRECATED File string OcisURL string `ocisConfig:"ocis_url"` Registry string `ocisConfig:"registry"` - Log shared.Log `ocisConfig:"log"` - Tracing Tracing `ocisConfig:"tracing"` TokenManager TokenManager `ocisConfig:"token_manager"` Runtime Runtime `ocisConfig:"runtime"` @@ -78,25 +104,6 @@ type Config struct { WebDAV *webdav.Config `ocisConfig:"webdav"` } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{ - Accounts: accounts.DefaultConfig(), - GLAuth: glauth.DefaultConfig(), - Graph: graph.DefaultConfig(), - IDP: idp.DefaultConfig(), - Proxy: proxy.DefaultConfig(), - GraphExplorer: graphExplorer.DefaultConfig(), - OCS: ocs.DefaultConfig(), - Settings: settings.DefaultConfig(), - Web: web.DefaultConfig(), - Store: store.DefaultConfig(), - Thumbnails: thumbnails.DefaultConfig(), - WebDAV: webdav.DefaultConfig(), - Storage: storage.DefaultConfig(), - } -} - func DefaultConfig() *Config { return &Config{ Tracing: Tracing{ @@ -149,6 +156,7 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ + // TODO: transform this too { EnvVars: []string{"OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 40acb44ef2c..cb3bdc62098 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 1b1ae5553dc..ecc94826caa 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index e4dc82e0247..7833206b916 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 17f2d927e69..243c27696f5 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 321298689b5..7458a80d669 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 7272c357f5f..ffcbba1b6db 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -5,7 +5,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" @@ -20,9 +19,12 @@ func Execute() error { Version: version.String, Usage: "ownCloud Infinite Scale Stack", Compiled: version.Compiled(), + Before: func(c *cli.Context) error { + //cfg.Service.Version = version.String return ParseConfig(c, cfg) }, + Authors: []*cli.Author{ { Name: "ownCloud GmbH", @@ -51,17 +53,6 @@ func Execute() error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("ocis"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - // ParseConfig loads ocis configuration. func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("ocis", cfg) @@ -69,6 +60,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // TODO: use envconfig here too + conf.LoadOSEnv(config.GetEnv(), false) bindings := config.StructMappings(cfg) diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index c750340e8be..c9262144d5c 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -1,11 +1,6 @@ -//go:build !simple -// +build !simple - package command import ( - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocis/pkg/runtime" @@ -23,9 +18,9 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { - cfg.Commons = &shared.Commons{ - Log: &cfg.Log, - } + //cfg.Commons = &shared.Commons{ + // Log: &cfg.Log, + //} r := runtime.New(cfg) return r.Start() diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index adb37be5b09..90bdafc304f 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storageappprovider.go b/ocis/pkg/command/storageappprovider.go index 5202959659a..03d886f3bc5 100644 --- a/ocis/pkg/command/storageappprovider.go +++ b/ocis/pkg/command/storageappprovider.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storageauthbasic.go b/ocis/pkg/command/storageauthbasic.go index 62cddc5c80f..1bfe109dbb8 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storageauthbearer.go b/ocis/pkg/command/storageauthbearer.go index 329e6446721..8b87968e0ba 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 9498c7a017a..18b9d8a183e 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storagefrontend.go b/ocis/pkg/command/storagefrontend.go index 29fb13ee21c..5fe8ef78c51 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storagegateway.go b/ocis/pkg/command/storagegateway.go index 4f24f3e4948..937305d8105 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storagegroupprovider.go b/ocis/pkg/command/storagegroupprovider.go index 530e8148ce0..6519772a12d 100644 --- a/ocis/pkg/command/storagegroupprovider.go +++ b/ocis/pkg/command/storagegroupprovider.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index e4d9dc75013..97057ed0089 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storageshares.go b/ocis/pkg/command/storageshares.go index fe38a4bc36a..7e94fd9e327 100644 --- a/ocis/pkg/command/storageshares.go +++ b/ocis/pkg/command/storageshares.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storagesharing.go b/ocis/pkg/command/storagesharing.go index 3a15d90eea9..d5d479c5cfa 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storageuserprovider.go b/ocis/pkg/command/storageuserprovider.go index fc423737a3f..984d7e86a9b 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/storageusers.go b/ocis/pkg/command/storageusers.go index a7978fb69ce..fbcd1d40a59 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 63946211797..5629abac378 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -1,11 +1,7 @@ -//go:build !simple -// +build !simple - package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/store/pkg/command" "github.com/urfave/cli/v2" @@ -13,7 +9,7 @@ import ( // StoreCommand is the entrypoint for the ocs command. func StoreCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log + //var globalLog shared.Log return &cli.Command{ Name: "store", @@ -27,16 +23,16 @@ func StoreCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + //globalLog = cfg.Log return nil }, Action: func(c *cli.Context) error { // if accounts logging is empty in ocis.yaml - if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.Store.Log = globalLog - } + //if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // // we can safely inherit the global logging values. + // cfg.Store.Log = globalLog + //} origCmd := command.Server(cfg.Store) return handleOriginalAction(c, origCmd) diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 0562b5d617d..01cdae6fc9a 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( @@ -24,9 +21,9 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.Thumbnails.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.Thumbnails.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/util.go b/ocis/pkg/command/util.go index a2e9b1abc0e..c49fb2c123e 100644 --- a/ocis/pkg/command/util.go +++ b/ocis/pkg/command/util.go @@ -2,7 +2,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/urfave/cli/v2" ) @@ -11,16 +10,16 @@ func ParseStorageCommon(ctx *cli.Context, cfg *config.Config) error { return err } - if cfg.Storage.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Storage.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Storage.Log == nil && cfg.Commons == nil { - cfg.Storage.Log = &shared.Log{} - } + //if cfg.Storage.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Storage.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Storage.Log == nil && cfg.Commons == nil { + // cfg.Storage.Log = &shared.Log{} + //} return nil } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index c3f2df2eafe..5d63587c2e7 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -18,9 +18,9 @@ func WebCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.Web.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.Web.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 0502642bb24..31cb2c52856 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index c66b07c3fd1..7c586838e06 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -164,9 +164,9 @@ func Start(o ...Option) error { } } - if s.cfg.Storage.Log == nil { - s.cfg.Storage.Log = &shared.Log{} - } + //if s.cfg.Storage.Log == nil { + // s.cfg.Storage.Log = &shared.Log{} + //} s.cfg.Storage.Log.Color = s.cfg.Commons.Color s.cfg.Storage.Log.Level = s.cfg.Commons.Level diff --git a/ocs/pkg/command/health.go b/ocs/pkg/command/health.go index 51474a3da2d..b1d2249e260 100644 --- a/ocs/pkg/command/health.go +++ b/ocs/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/ocs/pkg/config" + "github.com/owncloud/ocis/ocs/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 26c27151b73..01d18eb5849 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config" "github.com/thejerf/suture/v4" @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { Before: func(c *cli.Context) error { cfg.Service.Version = version.String - return nil + return ParseConfig(c, cfg) }, Commands: []*cli.Command{ @@ -54,17 +53,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("ocs"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - // ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) @@ -105,7 +93,7 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.OCS.Commons = cfg.Commons + //cfg.OCS.Commons = cfg.Commons return SutureService{ cfg: cfg.OCS, } diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 6c25c301756..c1d7145ad4a 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -74,27 +74,27 @@ type IdentityManagement struct { type Config struct { *shared.Commons - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - Tracing Tracing `ocisConfig:"tracing"` - TokenManager TokenManager `ocisConfig:"token_manager"` - Service Service `ocisConfig:"service"` - Reva Reva `ocisConfig:"reva"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + + TokenManager TokenManager `ocisConfig:"token_manager"` + Reva Reva `ocisConfig:"reva"` + IdentityManagement IdentityManagement `ocisConfig:"identity_management"` - AccountBackend string `ocisConfig:"account_backend" env:"OCS_ACCOUNT_BACKEND_TYPE"` - StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"` - MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"` + + AccountBackend string `ocisConfig:"account_backend" env:"OCS_ACCOUNT_BACKEND_TYPE"` + StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"` + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - // DefaultConfig provides default values for a config struct. func DefaultConfig() *Config { return &Config{ diff --git a/proxy/pkg/command/health.go b/proxy/pkg/command/health.go index adb3f0a77bd..3f904bda1b2 100644 --- a/proxy/pkg/command/health.go +++ b/proxy/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Usage: "Check health status", //Flags: flagset.HealthWithConfig(cfg), Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 13ea25e99d7..9801fe65a70 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -4,13 +4,13 @@ import ( "context" "os" + "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-proxy command. @@ -26,10 +26,12 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + Before: func(c *cli.Context) error { cfg.Service.Version = version.String - return nil + return ParseConfig(c, cfg) }, + Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -50,35 +52,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads proxy configuration. Loading will first attempt to parse config files in the expected locations -// and then parses environment variables. In the context of oCIS env variables will always overwrite values set -// in a config file. -// If this extension is run as a subcommand (i.e: ocis proxy) then there are 2 levels of config parsing: -// 1. ocis.yaml (if any) -// 2. proxy.yaml (if any) -// 3. environment variables. +// ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("proxy", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} + + // load all env variables relevant to the config in the current context. + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err } - conf.LoadOSEnv(config.GetEnv(cfg), false) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + return nil } // SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree. @@ -88,7 +92,7 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Proxy.Commons = cfg.Commons + //cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.Proxy, } @@ -102,14 +106,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("proxy"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index ed8e2d9c0a4..a99060d8b2c 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -20,6 +20,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/service/grpc" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/owncloud/ocis/proxy/pkg/cs3" + "github.com/owncloud/ocis/proxy/pkg/logging" "github.com/owncloud/ocis/proxy/pkg/metrics" "github.com/owncloud/ocis/proxy/pkg/middleware" "github.com/owncloud/ocis/proxy/pkg/proxy" @@ -62,9 +63,9 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index f9f93cc02bd..9afd1cc724b 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -8,45 +8,45 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) -// Log defines the available logging configuration. +// Log defines the available log configuration. type Log struct { - Level string `ocisConfig:"level"` - Pretty bool `ocisConfig:"pretty"` - Color bool `ocisConfig:"color"` - File string `ocisConfig:"file"` + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;PROXY_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;PROXY_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;PROXY_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;PROXY_LOG_FILE"` } // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"PROXY_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"PROXY_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"PROXY_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"PROXY_DEBUG_ZPAGES"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` + Addr string `ocisConfig:"addr" env:"PROXY_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"PROXY_HTTP_ROOT"` Namespace string - TLSCert string `ocisConfig:"tls_cert"` - TLSKey string `ocisConfig:"tls_key"` - TLS bool `ocisConfig:"tls"` + TLSCert string `ocisConfig:"tls_cert" env:"PROXY_TRANSPORT_TLS_CERT"` + TLSKey string `ocisConfig:"tls_key" env:"PROXY_TRANSPORT_TLS_KEY"` + TLS bool `ocisConfig:"tls" env:"PROXY_TLS"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;PROXY_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;PROXY_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;PROXY_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;PROXY_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"PROXY_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } // Policy enables us to use multiple directors. @@ -84,7 +84,7 @@ var ( // Reva defines all available REVA configuration. type Reva struct { - Address string `ocisConfig:"address"` + Address string `ocisConfig:"address" env:"REVA_GATEWAY"` Middleware Middleware `ocisConfig:"middleware"` } @@ -98,34 +98,31 @@ type Auth struct { CredentialsByUserAgent map[string]string `ocisConfig:""` } -// Cache is a TTL cache configuration. -type Cache struct { - Size int `ocisConfig:"size"` - TTL int `ocisConfig:"ttl"` -} - // Config combines all available configuration parts. type Config struct { *shared.Commons - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - Service Service `ocisConfig:"service"` - Tracing Tracing `ocisConfig:"tracing"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + Policies []Policy `ocisConfig:"policies"` OIDC OIDC `ocisConfig:"oidc"` TokenManager TokenManager `ocisConfig:"token_manager"` PolicySelector *PolicySelector `ocisConfig:"policy_selector"` Reva Reva `ocisConfig:"reva"` PreSignedURL PreSignedURL `ocisConfig:"pre_signed_url"` - AccountBackend string `ocisConfig:"account_backend"` - UserOIDCClaim string `ocisConfig:"user_oidc_claim"` - UserCS3Claim string `ocisConfig:"user_cs3_claim"` - MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key"` - AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts"` - EnableBasicAuth bool `ocisConfig:"enable_basic_auth"` - InsecureBackends bool `ocisConfig:"insecure_backends"` + AccountBackend string `ocisConfig:"account_backend" env:"PROXY_ACCOUNT_BACKEND_TYPE"` + UserOIDCClaim string `ocisConfig:"user_oidc_claim" env:"PROXY_USER_OIDC_CLAIM"` + UserCS3Claim string `ocisConfig:"user_cs3_claim" env:"PROXY_USER_CS3_CLAIM"` + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;PROXY_MACHINE_AUTH_API_KEY"` + AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts" env:"PROXY_AUTOPROVISION_ACCOUNTS"` + EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"` + InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` Context context.Context Supervised bool @@ -134,9 +131,15 @@ type Config struct { // OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request // with the configured oidc-provider type OIDC struct { - Issuer string `ocisConfig:"issuer"` - Insecure bool `ocisConfig:"insecure"` - UserinfoCache Cache `ocisConfig:"user_info_cache"` + Issuer string `ocisConfig:"issuer" env:"OCIS_URL;PROXY_OIDC_ISSUER"` + Insecure bool `ocisConfig:"insecure" env:"OCIS_INSECURE;PROXY_OIDC_INSECURE"` + UserinfoCache UserinfoCache `ocisConfig:"user_info_cache"` +} + +// UserinfoCache is a TTL cache configuration. +type UserinfoCache struct { + Size int `ocisConfig:"size" env:"PROXY_OIDC_USERINFO_CACHE_SIZE"` + TTL int `ocisConfig:"ttl" env:"PROXY_OIDC_USERINFO_CACHE_TTL"` } // PolicySelector is the toplevel-configuration for different selectors @@ -154,13 +157,13 @@ type StaticSelectorConf struct { // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;PROXY_JWT_SECRET"` } // PreSignedURL is the config for the presigned url middleware type PreSignedURL struct { AllowedHTTPMethods []string `ocisConfig:"allowed_http_methods"` - Enabled bool `ocisConfig:"enabled"` + Enabled bool `ocisConfig:"enabled" env:"PROXY_ENABLE_PRESIGNEDURLS"` } // MigrationSelectorConf is the config for the migration-selector @@ -192,13 +195,6 @@ type RegexRuleConf struct { Policy string `ocisConfig:"policy"` } -// New initializes a new configuration -func New() *Config { - return &Config{ - HTTP: HTTP{}, - } -} - // DefaultConfig provides with a working local configuration for a proxy service. func DefaultConfig() *Config { return &Config{ @@ -227,7 +223,7 @@ func DefaultConfig() *Config { Issuer: "https://localhost:9200", Insecure: true, //Insecure: true, - UserinfoCache: Cache{ + UserinfoCache: UserinfoCache{ Size: 1024, TTL: 10, }, @@ -243,14 +239,14 @@ func DefaultConfig() *Config { AllowedHTTPMethods: []string{"GET"}, Enabled: true, }, - AccountBackend: "accounts", - UserOIDCClaim: "email", - UserCS3Claim: "mail", - MachineAuthAPIKey: "change-me-please", - //AutoprovisionAccounts: false, - //EnableBasicAuth: false, - //InsecureBackends: false, - Context: nil, + AccountBackend: "accounts", + UserOIDCClaim: "email", + UserCS3Claim: "mail", + MachineAuthAPIKey: "change-me-please", + AutoprovisionAccounts: false, + EnableBasicAuth: false, + InsecureBackends: false, + // TODO: enable //Policies: defaultPolicies(), } } diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go deleted file mode 100644 index 101d9a70d27..00000000000 --- a/proxy/pkg/config/mappings.go +++ /dev/null @@ -1,182 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - // Logging - { - EnvVars: []string{"OCIS_LOG_LEVEL", "PROXY_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "PROXY_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "PROXY_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_FILE", "PROXY_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - - // Basic auth - { - EnvVars: []string{"PROXY_ENABLE_BASIC_AUTH"}, - Destination: &cfg.EnableBasicAuth, - }, - - // Debug (health) - { - EnvVars: []string{"PROXY_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - - // Tracing - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "PROXY_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "PROXY_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "PROXY_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "PROXY_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"PROXY_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - - // Debug - { - EnvVars: []string{"PROXY_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"PROXY_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"PROXY_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"PROXY_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - - // HTTP - { - EnvVars: []string{"PROXY_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"PROXY_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"PROXY_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"PROXY_TRANSPORT_TLS_CERT"}, - Destination: &cfg.HTTP.TLSCert, - }, - { - EnvVars: []string{"PROXY_TRANSPORT_TLS_KEY"}, - Destination: &cfg.HTTP.TLSKey, - }, - { - EnvVars: []string{"PROXY_TLS"}, - Destination: &cfg.HTTP.TLS, - }, - - // Other - { - EnvVars: []string{"OCIS_JWT_SECRET", "PROXY_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - - { - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Address, - }, - { - EnvVars: []string{"PROXY_INSECURE_BACKENDS"}, - Destination: &cfg.InsecureBackends, - }, - { - EnvVars: []string{"OCIS_URL", "PROXY_OIDC_ISSUER"}, - Destination: &cfg.OIDC.Issuer, - }, - { - EnvVars: []string{"OCIS_INSECURE", "PROXY_OIDC_INSECURE"}, - Destination: &cfg.OIDC.Insecure, - }, - { - EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_TTL"}, - Destination: &cfg.OIDC.UserinfoCache.TTL, - }, - { - EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_SIZE"}, - Destination: &cfg.OIDC.UserinfoCache.Size, - }, - { - EnvVars: []string{"PROXY_AUTOPROVISION_ACCOUNTS"}, - Destination: &cfg.AutoprovisionAccounts, - }, - { - EnvVars: []string{"PROXY_USER_OIDC_CLAIM"}, - Destination: &cfg.UserOIDCClaim, - }, - { - EnvVars: []string{"PROXY_USER_CS3_CLAIM"}, - Destination: &cfg.UserCS3Claim, - }, - { - EnvVars: []string{"PROXY_ENABLE_PRESIGNEDURLS"}, - Destination: &cfg.PreSignedURL.Enabled, - }, - { - EnvVars: []string{"PROXY_ACCOUNT_BACKEND_TYPE"}, - Destination: &cfg.AccountBackend, - }, - { - EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "PROXY_MACHINE_AUTH_API_KEY"}, - Destination: &cfg.MachineAuthAPIKey, - }, - // there are 2 missing bindings: - // EnvVars: []string{"PROXY_MIDDLEWARE_AUTH_CREDENTIALS_BY_USER_AGENT"}, - // EnvVars: []string{"PRESIGNEDURL_ALLOWED_METHODS"}, - // since they both have no destination - // see https://github.com/owncloud/ocis/blob/52e5effa4fa05a1626d46f7d4cb574dde3a54593/proxy/pkg/flagset/flagset.go#L256-L261 - // and https://github.com/owncloud/ocis/blob/52e5effa4fa05a1626d46f7d4cb574dde3a54593/proxy/pkg/flagset/flagset.go#L295-L300 - } -} diff --git a/proxy/pkg/cs3/client.go b/proxy/pkg/cs3/client.go index 68f52d2d7b5..dbaaa03ae9b 100644 --- a/proxy/pkg/cs3/client.go +++ b/proxy/pkg/cs3/client.go @@ -10,7 +10,7 @@ import ( func newConn(endpoint string) (*grpc.ClientConn, error) { conn, err := grpc.Dial( endpoint, - grpc.WithInsecure(), + grpc.WithInsecure(), //TODO: depreciated grpc.WithUnaryInterceptor( otelgrpc.UnaryClientInterceptor( otelgrpc.WithTracerProvider( @@ -28,6 +28,7 @@ func newConn(endpoint string) (*grpc.ClientConn, error) { // GetGatewayServiceClient returns a new cs3 gateway client func GetGatewayServiceClient(endpoint string) (gateway.GatewayAPIClient, error) { + // TODO: check connection pooling conn, err := newConn(endpoint) if err != nil { return nil, err diff --git a/proxy/pkg/logging/logging.go b/proxy/pkg/logging/logging.go new file mode 100644 index 00000000000..b2626eb7461 --- /dev/null +++ b/proxy/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/proxy/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/settings/pkg/command/health.go b/settings/pkg/command/health.go index 9b475f5e7ac..e561b84e082 100644 --- a/settings/pkg/command/health.go +++ b/settings/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 74c09626e38..24d5b361900 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -4,14 +4,13 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-settings command. @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { Before: func(c *cli.Context) error { cfg.Service.Version = version.String - return nil + return ParseConfig(c, cfg) }, Commands: []*cli.Command{ @@ -54,39 +53,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("settings"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - // ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("settings", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} + + // load all env variables relevant to the config in the current context. + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err } - conf.LoadOSEnv(config.GetEnv(cfg), false) - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree. @@ -96,7 +93,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Settings.Commons = cfg.Commons + //cfg.Settings.Commons = cfg.Commons return SutureService{ cfg: cfg.Settings, } diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index bd430f26313..a6e51c93044 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/logging" "github.com/owncloud/ocis/settings/pkg/metrics" "github.com/owncloud/ocis/settings/pkg/server/debug" "github.com/owncloud/ocis/settings/pkg/server/grpc" @@ -31,8 +32,7 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - + logger := logging.Configure(cfg.Service.Name, cfg.Log) err := tracing.Configure(cfg) if err != nil { return err diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index d07229723ca..fadd6722cd0 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -11,10 +11,10 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"SETTINGS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"SETTINGS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"SETTINGS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"SETTINGS_DEBUG_ZPAGES"` } // CORS defines the available cors configuration. @@ -27,55 +27,66 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` + Addr string `ocisConfig:"addr" env:"SETTINGS_HTTP_ADDR"` Namespace string - Root string `ocisConfig:"root"` - CacheTTL int `ocisConfig:"cache_ttl"` + Root string `ocisConfig:"root" env:"SETTINGS_HTTP_ROOT"` + CacheTTL int `ocisConfig:"cache_ttl" env:"SETTINGS_CACHE_TTL"` CORS CORS `ocisConfig:"cors"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `ocisConfig:"addr"` + Addr string `ocisConfig:"addr" env:"SETTINGS_GRPC_ADDR"` Namespace string } -// Service provides configuration options for the service +// Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` - DataPath string `ocisConfig:"data_path"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;SETTINGS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;SETTINGS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;SETTINGS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;SETTINGS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"SETTINGS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } -// Asset undocumented +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;SETTINGS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;SETTINGS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;SETTINGS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;SETTINGS_LOG_FILE"` +} + +// Asset defines the available asset configuration. type Asset struct { - Path string `ocisConfig:"asset"` + Path string `ocisConfig:"path" env:"SETTINGS_ASSET_PATH"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;SETTINGS_JWT_SECRET"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - Service Service `ocisConfig:"service"` - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - GRPC GRPC `ocisConfig:"grpc"` - Tracing Tracing `ocisConfig:"tracing"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + GRPC GRPC `ocisConfig:"grpc"` + + DataPath string `ocisConfig:"data_path" env:"SETTINGS_DATA_PATH"` Asset Asset `ocisConfig:"asset"` TokenManager TokenManager `ocisConfig:"token_manager"` @@ -83,17 +94,11 @@ type Config struct { Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - // DefaultConfig provides sane bootstrapping defaults. func DefaultConfig() *Config { return &Config{ Service: Service{ - Name: "settings", - DataPath: path.Join(defaults.BaseDataPath(), "settings"), + Name: "settings", }, Debug: Debug{ Addr: "127.0.0.1:9194", @@ -124,6 +129,7 @@ func DefaultConfig() *Config { Collector: "", Service: "settings", }, + DataPath: path.Join(defaults.BaseDataPath(), "settings"), Asset: Asset{ Path: "", }, diff --git a/settings/pkg/config/mappings.go b/settings/pkg/config/mappings.go deleted file mode 100644 index d4910269c91..00000000000 --- a/settings/pkg/config/mappings.go +++ /dev/null @@ -1,115 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_LEVEL", "SETTINGS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "SETTINGS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "SETTINGS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"SETTINGS_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "SETTINGS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "SETTINGS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "SETTINGS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "SETTINGS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"SETTINGS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"SETTINGS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"SETTINGS_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"SETTINGS_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"SETTINGS_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"SETTINGS_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"SETTINGS_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"SETTINGS_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"SETTINGS_CACHE_TTL"}, - Destination: &cfg.HTTP.CacheTTL, - }, - { - EnvVars: []string{"SETTINGS_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - { - EnvVars: []string{"SETTINGS_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - { - EnvVars: []string{"SETTINGS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - { - EnvVars: []string{"SETTINGS_DATA_PATH"}, - Destination: &cfg.Service.DataPath, - }, - { - EnvVars: []string{"OCIS_JWT_SECRET", "SETTINGS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - } -} diff --git a/settings/pkg/logging/logging.go b/settings/pkg/logging/logging.go new file mode 100644 index 00000000000..147d07e7c8c --- /dev/null +++ b/settings/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/settings/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/settings/pkg/proto/v0/settings.pb.micro_test.go b/settings/pkg/proto/v0/settings.pb.micro_test.go index 786b6ffaf4e..ec15d60a7ee 100644 --- a/settings/pkg/proto/v0/settings.pb.micro_test.go +++ b/settings/pkg/proto/v0/settings.pb.micro_test.go @@ -176,8 +176,8 @@ func init() { grpc.Address("localhost:9992"), ) - cfg := config.New() - cfg.Service.DataPath = dataPath + cfg := config.DefaultConfig() + cfg.DataPath = dataPath handler = svc.NewService(cfg, ocislog.NewLogger(ocislog.Color(true), ocislog.Pretty(true))) err := proto.RegisterBundleServiceHandler(service.Server(), handler) if err != nil { diff --git a/settings/pkg/store/filesystem/store.go b/settings/pkg/store/filesystem/store.go index cf81638b9e5..ccd0fe0111a 100644 --- a/settings/pkg/store/filesystem/store.go +++ b/settings/pkg/store/filesystem/store.go @@ -32,16 +32,16 @@ func New(cfg *config.Config) settings.Manager { //), } - if _, err := os.Stat(cfg.Service.DataPath); err != nil { - s.Logger.Info().Msgf("creating container on %v", cfg.Service.DataPath) - err = os.MkdirAll(cfg.Service.DataPath, 0700) + if _, err := os.Stat(cfg.DataPath); err != nil { + s.Logger.Info().Msgf("creating container on %v", cfg.DataPath) + err = os.MkdirAll(cfg.DataPath, 0700) if err != nil { - s.Logger.Err(err).Msgf("providing container on %v", cfg.Service.DataPath) + s.Logger.Err(err).Msgf("providing container on %v", cfg.DataPath) } } - s.dataPath = cfg.Service.DataPath + s.dataPath = cfg.DataPath return &s } diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 80c8c523bac..3ac4f71d44b 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -12,6 +12,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -27,7 +28,7 @@ func AppProvider(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-app-provider") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 10268754a14..40bd71ed192 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -13,6 +13,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +29,7 @@ func AuthBasic(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-auth-basic") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index af60ccbdac7..4424a6ef2f0 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -12,6 +12,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -27,7 +28,7 @@ func AuthBearer(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-auth-bearer") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index eaaa97cbf61..80c70f832ca 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -12,6 +12,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -27,7 +28,7 @@ func AuthMachine(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-auth-machine") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index c3e92788ded..8847a50f9dd 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -16,6 +16,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/conversions" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -34,7 +35,7 @@ func Frontend(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-frontend") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 0dff38512bb..431ef5027db 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -15,10 +15,10 @@ import ( "github.com/oklog/run" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/service/external" "github.com/owncloud/ocis/storage/pkg/tracing" @@ -43,7 +43,7 @@ func Gateway(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -425,16 +425,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) er } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} - } + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(cfg), false) diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 043c96fdcdc..625a231772a 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -13,6 +13,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +29,7 @@ func Groups(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-groups") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) diff --git a/storage/pkg/command/health.go b/storage/pkg/command/health.go index a3c3791a99c..244ce713d3a 100644 --- a/storage/pkg/command/health.go +++ b/storage/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 80e16d0719e..6170aa7cfa4 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -3,7 +3,6 @@ package command import ( "os" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" "github.com/urfave/cli/v2" @@ -23,8 +22,10 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + Before: func(c *cli.Context) error { - return ParseConfig(c, cfg, "storage") + cfg.Service.Version = version.String + return ParseConfig(c, cfg, "_") }, Commands: []*cli.Command{ @@ -57,14 +58,3 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } - -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("storage"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index abace4d50b2..1d8c032c8ee 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -7,6 +7,7 @@ import ( "path" "path/filepath" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -30,7 +31,7 @@ func Sharing(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-sharing") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index f77d1eca32e..34cf47c6573 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -7,6 +7,7 @@ import ( "path" "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/cs3org/reva/cmd/revad/runtime" "github.com/gofrs/uuid" @@ -34,7 +35,7 @@ func StorageMetadata(cfg *config.Config) *cli.Command { }, Category: "Extensions", Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index 0e3966b7d1f..92f4d37947b 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -12,6 +12,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +29,7 @@ func StoragePublicLink(cfg *config.Config) *cli.Command { }, Category: "Extensions", Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) diff --git a/storage/pkg/command/storageshares.go b/storage/pkg/command/storageshares.go index a239170a21c..35e44e9d679 100644 --- a/storage/pkg/command/storageshares.go +++ b/storage/pkg/command/storageshares.go @@ -7,6 +7,7 @@ import ( "path" "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/cs3org/reva/cmd/revad/runtime" "github.com/gofrs/uuid" @@ -28,7 +29,7 @@ func StorageShares(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-shares") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 9d671949a23..15cf235d4f4 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -13,6 +13,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/command/storagedrivers" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +29,7 @@ func StorageUsers(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-userprovider") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 34aee1d7c03..b7205a542ee 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -13,6 +13,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +29,7 @@ func Users(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-users") }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) tracing.Configure(cfg, logger) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 09adc2e980c..c46c0a61d98 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -10,6 +10,12 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} + // Log defines the available logging configuration. type Log struct { Level string `ocisConfig:"level"` @@ -507,16 +513,15 @@ type Asset struct { type Config struct { *shared.Commons - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - Reva Reva `ocisConfig:"reva"` - Tracing Tracing `ocisConfig:"tracing"` - Asset Asset `ocisConfig:"asset"` -} + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + Reva Reva `ocisConfig:"reva"` -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} + Asset Asset `ocisConfig:"asset"` } func DefaultConfig() *Config { diff --git a/storage/pkg/logging/logging.go b/storage/pkg/logging/logging.go new file mode 100644 index 00000000000..c9d44332140 --- /dev/null +++ b/storage/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/storage/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/store/pkg/command/health.go b/store/pkg/command/health.go index 38461c9ac5b..b280d8b0e45 100644 --- a/store/pkg/command/health.go +++ b/store/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/store/pkg/config" + "github.com/owncloud/ocis/store/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 49584e63cc3..5c63f8a3eb4 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -4,12 +4,13 @@ import ( "context" "os" + "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-store command. @@ -52,29 +53,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("store"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - -// ParseConfig loads idp configuration from known paths. +// ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("store", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} + // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(), false) + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the store command to be embedded and supervised by a suture supervisor tree. diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 4bc9b35b91f..add4beaef64 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,10 +3,7 @@ package command import ( "context" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/owncloud/ocis/store/pkg/logging" "github.com/owncloud/ocis/store/pkg/tracing" "github.com/oklog/run" @@ -23,31 +20,16 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log if err := ParseConfig(ctx, cfg); err != nil { return err } - if (cfg.Log == shared.Log{}) && (inLog != shared.Log{}) { - // set the default to the parent config - cfg.Log = inLog - - // and parse the environment - conf := &gofig.Config{} - conf.LoadOSEnv(config.GetEnv(), false) - bindings := config.StructMappings(cfg) - if err := ociscfg.BindEnv(conf, bindings); err != nil { - return err - } - } - return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index a804e7faf32..c96271fbd43 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -5,60 +5,63 @@ import ( "path" "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/shared" ) // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"STORE_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"STORE_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"STORE_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"STORE_DEBUG_ZPAGES"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` + Addr string `ocisConfig:"addr" env:"STORE_GRPC_ADDR"` Namespace string } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;STORE_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;STORE_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORE_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;STORE_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"STORE_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;STORE_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;STORE_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;STORE_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;STORE_LOG_FILE"` } // Config combines all available configuration parts. type Config struct { - Log shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - GRPC GRPC `ocisConfig:"grpc"` - Tracing Tracing `ocisConfig:"tracing"` - Datapath string `ocisConfig:"data_path"` - Service Service `ocisConfig:"service"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + GRPC GRPC `ocisConfig:"grpc"` + + Datapath string `ocisConfig:"data_path" env:"STORE_DATA_PATH"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9464", Token: "", @@ -82,14 +85,3 @@ func DefaultConfig() *Config { Datapath: path.Join(defaults.BaseDataPath(), "store"), } } - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv() []string { - var r = make([]string, len(structMappings(&Config{}))) - for i := range structMappings(&Config{}) { - r = append(r, structMappings(&Config{})[i].EnvVars...) - } - - return r -} diff --git a/store/pkg/config/mappings.go b/store/pkg/config/mappings.go deleted file mode 100644 index 9d883ca2325..00000000000 --- a/store/pkg/config/mappings.go +++ /dev/null @@ -1,80 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_LEVEL", "STORE_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "STORE_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "STORE_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_FILE", "STORE_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "STORE_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "STORE_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "STORE_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "STORE_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"STORE_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"STORE_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"STORE_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"STORE_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"STORE_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"STORE_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - { - EnvVars: []string{"STORE_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - { - EnvVars: []string{"STORE_DATA_PATH"}, - Destination: &cfg.Datapath, - }, - } -} diff --git a/store/pkg/logging/logging.go b/store/pkg/logging/logging.go new file mode 100644 index 00000000000..e6183eb1826 --- /dev/null +++ b/store/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/store/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/thumbnails/pkg/command/health.go b/thumbnails/pkg/command/health.go index 6b5c84939c3..1ba961d62ca 100644 --- a/thumbnails/pkg/command/health.go +++ b/thumbnails/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 30dc5c53ba6..57428daac6b 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -4,14 +4,13 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/thumbnails/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-thumbnails command. @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { Before: func(c *cli.Context) error { cfg.Service.Version = version.String - return nil + return ParseConfig(c, cfg) }, Commands: []*cli.Command{ @@ -54,40 +53,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("thumbnails"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - -// ParseConfig loads configuration from Viper known paths. -// ParseConfig loads glauth configuration from known paths. +// ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("thumbnails", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} + + // load all env variables relevant to the config in the current context. + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err } - conf.LoadOSEnv(config.GetEnv(cfg), false) - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the thumbnails command to be embedded and supervised by a suture supervisor tree. @@ -97,7 +93,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Thumbnails.Commons = cfg.Commons + //cfg.Thumbnails.Commons = cfg.Commons return SutureService{ cfg: cfg.Thumbnails, } diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index f76645ba860..42531f4d86a 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/logging" "github.com/owncloud/ocis/thumbnails/pkg/metrics" "github.com/owncloud/ocis/thumbnails/pkg/server/debug" "github.com/owncloud/ocis/thumbnails/pkg/server/grpc" @@ -25,8 +26,9 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 466c0085ca2..f9f1f3d7ea8 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -5,49 +5,56 @@ import ( "path" "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/shared" ) // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"THUMBNAILS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"THUMBNAILS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"THUMBNAILS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"THUMBNAILS_DEBUG_ZPAGES"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `ocisConfig:"addr"` + Addr string `ocisConfig:"addr" env:"THUMBNAILS_GRPC_ADDR"` Namespace string } -// Service provides configuration options for the service +// Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;THUMBNAILS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;THUMBNAILS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;THUMBNAILS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;THUMBNAILS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"THUMBNAILS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;THUMBNAILS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;THUMBNAILS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;THUMBNAILS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;THUMBNAILS_LOG_FILE"` } // Config combines all available configuration parts. type Config struct { - *shared.Commons + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` - File string `ocisConfig:"file"` - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - GRPC GRPC `ocisConfig:"grpc"` - Service Service `ocisConfig:"service"` - Tracing Tracing `ocisConfig:"tracing"` - Thumbnail Thumbnail `ocisConfig:"thumbnail"` + GRPC GRPC `ocisConfig:"grpc"` + + Thumbnail Thumbnail `ocisConfig:"thumbnail"` Context context.Context Supervised bool @@ -55,7 +62,7 @@ type Config struct { // FileSystemStorage defines the available filesystem storage configuration. type FileSystemStorage struct { - RootDirectory string `ocisConfig:"root_directory"` + RootDirectory string `ocisConfig:"root_directory" env:"THUMBNAILS_FILESYSTEMSTORAGE_ROOT"` } // FileSystemSource defines the available filesystem source configuration. @@ -65,17 +72,12 @@ type FileSystemSource struct { // Thumbnail defines the available thumbnail related configuration. type Thumbnail struct { - Resolutions []string `ocisConfig:"resolutions"` + Resolutions []string `ocisConfig:"resolutions"` // TODO: how to configure FileSystemStorage FileSystemStorage `ocisConfig:"filesystem_storage"` - WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure"` - CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure"` - RevaGateway string `ocisConfig:"reva_gateway"` - FontMapFile string `ocisConfig:"font_map_file"` -} - -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} + WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_WEBDAVSOURCE_INSECURE"` + CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_CS3SOURCE_INSECURE"` + RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` + FontMapFile string `ocisConfig:"font_map_file" env:"THUMBNAILS_TXT_FONTMAP_FILE"` } func DefaultConfig() *Config { diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go deleted file mode 100644 index fdd30b5019a..00000000000 --- a/thumbnails/pkg/config/mappings.go +++ /dev/null @@ -1,111 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_FILE", "THUMBNAILS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_LOG_LEVEL", "THUMBNAILS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "THUMBNAILS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "THUMBNAILS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"THUMBNAILS_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "THUMBNAILS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "THUMBNAILS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "THUMBNAILS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "THUMBNAILS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"THUMBNAILS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"THUMBNAILS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"THUMBNAILS_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"THUMBNAILS_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"THUMBNAILS_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"THUMBNAILS_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - { - EnvVars: []string{"THUMBNAILS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - { - EnvVars: []string{"THUMBNAILS_TXT_FONTMAP_FILE"}, - Destination: &cfg.Thumbnail.FontMapFile, - }, - { - EnvVars: []string{"THUMBNAILS_FILESYSTEMSTORAGE_ROOT"}, - Destination: &cfg.Thumbnail.FileSystemStorage.RootDirectory, - }, - { - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Thumbnail.RevaGateway, - }, - { - EnvVars: []string{"OCIS_INSECURE", "THUMBNAILS_WEBDAVSOURCE_INSECURE"}, - Destination: &cfg.Thumbnail.WebdavAllowInsecure, - }, - { - EnvVars: []string{"OCIS_INSECURE", "THUMBNAILS_CS3SOURCE_INSECURE"}, - Destination: &cfg.Thumbnail.CS3AllowInsecure, - }, - } -} diff --git a/thumbnails/pkg/logging/logging.go b/thumbnails/pkg/logging/logging.go new file mode 100644 index 00000000000..e097814b271 --- /dev/null +++ b/thumbnails/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/thumbnails/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go b/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go index d3298d62cd6..a435cdf364b 100644 --- a/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go +++ b/thumbnails/pkg/proto/v0/thumbnails.pb.micro_test.go @@ -26,7 +26,7 @@ func init() { grpc.Address("localhost:9992"), ) - cfg := config.New() + cfg := config.DefaultConfig() cfg.Thumbnail.Resolutions = []string{"16x16", "32x32", "64x64", "128x128"} wd, _ := os.Getwd() @@ -44,17 +44,17 @@ func init() { if err != nil { log.Fatalf("could not register ThumbnailHandler: %v", err) } - if err := service.Server().Start(); err != nil { - log.Fatalf("could not start server: %v", err) - } + if err := service.Server().Start(); err != nil { + log.Fatalf("could not start server: %v", err) + } } func TestGetThumbnailInvalidImage(t *testing.T) { req := proto.GetThumbnailRequest{ - Filepath: "invalid.png", + Filepath: "invalid.png", ThumbnailType: proto.GetThumbnailRequest_PNG, - Height: 32, - Width: 32, + Height: 32, + Width: 32, } client := service.Client() cl := proto.NewThumbnailService("com.owncloud.api.thumbnails", client) diff --git a/thumbnails/pkg/service/v0/service.go b/thumbnails/pkg/service/v0/service.go index 5d9fac80409..82ca913901c 100644 --- a/thumbnails/pkg/service/v0/service.go +++ b/thumbnails/pkg/service/v0/service.go @@ -31,8 +31,7 @@ func NewService(opts ...Option) v0proto.ThumbnailServiceHandler { logger.Fatal().Err(err).Msg("resolutions not configured correctly") } svc := Thumbnail{ - serviceID: options.Config.GRPC.Namespace + "." + options.Config.Service.Name, - webdavNamespace: options.Config.Thumbnail.WebdavNamespace, + serviceID: options.Config.GRPC.Namespace + "." + options.Config.Service.Name, manager: thumbnail.NewSimpleManager( resolutions, options.ThumbnailStorage, diff --git a/web/pkg/command/health.go b/web/pkg/command/health.go index 97206879bf4..d780d4058e4 100644 --- a/web/pkg/command/health.go +++ b/web/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 8c99ecad628..0a7e731c662 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -4,14 +4,13 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/web/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the web command. @@ -27,6 +26,12 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, + + Before: func(c *cli.Context) error { + cfg.Service.Version = version.String + return ParseConfig(c, cfg) + }, + Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -46,39 +51,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("web"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - -// ParseConfig loads graph configuration from known paths. +// ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("web", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} + + // load all env variables relevant to the config in the current context. + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } + + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err } - conf.LoadOSEnv(config.GetEnv(cfg), false) - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + return nil } // SutureService allows for the web command to be embedded and supervised by a suture supervisor tree. @@ -88,7 +91,7 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Web.Commons = cfg.Commons + //cfg.Web.Commons = cfg.Commons return SutureService{ cfg: cfg.Web, } diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index c8b8fd10717..6b3b1f9ad2a 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -8,6 +8,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/logging" "github.com/owncloud/ocis/web/pkg/metrics" "github.com/owncloud/ocis/web/pkg/server/debug" "github.com/owncloud/ocis/web/pkg/server/http" @@ -37,9 +38,9 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 0cfd317fc39..345ae8aec40 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -2,51 +2,57 @@ package config import ( "context" - - "github.com/owncloud/ocis/ocis-pkg/shared" ) // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"WEB_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"WEB_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"WEB_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"WEB_DEBUG_ZPAGES"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` + Addr string `ocisConfig:"addr" env:"WEB_HTTP_ADDR"` Namespace string - CacheTTL int `ocisConfig:"cache_ttl"` + Root string `ocisConfig:"root" env:"WEB_HTTP_ROOT"` + CacheTTL int `ocisConfig:"cache_ttl" env:"WEB_CACHE_TTL"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;WEB_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEB_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEB_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEB_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"WEB_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;WEB_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;WEB_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;WEB_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;WEB_LOG_FILE"` } // Asset defines the available asset configuration. type Asset struct { - Path string `ocisConfig:"path"` + Path string `ocisConfig:"path" env:"WEB_ASSET_PATH"` } // WebConfig defines the available web configuration for a dynamically rendered config.json. type WebConfig struct { - Server string `json:"server,omitempty" ocisConfig:"server"` - Theme string `json:"theme,omitempty" ocisConfig:"theme"` - Version string `json:"version,omitempty" ocisConfig:"version"` + Server string `json:"server,omitempty" ocisConfig:"server" env:"OCIS_URL;WEB_UI_CONFIG_SERVER"` + Theme string `json:"theme,omitempty" ocisConfig:"theme" env:""` + Version string `json:"version,omitempty" ocisConfig:"version" env:"WEB_UI_CONFIG_VERSION"` OpenIDConnect OIDC `json:"openIdConnect,omitempty" ocisConfig:"oids"` Apps []string `json:"apps" ocisConfig:"apps"` ExternalApps []ExternalApp `json:"external_apps,omitempty" ocisConfig:"external_apps"` @@ -55,11 +61,11 @@ type WebConfig struct { // OIDC defines the available oidc configuration type OIDC struct { - MetadataURL string `json:"metadata_url,omitempty" ocisConfig:"metadata_url"` - Authority string `json:"authority,omitempty" ocisConfig:"authority"` - ClientID string `json:"client_id,omitempty" ocisConfig:"client_id"` - ResponseType string `json:"response_type,omitempty" ocisConfig:"response_type"` - Scope string `json:"scope,omitempty" ocisConfig:"scope"` + MetadataURL string `json:"metadata_url,omitempty" ocisConfig:"metadata_url" env:"WEB_OIDC_METADATA_URL"` + Authority string `json:"authority,omitempty" ocisConfig:"authority" env:"OCIS_URL;WEB_OIDC_AUTHORITY"` + ClientID string `json:"client_id,omitempty" ocisConfig:"client_id" env:"WEB_OIDC_CLIENT_ID"` + ResponseType string `json:"response_type,omitempty" ocisConfig:"response_type" env:"WEB_OIDC_RESPONSE_TYPE"` + Scope string `json:"scope,omitempty" ocisConfig:"scope" env:"WEB_OIDC_SCOPE"` } // ExternalApp defines an external web app. @@ -79,38 +85,35 @@ type ExternalApp struct { // ExternalAppConfig defines an external web app configuration. type ExternalAppConfig struct { - URL string `json:"url,omitempty" ocisConfig:"url"` + URL string `json:"url,omitempty" ocisConfig:"url" env:""` } // Web defines the available web configuration. type Web struct { - Path string `ocisConfig:"path"` - ThemeServer string `ocisConfig:"theme_server"` // used to build Theme in WebConfig - ThemePath string `ocisConfig:"theme_path"` // used to build Theme in WebConfig + Path string `ocisConfig:"path" env:"WEB_UI_PATH"` + ThemeServer string `ocisConfig:"theme_server" env:"OCIS_URL;WEB_UI_THEME_SERVER"` // used to build Theme in WebConfig + ThemePath string `ocisConfig:"theme_path" env:"WEB_UI_THEME_PATH"` // used to build Theme in WebConfig Config WebConfig `ocisConfig:"config"` } // Config combines all available configuration parts. type Config struct { - *shared.Commons + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - Service Service `ocisConfig:"service"` - Tracing Tracing `ocisConfig:"tracing"` - Asset Asset `ocisConfig:"asset"` - Web Web `ocisConfig:"web"` + HTTP HTTP `ocisConfig:"http"` + + Asset Asset `ocisConfig:"asset"` + File string `ocisConfig:"file" env:"WEB_UI_CONFIG"` // TODO: rename this to a more self explaining string + Web Web `ocisConfig:"web"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - func DefaultConfig() *Config { return &Config{ Debug: Debug{ diff --git a/web/pkg/config/mappings.go b/web/pkg/config/mappings.go deleted file mode 100644 index 3957c225ed0..00000000000 --- a/web/pkg/config/mappings.go +++ /dev/null @@ -1,143 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_LEVEL", "WEB_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "WEB_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "WEB_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_FILE", "WEB_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"WEB_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "WEB_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "WEB_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "WEB_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "WEB_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"WEB_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"WEB_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"WEB_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"WEB_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"WEB_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"WEB_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"WEB_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"WEB_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"WEB_CACHE_TTL"}, - Destination: &cfg.HTTP.CacheTTL, - }, - { - EnvVars: []string{"WEB_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - { - EnvVars: []string{"WEB_UI_CONFIG"}, - Destination: &cfg.Web.Path, - }, - { - EnvVars: []string{"OCIS_URL", "WEB_UI_CONFIG_SERVER"}, // WEB_UI_CONFIG_SERVER takes precedence over OCIS_URL - Destination: &cfg.Web.Config.Server, - }, - { - EnvVars: []string{"OCIS_URL", "WEB_UI_THEME_SERVER"}, // WEB_UI_THEME_SERVER takes precedence over OCIS_URL - Destination: &cfg.Web.ThemeServer, - }, - { - EnvVars: []string{"WEB_UI_THEME_PATH"}, - Destination: &cfg.Web.ThemePath, - }, - { - EnvVars: []string{"WEB_UI_CONFIG_VERSION"}, - Destination: &cfg.Web.Config.Version, - }, - { - EnvVars: []string{"WEB_OIDC_METADATA_URL"}, - Destination: &cfg.Web.Config.OpenIDConnect.MetadataURL, - }, - { - EnvVars: []string{"OCIS_URL", "WEB_OIDC_AUTHORITY"}, // WEB_OIDC_AUTHORITY takes precedence over OCIS_URL - Destination: &cfg.Web.Config.OpenIDConnect.Authority, - }, - { - EnvVars: []string{"WEB_OIDC_CLIENT_ID"}, - Destination: &cfg.Web.Config.OpenIDConnect.ClientID, - }, - { - EnvVars: []string{"WEB_OIDC_RESPONSE_TYPE"}, - Destination: &cfg.Web.Config.OpenIDConnect.ResponseType, - }, - { - EnvVars: []string{"WEB_OIDC_SCOPE"}, - Destination: &cfg.Web.Config.OpenIDConnect.Scope, - }, - } -} diff --git a/web/pkg/logging/logging.go b/web/pkg/logging/logging.go new file mode 100644 index 00000000000..6510b8c21a8 --- /dev/null +++ b/web/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/web/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} diff --git a/webdav/pkg/command/health.go b/webdav/pkg/command/health.go index 58aca1e1d2e..e1f2be33e62 100644 --- a/webdav/pkg/command/health.go +++ b/webdav/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/logging" "github.com/urfave/cli/v2" ) @@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( fmt.Sprintf( diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index f221de83283..15d0db36912 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -4,14 +4,13 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - + "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/webdav/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-webdav command. @@ -30,7 +29,7 @@ func Execute(cfg *config.Config) error { }, Before: func(c *cli.Context) error { cfg.Service.Version = version.String - return nil + return ParseConfig(c, cfg) }, Commands: []*cli.Command{ @@ -52,41 +51,37 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("webdav"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - // ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("webdav", cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} - } + //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + // cfg.Log = &shared.Log{ + // Level: cfg.Commons.Log.Level, + // Pretty: cfg.Commons.Log.Pretty, + // Color: cfg.Commons.Log.Color, + // File: cfg.Commons.Log.File, + // } + //} else if cfg.Log == nil && cfg.Commons == nil { + // cfg.Log = &shared.Log{} + //} // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(cfg), false) + envCfg := config.Config{} + if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // merge environment variable config on top of the current config + if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + return err + } + + return nil } // SutureService allows for the webdav command to be embedded and supervised by a suture supervisor tree. @@ -96,7 +91,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Proxy.Commons = cfg.Commons + //cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.WebDAV, } diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index d3f68efcf83..7732f04bb75 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/logging" "github.com/owncloud/ocis/webdav/pkg/metrics" "github.com/owncloud/ocis/webdav/pkg/server/debug" "github.com/owncloud/ocis/webdav/pkg/server/http" @@ -30,9 +31,9 @@ func Server(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) - - if err := tracing.Configure(cfg); err != nil { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + err := tracing.Configure(cfg) + if err != nil { return err } diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 22964b3f95b..076c33177c6 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -8,10 +8,10 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Addr string `ocisConfig:"addr" env:"WEBDAV_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"WEBDAV_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"WEBDAV_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"WEBDAV_DEBUG_ZPAGES"` } // CORS defines the available cors configuration. @@ -24,50 +24,55 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string `ocisConfig:"addr"` - Root string `ocisConfig:"root"` + Addr string `ocisConfig:"addr" env:"WEBDAV_HTTP_ADDR"` Namespace string - CORS CORS `ocisConfig:"cors"` + Root string `ocisConfig:"root" env:"WEBDAV_HTTP_ROOT"` + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string `ocisConfig:"name"` - Version string `ocisConfig:"version"` + Name string + Version string } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;WEBDAV_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEBDAV_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEBDAV_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEBDAV_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"WEBDAV_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;WEBDAV_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;WEBDAV_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;WEBDAV_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;WEBDAV_LOG_FILE"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - File string `ocisConfig:"file"` - Log *shared.Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - HTTP HTTP `ocisConfig:"http"` - Tracing Tracing `ocisConfig:"tracing"` - Service Service `ocisConfig:"service"` - OcisPublicURL string `ocisConfig:"ocis_public_url"` - WebdavNamespace string `ocisConfig:"webdav_namespace"` - RevaGateway string `ocisConfig:"reva_gateway"` + Service Service `ocisConfig:"service"` + + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + HTTP HTTP `ocisConfig:"http"` + + OcisPublicURL string `ocisConfig:"ocis_public_url" env:"OCIS_URL;OCIS_PUBLIC_URL"` + WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` //TODO: prevent this cross config + RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` Context context.Context Supervised bool } -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} -} - func DefaultConfig() *Config { return &Config{ Debug: Debug{ diff --git a/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go deleted file mode 100644 index 350ab25fd63..00000000000 --- a/webdav/pkg/config/mappings.go +++ /dev/null @@ -1,107 +0,0 @@ -package config - -import "github.com/owncloud/ocis/ocis-pkg/shared" - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv(cfg *Config) []string { - var r = make([]string, len(structMappings(cfg))) - for i := range structMappings(cfg) { - r = append(r, structMappings(cfg)[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - { - EnvVars: []string{"OCIS_LOG_FILE", "WEBDAV_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_LOG_LEVEL", "WEBDAV_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY", "WEBDAV_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR", "WEBDAV_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"WEBDAV_CONFIG_FILE"}, - Destination: &cfg.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED", "WEBDAV_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE", "WEBDAV_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT", "WEBDAV_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR", "WEBDAV_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"WEBDAV_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - { - EnvVars: []string{"WEBDAV_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - { - EnvVars: []string{"WEBDAV_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - { - EnvVars: []string{"WEBDAV_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - { - EnvVars: []string{"WEBDAV_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - { - EnvVars: []string{"WEBDAV_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - { - EnvVars: []string{"WEBDAV_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - { - EnvVars: []string{"WEBDAV_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - { - EnvVars: []string{"OCIS_URL", "OCIS_PUBLIC_URL"}, - Destination: &cfg.OcisPublicURL, - }, - { - EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, - Destination: &cfg.WebdavNamespace, - }, - { - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.RevaGateway, - }, - } -} diff --git a/webdav/pkg/logging/logging.go b/webdav/pkg/logging/logging.go new file mode 100644 index 00000000000..11c8f85aafb --- /dev/null +++ b/webdav/pkg/logging/logging.go @@ -0,0 +1,17 @@ +package logging + +import ( + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/webdav/pkg/config" +) + +// LoggerFromConfig initializes a service-specific logger instance. +func Configure(name string, cfg config.Log) log.Logger { + return log.NewLogger( + log.Name(name), + log.Level(cfg.Level), + log.Pretty(cfg.Pretty), + log.Color(cfg.Color), + log.File(cfg.File), + ) +} From a13df3dcf74decb07ba795ccf6003376517888ad Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 11:47:18 +0100 Subject: [PATCH 45/84] split **/pkg/config/config.go up to multiple files --- accounts/pkg/config/config.go | 158 +------ accounts/pkg/config/debug.go | 10 + accounts/pkg/config/defaultconfig.go | 68 +++ accounts/pkg/config/grpc.go | 7 + accounts/pkg/config/http.go | 18 + accounts/pkg/config/log.go | 9 + accounts/pkg/config/service.go | 7 + accounts/pkg/config/tracing.go | 10 + glauth/pkg/config/config.go | 128 +----- glauth/pkg/config/debug.go | 9 + glauth/pkg/config/defaultconfig.go | 55 +++ glauth/pkg/config/ldap.go | 8 + glauth/pkg/config/ldaps.go | 10 + glauth/pkg/config/log.go | 9 + glauth/pkg/config/service.go | 7 + glauth/pkg/config/tracing.go | 10 + graph-explorer/pkg/config/config.go | 84 +--- graph-explorer/pkg/config/debug.go | 9 + graph-explorer/pkg/config/defaultconfig.go | 32 ++ graph-explorer/pkg/config/http.go | 16 + graph-explorer/pkg/config/log.go | 9 + graph-explorer/pkg/config/service.go | 7 + graph-explorer/pkg/config/tracing.go | 10 + graph/pkg/config/config.go | 133 +----- graph/pkg/config/debug.go | 9 + graph/pkg/config/defaultconfig.go | 56 +++ graph/pkg/config/http.go | 8 + graph/pkg/config/log.go | 9 + graph/pkg/config/reva.go | 11 + graph/pkg/config/service.go | 7 + graph/pkg/config/tracing.go | 10 + idp/pkg/config/config.go | 146 +------ idp/pkg/config/debug.go | 9 + idp/pkg/config/defaultconfig.go | 79 ++++ idp/pkg/config/http.go | 11 + idp/pkg/config/log.go | 9 + idp/pkg/config/service.go | 7 + idp/pkg/config/tracing.go | 10 + ocis-pkg/indexer/index/cs3/config.go | 1 + ocis/pkg/command/glauth.go | 6 +- ocis/pkg/command/graph.go | 6 +- ocis/pkg/command/graphexplorer.go | 6 +- ocis/pkg/command/idp.go | 6 +- ocis/pkg/command/ocs.go | 6 +- ocis/pkg/command/proxy.go | 6 +- ocis/pkg/command/settings.go | 6 +- ocis/pkg/command/webdav.go | 6 +- ocs/pkg/config/config.go | 116 +---- ocs/pkg/config/debug.go | 9 + ocs/pkg/config/defaultconfig.go | 43 ++ ocs/pkg/config/http.go | 17 + ocs/pkg/config/log.go | 9 + ocs/pkg/config/reva.go | 11 + ocs/pkg/config/service.go | 7 + ocs/pkg/config/tracing.go | 10 + proxy/pkg/config/config.go | 310 +------------ proxy/pkg/config/debug.go | 9 + proxy/pkg/config/defaultconfig.go | 220 ++++++++++ proxy/pkg/config/http.go | 11 + proxy/pkg/config/log.go | 9 + proxy/pkg/config/service.go | 7 + proxy/pkg/config/tracing.go | 10 + settings/pkg/config/config.go | 120 +---- settings/pkg/config/debug.go | 9 + settings/pkg/config/defaultconfig.go | 51 +++ settings/pkg/config/grpc.go | 7 + settings/pkg/config/http.go | 18 + settings/pkg/config/log.go | 9 + settings/pkg/config/reva.go | 6 + settings/pkg/config/service.go | 7 + settings/pkg/config/tracing.go | 10 + storage/pkg/command/appprovider.go | 2 +- storage/pkg/command/authbasic.go | 2 +- storage/pkg/command/authbearer.go | 2 +- storage/pkg/command/authmachine.go | 2 +- storage/pkg/command/frontend.go | 2 +- storage/pkg/command/gateway.go | 2 +- storage/pkg/command/groups.go | 2 +- storage/pkg/command/sharing.go | 2 +- storage/pkg/command/storagemetadata.go | 2 +- storage/pkg/command/storagepubliclink.go | 2 +- storage/pkg/command/storageshares.go | 2 +- storage/pkg/command/storageusers.go | 2 +- storage/pkg/command/users.go | 2 +- storage/pkg/config/config.go | 483 +-------------------- storage/pkg/config/debug.go | 9 + storage/pkg/config/defaultconfig.go | 436 +++++++++++++++++++ storage/pkg/config/grpc.go | 7 + storage/pkg/config/http.go | 18 + storage/pkg/config/log.go | 9 + storage/pkg/config/reva.go | 6 + storage/pkg/config/service.go | 7 + storage/pkg/config/tracing.go | 10 + store/pkg/config/config.go | 68 +-- store/pkg/config/debug.go | 9 + store/pkg/config/defaultconfig.go | 33 ++ store/pkg/config/grpc.go | 7 + store/pkg/config/log.go | 9 + store/pkg/config/service.go | 7 + store/pkg/config/tracing.go | 10 + thumbnails/pkg/config/config.go | 78 +--- thumbnails/pkg/config/debug.go | 9 + thumbnails/pkg/config/defaultconfig.go | 41 ++ thumbnails/pkg/config/grpc.go | 7 + thumbnails/pkg/config/log.go | 9 + thumbnails/pkg/config/service.go | 7 + thumbnails/pkg/config/tracing.go | 10 + web/pkg/config/config.go | 115 +---- web/pkg/config/debug.go | 9 + web/pkg/config/defaultconfig.go | 49 +++ web/pkg/config/http.go | 9 + web/pkg/config/log.go | 9 + web/pkg/config/service.go | 7 + web/pkg/config/tracing.go | 10 + webdav/pkg/config/config.go | 88 +--- webdav/pkg/config/debug.go | 9 + webdav/pkg/config/defaultconfig.go | 36 ++ webdav/pkg/config/http.go | 17 + webdav/pkg/config/log.go | 9 + webdav/pkg/config/service.go | 7 + webdav/pkg/config/tracing.go | 10 + 121 files changed, 2048 insertions(+), 1939 deletions(-) create mode 100644 accounts/pkg/config/debug.go create mode 100644 accounts/pkg/config/defaultconfig.go create mode 100644 accounts/pkg/config/grpc.go create mode 100644 accounts/pkg/config/http.go create mode 100644 accounts/pkg/config/log.go create mode 100644 accounts/pkg/config/service.go create mode 100644 accounts/pkg/config/tracing.go create mode 100644 glauth/pkg/config/debug.go create mode 100644 glauth/pkg/config/defaultconfig.go create mode 100644 glauth/pkg/config/ldap.go create mode 100644 glauth/pkg/config/ldaps.go create mode 100644 glauth/pkg/config/log.go create mode 100644 glauth/pkg/config/service.go create mode 100644 glauth/pkg/config/tracing.go create mode 100644 graph-explorer/pkg/config/debug.go create mode 100644 graph-explorer/pkg/config/defaultconfig.go create mode 100644 graph-explorer/pkg/config/http.go create mode 100644 graph-explorer/pkg/config/log.go create mode 100644 graph-explorer/pkg/config/service.go create mode 100644 graph-explorer/pkg/config/tracing.go create mode 100644 graph/pkg/config/debug.go create mode 100644 graph/pkg/config/defaultconfig.go create mode 100644 graph/pkg/config/http.go create mode 100644 graph/pkg/config/log.go create mode 100644 graph/pkg/config/reva.go create mode 100644 graph/pkg/config/service.go create mode 100644 graph/pkg/config/tracing.go create mode 100644 idp/pkg/config/debug.go create mode 100644 idp/pkg/config/defaultconfig.go create mode 100644 idp/pkg/config/http.go create mode 100644 idp/pkg/config/log.go create mode 100644 idp/pkg/config/service.go create mode 100644 idp/pkg/config/tracing.go create mode 100644 ocs/pkg/config/debug.go create mode 100644 ocs/pkg/config/defaultconfig.go create mode 100644 ocs/pkg/config/http.go create mode 100644 ocs/pkg/config/log.go create mode 100644 ocs/pkg/config/reva.go create mode 100644 ocs/pkg/config/service.go create mode 100644 ocs/pkg/config/tracing.go create mode 100644 proxy/pkg/config/debug.go create mode 100644 proxy/pkg/config/defaultconfig.go create mode 100644 proxy/pkg/config/http.go create mode 100644 proxy/pkg/config/log.go create mode 100644 proxy/pkg/config/service.go create mode 100644 proxy/pkg/config/tracing.go create mode 100644 settings/pkg/config/debug.go create mode 100644 settings/pkg/config/defaultconfig.go create mode 100644 settings/pkg/config/grpc.go create mode 100644 settings/pkg/config/http.go create mode 100644 settings/pkg/config/log.go create mode 100644 settings/pkg/config/reva.go create mode 100644 settings/pkg/config/service.go create mode 100644 settings/pkg/config/tracing.go create mode 100644 storage/pkg/config/debug.go create mode 100644 storage/pkg/config/defaultconfig.go create mode 100644 storage/pkg/config/grpc.go create mode 100644 storage/pkg/config/http.go create mode 100644 storage/pkg/config/log.go create mode 100644 storage/pkg/config/reva.go create mode 100644 storage/pkg/config/service.go create mode 100644 storage/pkg/config/tracing.go create mode 100644 store/pkg/config/debug.go create mode 100644 store/pkg/config/defaultconfig.go create mode 100644 store/pkg/config/grpc.go create mode 100644 store/pkg/config/log.go create mode 100644 store/pkg/config/service.go create mode 100644 store/pkg/config/tracing.go create mode 100644 thumbnails/pkg/config/debug.go create mode 100644 thumbnails/pkg/config/defaultconfig.go create mode 100644 thumbnails/pkg/config/grpc.go create mode 100644 thumbnails/pkg/config/log.go create mode 100644 thumbnails/pkg/config/service.go create mode 100644 thumbnails/pkg/config/tracing.go create mode 100644 web/pkg/config/debug.go create mode 100644 web/pkg/config/defaultconfig.go create mode 100644 web/pkg/config/http.go create mode 100644 web/pkg/config/log.go create mode 100644 web/pkg/config/service.go create mode 100644 web/pkg/config/tracing.go create mode 100644 webdav/pkg/config/debug.go create mode 100644 webdav/pkg/config/defaultconfig.go create mode 100644 webdav/pkg/config/http.go create mode 100644 webdav/pkg/config/log.go create mode 100644 webdav/pkg/config/service.go create mode 100644 webdav/pkg/config/tracing.go diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 5c138ad7845..e10f6a932da 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -1,49 +1,31 @@ -// Package config should be moved to internal package config import ( "context" - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -//TODO: use debug config -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"ACCOUNTS_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"ACCOUNTS_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"ACCOUNTS_DEBUG_ZPAGES"` -} +// Config combines all available configuration parts. +type Config struct { + Service Service -// CORS defines the available cors configuration. -type CORS struct { - AllowedOrigins []string `ocisConfig:"allowed_origins"` - AllowedMethods []string `ocisConfig:"allowed_methods"` - AllowedHeaders []string `ocisConfig:"allowed_headers"` - AllowCredentials bool `ocisConfig:"allowed_credentials"` -} + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"ACCOUNTS_HTTP_ADDR"` - Namespace string - Root string `ocisConfig:"root" env:"ACCOUNTS_HTTP_ROOT"` - CacheTTL int `ocisConfig:"cache_ttl" env:"ACCOUNTS_CACHE_TTL"` - CORS CORS `ocisConfig:"cors"` -} + HTTP HTTP `ocisConfig:"http"` + GRPC GRPC `ocisConfig:"grpc"` -// GRPC defines the available grpc configuration. -type GRPC struct { - Addr string `ocisConfig:"addr" env:"ACCOUNTS_GRPC_ADDR"` - Namespace string -} + TokenManager TokenManager `ocisConfig:"token_manager"` -// Service defines the available service configuration. -type Service struct { - Name string - Version string + Asset Asset `ocisConfig:"asset"` + Repo Repo `ocisConfig:"repo"` + Index Index `ocisConfig:"index"` + ServiceUser ServiceUser `ocisConfig:"service_user"` + HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"` + DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"` + + Context context.Context + Supervised bool } // Asset defines the available asset configuration. @@ -99,107 +81,3 @@ type UIDBound struct { Lower int64 `ocisConfig:"lower" env:"ACCOUNTS_UID_INDEX_LOWER_BOUND"` Upper int64 `ocisConfig:"upper" env:"ACCOUNTS_UID_INDEX_UPPER_BOUND"` } - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;ACCOUNTS_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;ACCOUNTS_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;ACCOUNTS_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;ACCOUNTS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"ACCOUNTS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;ACCOUNTS_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;ACCOUNTS_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;ACCOUNTS_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;ACCOUNTS_LOG_FILE"` -} - -// Config merges all Account config parameters. -type Config struct { - //*shared.Commons - - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - HTTP HTTP `ocisConfig:"http"` - GRPC GRPC `ocisConfig:"grpc"` - - TokenManager TokenManager `ocisConfig:"token_manager"` - - Asset Asset `ocisConfig:"asset"` - Repo Repo `ocisConfig:"repo"` - Index Index `ocisConfig:"index"` - ServiceUser ServiceUser `ocisConfig:"service_user"` - HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"` - DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"` - - Context context.Context - Supervised bool -} - -func DefaultConfig() *Config { - return &Config{ - - HTTP: HTTP{ - Addr: "127.0.0.1:9181", - Namespace: "com.owncloud.web", - Root: "/", - CacheTTL: 604800, // 7 days - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9180", - Namespace: "com.owncloud.api", - }, - Service: Service{ - Name: "accounts", - }, - Asset: Asset{}, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - HashDifficulty: 11, - DemoUsersAndGroups: true, - Repo: Repo{ - Backend: "CS3", - Disk: Disk{ - Path: path.Join(defaults.BaseDataPath(), "accounts"), - }, - CS3: CS3{ - ProviderAddr: "localhost:9215", - JWTSecret: "Pive-Fumkiu4", - }, - }, - Index: Index{ - UID: UIDBound{ - Lower: 0, - Upper: 1000, - }, - GID: GIDBound{ - Lower: 0, - Upper: 1000, - }, - }, - ServiceUser: ServiceUser{ - UUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Username: "", - UID: 0, - GID: 0, - }, - Tracing: Tracing{ - Type: "jaeger", - Service: "accounts", - }, - } -} diff --git a/accounts/pkg/config/debug.go b/accounts/pkg/config/debug.go new file mode 100644 index 00000000000..c95ef3a2666 --- /dev/null +++ b/accounts/pkg/config/debug.go @@ -0,0 +1,10 @@ +package config + +//TODO: use debug config +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"ACCOUNTS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"ACCOUNTS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"ACCOUNTS_DEBUG_ZPAGES"` +} diff --git a/accounts/pkg/config/defaultconfig.go b/accounts/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..8e7caa10179 --- /dev/null +++ b/accounts/pkg/config/defaultconfig.go @@ -0,0 +1,68 @@ +package config + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + + HTTP: HTTP{ + Addr: "127.0.0.1:9181", + Namespace: "com.owncloud.web", + Root: "/", + CacheTTL: 604800, // 7 days + CORS: CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + GRPC: GRPC{ + Addr: "127.0.0.1:9180", + Namespace: "com.owncloud.api", + }, + Service: Service{ + Name: "accounts", + }, + Asset: Asset{}, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + HashDifficulty: 11, + DemoUsersAndGroups: true, + Repo: Repo{ + Backend: "CS3", + Disk: Disk{ + Path: path.Join(defaults.BaseDataPath(), "accounts"), + }, + CS3: CS3{ + ProviderAddr: "localhost:9215", + JWTSecret: "Pive-Fumkiu4", + }, + }, + Index: Index{ + UID: UIDBound{ + Lower: 0, + Upper: 1000, + }, + GID: GIDBound{ + Lower: 0, + Upper: 1000, + }, + }, + ServiceUser: ServiceUser{ + UUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Username: "", + UID: 0, + GID: 0, + }, + Tracing: Tracing{ + Type: "jaeger", + Service: "accounts", + }, + } +} diff --git a/accounts/pkg/config/grpc.go b/accounts/pkg/config/grpc.go new file mode 100644 index 00000000000..f16de42f2b2 --- /dev/null +++ b/accounts/pkg/config/grpc.go @@ -0,0 +1,7 @@ +package config + +// GRPC defines the available grpc configuration. +type GRPC struct { + Addr string `ocisConfig:"addr" env:"ACCOUNTS_GRPC_ADDR"` + Namespace string +} diff --git a/accounts/pkg/config/http.go b/accounts/pkg/config/http.go new file mode 100644 index 00000000000..c8c7ab628e6 --- /dev/null +++ b/accounts/pkg/config/http.go @@ -0,0 +1,18 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"ACCOUNTS_HTTP_ADDR"` + Namespace string + Root string `ocisConfig:"root" env:"ACCOUNTS_HTTP_ROOT"` + CacheTTL int `ocisConfig:"cache_ttl" env:"ACCOUNTS_CACHE_TTL"` + CORS CORS `ocisConfig:"cors"` +} + +// CORS defines the available cors configuration. +type CORS struct { + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allowed_credentials"` +} diff --git a/accounts/pkg/config/log.go b/accounts/pkg/config/log.go new file mode 100644 index 00000000000..6ada8a7dd6a --- /dev/null +++ b/accounts/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;ACCOUNTS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;ACCOUNTS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;ACCOUNTS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;ACCOUNTS_LOG_FILE"` +} diff --git a/accounts/pkg/config/service.go b/accounts/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/accounts/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/accounts/pkg/config/tracing.go b/accounts/pkg/config/tracing.go new file mode 100644 index 00000000000..3547373fbb3 --- /dev/null +++ b/accounts/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;ACCOUNTS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;ACCOUNTS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;ACCOUNTS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;ACCOUNTS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"ACCOUNTS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 4876413f6b2..c13d732eadd 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -2,58 +2,26 @@ package config import ( "context" - "path" - - "github.com/owncloud/ocis/ocis-pkg/shared" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"GLAUTH_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"GLAUTH_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"GLAUTH_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"GLAUTH_DEBUG_ZPAGES"` -} +// Config combines all available configuration parts. +type Config struct { + Service Service -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GLAUTH_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GLAUTH_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GLAUTH_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GLAUTH_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"GLAUTH_TRACING_SERVICE"` // TODO: -} + Ldap Ldap `ocisConfig:"ldap"` + Ldaps Ldaps `ocisConfig:"ldaps"` -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GLAUTH_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GLAUTH_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GLAUTH_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;GLAUTH_LOG_FILE"` -} + Backend Backend `ocisConfig:"backend"` + Fallback FallbackBackend `ocisConfig:"fallback"` -// Ldap defined the available LDAP configuration. -type Ldap struct { - Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAP_ENABLED"` - Addr string `ocisConfig:"addr" env:"GLAUTH_LDAP_ADDR"` - Namespace string -} + RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` -// Ldaps defined the available LDAPS configuration. -type Ldaps struct { - Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAPS_ENABLED"` - Addr string `ocisConfig:"addr" env:"GLAUTH_LDAPS_ADDR"` - Namespace string - Cert string `ocisConfig:"cert" env:"GLAUTH_LDAPS_CERT"` - Key string `ocisConfig:"key" env:"GLAUTH_LDAPS_KEY"` + Context context.Context + Supervised bool } // Backend defined the available backend configuration. @@ -79,73 +47,3 @@ type FallbackBackend struct { SSHKeyAttr string `ocisConfig:"ssh_key_attr" env:"GLAUTH_FALLBACK_SSH_KEY_ATTR"` UseGraphAPI bool `ocisConfig:"use_graph_api" env:"GLAUTH_FALLBACK_USE_GRAPHAPI"` } - -// Config combines all available configuration parts. -type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - Ldap Ldap `ocisConfig:"ldap"` - Ldaps Ldaps `ocisConfig:"ldaps"` - - Backend Backend `ocisConfig:"backend"` - Fallback FallbackBackend `ocisConfig:"fallback"` - - RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` - - Context context.Context - Supervised bool -} - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9129", - }, - Tracing: Tracing{ - Type: "jaeger", - Service: "glauth", - }, - Service: Service{ - Name: "glauth", - }, - Ldap: Ldap{ - Enabled: true, - Addr: "127.0.0.1:9125", - Namespace: "com.owncloud.ldap", - }, - Ldaps: Ldaps{ - Enabled: true, - Addr: "127.0.0.1:9126", - Namespace: "com.owncloud.ldaps", - Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), - Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), - }, - Backend: Backend{ - Datastore: "accounts", - BaseDN: "dc=ocis,dc=test", - Insecure: false, - NameFormat: "cn", - GroupFormat: "ou", - Servers: nil, - SSHKeyAttr: "sshPublicKey", - UseGraphAPI: true, - }, - Fallback: FallbackBackend{ - Datastore: "", - BaseDN: "dc=ocis,dc=test", - Insecure: false, - NameFormat: "cn", - GroupFormat: "ou", - Servers: nil, - SSHKeyAttr: "sshPublicKey", - UseGraphAPI: true, - }, - RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin - } -} diff --git a/glauth/pkg/config/debug.go b/glauth/pkg/config/debug.go new file mode 100644 index 00000000000..1d612c88dec --- /dev/null +++ b/glauth/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"GLAUTH_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"GLAUTH_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"GLAUTH_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"GLAUTH_DEBUG_ZPAGES"` +} diff --git a/glauth/pkg/config/defaultconfig.go b/glauth/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..23c12f84463 --- /dev/null +++ b/glauth/pkg/config/defaultconfig.go @@ -0,0 +1,55 @@ +package config + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9129", + }, + Tracing: Tracing{ + Type: "jaeger", + Service: "glauth", + }, + Service: Service{ + Name: "glauth", + }, + Ldap: Ldap{ + Enabled: true, + Addr: "127.0.0.1:9125", + Namespace: "com.owncloud.ldap", + }, + Ldaps: Ldaps{ + Enabled: true, + Addr: "127.0.0.1:9126", + Namespace: "com.owncloud.ldaps", + Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), + }, + Backend: Backend{ + Datastore: "accounts", + BaseDN: "dc=ocis,dc=test", + Insecure: false, + NameFormat: "cn", + GroupFormat: "ou", + Servers: nil, + SSHKeyAttr: "sshPublicKey", + UseGraphAPI: true, + }, + Fallback: FallbackBackend{ + Datastore: "", + BaseDN: "dc=ocis,dc=test", + Insecure: false, + NameFormat: "cn", + GroupFormat: "ou", + Servers: nil, + SSHKeyAttr: "sshPublicKey", + UseGraphAPI: true, + }, + RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin + } +} diff --git a/glauth/pkg/config/ldap.go b/glauth/pkg/config/ldap.go new file mode 100644 index 00000000000..b0780084a6f --- /dev/null +++ b/glauth/pkg/config/ldap.go @@ -0,0 +1,8 @@ +package config + +// Ldap defines the available LDAP configuration. +type Ldap struct { + Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAP_ENABLED"` + Addr string `ocisConfig:"addr" env:"GLAUTH_LDAP_ADDR"` + Namespace string +} diff --git a/glauth/pkg/config/ldaps.go b/glauth/pkg/config/ldaps.go new file mode 100644 index 00000000000..2c09f2530b7 --- /dev/null +++ b/glauth/pkg/config/ldaps.go @@ -0,0 +1,10 @@ +package config + +// Ldaps defined the available LDAPS configuration. +type Ldaps struct { + Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAPS_ENABLED"` + Addr string `ocisConfig:"addr" env:"GLAUTH_LDAPS_ADDR"` + Namespace string + Cert string `ocisConfig:"cert" env:"GLAUTH_LDAPS_CERT"` + Key string `ocisConfig:"key" env:"GLAUTH_LDAPS_KEY"` +} diff --git a/glauth/pkg/config/log.go b/glauth/pkg/config/log.go new file mode 100644 index 00000000000..2ce88369b25 --- /dev/null +++ b/glauth/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GLAUTH_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GLAUTH_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GLAUTH_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;GLAUTH_LOG_FILE"` +} diff --git a/glauth/pkg/config/service.go b/glauth/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/glauth/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/glauth/pkg/config/tracing.go b/glauth/pkg/config/tracing.go new file mode 100644 index 00000000000..3caca270571 --- /dev/null +++ b/glauth/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GLAUTH_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GLAUTH_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GLAUTH_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GLAUTH_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"GLAUTH_TRACING_SERVICE"` // TODO: +} diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 9a76da1019e..9e11dd8e76a 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -4,55 +4,9 @@ import ( "context" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"GRAPH_EXPLORER_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"GRAPH_EXPLORER_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"GRAPH_EXPLORER_DEBUG_ZPAGES"` -} - -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_HTTP_ADDR"` - Root string `ocisConfig:"root" env:"GRAPH_EXPLORER_HTTP_ROOT"` - Namespace string -} - -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_EXPLORER_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_EXPLORER_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_EXPLORER_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_EXPLORER_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"GRAPH_EXPLORER_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GRAPH_EXPLORER_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GRAPH_EXPLORER_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GRAPH_EXPLORER_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;GRAPH_EXPLORER_LOG_FILE"` -} - -// GraphExplorer defines the available graph-explorer configuration. -type GraphExplorer struct { - ClientID string `ocisConfig:"client_id" env:"GRAPH_EXPLORER_CLIENT_ID"` - Issuer string `ocisConfig:"issuer" env:"OCIS_URL;GRAPH_EXPLORER_ISSUER"` - GraphURLBase string `ocisConfig:"graph_url_base" env:"OCIS_URL;GRAPH_EXPLORER_GRAPH_URL_BASE"` - GraphURLPath string `ocisConfig:"graph_url_path" env:"GRAPH_EXPLORER_GRAPH_URL_PATH"` -} - // Config combines all available configuration parts. type Config struct { - Service Service `ocisConfig:"service"` + Service Service Tracing Tracing `ocisConfig:"tracing"` Log Log `ocisConfig:"log"` @@ -66,34 +20,10 @@ type Config struct { Supervised bool } -// DefaultConfig provides with a working version of a config. -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9136", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9135", - Root: "/graph-explorer", - Namespace: "com.owncloud.web", - }, - Service: Service{ - Name: "graph-explorer", - }, - Tracing: Tracing{ - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "graph-explorer", - }, - GraphExplorer: GraphExplorer{ - ClientID: "ocis-explorer.js", - Issuer: "https://localhost:9200", - GraphURLBase: "https://localhost:9200", - GraphURLPath: "/graph", - }, - } +// GraphExplorer defines the available graph-explorer configuration. +type GraphExplorer struct { + ClientID string `ocisConfig:"client_id" env:"GRAPH_EXPLORER_CLIENT_ID"` + Issuer string `ocisConfig:"issuer" env:"OCIS_URL;GRAPH_EXPLORER_ISSUER"` + GraphURLBase string `ocisConfig:"graph_url_base" env:"OCIS_URL;GRAPH_EXPLORER_GRAPH_URL_BASE"` + GraphURLPath string `ocisConfig:"graph_url_path" env:"GRAPH_EXPLORER_GRAPH_URL_PATH"` } diff --git a/graph-explorer/pkg/config/debug.go b/graph-explorer/pkg/config/debug.go new file mode 100644 index 00000000000..3dfc27f7b3e --- /dev/null +++ b/graph-explorer/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"GRAPH_EXPLORER_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"GRAPH_EXPLORER_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"GRAPH_EXPLORER_DEBUG_ZPAGES"` +} diff --git a/graph-explorer/pkg/config/defaultconfig.go b/graph-explorer/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..b4492724332 --- /dev/null +++ b/graph-explorer/pkg/config/defaultconfig.go @@ -0,0 +1,32 @@ +package config + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9136", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9135", + Root: "/graph-explorer", + Namespace: "com.owncloud.web", + }, + Service: Service{ + Name: "graph-explorer", + }, + Tracing: Tracing{ + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "graph-explorer", + }, + GraphExplorer: GraphExplorer{ + ClientID: "ocis-explorer.js", + Issuer: "https://localhost:9200", + GraphURLBase: "https://localhost:9200", + GraphURLPath: "/graph", + }, + } +} diff --git a/graph-explorer/pkg/config/http.go b/graph-explorer/pkg/config/http.go new file mode 100644 index 00000000000..8990a455e24 --- /dev/null +++ b/graph-explorer/pkg/config/http.go @@ -0,0 +1,16 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"GRAPH_EXPLORER_HTTP_ROOT"` + Namespace string +} + +// CORS defines the available cors configuration. +type CORS struct { + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allowed_credentials"` +} diff --git a/graph-explorer/pkg/config/log.go b/graph-explorer/pkg/config/log.go new file mode 100644 index 00000000000..7c9c0f53882 --- /dev/null +++ b/graph-explorer/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GRAPH_EXPLORER_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GRAPH_EXPLORER_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GRAPH_EXPLORER_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;GRAPH_EXPLORER_LOG_FILE"` +} diff --git a/graph-explorer/pkg/config/service.go b/graph-explorer/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/graph-explorer/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/graph-explorer/pkg/config/tracing.go b/graph-explorer/pkg/config/tracing.go new file mode 100644 index 00000000000..cf4214eb4dc --- /dev/null +++ b/graph-explorer/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_EXPLORER_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_EXPLORER_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_EXPLORER_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_EXPLORER_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"GRAPH_EXPLORER_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index c3d22789a46..e2cc81c47df 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -2,56 +2,26 @@ package config import ( "context" - - "github.com/owncloud/ocis/ocis-pkg/shared" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"GRAPH_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"GRAPH_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"GRAPH_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"GRAPH_DEBUG_ZPAGES"` -} - -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"GRAPH_HTTP_ADDR"` - Namespace string - Root string `ocisConfig:"root" env:"GRAPH_HTTP_ROOT"` -} +// Config combines all available configuration parts. +type Config struct { + Service Service -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"GRAPH_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} + HTTP HTTP `ocisConfig:"http"` -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GRAPH_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GRAPH_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GRAPH_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;GRAPH_LOG_FILE"` -} + Reva Reva `ocisConfig:"reva"` + TokenManager TokenManager `ocisConfig:"token_manager"` -// Reva defines all available REVA configuration. -type Reva struct { - Address string `ocisConfig:"address" env:"REVA_GATEWAY"` -} + Spaces Spaces `ocisConfig:"spaces"` + Identity Identity `ocisConfig:"identity"` -// TokenManager is the config for using the reva token manager -type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;GRAPH_JWT_SECRET"` + Context context.Context + Supervised bool } type Spaces struct { @@ -85,80 +55,3 @@ type Identity struct { Backend string `ocisConfig:"backend" env:"GRAPH_IDENTITY_BACKEND"` LDAP LDAP `ocisConfig:"ldap"` } - -// Config combines all available configuration parts. -type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - HTTP HTTP `ocisConfig:"http"` - - Reva Reva `ocisConfig:"reva"` - TokenManager TokenManager `ocisConfig:"token_manager"` - - Spaces Spaces `ocisConfig:"spaces"` - Identity Identity `ocisConfig:"identity"` - - Context context.Context - Supervised bool -} - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9124", - Token: "", - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9120", - Namespace: "com.owncloud.graph", - Root: "/graph", - }, - Service: Service{ - Name: "graph", - }, - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Service: "graph", - }, - Reva: Reva{ - Address: "127.0.0.1:9142", - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - Spaces: Spaces{ - WebDavBase: "https://localhost:9200", - WebDavPath: "/dav/spaces/", - DefaultQuota: "1000000000", - }, - Identity: Identity{ - Backend: "cs3", - LDAP: LDAP{ - URI: "ldap://localhost:9125", - BindDN: "", - BindPassword: "", - UserBaseDN: "ou=users,dc=ocis,dc=test", - UserSearchScope: "sub", - UserFilter: "(objectClass=posixaccount)", - UserEmailAttribute: "mail", - UserDisplayNameAttribute: "displayName", - UserNameAttribute: "uid", - // FIXME: switch this to some more widely available attribute by default - // ideally this needs to be constant for the lifetime of a users - UserIDAttribute: "ownclouduuid", - GroupBaseDN: "ou=groups,dc=ocis,dc=test", - GroupSearchScope: "sub", - GroupFilter: "(objectclass=groupOfNames)", - GroupNameAttribute: "cn", - GroupIDAttribute: "cn", - }, - }, - } -} diff --git a/graph/pkg/config/debug.go b/graph/pkg/config/debug.go new file mode 100644 index 00000000000..c1284be9124 --- /dev/null +++ b/graph/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"GRAPH_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"GRAPH_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"GRAPH_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"GRAPH_DEBUG_ZPAGES"` +} diff --git a/graph/pkg/config/defaultconfig.go b/graph/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..b5d09a9d224 --- /dev/null +++ b/graph/pkg/config/defaultconfig.go @@ -0,0 +1,56 @@ +package config + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9124", + Token: "", + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9120", + Namespace: "com.owncloud.graph", + Root: "/graph", + }, + Service: Service{ + Name: "graph", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Service: "graph", + }, + Reva: Reva{ + Address: "127.0.0.1:9142", + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + Spaces: Spaces{ + WebDavBase: "https://localhost:9200", + WebDavPath: "/dav/spaces/", + DefaultQuota: "1000000000", + }, + Identity: Identity{ + Backend: "cs3", + LDAP: LDAP{ + URI: "ldap://localhost:9125", + BindDN: "", + BindPassword: "", + UserBaseDN: "ou=users,dc=ocis,dc=test", + UserSearchScope: "sub", + UserFilter: "(objectClass=posixaccount)", + UserEmailAttribute: "mail", + UserDisplayNameAttribute: "displayName", + UserNameAttribute: "uid", + // FIXME: switch this to some more widely available attribute by default + // ideally this needs to be constant for the lifetime of a users + UserIDAttribute: "ownclouduuid", + GroupBaseDN: "ou=groups,dc=ocis,dc=test", + GroupSearchScope: "sub", + GroupFilter: "(objectclass=groupOfNames)", + GroupNameAttribute: "cn", + GroupIDAttribute: "cn", + }, + }, + } +} diff --git a/graph/pkg/config/http.go b/graph/pkg/config/http.go new file mode 100644 index 00000000000..64351105b09 --- /dev/null +++ b/graph/pkg/config/http.go @@ -0,0 +1,8 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"GRAPH_HTTP_ADDR"` + Namespace string + Root string `ocisConfig:"root" env:"GRAPH_HTTP_ROOT"` +} diff --git a/graph/pkg/config/log.go b/graph/pkg/config/log.go new file mode 100644 index 00000000000..3f1f846033b --- /dev/null +++ b/graph/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;GRAPH_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;GRAPH_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;GRAPH_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;GRAPH_LOG_FILE"` +} diff --git a/graph/pkg/config/reva.go b/graph/pkg/config/reva.go new file mode 100644 index 00000000000..31f48fbb624 --- /dev/null +++ b/graph/pkg/config/reva.go @@ -0,0 +1,11 @@ +package config + +// Reva defines all available REVA configuration. +type Reva struct { + Address string `ocisConfig:"address" env:"REVA_GATEWAY"` +} + +// TokenManager is the config for using the reva token manager +type TokenManager struct { + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;OCS_JWT_SECRET"` +} diff --git a/graph/pkg/config/service.go b/graph/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/graph/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/graph/pkg/config/tracing.go b/graph/pkg/config/tracing.go new file mode 100644 index 00000000000..457edb0fd87 --- /dev/null +++ b/graph/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"GRAPH_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 6793294e6ba..cc1e3b53856 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -2,35 +2,24 @@ package config import ( "context" - "path" +) - "github.com/owncloud/ocis/ocis-pkg/shared" +// Config combines all available configuration parts. +type Config struct { + Service Service - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"IDP_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"IDP_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"IDP_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"IDP_DEBUG_ZPAGES"` -} + HTTP HTTP `ocisConfig:"http"` -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"IDP_HTTP_ADDR"` - Root string `ocisConfig:"root" env:"IDP_HTTP_ROOT"` - Namespace string - TLSCert string `ocisConfig:"tls_cert" env:"IDP_TRANSPORT_TLS_CERT"` - TLSKey string `ocisConfig:"tls_key" env:"IDP_TRANSPORT_TLS_KEY"` - TLS bool `ocisConfig:"tls" env:"IDP_TLS"` -} + Asset Asset `ocisConfig:"asset"` + IDP Settings `ocisConfig:"idp"` + Ldap Ldap `ocisConfig:"ldap"` -// Service defines the available service configuration. -type Service struct { - Name string - Version string + Context context.Context + Supervised bool } // Ldap defines the available LDAP configuration. @@ -52,23 +41,6 @@ type Ldap struct { Filter string `ocisConfig:"filter" env:"IDP_LDAP_FILTER"` } -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;IDP_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;IDP_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;IDP_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;IDP_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"IDP_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;IDP_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;IDP_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;IDP_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;IDP_LOG_FILE"` -} - // Asset defines the available asset configuration. type Asset struct { Path string `ocisConfig:"asset" env:"IDP_ASSET_PATH"` @@ -123,95 +95,3 @@ type Settings struct { RefreshTokenDurationSeconds uint64 `ocisConfig:"refresh_token_duration_seconds" env:"IDP_REFRESH_TOKEN_EXPIRATION"` DyamicClientSecretDurationSeconds uint64 `ocisConfig:"dynamic_client_secret_duration_seconds" env:""` } - -// Config combines all available configuration parts. -type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - HTTP HTTP `ocisConfig:"http"` - - Asset Asset `ocisConfig:"asset"` - IDP Settings `ocisConfig:"idp"` - Ldap Ldap `ocisConfig:"ldap"` - - Context context.Context - Supervised bool -} - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9134", - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9130", - Root: "/", - Namespace: "com.owncloud.web", - TLSCert: path.Join(defaults.BaseDataPath(), "idp", "server.crt"), - TLSKey: path.Join(defaults.BaseDataPath(), "idp", "server.key"), - TLS: false, - }, - Service: Service{ - Name: "idp", - }, - Tracing: Tracing{ - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "idp", - }, - Asset: Asset{}, - IDP: Settings{ - Iss: "https://localhost:9200", - IdentityManager: "ldap", - URIBasePath: "", - SignInURI: "", - SignedOutURI: "", - AuthorizationEndpointURI: "", - EndsessionEndpointURI: "", - Insecure: false, - TrustedProxy: nil, - AllowScope: nil, - AllowClientGuests: false, - AllowDynamicClientRegistration: false, - EncryptionSecretFile: "", - Listen: "", - IdentifierClientDisabled: true, - IdentifierClientPath: path.Join(defaults.BaseDataPath(), "idp"), - IdentifierRegistrationConf: path.Join(defaults.BaseDataPath(), "idp", "identifier-registration.yaml"), - IdentifierScopesConf: "", - IdentifierDefaultBannerLogo: "", - IdentifierDefaultSignInPageText: "", - IdentifierDefaultUsernameHintText: "", - SigningKid: "", - SigningMethod: "PS256", - SigningPrivateKeyFiles: nil, - ValidationKeysPath: "", - CookieBackendURI: "", - CookieNames: nil, - AccessTokenDurationSeconds: 60 * 10, // 10 minutes - IDTokenDurationSeconds: 60 * 60, // 1 hour - RefreshTokenDurationSeconds: 60 * 60 * 24 * 365 * 3, // 1 year - DyamicClientSecretDurationSeconds: 0, - }, - Ldap: Ldap{ - URI: "ldap://localhost:9125", - BindDN: "cn=idp,ou=sysusers,dc=ocis,dc=test", - BindPassword: "idp", - BaseDN: "ou=users,dc=ocis,dc=test", - Scope: "sub", - LoginAttribute: "cn", - EmailAttribute: "mail", - NameAttribute: "sn", - UUIDAttribute: "uid", - UUIDAttributeType: "text", - Filter: "(objectClass=posixaccount)", - }, - } -} diff --git a/idp/pkg/config/debug.go b/idp/pkg/config/debug.go new file mode 100644 index 00000000000..f713bc34157 --- /dev/null +++ b/idp/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"IDP_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"IDP_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"IDP_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"IDP_DEBUG_ZPAGES"` +} diff --git a/idp/pkg/config/defaultconfig.go b/idp/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..dbaa3ba57be --- /dev/null +++ b/idp/pkg/config/defaultconfig.go @@ -0,0 +1,79 @@ +package config + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9134", + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9130", + Root: "/", + Namespace: "com.owncloud.web", + TLSCert: path.Join(defaults.BaseDataPath(), "idp", "server.crt"), + TLSKey: path.Join(defaults.BaseDataPath(), "idp", "server.key"), + TLS: false, + }, + Service: Service{ + Name: "idp", + }, + Tracing: Tracing{ + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "idp", + }, + Asset: Asset{}, + IDP: Settings{ + Iss: "https://localhost:9200", + IdentityManager: "ldap", + URIBasePath: "", + SignInURI: "", + SignedOutURI: "", + AuthorizationEndpointURI: "", + EndsessionEndpointURI: "", + Insecure: false, + TrustedProxy: nil, + AllowScope: nil, + AllowClientGuests: false, + AllowDynamicClientRegistration: false, + EncryptionSecretFile: "", + Listen: "", + IdentifierClientDisabled: true, + IdentifierClientPath: path.Join(defaults.BaseDataPath(), "idp"), + IdentifierRegistrationConf: path.Join(defaults.BaseDataPath(), "idp", "identifier-registration.yaml"), + IdentifierScopesConf: "", + IdentifierDefaultBannerLogo: "", + IdentifierDefaultSignInPageText: "", + IdentifierDefaultUsernameHintText: "", + SigningKid: "", + SigningMethod: "PS256", + SigningPrivateKeyFiles: nil, + ValidationKeysPath: "", + CookieBackendURI: "", + CookieNames: nil, + AccessTokenDurationSeconds: 60 * 10, // 10 minutes + IDTokenDurationSeconds: 60 * 60, // 1 hour + RefreshTokenDurationSeconds: 60 * 60 * 24 * 365 * 3, // 1 year + DyamicClientSecretDurationSeconds: 0, + }, + Ldap: Ldap{ + URI: "ldap://localhost:9125", + BindDN: "cn=idp,ou=sysusers,dc=ocis,dc=test", + BindPassword: "idp", + BaseDN: "ou=users,dc=ocis,dc=test", + Scope: "sub", + LoginAttribute: "cn", + EmailAttribute: "mail", + NameAttribute: "sn", + UUIDAttribute: "uid", + UUIDAttributeType: "text", + Filter: "(objectClass=posixaccount)", + }, + } +} diff --git a/idp/pkg/config/http.go b/idp/pkg/config/http.go new file mode 100644 index 00000000000..4d528e027ce --- /dev/null +++ b/idp/pkg/config/http.go @@ -0,0 +1,11 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"IDP_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"IDP_HTTP_ROOT"` + Namespace string + TLSCert string `ocisConfig:"tls_cert" env:"IDP_TRANSPORT_TLS_CERT"` + TLSKey string `ocisConfig:"tls_key" env:"IDP_TRANSPORT_TLS_KEY"` + TLS bool `ocisConfig:"tls" env:"IDP_TLS"` +} diff --git a/idp/pkg/config/log.go b/idp/pkg/config/log.go new file mode 100644 index 00000000000..39ba2d9e513 --- /dev/null +++ b/idp/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;IDP_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;IDP_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;IDP_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;IDP_LOG_FILE"` +} diff --git a/idp/pkg/config/service.go b/idp/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/idp/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/idp/pkg/config/tracing.go b/idp/pkg/config/tracing.go new file mode 100644 index 00000000000..8cb1d9db62d --- /dev/null +++ b/idp/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;IDP_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;IDP_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;IDP_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;IDP_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"IDP_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/ocis-pkg/indexer/index/cs3/config.go b/ocis-pkg/indexer/index/cs3/config.go index 430927d4c6f..9326de762e8 100644 --- a/ocis-pkg/indexer/index/cs3/config.go +++ b/ocis-pkg/indexer/index/cs3/config.go @@ -4,6 +4,7 @@ import ( acccfg "github.com/owncloud/ocis/accounts/pkg/config" ) +//TODO: remove? // Config represents cs3conf. Should be deprecated in favor of config.Config. type Config struct { ProviderAddr string diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index c6baacfdeb5..d6adfa74a44 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -18,9 +18,9 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.GLAuth.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.GLAuth.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index ecc94826caa..162416d24ec 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -18,9 +18,9 @@ func GraphCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.Graph.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.Graph.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index 7833206b916..ede47b9c8ca 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -18,9 +18,9 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.Graph.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.Graph.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 7b35c15ba89..399b9339a6c 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -21,9 +21,9 @@ func IDPCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.IDP.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.IDP.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 243c27696f5..40c79fd32ae 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -18,9 +18,9 @@ func OCSCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.OCS.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.OCS.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 7458a80d669..6b3dc5b957b 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -21,9 +21,9 @@ func ProxyCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.Proxy.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.Proxy.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 90bdafc304f..7980f9d0b47 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -21,9 +21,9 @@ func SettingsCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.Settings.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.Settings.Commons = cfg.Commons + //} return nil }, diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 31cb2c52856..ad95e8498bb 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -22,9 +22,9 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { return err } - if cfg.Commons != nil { - cfg.WebDAV.Commons = cfg.Commons - } + //if cfg.Commons != nil { + // cfg.WebDAV.Commons = cfg.Commons + //} return nil }, diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index c1d7145ad4a..b8554f88797 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -2,79 +2,11 @@ package config import ( "context" - - "github.com/owncloud/ocis/ocis-pkg/shared" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"OCS_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"OCS_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"OCS_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"OCS_DEBUG_ZPAGES"` -} - -// CORS defines the available cors configuration. -type CORS struct { - AllowedOrigins []string `ocisConfig:"allowed_origins"` - AllowedMethods []string `ocisConfig:"allowed_methods"` - AllowedHeaders []string `ocisConfig:"allowed_headers"` - AllowCredentials bool `ocisConfig:"allow_credentials"` -} - -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"OCS_HTTP_ADDR"` - Root string `ocisConfig:"root" env:"OCS_HTTP_ROOT"` - Namespace string - CORS CORS `ocisConfig:"cors"` -} - -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;OCS_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;OCS_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;OCS_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;OCS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"OCS_TRACING_SERVICE"` -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;OCS_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;OCS_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;OCS_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;OCS_LOG_FILE"` -} - -// Reva defines all available REVA configuration. -type Reva struct { - Address string `ocisConfig:"address" env:"REVA_GATEWAY"` -} - -// TokenManager is the config for using the reva token manager -type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;OCS_JWT_SECRET"` -} - -// IdentityManagement keeps track of the OIDC address. This is because Reva requisite of uniqueness for users -// is based in the combination of IDP hostname + UserID. For more information see: -// https://github.com/cs3org/reva/blob/4fd0229f13fae5bc9684556a82dbbd0eced65ef9/pkg/storage/utils/decomposedfs/node/node.go#L856-L865 -type IdentityManagement struct { - Address string `ocisConfig:"address" env:"OCIS_URL;OCS_IDM_ADDRESS"` -} - // Config combines all available configuration parts. type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` + Service Service Tracing Tracing `ocisConfig:"tracing"` Log Log `ocisConfig:"log"` @@ -95,45 +27,9 @@ type Config struct { Supervised bool } -// DefaultConfig provides default values for a config struct. -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9114", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9110", - Root: "/ocs", - Namespace: "com.owncloud.web", - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - Service: Service{ - Name: "ocs", - }, - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "ocs", - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - AccountBackend: "accounts", - Reva: Reva{Address: "127.0.0.1:9142"}, - StorageUsersDriver: "ocis", - MachineAuthAPIKey: "change-me-please", - IdentityManagement: IdentityManagement{ - Address: "https://localhost:9200", - }, - } +// IdentityManagement keeps track of the OIDC address. This is because Reva requisite of uniqueness for users +// is based in the combination of IDP hostname + UserID. For more information see: +// https://github.com/cs3org/reva/blob/4fd0229f13fae5bc9684556a82dbbd0eced65ef9/pkg/storage/utils/decomposedfs/node/node.go#L856-L865 +type IdentityManagement struct { + Address string `ocisConfig:"address" env:"OCIS_URL;OCS_IDM_ADDRESS"` } diff --git a/ocs/pkg/config/debug.go b/ocs/pkg/config/debug.go new file mode 100644 index 00000000000..baef3748862 --- /dev/null +++ b/ocs/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"OCS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"OCS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"OCS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"OCS_DEBUG_ZPAGES"` +} diff --git a/ocs/pkg/config/defaultconfig.go b/ocs/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..428b254a40b --- /dev/null +++ b/ocs/pkg/config/defaultconfig.go @@ -0,0 +1,43 @@ +package config + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9114", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9110", + Root: "/ocs", + Namespace: "com.owncloud.web", + CORS: CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Service: Service{ + Name: "ocs", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "ocs", + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + AccountBackend: "accounts", + Reva: Reva{Address: "127.0.0.1:9142"}, + StorageUsersDriver: "ocis", + MachineAuthAPIKey: "change-me-please", + IdentityManagement: IdentityManagement{ + Address: "https://localhost:9200", + }, + } +} diff --git a/ocs/pkg/config/http.go b/ocs/pkg/config/http.go new file mode 100644 index 00000000000..b965e78b3bd --- /dev/null +++ b/ocs/pkg/config/http.go @@ -0,0 +1,17 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"OCS_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"OCS_HTTP_ROOT"` + Namespace string + CORS CORS `ocisConfig:"cors"` +} + +// CORS defines the available cors configuration. +type CORS struct { + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allowed_credentials"` +} diff --git a/ocs/pkg/config/log.go b/ocs/pkg/config/log.go new file mode 100644 index 00000000000..4f235f1ca06 --- /dev/null +++ b/ocs/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;OCS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;OCS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;OCS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;OCS_LOG_FILE"` +} diff --git a/ocs/pkg/config/reva.go b/ocs/pkg/config/reva.go new file mode 100644 index 00000000000..31f48fbb624 --- /dev/null +++ b/ocs/pkg/config/reva.go @@ -0,0 +1,11 @@ +package config + +// Reva defines all available REVA configuration. +type Reva struct { + Address string `ocisConfig:"address" env:"REVA_GATEWAY"` +} + +// TokenManager is the config for using the reva token manager +type TokenManager struct { + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;OCS_JWT_SECRET"` +} diff --git a/ocs/pkg/config/service.go b/ocs/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/ocs/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/ocs/pkg/config/tracing.go b/ocs/pkg/config/tracing.go new file mode 100644 index 00000000000..f627ec38207 --- /dev/null +++ b/ocs/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;OCS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;OCS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;OCS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;OCS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"OCS_TRACING_SERVICE"` +} diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 9afd1cc724b..4408550b777 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -1,52 +1,33 @@ package config -import ( - "context" - "path" +import "context" - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/shared" -) - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;PROXY_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;PROXY_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;PROXY_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;PROXY_LOG_FILE"` -} +// Config combines all available configuration parts. +type Config struct { + Service Service -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"PROXY_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"PROXY_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"PROXY_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"PROXY_DEBUG_ZPAGES"` -} + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"PROXY_HTTP_ADDR"` - Root string `ocisConfig:"root" env:"PROXY_HTTP_ROOT"` - Namespace string - TLSCert string `ocisConfig:"tls_cert" env:"PROXY_TRANSPORT_TLS_CERT"` - TLSKey string `ocisConfig:"tls_key" env:"PROXY_TRANSPORT_TLS_KEY"` - TLS bool `ocisConfig:"tls" env:"PROXY_TLS"` -} + HTTP HTTP `ocisConfig:"http"` -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} + Policies []Policy `ocisConfig:"policies"` + OIDC OIDC `ocisConfig:"oidc"` + TokenManager TokenManager `ocisConfig:"token_manager"` + PolicySelector *PolicySelector `ocisConfig:"policy_selector"` + Reva Reva `ocisConfig:"reva"` + PreSignedURL PreSignedURL `ocisConfig:"pre_signed_url"` + AccountBackend string `ocisConfig:"account_backend" env:"PROXY_ACCOUNT_BACKEND_TYPE"` + UserOIDCClaim string `ocisConfig:"user_oidc_claim" env:"PROXY_USER_OIDC_CLAIM"` + UserCS3Claim string `ocisConfig:"user_cs3_claim" env:"PROXY_USER_CS3_CLAIM"` + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;PROXY_MACHINE_AUTH_API_KEY"` + AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts" env:"PROXY_AUTOPROVISION_ACCOUNTS"` + EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"` + InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;PROXY_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;PROXY_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;PROXY_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;PROXY_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"PROXY_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? + Context context.Context + Supervised bool } // Policy enables us to use multiple directors. @@ -82,6 +63,7 @@ var ( RouteTypes = []RouteType{QueryRoute, RegexRoute, PrefixRoute} ) +// TODO: use reva config here // Reva defines all available REVA configuration. type Reva struct { Address string `ocisConfig:"address" env:"REVA_GATEWAY"` @@ -98,36 +80,6 @@ type Auth struct { CredentialsByUserAgent map[string]string `ocisConfig:""` } -// Config combines all available configuration parts. -type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - HTTP HTTP `ocisConfig:"http"` - - Policies []Policy `ocisConfig:"policies"` - OIDC OIDC `ocisConfig:"oidc"` - TokenManager TokenManager `ocisConfig:"token_manager"` - PolicySelector *PolicySelector `ocisConfig:"policy_selector"` - Reva Reva `ocisConfig:"reva"` - PreSignedURL PreSignedURL `ocisConfig:"pre_signed_url"` - AccountBackend string `ocisConfig:"account_backend" env:"PROXY_ACCOUNT_BACKEND_TYPE"` - UserOIDCClaim string `ocisConfig:"user_oidc_claim" env:"PROXY_USER_OIDC_CLAIM"` - UserCS3Claim string `ocisConfig:"user_cs3_claim" env:"PROXY_USER_CS3_CLAIM"` - MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;PROXY_MACHINE_AUTH_API_KEY"` - AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts" env:"PROXY_AUTOPROVISION_ACCOUNTS"` - EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"` - InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` - - Context context.Context - Supervised bool -} - // OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request // with the configured oidc-provider type OIDC struct { @@ -194,217 +146,3 @@ type RegexRuleConf struct { Match string `ocisConfig:"match"` Policy string `ocisConfig:"policy"` } - -// DefaultConfig provides with a working local configuration for a proxy service. -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "0.0.0.0:9205", - Token: "", - }, - HTTP: HTTP{ - Addr: "0.0.0.0:9200", - Root: "/", - Namespace: "com.owncloud.web", - TLSCert: path.Join(defaults.BaseDataPath(), "proxy", "server.crt"), - TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"), - TLS: true, - }, - Service: Service{ - Name: "proxy", - }, - Tracing: Tracing{ - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "proxy", - }, - OIDC: OIDC{ - Issuer: "https://localhost:9200", - Insecure: true, - //Insecure: true, - UserinfoCache: UserinfoCache{ - Size: 1024, - TTL: 10, - }, - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - PolicySelector: nil, - Reva: Reva{ - Address: "127.0.0.1:9142", - }, - PreSignedURL: PreSignedURL{ - AllowedHTTPMethods: []string{"GET"}, - Enabled: true, - }, - AccountBackend: "accounts", - UserOIDCClaim: "email", - UserCS3Claim: "mail", - MachineAuthAPIKey: "change-me-please", - AutoprovisionAccounts: false, - EnableBasicAuth: false, - InsecureBackends: false, - // TODO: enable - //Policies: defaultPolicies(), - } -} - -func DefaultPolicies() []Policy { - return []Policy{ - { - Name: "ocis", - Routes: []Route{ - { - Endpoint: "/", - Backend: "http://localhost:9100", - }, - { - Endpoint: "/.well-known/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/konnect/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/signin/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/archiver", - Backend: "http://localhost:9140", - }, - { - Type: RegexRoute, - Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs - Backend: "http://localhost:9110", - }, - { - Endpoint: "/ocs/", - Backend: "http://localhost:9140", - }, - { - Type: QueryRoute, - Endpoint: "/remote.php/?preview=1", - Backend: "http://localhost:9115", - }, - { - Endpoint: "/remote.php/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/dav/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/webdav/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/status.php", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/index.php/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/data", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/app/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/graph/", - Backend: "http://localhost:9120", - }, - { - Endpoint: "/graph-explorer", - Backend: "http://localhost:9135", - }, - // if we were using the go micro api gateway we could look up the endpoint in the registry dynamically - { - Endpoint: "/api/v0/accounts", - Backend: "http://localhost:9181", - }, - // TODO the lookup needs a better mechanism - { - Endpoint: "/accounts.js", - Backend: "http://localhost:9181", - }, - { - Endpoint: "/api/v0/settings", - Backend: "http://localhost:9190", - }, - { - Endpoint: "/settings.js", - Backend: "http://localhost:9190", - }, - }, - }, - { - Name: "oc10", - Routes: []Route{ - { - Endpoint: "/", - Backend: "http://localhost:9100", - }, - { - Endpoint: "/.well-known/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/konnect/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/signin/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/archiver", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/ocs/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/remote.php/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/dav/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/webdav/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/status.php", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/index.php/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/data", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - }, - }, - } -} diff --git a/proxy/pkg/config/debug.go b/proxy/pkg/config/debug.go new file mode 100644 index 00000000000..1c450cc4d00 --- /dev/null +++ b/proxy/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"PROXY_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"PROXY_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"PROXY_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"PROXY_DEBUG_ZPAGES"` +} diff --git a/proxy/pkg/config/defaultconfig.go b/proxy/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..ea1940a5769 --- /dev/null +++ b/proxy/pkg/config/defaultconfig.go @@ -0,0 +1,220 @@ +package config + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "0.0.0.0:9205", + Token: "", + }, + HTTP: HTTP{ + Addr: "0.0.0.0:9200", + Root: "/", + Namespace: "com.owncloud.web", + TLSCert: path.Join(defaults.BaseDataPath(), "proxy", "server.crt"), + TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"), + TLS: true, + }, + Service: Service{ + Name: "proxy", + }, + Tracing: Tracing{ + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "proxy", + }, + OIDC: OIDC{ + Issuer: "https://localhost:9200", + Insecure: true, + //Insecure: true, + UserinfoCache: UserinfoCache{ + Size: 1024, + TTL: 10, + }, + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + PolicySelector: nil, + Reva: Reva{ + Address: "127.0.0.1:9142", + }, + PreSignedURL: PreSignedURL{ + AllowedHTTPMethods: []string{"GET"}, + Enabled: true, + }, + AccountBackend: "accounts", + UserOIDCClaim: "email", + UserCS3Claim: "mail", + MachineAuthAPIKey: "change-me-please", + AutoprovisionAccounts: false, + EnableBasicAuth: false, + InsecureBackends: false, + // TODO: enable + //Policies: defaultPolicies(), + } +} + +func DefaultPolicies() []Policy { + return []Policy{ + { + Name: "ocis", + Routes: []Route{ + { + Endpoint: "/", + Backend: "http://localhost:9100", + }, + { + Endpoint: "/.well-known/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/konnect/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/signin/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/archiver", + Backend: "http://localhost:9140", + }, + { + Type: RegexRoute, + Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs + Backend: "http://localhost:9110", + }, + { + Endpoint: "/ocs/", + Backend: "http://localhost:9140", + }, + { + Type: QueryRoute, + Endpoint: "/remote.php/?preview=1", + Backend: "http://localhost:9115", + }, + { + Endpoint: "/remote.php/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/dav/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/webdav/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/status.php", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/index.php/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/data", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/app/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/graph/", + Backend: "http://localhost:9120", + }, + { + Endpoint: "/graph-explorer", + Backend: "http://localhost:9135", + }, + // if we were using the go micro api gateway we could look up the endpoint in the registry dynamically + { + Endpoint: "/api/v0/accounts", + Backend: "http://localhost:9181", + }, + // TODO the lookup needs a better mechanism + { + Endpoint: "/accounts.js", + Backend: "http://localhost:9181", + }, + { + Endpoint: "/api/v0/settings", + Backend: "http://localhost:9190", + }, + { + Endpoint: "/settings.js", + Backend: "http://localhost:9190", + }, + }, + }, + { + Name: "oc10", + Routes: []Route{ + { + Endpoint: "/", + Backend: "http://localhost:9100", + }, + { + Endpoint: "/.well-known/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/konnect/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/signin/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/archiver", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/ocs/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/remote.php/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/dav/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/webdav/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/status.php", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/index.php/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/data", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + }, + }, + } +} diff --git a/proxy/pkg/config/http.go b/proxy/pkg/config/http.go new file mode 100644 index 00000000000..8ab55306323 --- /dev/null +++ b/proxy/pkg/config/http.go @@ -0,0 +1,11 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"PROXY_HTTP_ADDR"` + Root string `ocisConfig:"root" env:"PROXY_HTTP_ROOT"` + Namespace string + TLSCert string `ocisConfig:"tls_cert" env:"PROXY_TRANSPORT_TLS_CERT"` + TLSKey string `ocisConfig:"tls_key" env:"PROXY_TRANSPORT_TLS_KEY"` + TLS bool `ocisConfig:"tls" env:"PROXY_TLS"` +} diff --git a/proxy/pkg/config/log.go b/proxy/pkg/config/log.go new file mode 100644 index 00000000000..54612fc204d --- /dev/null +++ b/proxy/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;PROXY_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;PROXY_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;PROXY_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;PROXY_LOG_FILE"` +} diff --git a/proxy/pkg/config/service.go b/proxy/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/proxy/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/proxy/pkg/config/tracing.go b/proxy/pkg/config/tracing.go new file mode 100644 index 00000000000..91472675939 --- /dev/null +++ b/proxy/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;PROXY_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;PROXY_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;PROXY_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;PROXY_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"PROXY_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index fadd6722cd0..18284a56c5d 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -2,82 +2,11 @@ package config import ( "context" - "path" - - "github.com/owncloud/ocis/ocis-pkg/shared" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"SETTINGS_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"SETTINGS_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"SETTINGS_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"SETTINGS_DEBUG_ZPAGES"` -} - -// CORS defines the available cors configuration. -type CORS struct { - AllowedOrigins []string `ocisConfig:"allowed_origins"` - AllowedMethods []string `ocisConfig:"allowed_methods"` - AllowedHeaders []string `ocisConfig:"allowed_headers"` - AllowCredentials bool `ocisConfig:"allow_credentials"` -} - -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"SETTINGS_HTTP_ADDR"` - Namespace string - Root string `ocisConfig:"root" env:"SETTINGS_HTTP_ROOT"` - CacheTTL int `ocisConfig:"cache_ttl" env:"SETTINGS_CACHE_TTL"` - CORS CORS `ocisConfig:"cors"` -} - -// GRPC defines the available grpc configuration. -type GRPC struct { - Addr string `ocisConfig:"addr" env:"SETTINGS_GRPC_ADDR"` - Namespace string -} - -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;SETTINGS_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;SETTINGS_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;SETTINGS_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;SETTINGS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"SETTINGS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;SETTINGS_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;SETTINGS_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;SETTINGS_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;SETTINGS_LOG_FILE"` -} - -// Asset defines the available asset configuration. -type Asset struct { - Path string `ocisConfig:"path" env:"SETTINGS_ASSET_PATH"` -} - -// TokenManager is the config for using the reva token manager -type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;SETTINGS_JWT_SECRET"` -} - // Config combines all available configuration parts. type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` + Service Service Tracing Tracing `ocisConfig:"tracing"` Log Log `ocisConfig:"log"` @@ -94,47 +23,8 @@ type Config struct { Supervised bool } -// DefaultConfig provides sane bootstrapping defaults. -func DefaultConfig() *Config { - return &Config{ - Service: Service{ - Name: "settings", - }, - Debug: Debug{ - Addr: "127.0.0.1:9194", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9190", - Namespace: "com.owncloud.web", - Root: "/", - CacheTTL: 604800, // 7 days - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9191", - Namespace: "com.owncloud.api", - }, - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "settings", - }, - DataPath: path.Join(defaults.BaseDataPath(), "settings"), - Asset: Asset{ - Path: "", - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - } +// Asset defines the available asset configuration. +type Asset struct { + Path string `ocisConfig:"path" env:"SETTINGS_ASSET_PATH"` } + diff --git a/settings/pkg/config/debug.go b/settings/pkg/config/debug.go new file mode 100644 index 00000000000..5cec3b97b34 --- /dev/null +++ b/settings/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"SETTINGS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"SETTINGS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"SETTINGS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"SETTINGS_DEBUG_ZPAGES"` +} diff --git a/settings/pkg/config/defaultconfig.go b/settings/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..100c1e80fff --- /dev/null +++ b/settings/pkg/config/defaultconfig.go @@ -0,0 +1,51 @@ +package config + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + Service: Service{ + Name: "settings", + }, + Debug: Debug{ + Addr: "127.0.0.1:9194", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9190", + Namespace: "com.owncloud.web", + Root: "/", + CacheTTL: 604800, // 7 days + CORS: CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + GRPC: GRPC{ + Addr: "127.0.0.1:9191", + Namespace: "com.owncloud.api", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "settings", + }, + DataPath: path.Join(defaults.BaseDataPath(), "settings"), + Asset: Asset{ + Path: "", + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + } +} diff --git a/settings/pkg/config/grpc.go b/settings/pkg/config/grpc.go new file mode 100644 index 00000000000..016b61fa919 --- /dev/null +++ b/settings/pkg/config/grpc.go @@ -0,0 +1,7 @@ +package config + +// GRPC defines the available grpc configuration. +type GRPC struct { + Addr string `ocisConfig:"addr" env:"SETTINGS_GRPC_ADDR"` + Namespace string +} diff --git a/settings/pkg/config/http.go b/settings/pkg/config/http.go new file mode 100644 index 00000000000..f2099febf95 --- /dev/null +++ b/settings/pkg/config/http.go @@ -0,0 +1,18 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"SETTINGS_HTTP_ADDR"` + Namespace string + Root string `ocisConfig:"root" env:"SETTINGS_HTTP_ROOT"` + CacheTTL int `ocisConfig:"cache_ttl" env:"SETTINGS_CACHE_TTL"` + CORS CORS `ocisConfig:"cors"` +} + +// CORS defines the available cors configuration. +type CORS struct { + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allowed_credentials"` +} diff --git a/settings/pkg/config/log.go b/settings/pkg/config/log.go new file mode 100644 index 00000000000..48247bd17e3 --- /dev/null +++ b/settings/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;SETTINGS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;SETTINGS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;SETTINGS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;SETTINGS_LOG_FILE"` +} diff --git a/settings/pkg/config/reva.go b/settings/pkg/config/reva.go new file mode 100644 index 00000000000..5427747df89 --- /dev/null +++ b/settings/pkg/config/reva.go @@ -0,0 +1,6 @@ +package config + +// TokenManager is the config for using the reva token manager +type TokenManager struct { + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;SETTINGS_JWT_SECRET"` +} diff --git a/settings/pkg/config/service.go b/settings/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/settings/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/settings/pkg/config/tracing.go b/settings/pkg/config/tracing.go new file mode 100644 index 00000000000..543298663f5 --- /dev/null +++ b/settings/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;SETTINGS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;SETTINGS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;SETTINGS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;SETTINGS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"SETTINGS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 3ac4f71d44b..86ccac4f02a 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -129,7 +129,7 @@ type AppProviderSutureService struct { // NewAppProvider creates a new store.AppProviderSutureService func NewAppProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + ////cfg.Storage.Commons = cfg.Commons return AppProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 40bd71ed192..1d57341f1c9 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -148,7 +148,7 @@ type AuthBasicSutureService struct { // NewAuthBasicSutureService creates a new store.AuthBasicSutureService func NewAuthBasic(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return AuthBasicSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index 4424a6ef2f0..7c2e23a845d 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -124,7 +124,7 @@ type AuthBearerSutureService struct { // NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService func NewAuthBearer(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return AuthBearerSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index 80c70f832ca..9bce040bf92 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -120,7 +120,7 @@ type AuthMachineSutureService struct { // NewAuthMachineSutureService creates a new gateway.AuthMachineSutureService func NewAuthMachine(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return AuthMachineSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 8847a50f9dd..3682bec4b31 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -344,7 +344,7 @@ type FrontendSutureService struct { // NewFrontend creates a new frontend.FrontendSutureService func NewFrontend(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return FrontendSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 431ef5027db..5dabd93e7e7 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -389,7 +389,7 @@ type GatewaySutureService struct { // NewGatewaySutureService creates a new gateway.GatewaySutureService func NewGateway(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return GatewaySutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 625a231772a..0d37c4149ff 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -162,7 +162,7 @@ type GroupSutureService struct { // NewGroupProviderSutureService creates a new storage.GroupProvider func NewGroupProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return GroupSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index 1d8c032c8ee..7229b7f2818 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -188,7 +188,7 @@ type SharingSutureService struct { // NewSharingSutureService creates a new store.SharingSutureService func NewSharing(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return SharingSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 34cf47c6573..197e403ac1e 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -166,7 +166,7 @@ type MetadataSutureService struct { // NewSutureService creates a new storagemetadata.SutureService func NewStorageMetadata(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return MetadataSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index 92f4d37947b..8636463f603 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -126,7 +126,7 @@ type StoragePublicLinkSutureService struct { // NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return StoragePublicLinkSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storageshares.go b/storage/pkg/command/storageshares.go index 35e44e9d679..7735ef9a21f 100644 --- a/storage/pkg/command/storageshares.go +++ b/storage/pkg/command/storageshares.go @@ -125,7 +125,7 @@ type StorageSharesSutureService struct { // NewStorageShares creates a new storage.StorageSharesSutureService func NewStorageShares(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return StorageSharesSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 15cf235d4f4..2d9331d3307 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -146,7 +146,7 @@ type StorageUsersSutureService struct { // NewStorageUsersSutureService creates a new storage.StorageUsersSutureService func NewStorageUsers(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return StorageUsersSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index b7205a542ee..908865ae7cb 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -183,7 +183,7 @@ type UserProviderSutureService struct { // NewUserProviderSutureService creates a new storage.UserProvider func NewUserProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return UserProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index c46c0a61d98..b455de8ab3a 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -2,34 +2,21 @@ package config import ( "context" - "os" - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/shared" ) -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} +// Config combines all available configuration parts. +type Config struct { + Service Service -// Log defines the available logging configuration. -type Log struct { - Level string `ocisConfig:"level"` - Pretty bool `ocisConfig:"pretty"` - Color bool `ocisConfig:"color"` - File string `ocisConfig:"file"` -} + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr"` - Token string `ocisConfig:"token"` - Pprof bool `ocisConfig:"pprof"` - Zpages bool `ocisConfig:"zpages"` + Reva Reva `ocisConfig:"reva"` + + Asset Asset `ocisConfig:"asset"` } // Gateway defines the available gateway configuration. @@ -495,463 +482,11 @@ type Reva struct { DefaultUploadProtocol string `ocisConfig:"default_upload_protocol"` } -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` -} - // Asset defines the available asset configuration. type Asset struct { Path string `ocisConfig:"path"` } -// Config combines all available configuration parts. -type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - Reva Reva `ocisConfig:"reva"` - - Asset Asset `ocisConfig:"asset"` -} - -func DefaultConfig() *Config { - return &Config{ - // log is inherited - Debug: Debug{ - Addr: "127.0.0.1:9109", - }, - Reva: Reva{ - JWTSecret: "Pive-Fumkiu4", - SkipUserGroupsInToken: false, - TransferSecret: "replace-me-with-a-transfer-secret", - TransferExpires: 24 * 60 * 60, - OIDC: OIDC{ - Issuer: "https://localhost:9200", - Insecure: false, - IDClaim: "preferred_username", - }, - LDAP: LDAP{ - Hostname: "localhost", - Port: 9126, - CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), - Insecure: false, - BaseDN: "dc=ocis,dc=test", - LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", - UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", - UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", - UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - UserGroupFilter: "(&(objectclass=posixGroup)(cn={{.}}*))", // FIXME (&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*)) in reva the template is executed with a string. IIRC rhaferkamp mentioned this - GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", - GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", - GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", - BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", - BindPassword: "reva", - IDP: "https://localhost:9200", - UserSchema: LDAPUserSchema{ - UID: "ownclouduuid", - Mail: "mail", - DisplayName: "displayname", - CN: "cn", - UIDNumber: "uidnumber", - GIDNumber: "gidnumber", - }, - GroupSchema: LDAPGroupSchema{ - GID: "cn", - Mail: "mail", - DisplayName: "cn", - CN: "cn", - GIDNumber: "gidnumber", - }, - }, - UserGroupRest: UserGroupRest{ - RedisAddress: "localhost:6379", - }, - UserOwnCloudSQL: UserOwnCloudSQL{ - DBUsername: "owncloud", - DBPassword: "secret", - DBHost: "mysql", - DBPort: 3306, - DBName: "owncloud", - Idp: "https://localhost:9200", - Nobody: 90, - JoinUsername: false, - JoinOwnCloudUUID: false, - EnableMedialSearch: false, - }, - OCDav: OCDav{ - WebdavNamespace: "/users/{{.Id.OpaqueId}}", - DavFilesNamespace: "/users/{{.Id.OpaqueId}}", - }, - Archiver: Archiver{ - MaxNumFiles: 10000, - MaxSize: 1073741824, - ArchiverURL: "/archiver", - }, - UserStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ - Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", - UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", - }, - ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") - UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") - EosBinary: "/usr/bin/eos", - XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - CacheDirectory: os.TempDir(), - GatewaySVC: "127.0.0.1:9142", - }, - Local: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Username}}", - EnableHome: false, - }, - OwnCloud: DriverOwnCloud{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), - Redis: ":6379", - Scan: true, - }, - OwnCloudSQL: DriverOwnCloudSQL{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Username}}", - EnableHome: false, - }, - UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), - DBUsername: "owncloud", - DBPassword: "owncloud", - DBHost: "", - DBPort: 3306, - DBName: "owncloud", - }, - S3: DriverS3{ - DriverCommon: DriverCommon{}, - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - }, - }, - MetadataStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ - Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", - UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", - EnableHome: false, - }, - ShadowNamespace: "", - UploadsNamespace: "", - EosBinary: "/usr/bin/eos", - XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - GrpcURI: "", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - CacheDirectory: os.TempDir(), - EnableLogging: false, - ShowHiddenSysFiles: false, - ForceSingleUserMode: false, - UseKeytab: false, - SecProtocol: "", - Keytab: "", - SingleUsername: "", - GatewaySVC: "127.0.0.1:9142", - }, - Local: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), - }, - OwnCloud: DriverOwnCloud{}, - OwnCloudSQL: DriverOwnCloudSQL{}, - S3: DriverS3{ - DriverCommon: DriverCommon{}, - Region: "default", - }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), - ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), - ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - }, - }, - Frontend: FrontendPort{ - Port: Port{ - MaxCPUs: "", - LogLevel: "", - GRPCNetwork: "", - GRPCAddr: "", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9140", - Protocol: "", - Endpoint: "", - DebugAddr: "127.0.0.1:9141", - Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, - Config: nil, - Context: nil, - Supervised: false, - }, - AppProviderInsecure: false, - AppProviderPrefix: "", - ArchiverInsecure: false, - ArchiverPrefix: "archiver", - DatagatewayPrefix: "data", - Favorites: false, - OCDavInsecure: true, - OCDavPrefix: "", - OCSPrefix: "ocs", - OCSSharePrefix: "/Shares", - OCSHomeNamespace: "/users/{{.Id.OpaqueId}}", - PublicURL: "https://localhost:9200", - OCSCacheWarmupDriver: "", - OCSAdditionalInfoAttribute: "{{.Mail}}", - OCSResourceInfoCacheTTL: 0, - Middleware: Middleware{}, - }, - DataGateway: DataGatewayPort{ - Port: Port{}, - PublicURL: "", - }, - Gateway: Gateway{ - Port: Port{ - Endpoint: "127.0.0.1:9142", - DebugAddr: "127.0.0.1:9143", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9142", - }, - CommitShareToStorageGrant: true, - CommitShareToStorageRef: true, - DisableHomeCreationOnLogin: false, - ShareFolder: "Shares", - LinkGrants: "", - HomeMapping: "", - EtagCacheTTL: 0, - }, - StorageRegistry: StorageRegistry{ - Driver: "spaces", - HomeProvider: "/home", - JSON: "", - }, - AppRegistry: AppRegistry{ - Driver: "static", - MimetypesJSON: "", - }, - Users: Users{ - Port: Port{ - Endpoint: "localhost:9144", - DebugAddr: "127.0.0.1:9145", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9144", - Services: []string{"userprovider"}, - }, - Driver: "ldap", - UserGroupsCacheExpiration: 5, - }, - Groups: Groups{ - Port: Port{ - Endpoint: "localhost:9160", - DebugAddr: "127.0.0.1:9161", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9160", - Services: []string{"groupprovider"}, - }, - Driver: "ldap", - GroupMembersCacheExpiration: 5, - }, - AuthProvider: Users{ - Port: Port{}, - Driver: "ldap", - UserGroupsCacheExpiration: 0, - }, - AuthBasic: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9146", - DebugAddr: "127.0.0.1:9147", - Services: []string{"authprovider"}, - Endpoint: "localhost:9146", - }, - AuthBearer: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9148", - DebugAddr: "127.0.0.1:9149", - Services: []string{"authprovider"}, - Endpoint: "localhost:9148", - }, - AuthMachine: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9166", - DebugAddr: "127.0.0.1:9167", - Services: []string{"authprovider"}, - Endpoint: "localhost:9166", - }, - AuthMachineConfig: AuthMachineConfig{ - MachineAuthAPIKey: "change-me-please", - }, - Sharing: Sharing{ - Port: Port{ - Endpoint: "localhost:9150", - DebugAddr: "127.0.0.1:9151", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9150", - Services: []string{"usershareprovider", "publicshareprovider"}, - }, - UserDriver: "json", - UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), - UserSQLUsername: "", - UserSQLPassword: "", - UserSQLHost: "", - UserSQLPort: 1433, - UserSQLName: "", - PublicDriver: "json", - PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), - PublicPasswordHashCost: 11, - PublicEnableExpiredSharesCleanup: true, - PublicJanitorRunInterval: 60, - UserStorageMountID: "", - }, - StorageShares: StoragePort{ - Port: Port{ - Endpoint: "localhost:9154", - DebugAddr: "127.0.0.1:9156", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9154", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9155", - }, - ReadOnly: false, - AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", - MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - }, - StorageUsers: StoragePort{ - Port: Port{ - Endpoint: "localhost:9157", - DebugAddr: "127.0.0.1:9159", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9157", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9158", - }, - MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - Driver: "ocis", - DataServerURL: "http://localhost:9158/data", - HTTPPrefix: "data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), - }, - StoragePublicLink: PublicStorage{ - StoragePort: StoragePort{ - Port: Port{ - Endpoint: "localhost:9178", - DebugAddr: "127.0.0.1:9179", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9178", - }, - MountID: "7993447f-687f-490d-875c-ac95e89a62a4", - }, - PublicShareProviderAddr: "", - UserProviderAddr: "", - }, - StorageMetadata: StoragePort{ - Port: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9215", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9216", - DebugAddr: "127.0.0.1:9217", - }, - Driver: "ocis", - ExposeDataServer: false, - DataServerURL: "http://localhost:9216/data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), - DataProvider: DataProvider{}, - }, - AppProvider: AppProvider{ - Port: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9164", - DebugAddr: "127.0.0.1:9165", - Endpoint: "localhost:9164", - Services: []string{"appprovider"}, - }, - ExternalAddr: "127.0.0.1:9164", - WopiDriver: WopiDriver{}, - AppsURL: "/app/list", - OpenURL: "/app/open", - NewURL: "/app/new", - }, - Configs: nil, - UploadMaxChunkSize: 1e+8, - UploadHTTPMethodOverride: "", - ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, - ChecksumPreferredUploadType: "", - DefaultUploadProtocol: "tus", - }, - Tracing: Tracing{ - Service: "storage", - Type: "jaeger", - }, - Asset: Asset{}, - } -} - // StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the // Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets // us propagate changes easier. diff --git a/storage/pkg/config/debug.go b/storage/pkg/config/debug.go new file mode 100644 index 00000000000..f9283a9b295 --- /dev/null +++ b/storage/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"STORAGE_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"STORAGE_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"STORAGE_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"STORAGE_DEBUG_ZPAGES"` +} diff --git a/storage/pkg/config/defaultconfig.go b/storage/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..00e0dba3633 --- /dev/null +++ b/storage/pkg/config/defaultconfig.go @@ -0,0 +1,436 @@ +package config + +import ( + "os" + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + // log is inherited + Debug: Debug{ + Addr: "127.0.0.1:9109", + }, + Reva: Reva{ + JWTSecret: "Pive-Fumkiu4", + SkipUserGroupsInToken: false, + TransferSecret: "replace-me-with-a-transfer-secret", + TransferExpires: 24 * 60 * 60, + OIDC: OIDC{ + Issuer: "https://localhost:9200", + Insecure: false, + IDClaim: "preferred_username", + }, + LDAP: LDAP{ + Hostname: "localhost", + Port: 9126, + CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Insecure: false, + BaseDN: "dc=ocis,dc=test", + LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", + UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", + UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", + GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", + GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", + BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", + BindPassword: "reva", + IDP: "https://localhost:9200", + UserSchema: LDAPUserSchema{ + UID: "ownclouduuid", + Mail: "mail", + DisplayName: "displayname", + CN: "cn", + UIDNumber: "uidnumber", + GIDNumber: "gidnumber", + }, + GroupSchema: LDAPGroupSchema{ + GID: "cn", + Mail: "mail", + DisplayName: "cn", + CN: "cn", + GIDNumber: "gidnumber", + }, + }, + UserGroupRest: UserGroupRest{ + RedisAddress: "localhost:6379", + }, + UserOwnCloudSQL: UserOwnCloudSQL{ + DBUsername: "owncloud", + DBPassword: "secret", + DBHost: "mysql", + DBPort: 3306, + DBName: "owncloud", + Idp: "https://localhost:9200", + Nobody: 90, + JoinUsername: false, + JoinOwnCloudUUID: false, + EnableMedialSearch: false, + }, + OCDav: OCDav{ + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + DavFilesNamespace: "/users/{{.Id.OpaqueId}}", + }, + Archiver: Archiver{ + MaxNumFiles: 10000, + MaxSize: 1073741824, + ArchiverURL: "/archiver", + }, + UserStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + }, + ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") + UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + OwnCloud: DriverOwnCloud{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + Redis: ":6379", + Scan: true, + }, + OwnCloudSQL: DriverOwnCloudSQL{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + DBUsername: "owncloud", + DBPassword: "owncloud", + DBHost: "", + DBPort: 3306, + DBName: "owncloud", + }, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + MetadataStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + EnableHome: false, + }, + ShadowNamespace: "", + UploadsNamespace: "", + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + GrpcURI: "", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + EnableLogging: false, + ShowHiddenSysFiles: false, + ForceSingleUserMode: false, + UseKeytab: false, + SecProtocol: "", + Keytab: "", + SingleUsername: "", + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), + }, + OwnCloud: DriverOwnCloud{}, + OwnCloudSQL: DriverOwnCloudSQL{}, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + Frontend: FrontendPort{ + Port: Port{ + MaxCPUs: "", + LogLevel: "", + GRPCNetwork: "", + GRPCAddr: "", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9140", + Protocol: "", + Endpoint: "", + DebugAddr: "127.0.0.1:9141", + Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, + Config: nil, + Context: nil, + Supervised: false, + }, + AppProviderInsecure: false, + AppProviderPrefix: "", + ArchiverInsecure: false, + ArchiverPrefix: "archiver", + DatagatewayPrefix: "data", + Favorites: false, + OCDavInsecure: false, + OCDavPrefix: "", + OCSPrefix: "ocs", + OCSSharePrefix: "/Shares", + OCSHomeNamespace: "/users/{{.Id.OpaqueId}}", + PublicURL: "https://localhost:9200", + OCSCacheWarmupDriver: "", + OCSAdditionalInfoAttribute: "{{.Mail}}", + OCSResourceInfoCacheTTL: 0, + Middleware: Middleware{}, + }, + DataGateway: DataGatewayPort{ + Port: Port{}, + PublicURL: "", + }, + Gateway: Gateway{ + Port: Port{ + Endpoint: "127.0.0.1:9142", + DebugAddr: "127.0.0.1:9143", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9142", + }, + CommitShareToStorageGrant: true, + CommitShareToStorageRef: true, + DisableHomeCreationOnLogin: false, + ShareFolder: "Shares", + LinkGrants: "", + HomeMapping: "", + EtagCacheTTL: 0, + }, + StorageRegistry: StorageRegistry{ + Driver: "spaces", + HomeProvider: "/home", + JSON: "", + }, + AppRegistry: AppRegistry{ + Driver: "static", + MimetypesJSON: "", + }, + Users: Users{ + Port: Port{ + Endpoint: "localhost:9144", + DebugAddr: "127.0.0.1:9145", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9144", + Services: []string{"userprovider"}, + }, + Driver: "ldap", + UserGroupsCacheExpiration: 5, + }, + Groups: Groups{ + Port: Port{ + Endpoint: "localhost:9160", + DebugAddr: "127.0.0.1:9161", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9160", + Services: []string{"groupprovider"}, + }, + Driver: "ldap", + GroupMembersCacheExpiration: 5, + }, + AuthProvider: Users{ + Port: Port{}, + Driver: "ldap", + UserGroupsCacheExpiration: 0, + }, + AuthBasic: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9146", + DebugAddr: "127.0.0.1:9147", + Services: []string{"authprovider"}, + Endpoint: "localhost:9146", + }, + AuthBearer: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9148", + DebugAddr: "127.0.0.1:9149", + Services: []string{"authprovider"}, + Endpoint: "localhost:9148", + }, + AuthMachine: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9166", + DebugAddr: "127.0.0.1:9167", + Services: []string{"authprovider"}, + Endpoint: "localhost:9166", + }, + AuthMachineConfig: AuthMachineConfig{ + MachineAuthAPIKey: "change-me-please", + }, + Sharing: Sharing{ + Port: Port{ + Endpoint: "localhost:9150", + DebugAddr: "127.0.0.1:9151", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9150", + Services: []string{"usershareprovider", "publicshareprovider"}, + }, + UserDriver: "json", + UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), + UserSQLUsername: "", + UserSQLPassword: "", + UserSQLHost: "", + UserSQLPort: 1433, + UserSQLName: "", + PublicDriver: "json", + PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), + PublicPasswordHashCost: 11, + PublicEnableExpiredSharesCleanup: true, + PublicJanitorRunInterval: 60, + UserStorageMountID: "", + }, + StorageShares: StoragePort{ + Port: Port{ + Endpoint: "localhost:9154", + DebugAddr: "127.0.0.1:9156", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9154", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9155", + }, + ReadOnly: false, + AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + }, + StorageUsers: StoragePort{ + Port: Port{ + Endpoint: "localhost:9157", + DebugAddr: "127.0.0.1:9159", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9157", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9158", + }, + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + Driver: "ocis", + DataServerURL: "http://localhost:9158/data", + HTTPPrefix: "data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), + }, + StoragePublicLink: PublicStorage{ + StoragePort: StoragePort{ + Port: Port{ + Endpoint: "localhost:9178", + DebugAddr: "127.0.0.1:9179", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9178", + }, + MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", + }, + PublicShareProviderAddr: "", + UserProviderAddr: "", + }, + StorageMetadata: StoragePort{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9215", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9216", + DebugAddr: "127.0.0.1:9217", + }, + Driver: "ocis", + ExposeDataServer: false, + DataServerURL: "http://localhost:9216/data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), + DataProvider: DataProvider{}, + }, + AppProvider: AppProvider{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9164", + DebugAddr: "127.0.0.1:9165", + Endpoint: "localhost:9164", + Services: []string{"appprovider"}, + }, + ExternalAddr: "127.0.0.1:9164", + WopiDriver: WopiDriver{}, + AppsURL: "/app/list", + OpenURL: "/app/open", + NewURL: "/app/new", + }, + Configs: nil, + UploadMaxChunkSize: 1e+8, + UploadHTTPMethodOverride: "", + ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, + ChecksumPreferredUploadType: "", + DefaultUploadProtocol: "tus", + }, + Tracing: Tracing{ + Service: "storage", + Type: "jaeger", + }, + Asset: Asset{}, + } +} diff --git a/storage/pkg/config/grpc.go b/storage/pkg/config/grpc.go new file mode 100644 index 00000000000..016b61fa919 --- /dev/null +++ b/storage/pkg/config/grpc.go @@ -0,0 +1,7 @@ +package config + +// GRPC defines the available grpc configuration. +type GRPC struct { + Addr string `ocisConfig:"addr" env:"SETTINGS_GRPC_ADDR"` + Namespace string +} diff --git a/storage/pkg/config/http.go b/storage/pkg/config/http.go new file mode 100644 index 00000000000..f2099febf95 --- /dev/null +++ b/storage/pkg/config/http.go @@ -0,0 +1,18 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"SETTINGS_HTTP_ADDR"` + Namespace string + Root string `ocisConfig:"root" env:"SETTINGS_HTTP_ROOT"` + CacheTTL int `ocisConfig:"cache_ttl" env:"SETTINGS_CACHE_TTL"` + CORS CORS `ocisConfig:"cors"` +} + +// CORS defines the available cors configuration. +type CORS struct { + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allowed_credentials"` +} diff --git a/storage/pkg/config/log.go b/storage/pkg/config/log.go new file mode 100644 index 00000000000..eb14a82e87a --- /dev/null +++ b/storage/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;STORAGE_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;STORAGE_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;STORAGE_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;STORAGE_LOG_FILE"` +} diff --git a/storage/pkg/config/reva.go b/storage/pkg/config/reva.go new file mode 100644 index 00000000000..5427747df89 --- /dev/null +++ b/storage/pkg/config/reva.go @@ -0,0 +1,6 @@ +package config + +// TokenManager is the config for using the reva token manager +type TokenManager struct { + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;SETTINGS_JWT_SECRET"` +} diff --git a/storage/pkg/config/service.go b/storage/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/storage/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/storage/pkg/config/tracing.go b/storage/pkg/config/tracing.go new file mode 100644 index 00000000000..b5c95544455 --- /dev/null +++ b/storage/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;STORAGE_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORAGE_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"STORAGE_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index c96271fbd43..bb79327e88d 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -2,51 +2,11 @@ package config import ( "context" - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"STORE_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"STORE_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"STORE_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"STORE_DEBUG_ZPAGES"` -} - -// GRPC defines the available grpc configuration. -type GRPC struct { - Addr string `ocisConfig:"addr" env:"STORE_GRPC_ADDR"` - Namespace string -} - -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;STORE_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;STORE_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORE_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;STORE_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"STORE_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;STORE_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;STORE_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;STORE_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;STORE_LOG_FILE"` -} - // Config combines all available configuration parts. type Config struct { - Service Service `ocisConfig:"service"` + Service Service Tracing Tracing `ocisConfig:"tracing"` Log Log `ocisConfig:"log"` @@ -59,29 +19,3 @@ type Config struct { Context context.Context Supervised bool } - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9464", - Token: "", - Pprof: false, - Zpages: false, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9460", - Namespace: "com.owncloud.api", - }, - Service: Service{ - Name: "store", - }, - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "store", - }, - Datapath: path.Join(defaults.BaseDataPath(), "store"), - } -} diff --git a/store/pkg/config/debug.go b/store/pkg/config/debug.go new file mode 100644 index 00000000000..a168ce8468a --- /dev/null +++ b/store/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"STORE_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"STORE_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"STORE_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"STORE_DEBUG_ZPAGES"` +} diff --git a/store/pkg/config/defaultconfig.go b/store/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..4ba99550cef --- /dev/null +++ b/store/pkg/config/defaultconfig.go @@ -0,0 +1,33 @@ +package config + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9464", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: GRPC{ + Addr: "127.0.0.1:9460", + Namespace: "com.owncloud.api", + }, + Service: Service{ + Name: "store", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "store", + }, + Datapath: path.Join(defaults.BaseDataPath(), "store"), + } +} diff --git a/store/pkg/config/grpc.go b/store/pkg/config/grpc.go new file mode 100644 index 00000000000..ed87112dd5f --- /dev/null +++ b/store/pkg/config/grpc.go @@ -0,0 +1,7 @@ +package config + +// GRPC defines the available grpc configuration. +type GRPC struct { + Addr string `ocisConfig:"addr" env:"STORE_GRPC_ADDR"` + Namespace string +} diff --git a/store/pkg/config/log.go b/store/pkg/config/log.go new file mode 100644 index 00000000000..a00934bb2d3 --- /dev/null +++ b/store/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;STORE_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;STORE_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;STORE_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;STORE_LOG_FILE"` +} diff --git a/store/pkg/config/service.go b/store/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/store/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/store/pkg/config/tracing.go b/store/pkg/config/tracing.go new file mode 100644 index 00000000000..a54001c94f9 --- /dev/null +++ b/store/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;STORE_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;STORE_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORE_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;STORE_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"STORE_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index f9f1f3d7ea8..fff16e78b5d 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -2,51 +2,11 @@ package config import ( "context" - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"THUMBNAILS_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"THUMBNAILS_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"THUMBNAILS_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"THUMBNAILS_DEBUG_ZPAGES"` -} - -// GRPC defines the available grpc configuration. -type GRPC struct { - Addr string `ocisConfig:"addr" env:"THUMBNAILS_GRPC_ADDR"` - Namespace string -} - -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;THUMBNAILS_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;THUMBNAILS_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;THUMBNAILS_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;THUMBNAILS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"THUMBNAILS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;THUMBNAILS_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;THUMBNAILS_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;THUMBNAILS_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;THUMBNAILS_LOG_FILE"` -} - // Config combines all available configuration parts. type Config struct { - Service Service `ocisConfig:"service"` + Service Service Tracing Tracing `ocisConfig:"tracing"` Log Log `ocisConfig:"log"` @@ -76,40 +36,6 @@ type Thumbnail struct { FileSystemStorage FileSystemStorage `ocisConfig:"filesystem_storage"` WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_WEBDAVSOURCE_INSECURE"` CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_CS3SOURCE_INSECURE"` - RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` + RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` //TODO: use REVA config FontMapFile string `ocisConfig:"font_map_file" env:"THUMBNAILS_TXT_FONTMAP_FILE"` } - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9189", - Token: "", - Pprof: false, - Zpages: false, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9185", - Namespace: "com.owncloud.api", - }, - Service: Service{ - Name: "thumbnails", - }, - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "thumbnails", - }, - Thumbnail: Thumbnail{ - Resolutions: []string{"16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"}, - FileSystemStorage: FileSystemStorage{ - RootDirectory: path.Join(defaults.BaseDataPath(), "thumbnails"), - }, - WebdavAllowInsecure: true, - RevaGateway: "127.0.0.1:9142", - CS3AllowInsecure: false, - }, - } -} diff --git a/thumbnails/pkg/config/debug.go b/thumbnails/pkg/config/debug.go new file mode 100644 index 00000000000..f1f3a01e146 --- /dev/null +++ b/thumbnails/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"THUMBNAILS_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"THUMBNAILS_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"THUMBNAILS_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"THUMBNAILS_DEBUG_ZPAGES"` +} diff --git a/thumbnails/pkg/config/defaultconfig.go b/thumbnails/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..d06ee1c34d1 --- /dev/null +++ b/thumbnails/pkg/config/defaultconfig.go @@ -0,0 +1,41 @@ +package config + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9189", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: GRPC{ + Addr: "127.0.0.1:9185", + Namespace: "com.owncloud.api", + }, + Service: Service{ + Name: "thumbnails", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "thumbnails", + }, + Thumbnail: Thumbnail{ + Resolutions: []string{"16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"}, + FileSystemStorage: FileSystemStorage{ + RootDirectory: path.Join(defaults.BaseDataPath(), "thumbnails"), + }, + WebdavAllowInsecure: true, + RevaGateway: "127.0.0.1:9142", + CS3AllowInsecure: false, + }, + } +} diff --git a/thumbnails/pkg/config/grpc.go b/thumbnails/pkg/config/grpc.go new file mode 100644 index 00000000000..9682ed12c58 --- /dev/null +++ b/thumbnails/pkg/config/grpc.go @@ -0,0 +1,7 @@ +package config + +// GRPC defines the available grpc configuration. +type GRPC struct { + Addr string `ocisConfig:"addr" env:"THUMBNAILS_GRPC_ADDR"` + Namespace string +} diff --git a/thumbnails/pkg/config/log.go b/thumbnails/pkg/config/log.go new file mode 100644 index 00000000000..a9b19f07077 --- /dev/null +++ b/thumbnails/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;THUMBNAILS_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;THUMBNAILS_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;THUMBNAILS_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;THUMBNAILS_LOG_FILE"` +} diff --git a/thumbnails/pkg/config/service.go b/thumbnails/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/thumbnails/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/thumbnails/pkg/config/tracing.go b/thumbnails/pkg/config/tracing.go new file mode 100644 index 00000000000..e118e153039 --- /dev/null +++ b/thumbnails/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;THUMBNAILS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;THUMBNAILS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;THUMBNAILS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;THUMBNAILS_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"THUMBNAILS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 345ae8aec40..6a1ef7eaba8 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -1,46 +1,23 @@ package config -import ( - "context" -) +import "context" -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"WEB_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"WEB_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"WEB_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"WEB_DEBUG_ZPAGES"` -} +// Config combines all available configuration parts. +type Config struct { + Service Service -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"WEB_HTTP_ADDR"` - Namespace string - Root string `ocisConfig:"root" env:"WEB_HTTP_ROOT"` - CacheTTL int `ocisConfig:"cache_ttl" env:"WEB_CACHE_TTL"` -} + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} + HTTP HTTP `ocisConfig:"http"` -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;WEB_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEB_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEB_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEB_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"WEB_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} + Asset Asset `ocisConfig:"asset"` + File string `ocisConfig:"file" env:"WEB_UI_CONFIG"` // TODO: rename this to a more self explaining string + Web Web `ocisConfig:"web"` -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;WEB_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;WEB_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;WEB_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;WEB_LOG_FILE"` + Context context.Context + Supervised bool } // Asset defines the available asset configuration. @@ -95,69 +72,3 @@ type Web struct { ThemePath string `ocisConfig:"theme_path" env:"WEB_UI_THEME_PATH"` // used to build Theme in WebConfig Config WebConfig `ocisConfig:"config"` } - -// Config combines all available configuration parts. -type Config struct { - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - HTTP HTTP `ocisConfig:"http"` - - Asset Asset `ocisConfig:"asset"` - File string `ocisConfig:"file" env:"WEB_UI_CONFIG"` // TODO: rename this to a more self explaining string - Web Web `ocisConfig:"web"` - - Context context.Context - Supervised bool -} - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9104", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9100", - Root: "/", - Namespace: "com.owncloud.web", - CacheTTL: 604800, // 7 days - }, - Service: Service{ - Name: "web", - }, - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "web", - }, - Asset: Asset{ - Path: "", - }, - Web: Web{ - Path: "", - ThemeServer: "https://localhost:9200", - ThemePath: "/themes/owncloud/theme.json", - Config: WebConfig{ - Server: "https://localhost:9200", - Theme: "", - Version: "0.1.0", - OpenIDConnect: OIDC{ - MetadataURL: "", - Authority: "https://localhost:9200", - ClientID: "web", - ResponseType: "code", - Scope: "openid profile email", - }, - Apps: []string{"files", "search", "media-viewer", "external"}, - }, - }, - } -} diff --git a/web/pkg/config/debug.go b/web/pkg/config/debug.go new file mode 100644 index 00000000000..d4dda707d14 --- /dev/null +++ b/web/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"WEB_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"WEB_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"WEB_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"WEB_DEBUG_ZPAGES"` +} diff --git a/web/pkg/config/defaultconfig.go b/web/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..a41d1af4dde --- /dev/null +++ b/web/pkg/config/defaultconfig.go @@ -0,0 +1,49 @@ +package config + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9104", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9100", + Root: "/", + Namespace: "com.owncloud.web", + CacheTTL: 604800, // 7 days + }, + Service: Service{ + Name: "web", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "web", + }, + Asset: Asset{ + Path: "", + }, + Web: Web{ + Path: "", + ThemeServer: "https://localhost:9200", + ThemePath: "/themes/owncloud/theme.json", + Config: WebConfig{ + Server: "https://localhost:9200", + Theme: "", + Version: "0.1.0", + OpenIDConnect: OIDC{ + MetadataURL: "", + Authority: "https://localhost:9200", + ClientID: "web", + ResponseType: "code", + Scope: "openid profile email", + }, + Apps: []string{"files", "search", "media-viewer", "external"}, + }, + }, + } +} diff --git a/web/pkg/config/http.go b/web/pkg/config/http.go new file mode 100644 index 00000000000..317b93497fb --- /dev/null +++ b/web/pkg/config/http.go @@ -0,0 +1,9 @@ +package config + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"WEB_HTTP_ADDR"` + Namespace string + Root string `ocisConfig:"root" env:"WEB_HTTP_ROOT"` + CacheTTL int `ocisConfig:"cache_ttl" env:"WEB_CACHE_TTL"` +} diff --git a/web/pkg/config/log.go b/web/pkg/config/log.go new file mode 100644 index 00000000000..1a331072864 --- /dev/null +++ b/web/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;WEB_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;WEB_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;WEB_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;WEB_LOG_FILE"` +} diff --git a/web/pkg/config/service.go b/web/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/web/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/web/pkg/config/tracing.go b/web/pkg/config/tracing.go new file mode 100644 index 00000000000..c6bb6569ad2 --- /dev/null +++ b/web/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;WEB_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEB_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEB_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEB_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"WEB_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 076c33177c6..af5df5a5b5f 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -2,62 +2,11 @@ package config import ( "context" - - "github.com/owncloud/ocis/ocis-pkg/shared" ) -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"WEBDAV_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"WEBDAV_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"WEBDAV_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"WEBDAV_DEBUG_ZPAGES"` -} - -// CORS defines the available cors configuration. -type CORS struct { - AllowedOrigins []string `ocisConfig:"allowed_origins"` - AllowedMethods []string `ocisConfig:"allowed_methods"` - AllowedHeaders []string `ocisConfig:"allowed_headers"` - AllowCredentials bool `ocisConfig:"allow_credentials"` -} - -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"WEBDAV_HTTP_ADDR"` - Namespace string - Root string `ocisConfig:"root" env:"WEBDAV_HTTP_ROOT"` - CORS CORS `ocisConfig:"cors"` -} - -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;WEBDAV_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEBDAV_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEBDAV_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEBDAV_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"WEBDAV_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;WEBDAV_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;WEBDAV_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;WEBDAV_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;WEBDAV_LOG_FILE"` -} - // Config combines all available configuration parts. type Config struct { - *shared.Commons - - Service Service `ocisConfig:"service"` + Service Service Tracing Tracing `ocisConfig:"tracing"` Log Log `ocisConfig:"log"` @@ -72,38 +21,3 @@ type Config struct { Context context.Context Supervised bool } - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9119", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9115", - Root: "/", - Namespace: "com.owncloud.web", - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - Service: Service{ - Name: "webdav", - }, - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "webdav", - }, - OcisPublicURL: "https://127.0.0.1:9200", - WebdavNamespace: "/users/{{.Id.OpaqueId}}", - RevaGateway: "127.0.0.1:9142", - } -} diff --git a/webdav/pkg/config/debug.go b/webdav/pkg/config/debug.go new file mode 100644 index 00000000000..2551ce17a17 --- /dev/null +++ b/webdav/pkg/config/debug.go @@ -0,0 +1,9 @@ +package config + +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr" env:"WEBDAV_DEBUG_ADDR"` + Token string `ocisConfig:"token" env:"WEBDAV_DEBUG_TOKEN"` + Pprof bool `ocisConfig:"pprof" env:"WEBDAV_DEBUG_PPROF"` + Zpages bool `ocisConfig:"zpages" env:"WEBDAV_DEBUG_ZPAGES"` +} diff --git a/webdav/pkg/config/defaultconfig.go b/webdav/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..38d6f76946e --- /dev/null +++ b/webdav/pkg/config/defaultconfig.go @@ -0,0 +1,36 @@ +package config + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9119", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9115", + Root: "/", + Namespace: "com.owncloud.web", + CORS: CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Service: Service{ + Name: "webdav", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "webdav", + }, + OcisPublicURL: "https://127.0.0.1:9200", + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + RevaGateway: "127.0.0.1:9142", + } +} diff --git a/webdav/pkg/config/http.go b/webdav/pkg/config/http.go new file mode 100644 index 00000000000..4ce2f2dcd2f --- /dev/null +++ b/webdav/pkg/config/http.go @@ -0,0 +1,17 @@ +package config + +// CORS defines the available cors configuration. +type CORS struct { + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allow_credentials"` +} + +// HTTP defines the available http configuration. +type HTTP struct { + Addr string `ocisConfig:"addr" env:"WEBDAV_HTTP_ADDR"` + Namespace string + Root string `ocisConfig:"root" env:"WEBDAV_HTTP_ROOT"` + CORS CORS `ocisConfig:"cors"` +} diff --git a/webdav/pkg/config/log.go b/webdav/pkg/config/log.go new file mode 100644 index 00000000000..211aad1a4a6 --- /dev/null +++ b/webdav/pkg/config/log.go @@ -0,0 +1,9 @@ +package config + +// Log defines the available log configuration. +type Log struct { + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;WEBDAV_LOG_LEVEL"` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;WEBDAV_LOG_PRETTY"` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;WEBDAV_LOG_COLOR"` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;WEBDAV_LOG_FILE"` +} diff --git a/webdav/pkg/config/service.go b/webdav/pkg/config/service.go new file mode 100644 index 00000000000..c12faf34442 --- /dev/null +++ b/webdav/pkg/config/service.go @@ -0,0 +1,7 @@ +package config + +// Service defines the available service configuration. +type Service struct { + Name string + Version string +} diff --git a/webdav/pkg/config/tracing.go b/webdav/pkg/config/tracing.go new file mode 100644 index 00000000000..f63b2480d83 --- /dev/null +++ b/webdav/pkg/config/tracing.go @@ -0,0 +1,10 @@ +package config + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;WEBDAV_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEBDAV_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEBDAV_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEBDAV_TRACING_COLLECTOR"` + Service string `ocisConfig:"service" env:"WEBDAV_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? +} From 9422388b746f12d05f061b2244b9fa1c1e13e715 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 15:14:01 +0100 Subject: [PATCH 46/84] add version to accounts --- accounts/pkg/command/health.go | 51 ++++++++++++++++++++++++++++++++++ accounts/pkg/command/root.go | 4 ++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 accounts/pkg/command/health.go diff --git a/accounts/pkg/command/health.go b/accounts/pkg/command/health.go new file mode 100644 index 00000000000..5a4d79cef2e --- /dev/null +++ b/accounts/pkg/command/health.go @@ -0,0 +1,51 @@ +package command + +import ( + "fmt" + "net/http" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/logging" + "github.com/urfave/cli/v2" +) + +// Health is the entrypoint for the health command. +func Health(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "health", + Usage: "Check health status", + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, + Action: func(c *cli.Context) error { + logger := logging.Configure(cfg.Service.Name, cfg.Log) + + resp, err := http.Get( + fmt.Sprintf( + "http://%s/healthz", + cfg.Debug.Addr, + ), + ) + + if err != nil { + logger.Fatal(). + Err(err). + Msg("Failed to request health check") + } + + defer resp.Body.Close() + + if resp.StatusCode != 200 { + logger.Fatal(). + Int("code", resp.StatusCode). + Msg("Health seems to be in bad state") + } + + logger.Debug(). + Int("code", resp.StatusCode). + Msg("Health got a good state") + + return nil + }, + } +} diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 97088ea2057..5854e0f601e 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -39,8 +39,10 @@ func Execute(cfg *config.Config) error { ListAccounts(cfg), InspectAccount(cfg), RemoveAccount(cfg), - PrintVersion(cfg), RebuildIndex(cfg), + + Health(cfg), + PrintVersion(cfg), }, } From 3c3fc2e098cd73c9f6ec9c859ce2402299da0014 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 16:30:57 +0100 Subject: [PATCH 47/84] revert storage, remove tracing.service and bring back common --- accounts/pkg/command/root.go | 22 +- accounts/pkg/config/config.go | 6 +- accounts/pkg/config/defaultconfig.go | 5 - accounts/pkg/config/tracing.go | 1 - accounts/pkg/logging/logging.go | 2 +- accounts/pkg/service/v0/service.go | 6 +- accounts/pkg/tracing/tracing.go | 2 +- glauth/pkg/command/root.go | 22 +- glauth/pkg/config/config.go | 6 +- glauth/pkg/config/defaultconfig.go | 6 +- glauth/pkg/config/tracing.go | 1 - glauth/pkg/logging/logging.go | 2 +- glauth/pkg/tracing/tracing.go | 2 +- graph-explorer/pkg/command/root.go | 22 +- graph-explorer/pkg/config/config.go | 6 +- graph-explorer/pkg/config/defaultconfig.go | 2 +- graph-explorer/pkg/config/tracing.go | 1 - graph-explorer/pkg/logging/logging.go | 2 +- graph-explorer/pkg/tracing/tracing.go | 2 +- graph/pkg/command/root.go | 22 +- graph/pkg/config/config.go | 6 +- graph/pkg/config/defaultconfig.go | 7 +- graph/pkg/config/tracing.go | 1 - graph/pkg/logging/logging.go | 2 +- graph/pkg/tracing/tracing.go | 2 +- idp/pkg/command/root.go | 22 +- idp/pkg/config/config.go | 6 +- idp/pkg/config/defaultconfig.go | 2 +- idp/pkg/config/tracing.go | 1 - idp/pkg/logging/logging.go | 2 +- idp/pkg/tracing/tracing.go | 2 +- ocis-pkg/config/config.go | 41 +- ocis-pkg/log/log.go | 2 +- ocis-pkg/shared/shared_types.go | 9 + ocis/pkg/command/accounts.go | 6 +- ocis/pkg/command/glauth.go | 6 +- ocis/pkg/command/graph.go | 6 +- ocis/pkg/command/graphexplorer.go | 6 +- ocis/pkg/command/idp.go | 6 +- ocis/pkg/command/ocs.go | 6 +- ocis/pkg/command/proxy.go | 6 +- ocis/pkg/command/settings.go | 6 +- ocis/pkg/command/thumbnails.go | 6 +- ocis/pkg/command/util.go | 21 +- ocis/pkg/command/web.go | 6 +- ocis/pkg/command/webdav.go | 6 +- ocis/pkg/runtime/service/service.go | 6 +- ocs/pkg/command/root.go | 22 +- ocs/pkg/config/config.go | 6 +- ocs/pkg/config/defaultconfig.go | 1 - ocs/pkg/config/tracing.go | 1 - ocs/pkg/logging/logging.go | 2 +- ocs/pkg/tracing/tracing.go | 2 +- proxy/pkg/command/root.go | 22 +- proxy/pkg/config/config.go | 10 +- proxy/pkg/config/defaultconfig.go | 2 +- proxy/pkg/config/tracing.go | 1 - proxy/pkg/logging/logging.go | 2 +- proxy/pkg/tracing/tracing.go | 2 +- settings/pkg/command/root.go | 22 +- settings/pkg/config/config.go | 7 +- settings/pkg/config/defaultconfig.go | 1 - settings/pkg/config/tracing.go | 1 - settings/pkg/logging/logging.go | 2 +- settings/pkg/tracing/tracing.go | 2 +- storage/pkg/command/appprovider.go | 5 +- storage/pkg/command/authbasic.go | 5 +- storage/pkg/command/authbearer.go | 5 +- storage/pkg/command/authmachine.go | 5 +- storage/pkg/command/frontend.go | 5 +- storage/pkg/command/gateway.go | 26 +- storage/pkg/command/groups.go | 5 +- storage/pkg/command/health.go | 3 +- storage/pkg/command/root.go | 17 +- storage/pkg/command/sharing.go | 5 +- storage/pkg/command/storagemetadata.go | 5 +- storage/pkg/command/storagepubliclink.go | 5 +- storage/pkg/command/storageshares.go | 5 +- storage/pkg/command/storageusers.go | 5 +- storage/pkg/command/users.go | 5 +- storage/pkg/config/config.go | 488 ++++++++++++++++++++- storage/pkg/config/debug.go | 9 - storage/pkg/config/defaultconfig.go | 436 ------------------ storage/pkg/config/grpc.go | 7 - storage/pkg/config/http.go | 18 - storage/pkg/config/log.go | 9 - storage/pkg/config/reva.go | 6 - storage/pkg/config/service.go | 7 - storage/pkg/config/tracing.go | 10 - storage/pkg/logging/logging.go | 17 - store/pkg/command/root.go | 22 +- store/pkg/config/config.go | 6 +- store/pkg/config/defaultconfig.go | 1 - store/pkg/config/tracing.go | 1 - store/pkg/logging/logging.go | 2 +- store/pkg/tracing/tracing.go | 2 +- thumbnails/pkg/command/root.go | 22 +- thumbnails/pkg/config/config.go | 6 +- thumbnails/pkg/config/defaultconfig.go | 1 - thumbnails/pkg/config/tracing.go | 1 - thumbnails/pkg/logging/logging.go | 2 +- thumbnails/pkg/tracing/tracing.go | 2 +- web/pkg/command/root.go | 22 +- web/pkg/config/config.go | 10 +- web/pkg/config/defaultconfig.go | 1 - web/pkg/config/tracing.go | 1 - web/pkg/logging/logging.go | 2 +- web/pkg/tracing/tracing.go | 2 +- webdav/pkg/command/root.go | 22 +- webdav/pkg/config/config.go | 6 +- webdav/pkg/config/defaultconfig.go | 1 - webdav/pkg/config/tracing.go | 1 - webdav/pkg/logging/logging.go | 2 +- webdav/pkg/tracing/tracing.go | 2 +- 114 files changed, 824 insertions(+), 875 deletions(-) delete mode 100644 storage/pkg/config/debug.go delete mode 100644 storage/pkg/config/defaultconfig.go delete mode 100644 storage/pkg/config/grpc.go delete mode 100644 storage/pkg/config/http.go delete mode 100644 storage/pkg/config/log.go delete mode 100644 storage/pkg/config/reva.go delete mode 100644 storage/pkg/config/service.go delete mode 100644 storage/pkg/config/tracing.go delete mode 100644 storage/pkg/logging/logging.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 5854e0f601e..366abad0fd7 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -67,16 +67,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -99,7 +99,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.Accounts.Commons = cfg.Commons + cfg.Accounts.Commons = cfg.Commons return SutureService{ cfg: cfg.Accounts, } diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index e10f6a932da..eb07e2ca592 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/accounts/pkg/config/defaultconfig.go b/accounts/pkg/config/defaultconfig.go index 8e7caa10179..5b027a54598 100644 --- a/accounts/pkg/config/defaultconfig.go +++ b/accounts/pkg/config/defaultconfig.go @@ -8,7 +8,6 @@ import ( func DefaultConfig() *Config { return &Config{ - HTTP: HTTP{ Addr: "127.0.0.1:9181", Namespace: "com.owncloud.web", @@ -60,9 +59,5 @@ func DefaultConfig() *Config { UID: 0, GID: 0, }, - Tracing: Tracing{ - Type: "jaeger", - Service: "accounts", - }, } } diff --git a/accounts/pkg/config/tracing.go b/accounts/pkg/config/tracing.go index 3547373fbb3..fc673f8246b 100644 --- a/accounts/pkg/config/tracing.go +++ b/accounts/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;ACCOUNTS_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;ACCOUNTS_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;ACCOUNTS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"ACCOUNTS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/accounts/pkg/logging/logging.go b/accounts/pkg/logging/logging.go index 9b09b128ed8..4836eaec410 100644 --- a/accounts/pkg/logging/logging.go +++ b/accounts/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/accounts/pkg/service/v0/service.go b/accounts/pkg/service/v0/service.go index 957f5a50cf1..18703e80515 100644 --- a/accounts/pkg/service/v0/service.go +++ b/accounts/pkg/service/v0/service.go @@ -109,9 +109,9 @@ func (s Service) buildIndex() (*indexer.Indexer, error) { func configFromSvc(cfg *config.Config) (*idxcfg.Config, error) { c := idxcfg.New() - //if cfg.Log == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil { + cfg.Log = &config.Log{} + } defer func(cfg *config.Config) { l := log.NewLogger(log.Color(cfg.Log.Color), log.Pretty(cfg.Log.Pretty), log.Level(cfg.Log.Level)) diff --git a/accounts/pkg/tracing/tracing.go b/accounts/pkg/tracing/tracing.go index 4da38009fe9..5f9bd3b65aa 100644 --- a/accounts/pkg/tracing/tracing.go +++ b/accounts/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "accounts", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index b7b5fef7c94..3b16d07a21a 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -59,16 +59,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -91,7 +91,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.GLAuth.Commons = cfg.Commons + cfg.GLAuth.Commons = cfg.Commons return SutureService{ cfg: cfg.GLAuth, } diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index c13d732eadd..6292cfc3506 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` Ldap Ldap `ocisConfig:"ldap"` diff --git a/glauth/pkg/config/defaultconfig.go b/glauth/pkg/config/defaultconfig.go index 23c12f84463..becff0bb9d8 100644 --- a/glauth/pkg/config/defaultconfig.go +++ b/glauth/pkg/config/defaultconfig.go @@ -12,8 +12,10 @@ func DefaultConfig() *Config { Addr: "127.0.0.1:9129", }, Tracing: Tracing{ - Type: "jaeger", - Service: "glauth", + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", }, Service: Service{ Name: "glauth", diff --git a/glauth/pkg/config/tracing.go b/glauth/pkg/config/tracing.go index 3caca270571..52733d097c7 100644 --- a/glauth/pkg/config/tracing.go +++ b/glauth/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GLAUTH_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GLAUTH_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GLAUTH_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"GLAUTH_TRACING_SERVICE"` // TODO: } diff --git a/glauth/pkg/logging/logging.go b/glauth/pkg/logging/logging.go index 2dd2f1cd4cd..5282014a62d 100644 --- a/glauth/pkg/logging/logging.go +++ b/glauth/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/glauth/pkg/tracing/tracing.go b/glauth/pkg/tracing/tracing.go index a02161687bf..734fd1d523b 100644 --- a/glauth/pkg/tracing/tracing.go +++ b/glauth/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "glauth", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 621958d0091..f99e3eaf343 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -56,17 +56,17 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 9e11dd8e76a..ea0577b0f9a 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/graph-explorer/pkg/config/defaultconfig.go b/graph-explorer/pkg/config/defaultconfig.go index b4492724332..7ea49081939 100644 --- a/graph-explorer/pkg/config/defaultconfig.go +++ b/graph-explorer/pkg/config/defaultconfig.go @@ -17,10 +17,10 @@ func DefaultConfig() *Config { Name: "graph-explorer", }, Tracing: Tracing{ + Enabled: false, Type: "jaeger", Endpoint: "", Collector: "", - Service: "graph-explorer", }, GraphExplorer: GraphExplorer{ ClientID: "ocis-explorer.js", diff --git a/graph-explorer/pkg/config/tracing.go b/graph-explorer/pkg/config/tracing.go index cf4214eb4dc..db55ec8c5c9 100644 --- a/graph-explorer/pkg/config/tracing.go +++ b/graph-explorer/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_EXPLORER_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_EXPLORER_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_EXPLORER_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"GRAPH_EXPLORER_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/graph-explorer/pkg/logging/logging.go b/graph-explorer/pkg/logging/logging.go index 8d3175cbf61..24a2567a1b0 100644 --- a/graph-explorer/pkg/logging/logging.go +++ b/graph-explorer/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/graph-explorer/pkg/tracing/tracing.go b/graph-explorer/pkg/tracing/tracing.go index b7fe7a3f631..73b4c863c60 100644 --- a/graph-explorer/pkg/tracing/tracing.go +++ b/graph-explorer/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "graph-explorer", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 7168eb16aa4..2492597ef82 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -58,16 +58,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -90,7 +90,7 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.Graph.Commons = cfg.Commons + cfg.Graph.Commons = cfg.Commons return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index e2cc81c47df..03ec948bb36 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/graph/pkg/config/defaultconfig.go b/graph/pkg/config/defaultconfig.go index b5d09a9d224..5879b9487af 100644 --- a/graph/pkg/config/defaultconfig.go +++ b/graph/pkg/config/defaultconfig.go @@ -15,9 +15,10 @@ func DefaultConfig() *Config { Name: "graph", }, Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Service: "graph", + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", }, Reva: Reva{ Address: "127.0.0.1:9142", diff --git a/graph/pkg/config/tracing.go b/graph/pkg/config/tracing.go index 457edb0fd87..077a4819ae5 100644 --- a/graph/pkg/config/tracing.go +++ b/graph/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;GRAPH_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"GRAPH_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/graph/pkg/logging/logging.go b/graph/pkg/logging/logging.go index 07f8b44502c..daf29f40b84 100644 --- a/graph/pkg/logging/logging.go +++ b/graph/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/graph/pkg/tracing/tracing.go b/graph/pkg/tracing/tracing.go index 5e67b08eb4c..3f2d775a51a 100644 --- a/graph/pkg/tracing/tracing.go +++ b/graph/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "graph", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 77c740592b8..ec61ab260d5 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -60,16 +60,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -92,7 +92,7 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.IDP.Commons = cfg.Commons + cfg.IDP.Commons = cfg.Commons return SutureService{ cfg: cfg.IDP, } diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index cc1e3b53856..426c34dd481 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/idp/pkg/config/defaultconfig.go b/idp/pkg/config/defaultconfig.go index dbaa3ba57be..21e59a33910 100644 --- a/idp/pkg/config/defaultconfig.go +++ b/idp/pkg/config/defaultconfig.go @@ -23,10 +23,10 @@ func DefaultConfig() *Config { Name: "idp", }, Tracing: Tracing{ + Enabled: false, Type: "jaeger", Endpoint: "", Collector: "", - Service: "idp", }, Asset: Asset{}, IDP: Settings{ diff --git a/idp/pkg/config/tracing.go b/idp/pkg/config/tracing.go index 8cb1d9db62d..c149f9da1ae 100644 --- a/idp/pkg/config/tracing.go +++ b/idp/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;IDP_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;IDP_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;IDP_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"IDP_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/idp/pkg/logging/logging.go b/idp/pkg/logging/logging.go index cbcc6483367..97eb83fcd19 100644 --- a/idp/pkg/logging/logging.go +++ b/idp/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/idp/pkg/tracing/tracing.go b/idp/pkg/tracing/tracing.go index eb116d6ce35..756b6210c92 100644 --- a/idp/pkg/tracing/tracing.go +++ b/idp/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "idp", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 40436f6faa8..bdd6cd54974 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -24,7 +24,6 @@ type Tracing struct { Type string `ocisConfig:"type"` Endpoint string `ocisConfig:"endpoint"` Collector string `ocisConfig:"collector"` - Service string `ocisConfig:"service"` } // TokenManager is the config for using the reva token manager @@ -42,28 +41,6 @@ const ( type Mode int -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} - -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"ACCOUNTS_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"ACCOUNTS_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"ACCOUNTS_DEBUG_ZPAGES"` -} - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE"` -} - // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { Port string `ocisConfig:"port"` @@ -75,11 +52,8 @@ type Runtime struct { type Config struct { *shared.Commons `ocisConfig:"shared"` - Service Service `ocisConfig:"service"` - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` + Tracing shared.Tracing `ocisConfig:"tracing"` + Log shared.Log `ocisConfig:"log"` Mode Mode // DEPRECATED File string @@ -106,13 +80,6 @@ type Config struct { func DefaultConfig() *Config { return &Config{ - Tracing: Tracing{ - Enabled: false, - Type: "jaeger", - Endpoint: "", - Collector: "", - Service: "ocis", - }, TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, @@ -189,10 +156,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { EnvVars: []string{"OCIS_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, - { - EnvVars: []string{"OCIS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, { EnvVars: []string{"OCIS_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, diff --git a/ocis-pkg/log/log.go b/ocis-pkg/log/log.go index 42ae508f825..f2ab74e1222 100644 --- a/ocis-pkg/log/log.go +++ b/ocis-pkg/log/log.go @@ -21,7 +21,7 @@ type Logger struct { } // LoggerFromConfig initializes a service-specific logger instance. -func LoggerFromConfig(name string, cfg shared.Log) Logger { +func LoggerFromConfig(name string, cfg *shared.Log) Logger { return NewLogger( Name(name), Level(cfg.Level), diff --git a/ocis-pkg/shared/shared_types.go b/ocis-pkg/shared/shared_types.go index fc655e73df2..25aa9626960 100644 --- a/ocis-pkg/shared/shared_types.go +++ b/ocis-pkg/shared/shared_types.go @@ -16,9 +16,18 @@ type Log struct { File string `mapstructure:"file"` } +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` +} + // Commons holds configuration that are common to all extensions. Each extension can then decide whether // to overwrite its values. type Commons struct { *Log `mapstructure:"log"` + Tracing `mapstrucuture:"log"` OcisURL string `mapstructure:"ocis_url"` } diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index cb3bdc62098..1c3db45c0da 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -26,9 +26,9 @@ func AccountsCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.Accounts.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.Accounts.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index d6adfa74a44..c6baacfdeb5 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -18,9 +18,9 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.GLAuth.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.GLAuth.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 162416d24ec..ecc94826caa 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -18,9 +18,9 @@ func GraphCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.Graph.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.Graph.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index ede47b9c8ca..7833206b916 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -18,9 +18,9 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.Graph.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.Graph.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 399b9339a6c..7b35c15ba89 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -21,9 +21,9 @@ func IDPCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.IDP.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.IDP.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 40c79fd32ae..243c27696f5 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -18,9 +18,9 @@ func OCSCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.OCS.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.OCS.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 6b3dc5b957b..7458a80d669 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -21,9 +21,9 @@ func ProxyCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.Proxy.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.Proxy.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 7980f9d0b47..90bdafc304f 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -21,9 +21,9 @@ func SettingsCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.Settings.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.Settings.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 01cdae6fc9a..f671358e779 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -21,9 +21,9 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.Thumbnails.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.Thumbnails.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/util.go b/ocis/pkg/command/util.go index c49fb2c123e..a2e9b1abc0e 100644 --- a/ocis/pkg/command/util.go +++ b/ocis/pkg/command/util.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/urfave/cli/v2" ) @@ -10,16 +11,16 @@ func ParseStorageCommon(ctx *cli.Context, cfg *config.Config) error { return err } - //if cfg.Storage.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Storage.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Storage.Log == nil && cfg.Commons == nil { - // cfg.Storage.Log = &shared.Log{} - //} + if cfg.Storage.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Storage.Log = &shared.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Storage.Log == nil && cfg.Commons == nil { + cfg.Storage.Log = &shared.Log{} + } return nil } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 5d63587c2e7..c3f2df2eafe 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -18,9 +18,9 @@ func WebCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.Web.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.Web.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index ad95e8498bb..31cb2c52856 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -22,9 +22,9 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { return err } - //if cfg.Commons != nil { - // cfg.WebDAV.Commons = cfg.Commons - //} + if cfg.Commons != nil { + cfg.WebDAV.Commons = cfg.Commons + } return nil }, diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 7c586838e06..c66b07c3fd1 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -164,9 +164,9 @@ func Start(o ...Option) error { } } - //if s.cfg.Storage.Log == nil { - // s.cfg.Storage.Log = &shared.Log{} - //} + if s.cfg.Storage.Log == nil { + s.cfg.Storage.Log = &shared.Log{} + } s.cfg.Storage.Log.Color = s.cfg.Commons.Color s.cfg.Storage.Log.Level = s.cfg.Commons.Level diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 01d18eb5849..141bc1bdadc 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -61,16 +61,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -93,7 +93,7 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.OCS.Commons = cfg.Commons + cfg.OCS.Commons = cfg.Commons return SutureService{ cfg: cfg.OCS, } diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index b8554f88797..0171ef7a06f 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/ocs/pkg/config/defaultconfig.go b/ocs/pkg/config/defaultconfig.go index 428b254a40b..59cbfb8f1f1 100644 --- a/ocs/pkg/config/defaultconfig.go +++ b/ocs/pkg/config/defaultconfig.go @@ -27,7 +27,6 @@ func DefaultConfig() *Config { Type: "jaeger", Endpoint: "", Collector: "", - Service: "ocs", }, TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", diff --git a/ocs/pkg/config/tracing.go b/ocs/pkg/config/tracing.go index f627ec38207..310462e90a5 100644 --- a/ocs/pkg/config/tracing.go +++ b/ocs/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;OCS_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;OCS_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;OCS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"OCS_TRACING_SERVICE"` } diff --git a/ocs/pkg/logging/logging.go b/ocs/pkg/logging/logging.go index 355ab6c0dd9..80350b0d095 100644 --- a/ocs/pkg/logging/logging.go +++ b/ocs/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/ocs/pkg/tracing/tracing.go b/ocs/pkg/tracing/tracing.go index d79ef622fe0..bd48730362b 100644 --- a/ocs/pkg/tracing/tracing.go +++ b/ocs/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "ocs", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 9801fe65a70..1d771d9cb6c 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -60,16 +60,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -92,7 +92,7 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.Proxy.Commons = cfg.Commons + cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.Proxy, } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 4408550b777..048928e6ac0 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -1,13 +1,19 @@ package config -import "context" +import ( + "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/proxy/pkg/config/defaultconfig.go b/proxy/pkg/config/defaultconfig.go index ea1940a5769..b4101401360 100644 --- a/proxy/pkg/config/defaultconfig.go +++ b/proxy/pkg/config/defaultconfig.go @@ -24,10 +24,10 @@ func DefaultConfig() *Config { Name: "proxy", }, Tracing: Tracing{ + Enabled: false, Type: "jaeger", Endpoint: "", Collector: "", - Service: "proxy", }, OIDC: OIDC{ Issuer: "https://localhost:9200", diff --git a/proxy/pkg/config/tracing.go b/proxy/pkg/config/tracing.go index 91472675939..79429ee5c4e 100644 --- a/proxy/pkg/config/tracing.go +++ b/proxy/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;PROXY_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;PROXY_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;PROXY_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"PROXY_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/proxy/pkg/logging/logging.go b/proxy/pkg/logging/logging.go index b2626eb7461..dfaeabd2469 100644 --- a/proxy/pkg/logging/logging.go +++ b/proxy/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/proxy/pkg/tracing/tracing.go b/proxy/pkg/tracing/tracing.go index e3b3aa50c03..5ab072223f9 100644 --- a/proxy/pkg/tracing/tracing.go +++ b/proxy/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "proxy", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 24d5b361900..fb7c930cb70 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -61,16 +61,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -93,7 +93,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.Settings.Commons = cfg.Commons + cfg.Settings.Commons = cfg.Commons return SutureService{ cfg: cfg.Settings, } diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 18284a56c5d..052a07360d4 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` @@ -27,4 +31,3 @@ type Config struct { type Asset struct { Path string `ocisConfig:"path" env:"SETTINGS_ASSET_PATH"` } - diff --git a/settings/pkg/config/defaultconfig.go b/settings/pkg/config/defaultconfig.go index 100c1e80fff..a667c0c2511 100644 --- a/settings/pkg/config/defaultconfig.go +++ b/settings/pkg/config/defaultconfig.go @@ -38,7 +38,6 @@ func DefaultConfig() *Config { Type: "jaeger", Endpoint: "", Collector: "", - Service: "settings", }, DataPath: path.Join(defaults.BaseDataPath(), "settings"), Asset: Asset{ diff --git a/settings/pkg/config/tracing.go b/settings/pkg/config/tracing.go index 543298663f5..7197a69f354 100644 --- a/settings/pkg/config/tracing.go +++ b/settings/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;SETTINGS_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;SETTINGS_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;SETTINGS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"SETTINGS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/settings/pkg/logging/logging.go b/settings/pkg/logging/logging.go index 147d07e7c8c..aba0cbe821f 100644 --- a/settings/pkg/logging/logging.go +++ b/settings/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/settings/pkg/tracing/tracing.go b/settings/pkg/tracing/tracing.go index 09d85008bdb..620d261cc4b 100644 --- a/settings/pkg/tracing/tracing.go +++ b/settings/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "settings", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 86ccac4f02a..80c8c523bac 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +27,7 @@ func AppProvider(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-app-provider") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -129,7 +128,7 @@ type AppProviderSutureService struct { // NewAppProvider creates a new store.AppProviderSutureService func NewAppProvider(cfg *ociscfg.Config) suture.Service { - ////cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return AppProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 1d57341f1c9..10268754a14 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -13,7 +13,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -29,7 +28,7 @@ func AuthBasic(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-auth-basic") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -148,7 +147,7 @@ type AuthBasicSutureService struct { // NewAuthBasicSutureService creates a new store.AuthBasicSutureService func NewAuthBasic(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return AuthBasicSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index 7c2e23a845d..af60ccbdac7 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +27,7 @@ func AuthBearer(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-auth-bearer") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -124,7 +123,7 @@ type AuthBearerSutureService struct { // NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService func NewAuthBearer(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return AuthBearerSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index 9bce040bf92..eaaa97cbf61 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,7 +27,7 @@ func AuthMachine(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-auth-machine") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -120,7 +119,7 @@ type AuthMachineSutureService struct { // NewAuthMachineSutureService creates a new gateway.AuthMachineSutureService func NewAuthMachine(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return AuthMachineSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 3682bec4b31..c3e92788ded 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -16,7 +16,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/conversions" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -35,7 +34,7 @@ func Frontend(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-frontend") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) @@ -344,7 +343,7 @@ type FrontendSutureService struct { // NewFrontend creates a new frontend.FrontendSutureService func NewFrontend(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return FrontendSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 5dabd93e7e7..0dff38512bb 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -15,10 +15,10 @@ import ( "github.com/oklog/run" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/service/external" "github.com/owncloud/ocis/storage/pkg/tracing" @@ -43,7 +43,7 @@ func Gateway(cfg *config.Config) *cli.Command { return nil }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -389,7 +389,7 @@ type GatewaySutureService struct { // NewGatewaySutureService creates a new gateway.GatewaySutureService func NewGateway(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return GatewaySutureService{ cfg: cfg.Storage, } @@ -425,16 +425,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) er } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &shared.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &shared.Log{} + } // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(cfg), false) diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 0d37c4149ff..043c96fdcdc 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -13,7 +13,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -29,7 +28,7 @@ func Groups(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-groups") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -162,7 +161,7 @@ type GroupSutureService struct { // NewGroupProviderSutureService creates a new storage.GroupProvider func NewGroupProvider(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return GroupSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/health.go b/storage/pkg/command/health.go index 244ce713d3a..a3c3791a99c 100644 --- a/storage/pkg/command/health.go +++ b/storage/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/urfave/cli/v2" ) @@ -18,7 +17,7 @@ func Health(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) resp, err := http.Get( fmt.Sprintf( diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 6170aa7cfa4..7de4fc5aa56 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -3,6 +3,7 @@ package command import ( "os" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" "github.com/urfave/cli/v2" @@ -22,10 +23,8 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg, "_") + return ParseConfig(c, cfg, "storage") }, Commands: []*cli.Command{ @@ -36,7 +35,6 @@ func Execute(cfg *config.Config) error { AppProvider(cfg), AuthBasic(cfg), AuthBearer(cfg), - AuthMachine(cfg), Sharing(cfg), StorageUsers(cfg), StorageShares(cfg), @@ -58,3 +56,14 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } + +// NewLogger initializes a service-specific logger instance. +func NewLogger(cfg *config.Config) log.Logger { + return log.NewLogger( + log.Name("storage"), + log.Level(cfg.Log.Level), + log.Pretty(cfg.Log.Pretty), + log.Color(cfg.Log.Color), + log.File(cfg.Log.File), + ) +} diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index 7229b7f2818..abace4d50b2 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -7,7 +7,6 @@ import ( "path" "path/filepath" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -31,7 +30,7 @@ func Sharing(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-sharing") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) @@ -188,7 +187,7 @@ type SharingSutureService struct { // NewSharingSutureService creates a new store.SharingSutureService func NewSharing(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return SharingSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 197e403ac1e..f77d1eca32e 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -7,7 +7,6 @@ import ( "path" "github.com/owncloud/ocis/ocis-pkg/sync" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/cs3org/reva/cmd/revad/runtime" "github.com/gofrs/uuid" @@ -35,7 +34,7 @@ func StorageMetadata(cfg *config.Config) *cli.Command { }, Category: "Extensions", Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} @@ -166,7 +165,7 @@ type MetadataSutureService struct { // NewSutureService creates a new storagemetadata.SutureService func NewStorageMetadata(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return MetadataSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index 8636463f603..0e3966b7d1f 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -29,7 +28,7 @@ func StoragePublicLink(cfg *config.Config) *cli.Command { }, Category: "Extensions", Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) @@ -126,7 +125,7 @@ type StoragePublicLinkSutureService struct { // NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return StoragePublicLinkSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storageshares.go b/storage/pkg/command/storageshares.go index 7735ef9a21f..a239170a21c 100644 --- a/storage/pkg/command/storageshares.go +++ b/storage/pkg/command/storageshares.go @@ -7,7 +7,6 @@ import ( "path" "github.com/owncloud/ocis/ocis-pkg/sync" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/cs3org/reva/cmd/revad/runtime" "github.com/gofrs/uuid" @@ -29,7 +28,7 @@ func StorageShares(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-shares") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) @@ -125,7 +124,7 @@ type StorageSharesSutureService struct { // NewStorageShares creates a new storage.StorageSharesSutureService func NewStorageShares(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return StorageSharesSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 2d9331d3307..9d671949a23 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -13,7 +13,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/command/storagedrivers" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -29,7 +28,7 @@ func StorageUsers(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-userprovider") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) @@ -146,7 +145,7 @@ type StorageUsersSutureService struct { // NewStorageUsersSutureService creates a new storage.StorageUsersSutureService func NewStorageUsers(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return StorageUsersSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 908865ae7cb..34aee1d7c03 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -13,7 +13,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/logging" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -29,7 +28,7 @@ func Users(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-users") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) @@ -183,7 +182,7 @@ type UserProviderSutureService struct { // NewUserProviderSutureService creates a new storage.UserProvider func NewUserProvider(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return UserProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index b455de8ab3a..c2d7a4c6264 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -2,21 +2,28 @@ package config import ( "context" + "os" + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/shared" ) -// Config combines all available configuration parts. -type Config struct { - Service Service - - Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` - Debug Debug `ocisConfig:"debug"` - - Reva Reva `ocisConfig:"reva"` +// Log defines the available logging configuration. +type Log struct { + Level string `ocisConfig:"level"` + Pretty bool `ocisConfig:"pretty"` + Color bool `ocisConfig:"color"` + File string `ocisConfig:"file"` +} - Asset Asset `ocisConfig:"asset"` +// Debug defines the available debug configuration. +type Debug struct { + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // Gateway defines the available gateway configuration. @@ -482,11 +489,472 @@ type Reva struct { DefaultUploadProtocol string `ocisConfig:"default_upload_protocol"` } +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` +} + // Asset defines the available asset configuration. type Asset struct { Path string `ocisConfig:"path"` } +// Config combines all available configuration parts. +type Config struct { + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + Reva Reva `ocisConfig:"reva"` + Tracing Tracing `ocisConfig:"tracing"` + Asset Asset `ocisConfig:"asset"` +} + +// New initializes a new configuration with or without defaults. +func New() *Config { + return &Config{} +} + +func DefaultConfig() *Config { + return &Config{ + // log is inherited + Debug: Debug{ + Addr: "127.0.0.1:9109", + }, + Reva: Reva{ + JWTSecret: "Pive-Fumkiu4", + SkipUserGroupsInToken: false, + TransferSecret: "replace-me-with-a-transfer-secret", + TransferExpires: 24 * 60 * 60, + OIDC: OIDC{ + Issuer: "https://localhost:9200", + Insecure: false, + IDClaim: "preferred_username", + }, + LDAP: LDAP{ + Hostname: "localhost", + Port: 9126, + CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Insecure: false, + BaseDN: "dc=ocis,dc=test", + LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", + UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", + UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", + GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", + GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", + BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", + BindPassword: "reva", + IDP: "https://localhost:9200", + UserSchema: LDAPUserSchema{ + UID: "ownclouduuid", + Mail: "mail", + DisplayName: "displayname", + CN: "cn", + UIDNumber: "uidnumber", + GIDNumber: "gidnumber", + }, + GroupSchema: LDAPGroupSchema{ + GID: "cn", + Mail: "mail", + DisplayName: "cn", + CN: "cn", + GIDNumber: "gidnumber", + }, + }, + UserGroupRest: UserGroupRest{ + RedisAddress: "localhost:6379", + }, + UserOwnCloudSQL: UserOwnCloudSQL{ + DBUsername: "owncloud", + DBPassword: "secret", + DBHost: "mysql", + DBPort: 3306, + DBName: "owncloud", + Idp: "https://localhost:9200", + Nobody: 90, + JoinUsername: false, + JoinOwnCloudUUID: false, + EnableMedialSearch: false, + }, + OCDav: OCDav{ + WebdavNamespace: "/home/", + DavFilesNamespace: "/users/", + }, + Archiver: Archiver{ + MaxNumFiles: 10000, + MaxSize: 1073741824, + ArchiverURL: "/archiver", + }, + UserStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + }, + ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") + UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + OwnCloud: DriverOwnCloud{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + Redis: ":6379", + Scan: true, + }, + OwnCloudSQL: DriverOwnCloudSQL{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + DBUsername: "owncloud", + DBPassword: "owncloud", + DBHost: "", + DBPort: 3306, + DBName: "owncloud", + }, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + MetadataStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + EnableHome: false, + }, + ShadowNamespace: "", + UploadsNamespace: "", + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + GrpcURI: "", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + EnableLogging: false, + ShowHiddenSysFiles: false, + ForceSingleUserMode: false, + UseKeytab: false, + SecProtocol: "", + Keytab: "", + SingleUsername: "", + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), + }, + OwnCloud: DriverOwnCloud{}, + OwnCloudSQL: DriverOwnCloudSQL{}, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + Frontend: FrontendPort{ + Port: Port{ + MaxCPUs: "", + LogLevel: "", + GRPCNetwork: "", + GRPCAddr: "", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9140", + Protocol: "", + Endpoint: "", + DebugAddr: "127.0.0.1:9141", + Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, + Config: nil, + Context: nil, + Supervised: false, + }, + AppProviderInsecure: false, + AppProviderPrefix: "", + ArchiverInsecure: false, + ArchiverPrefix: "archiver", + DatagatewayPrefix: "data", + Favorites: false, + OCDavInsecure: false, + OCDavPrefix: "", + OCSPrefix: "ocs", + OCSSharePrefix: "/Shares", + OCSHomeNamespace: "/home", + PublicURL: "https://localhost:9200", + OCSCacheWarmupDriver: "", + OCSAdditionalInfoAttribute: "{{.Mail}}", + OCSResourceInfoCacheTTL: 0, + Middleware: Middleware{}, + }, + DataGateway: DataGatewayPort{ + Port: Port{}, + PublicURL: "", + }, + Gateway: Gateway{ + Port: Port{ + Endpoint: "127.0.0.1:9142", + DebugAddr: "127.0.0.1:9143", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9142", + }, + CommitShareToStorageGrant: true, + CommitShareToStorageRef: true, + DisableHomeCreationOnLogin: false, + ShareFolder: "Shares", + LinkGrants: "", + HomeMapping: "", + EtagCacheTTL: 0, + }, + StorageRegistry: StorageRegistry{ + Driver: "static", + HomeProvider: "/home", + JSON: "", + }, + AppRegistry: AppRegistry{ + Driver: "static", + MimetypesJSON: "", + }, + Users: Users{ + Port: Port{ + Endpoint: "localhost:9144", + DebugAddr: "127.0.0.1:9145", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9144", + Services: []string{"userprovider"}, + }, + Driver: "ldap", + UserGroupsCacheExpiration: 5, + }, + Groups: Groups{ + Port: Port{ + Endpoint: "localhost:9160", + DebugAddr: "127.0.0.1:9161", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9160", + Services: []string{"groupprovider"}, + }, + Driver: "ldap", + GroupMembersCacheExpiration: 5, + }, + AuthProvider: Users{ + Port: Port{}, + Driver: "ldap", + UserGroupsCacheExpiration: 0, + }, + AuthBasic: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9146", + DebugAddr: "127.0.0.1:9147", + Services: []string{"authprovider"}, + Endpoint: "localhost:9146", + }, + AuthBearer: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9148", + DebugAddr: "127.0.0.1:9149", + Services: []string{"authprovider"}, + Endpoint: "localhost:9148", + }, + AuthMachine: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9166", + DebugAddr: "127.0.0.1:9167", + Services: []string{"authprovider"}, + Endpoint: "localhost:9166", + }, + AuthMachineConfig: AuthMachineConfig{ + MachineAuthAPIKey: "change-me-please", + }, + Sharing: Sharing{ + Port: Port{ + Endpoint: "localhost:9150", + DebugAddr: "127.0.0.1:9151", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9150", + Services: []string{"usershareprovider", "publicshareprovider"}, + }, + UserDriver: "json", + UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), + UserSQLUsername: "", + UserSQLPassword: "", + UserSQLHost: "", + UserSQLPort: 1433, + UserSQLName: "", + PublicDriver: "json", + PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), + PublicPasswordHashCost: 11, + PublicEnableExpiredSharesCleanup: true, + PublicJanitorRunInterval: 60, + UserStorageMountID: "", + }, + StorageHome: StoragePort{ + Port: Port{ + Endpoint: "localhost:9154", + DebugAddr: "127.0.0.1:9156", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9154", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9155", + }, + Driver: "ocis", + ReadOnly: false, + MountPath: "/home", + AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + DataServerURL: "http://localhost:9155/data", + HTTPPrefix: "data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "home"), + }, + StorageUsers: StoragePort{ + Port: Port{ + Endpoint: "localhost:9157", + DebugAddr: "127.0.0.1:9159", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9157", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9158", + }, + MountPath: "/users", + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + Driver: "ocis", + DataServerURL: "http://localhost:9158/data", + HTTPPrefix: "data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), + }, + StoragePublicLink: PublicStorage{ + StoragePort: StoragePort{ + Port: Port{ + Endpoint: "localhost:9178", + DebugAddr: "127.0.0.1:9179", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9178", + }, + MountPath: "/public", + MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", + }, + PublicShareProviderAddr: "", + UserProviderAddr: "", + }, + StorageMetadata: StoragePort{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9215", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9216", + DebugAddr: "127.0.0.1:9217", + }, + Driver: "ocis", + ExposeDataServer: false, + DataServerURL: "http://localhost:9216/data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), + DataProvider: DataProvider{}, + }, + AppProvider: AppProvider{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9164", + DebugAddr: "127.0.0.1:9165", + Endpoint: "localhost:9164", + Services: []string{"appprovider"}, + }, + ExternalAddr: "127.0.0.1:9164", + WopiDriver: WopiDriver{}, + AppsURL: "/app/list", + OpenURL: "/app/open", + NewURL: "/app/new", + }, + Configs: nil, + UploadMaxChunkSize: 1e+8, + UploadHTTPMethodOverride: "", + ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, + ChecksumPreferredUploadType: "", + DefaultUploadProtocol: "tus", + }, + Tracing: Tracing{ + Service: "storage", + Type: "jaeger", + }, + Asset: Asset{}, + } +} + // StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the // Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets // us propagate changes easier. diff --git a/storage/pkg/config/debug.go b/storage/pkg/config/debug.go deleted file mode 100644 index f9283a9b295..00000000000 --- a/storage/pkg/config/debug.go +++ /dev/null @@ -1,9 +0,0 @@ -package config - -// Debug defines the available debug configuration. -type Debug struct { - Addr string `ocisConfig:"addr" env:"STORAGE_DEBUG_ADDR"` - Token string `ocisConfig:"token" env:"STORAGE_DEBUG_TOKEN"` - Pprof bool `ocisConfig:"pprof" env:"STORAGE_DEBUG_PPROF"` - Zpages bool `ocisConfig:"zpages" env:"STORAGE_DEBUG_ZPAGES"` -} diff --git a/storage/pkg/config/defaultconfig.go b/storage/pkg/config/defaultconfig.go deleted file mode 100644 index 00e0dba3633..00000000000 --- a/storage/pkg/config/defaultconfig.go +++ /dev/null @@ -1,436 +0,0 @@ -package config - -import ( - "os" - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - // log is inherited - Debug: Debug{ - Addr: "127.0.0.1:9109", - }, - Reva: Reva{ - JWTSecret: "Pive-Fumkiu4", - SkipUserGroupsInToken: false, - TransferSecret: "replace-me-with-a-transfer-secret", - TransferExpires: 24 * 60 * 60, - OIDC: OIDC{ - Issuer: "https://localhost:9200", - Insecure: false, - IDClaim: "preferred_username", - }, - LDAP: LDAP{ - Hostname: "localhost", - Port: 9126, - CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), - Insecure: false, - BaseDN: "dc=ocis,dc=test", - LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", - UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", - UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", - UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", - GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", - GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", - GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", - BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", - BindPassword: "reva", - IDP: "https://localhost:9200", - UserSchema: LDAPUserSchema{ - UID: "ownclouduuid", - Mail: "mail", - DisplayName: "displayname", - CN: "cn", - UIDNumber: "uidnumber", - GIDNumber: "gidnumber", - }, - GroupSchema: LDAPGroupSchema{ - GID: "cn", - Mail: "mail", - DisplayName: "cn", - CN: "cn", - GIDNumber: "gidnumber", - }, - }, - UserGroupRest: UserGroupRest{ - RedisAddress: "localhost:6379", - }, - UserOwnCloudSQL: UserOwnCloudSQL{ - DBUsername: "owncloud", - DBPassword: "secret", - DBHost: "mysql", - DBPort: 3306, - DBName: "owncloud", - Idp: "https://localhost:9200", - Nobody: 90, - JoinUsername: false, - JoinOwnCloudUUID: false, - EnableMedialSearch: false, - }, - OCDav: OCDav{ - WebdavNamespace: "/users/{{.Id.OpaqueId}}", - DavFilesNamespace: "/users/{{.Id.OpaqueId}}", - }, - Archiver: Archiver{ - MaxNumFiles: 10000, - MaxSize: 1073741824, - ArchiverURL: "/archiver", - }, - UserStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ - Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", - UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", - }, - ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") - UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") - EosBinary: "/usr/bin/eos", - XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - CacheDirectory: os.TempDir(), - GatewaySVC: "127.0.0.1:9142", - }, - Local: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Username}}", - EnableHome: false, - }, - OwnCloud: DriverOwnCloud{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), - Redis: ":6379", - Scan: true, - }, - OwnCloudSQL: DriverOwnCloudSQL{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Username}}", - EnableHome: false, - }, - UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), - DBUsername: "owncloud", - DBPassword: "owncloud", - DBHost: "", - DBPort: 3306, - DBName: "owncloud", - }, - S3: DriverS3{ - DriverCommon: DriverCommon{}, - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - }, - }, - MetadataStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ - Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", - UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", - EnableHome: false, - }, - ShadowNamespace: "", - UploadsNamespace: "", - EosBinary: "/usr/bin/eos", - XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - GrpcURI: "", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - CacheDirectory: os.TempDir(), - EnableLogging: false, - ShowHiddenSysFiles: false, - ForceSingleUserMode: false, - UseKeytab: false, - SecProtocol: "", - Keytab: "", - SingleUsername: "", - GatewaySVC: "127.0.0.1:9142", - }, - Local: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), - }, - OwnCloud: DriverOwnCloud{}, - OwnCloudSQL: DriverOwnCloudSQL{}, - S3: DriverS3{ - DriverCommon: DriverCommon{}, - Region: "default", - }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), - ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), - ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - }, - }, - Frontend: FrontendPort{ - Port: Port{ - MaxCPUs: "", - LogLevel: "", - GRPCNetwork: "", - GRPCAddr: "", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9140", - Protocol: "", - Endpoint: "", - DebugAddr: "127.0.0.1:9141", - Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, - Config: nil, - Context: nil, - Supervised: false, - }, - AppProviderInsecure: false, - AppProviderPrefix: "", - ArchiverInsecure: false, - ArchiverPrefix: "archiver", - DatagatewayPrefix: "data", - Favorites: false, - OCDavInsecure: false, - OCDavPrefix: "", - OCSPrefix: "ocs", - OCSSharePrefix: "/Shares", - OCSHomeNamespace: "/users/{{.Id.OpaqueId}}", - PublicURL: "https://localhost:9200", - OCSCacheWarmupDriver: "", - OCSAdditionalInfoAttribute: "{{.Mail}}", - OCSResourceInfoCacheTTL: 0, - Middleware: Middleware{}, - }, - DataGateway: DataGatewayPort{ - Port: Port{}, - PublicURL: "", - }, - Gateway: Gateway{ - Port: Port{ - Endpoint: "127.0.0.1:9142", - DebugAddr: "127.0.0.1:9143", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9142", - }, - CommitShareToStorageGrant: true, - CommitShareToStorageRef: true, - DisableHomeCreationOnLogin: false, - ShareFolder: "Shares", - LinkGrants: "", - HomeMapping: "", - EtagCacheTTL: 0, - }, - StorageRegistry: StorageRegistry{ - Driver: "spaces", - HomeProvider: "/home", - JSON: "", - }, - AppRegistry: AppRegistry{ - Driver: "static", - MimetypesJSON: "", - }, - Users: Users{ - Port: Port{ - Endpoint: "localhost:9144", - DebugAddr: "127.0.0.1:9145", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9144", - Services: []string{"userprovider"}, - }, - Driver: "ldap", - UserGroupsCacheExpiration: 5, - }, - Groups: Groups{ - Port: Port{ - Endpoint: "localhost:9160", - DebugAddr: "127.0.0.1:9161", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9160", - Services: []string{"groupprovider"}, - }, - Driver: "ldap", - GroupMembersCacheExpiration: 5, - }, - AuthProvider: Users{ - Port: Port{}, - Driver: "ldap", - UserGroupsCacheExpiration: 0, - }, - AuthBasic: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9146", - DebugAddr: "127.0.0.1:9147", - Services: []string{"authprovider"}, - Endpoint: "localhost:9146", - }, - AuthBearer: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9148", - DebugAddr: "127.0.0.1:9149", - Services: []string{"authprovider"}, - Endpoint: "localhost:9148", - }, - AuthMachine: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9166", - DebugAddr: "127.0.0.1:9167", - Services: []string{"authprovider"}, - Endpoint: "localhost:9166", - }, - AuthMachineConfig: AuthMachineConfig{ - MachineAuthAPIKey: "change-me-please", - }, - Sharing: Sharing{ - Port: Port{ - Endpoint: "localhost:9150", - DebugAddr: "127.0.0.1:9151", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9150", - Services: []string{"usershareprovider", "publicshareprovider"}, - }, - UserDriver: "json", - UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), - UserSQLUsername: "", - UserSQLPassword: "", - UserSQLHost: "", - UserSQLPort: 1433, - UserSQLName: "", - PublicDriver: "json", - PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), - PublicPasswordHashCost: 11, - PublicEnableExpiredSharesCleanup: true, - PublicJanitorRunInterval: 60, - UserStorageMountID: "", - }, - StorageShares: StoragePort{ - Port: Port{ - Endpoint: "localhost:9154", - DebugAddr: "127.0.0.1:9156", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9154", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9155", - }, - ReadOnly: false, - AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", - MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - }, - StorageUsers: StoragePort{ - Port: Port{ - Endpoint: "localhost:9157", - DebugAddr: "127.0.0.1:9159", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9157", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9158", - }, - MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - Driver: "ocis", - DataServerURL: "http://localhost:9158/data", - HTTPPrefix: "data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), - }, - StoragePublicLink: PublicStorage{ - StoragePort: StoragePort{ - Port: Port{ - Endpoint: "localhost:9178", - DebugAddr: "127.0.0.1:9179", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9178", - }, - MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", - }, - PublicShareProviderAddr: "", - UserProviderAddr: "", - }, - StorageMetadata: StoragePort{ - Port: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9215", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9216", - DebugAddr: "127.0.0.1:9217", - }, - Driver: "ocis", - ExposeDataServer: false, - DataServerURL: "http://localhost:9216/data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), - DataProvider: DataProvider{}, - }, - AppProvider: AppProvider{ - Port: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9164", - DebugAddr: "127.0.0.1:9165", - Endpoint: "localhost:9164", - Services: []string{"appprovider"}, - }, - ExternalAddr: "127.0.0.1:9164", - WopiDriver: WopiDriver{}, - AppsURL: "/app/list", - OpenURL: "/app/open", - NewURL: "/app/new", - }, - Configs: nil, - UploadMaxChunkSize: 1e+8, - UploadHTTPMethodOverride: "", - ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, - ChecksumPreferredUploadType: "", - DefaultUploadProtocol: "tus", - }, - Tracing: Tracing{ - Service: "storage", - Type: "jaeger", - }, - Asset: Asset{}, - } -} diff --git a/storage/pkg/config/grpc.go b/storage/pkg/config/grpc.go deleted file mode 100644 index 016b61fa919..00000000000 --- a/storage/pkg/config/grpc.go +++ /dev/null @@ -1,7 +0,0 @@ -package config - -// GRPC defines the available grpc configuration. -type GRPC struct { - Addr string `ocisConfig:"addr" env:"SETTINGS_GRPC_ADDR"` - Namespace string -} diff --git a/storage/pkg/config/http.go b/storage/pkg/config/http.go deleted file mode 100644 index f2099febf95..00000000000 --- a/storage/pkg/config/http.go +++ /dev/null @@ -1,18 +0,0 @@ -package config - -// HTTP defines the available http configuration. -type HTTP struct { - Addr string `ocisConfig:"addr" env:"SETTINGS_HTTP_ADDR"` - Namespace string - Root string `ocisConfig:"root" env:"SETTINGS_HTTP_ROOT"` - CacheTTL int `ocisConfig:"cache_ttl" env:"SETTINGS_CACHE_TTL"` - CORS CORS `ocisConfig:"cors"` -} - -// CORS defines the available cors configuration. -type CORS struct { - AllowedOrigins []string `ocisConfig:"allowed_origins"` - AllowedMethods []string `ocisConfig:"allowed_methods"` - AllowedHeaders []string `ocisConfig:"allowed_headers"` - AllowCredentials bool `ocisConfig:"allowed_credentials"` -} diff --git a/storage/pkg/config/log.go b/storage/pkg/config/log.go deleted file mode 100644 index eb14a82e87a..00000000000 --- a/storage/pkg/config/log.go +++ /dev/null @@ -1,9 +0,0 @@ -package config - -// Log defines the available log configuration. -type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;STORAGE_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;STORAGE_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;STORAGE_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;STORAGE_LOG_FILE"` -} diff --git a/storage/pkg/config/reva.go b/storage/pkg/config/reva.go deleted file mode 100644 index 5427747df89..00000000000 --- a/storage/pkg/config/reva.go +++ /dev/null @@ -1,6 +0,0 @@ -package config - -// TokenManager is the config for using the reva token manager -type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;SETTINGS_JWT_SECRET"` -} diff --git a/storage/pkg/config/service.go b/storage/pkg/config/service.go deleted file mode 100644 index c12faf34442..00000000000 --- a/storage/pkg/config/service.go +++ /dev/null @@ -1,7 +0,0 @@ -package config - -// Service defines the available service configuration. -type Service struct { - Name string - Version string -} diff --git a/storage/pkg/config/tracing.go b/storage/pkg/config/tracing.go deleted file mode 100644 index b5c95544455..00000000000 --- a/storage/pkg/config/tracing.go +++ /dev/null @@ -1,10 +0,0 @@ -package config - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_TRACING_ENABLED"` - Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;STORAGE_TRACING_TYPE"` - Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORAGE_TRACING_ENDPOINT"` - Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"STORAGE_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? -} diff --git a/storage/pkg/logging/logging.go b/storage/pkg/logging/logging.go deleted file mode 100644 index c9d44332140..00000000000 --- a/storage/pkg/logging/logging.go +++ /dev/null @@ -1,17 +0,0 @@ -package logging - -import ( - "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/storage/pkg/config" -) - -// LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { - return log.NewLogger( - log.Name(name), - log.Level(cfg.Level), - log.Pretty(cfg.Pretty), - log.Color(cfg.Color), - log.File(cfg.File), - ) -} diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 5c63f8a3eb4..e796cf59093 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -60,17 +60,17 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index bb79327e88d..c8b807bdb1e 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` GRPC GRPC `ocisConfig:"grpc"` diff --git a/store/pkg/config/defaultconfig.go b/store/pkg/config/defaultconfig.go index 4ba99550cef..66e44044d37 100644 --- a/store/pkg/config/defaultconfig.go +++ b/store/pkg/config/defaultconfig.go @@ -26,7 +26,6 @@ func DefaultConfig() *Config { Type: "jaeger", Endpoint: "", Collector: "", - Service: "store", }, Datapath: path.Join(defaults.BaseDataPath(), "store"), } diff --git a/store/pkg/config/tracing.go b/store/pkg/config/tracing.go index a54001c94f9..7e1ba182188 100644 --- a/store/pkg/config/tracing.go +++ b/store/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;STORE_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORE_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;STORE_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"STORE_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/store/pkg/logging/logging.go b/store/pkg/logging/logging.go index e6183eb1826..c5c6d452048 100644 --- a/store/pkg/logging/logging.go +++ b/store/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/store/pkg/tracing/tracing.go b/store/pkg/tracing/tracing.go index b6f66479ff7..54eef8ca32b 100644 --- a/store/pkg/tracing/tracing.go +++ b/store/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "store", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 57428daac6b..eae5eed508a 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -61,16 +61,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -93,7 +93,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.Thumbnails.Commons = cfg.Commons + cfg.Thumbnails.Commons = cfg.Commons return SutureService{ cfg: cfg.Thumbnails, } diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index fff16e78b5d..b06e4a723e2 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` GRPC GRPC `ocisConfig:"grpc"` diff --git a/thumbnails/pkg/config/defaultconfig.go b/thumbnails/pkg/config/defaultconfig.go index d06ee1c34d1..ac2da94d295 100644 --- a/thumbnails/pkg/config/defaultconfig.go +++ b/thumbnails/pkg/config/defaultconfig.go @@ -26,7 +26,6 @@ func DefaultConfig() *Config { Type: "jaeger", Endpoint: "", Collector: "", - Service: "thumbnails", }, Thumbnail: Thumbnail{ Resolutions: []string{"16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"}, diff --git a/thumbnails/pkg/config/tracing.go b/thumbnails/pkg/config/tracing.go index e118e153039..bbb13435cbb 100644 --- a/thumbnails/pkg/config/tracing.go +++ b/thumbnails/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;THUMBNAILS_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;THUMBNAILS_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;THUMBNAILS_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"THUMBNAILS_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/thumbnails/pkg/logging/logging.go b/thumbnails/pkg/logging/logging.go index e097814b271..41d5583269d 100644 --- a/thumbnails/pkg/logging/logging.go +++ b/thumbnails/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/thumbnails/pkg/tracing/tracing.go b/thumbnails/pkg/tracing/tracing.go index 6bbd7afc844..16db3bb6fd5 100644 --- a/thumbnails/pkg/tracing/tracing.go +++ b/thumbnails/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "thumbnails", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 0a7e731c662..11c6b5ffa55 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -59,16 +59,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -91,7 +91,7 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.Web.Commons = cfg.Commons + cfg.Web.Commons = cfg.Commons return SutureService{ cfg: cfg.Web, } diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 6a1ef7eaba8..df0f7ab6dde 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -1,13 +1,19 @@ package config -import "context" +import ( + "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/web/pkg/config/defaultconfig.go b/web/pkg/config/defaultconfig.go index a41d1af4dde..42f22beda3d 100644 --- a/web/pkg/config/defaultconfig.go +++ b/web/pkg/config/defaultconfig.go @@ -22,7 +22,6 @@ func DefaultConfig() *Config { Type: "jaeger", Endpoint: "", Collector: "", - Service: "web", }, Asset: Asset{ Path: "", diff --git a/web/pkg/config/tracing.go b/web/pkg/config/tracing.go index c6bb6569ad2..6c54223d6aa 100644 --- a/web/pkg/config/tracing.go +++ b/web/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEB_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEB_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEB_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"WEB_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/web/pkg/logging/logging.go b/web/pkg/logging/logging.go index 6510b8c21a8..57616a43b66 100644 --- a/web/pkg/logging/logging.go +++ b/web/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/web/pkg/tracing/tracing.go b/web/pkg/tracing/tracing.go index 1bd7caf66ab..cebc588bd0a 100644 --- a/web/pkg/tracing/tracing.go +++ b/web/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "web", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 15d0db36912..f2ec6221af7 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -59,16 +59,16 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - //if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - // cfg.Log = &shared.Log{ - // Level: cfg.Commons.Log.Level, - // Pretty: cfg.Commons.Log.Pretty, - // Color: cfg.Commons.Log.Color, - // File: cfg.Commons.Log.File, - // } - //} else if cfg.Log == nil && cfg.Commons == nil { - // cfg.Log = &shared.Log{} - //} + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } // load all env variables relevant to the config in the current context. envCfg := config.Config{} @@ -91,7 +91,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.Proxy.Commons = cfg.Commons + cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.WebDAV, } diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index af5df5a5b5f..d8e9ebe7cfc 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -2,14 +2,18 @@ package config import ( "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Config combines all available configuration parts. type Config struct { + *shared.Commons + Service Service Tracing Tracing `ocisConfig:"tracing"` - Log Log `ocisConfig:"log"` + Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` HTTP HTTP `ocisConfig:"http"` diff --git a/webdav/pkg/config/defaultconfig.go b/webdav/pkg/config/defaultconfig.go index 38d6f76946e..dcd3c04f9ef 100644 --- a/webdav/pkg/config/defaultconfig.go +++ b/webdav/pkg/config/defaultconfig.go @@ -27,7 +27,6 @@ func DefaultConfig() *Config { Type: "jaeger", Endpoint: "", Collector: "", - Service: "webdav", }, OcisPublicURL: "https://127.0.0.1:9200", WebdavNamespace: "/users/{{.Id.OpaqueId}}", diff --git a/webdav/pkg/config/tracing.go b/webdav/pkg/config/tracing.go index f63b2480d83..311e5fbc02d 100644 --- a/webdav/pkg/config/tracing.go +++ b/webdav/pkg/config/tracing.go @@ -6,5 +6,4 @@ type Tracing struct { Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE;WEBDAV_TRACING_TYPE"` Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEBDAV_TRACING_ENDPOINT"` Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;WEBDAV_TRACING_COLLECTOR"` - Service string `ocisConfig:"service" env:"WEBDAV_TRACING_SERVICE"` //TODO: should this be an ID? or the same as Service.Name? } diff --git a/webdav/pkg/logging/logging.go b/webdav/pkg/logging/logging.go index 11c8f85aafb..ff82b1f6bfc 100644 --- a/webdav/pkg/logging/logging.go +++ b/webdav/pkg/logging/logging.go @@ -6,7 +6,7 @@ import ( ) // LoggerFromConfig initializes a service-specific logger instance. -func Configure(name string, cfg config.Log) log.Logger { +func Configure(name string, cfg *config.Log) log.Logger { return log.NewLogger( log.Name(name), log.Level(cfg.Level), diff --git a/webdav/pkg/tracing/tracing.go b/webdav/pkg/tracing/tracing.go index f3efeecd004..8a2c5392911 100644 --- a/webdav/pkg/tracing/tracing.go +++ b/webdav/pkg/tracing/tracing.go @@ -14,7 +14,7 @@ var ( func Configure(cfg *config.Config) error { var err error if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "webdav", cfg.Tracing.Type); err != nil { + if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { return err } } From e006ad6e40fe912ca623b97d0f40cc2a59b2a1eb Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 16:54:26 +0100 Subject: [PATCH 48/84] directly pass env to config --- accounts/pkg/command/root.go | 9 +-------- glauth/pkg/command/root.go | 9 +-------- go.mod | 2 +- graph-explorer/pkg/command/root.go | 11 ++--------- graph/pkg/command/root.go | 9 +-------- idp/pkg/command/root.go | 9 +-------- ocs/pkg/command/root.go | 9 +-------- proxy/pkg/command/root.go | 9 +-------- settings/pkg/command/root.go | 9 +-------- store/pkg/command/root.go | 11 ++--------- thumbnails/pkg/command/root.go | 10 +--------- web/pkg/command/root.go | 9 +-------- webdav/pkg/command/root.go | 9 +-------- 13 files changed, 15 insertions(+), 100 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 366abad0fd7..b8448000767 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" "github.com/owncloud/ocis/accounts/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" @@ -79,13 +78,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 3b16d07a21a..e46b8c014c6 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" "github.com/owncloud/ocis/glauth/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" @@ -71,13 +70,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/go.mod b/go.mod index 4461af23bb9..437bedcc8d7 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,6 @@ require ( github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.2 github.com/iancoleman/strcase v0.2.0 - github.com/imdario/mergo v0.3.12 github.com/justinas/alice v1.2.0 github.com/libregraph/lico v0.53.1 github.com/mennanov/fieldmask-utils v0.5.0 @@ -152,6 +151,7 @@ require ( github.com/hashicorp/go-plugin v1.4.3 // indirect github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect github.com/huandu/xstrings v1.3.2 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index f99e3eaf343..034fb7ea243 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" "github.com/owncloud/ocis/graph-explorer/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" @@ -56,7 +55,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { cfg.Log = &config.Log{ Level: cfg.Commons.Log.Level, @@ -69,13 +68,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 2492597ef82..5df88df4633 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" "github.com/thejerf/suture/v4" "github.com/wkloucek/envdecode" @@ -70,13 +69,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index ec61ab260d5..85fda3c5218 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" "github.com/owncloud/ocis/idp/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" @@ -72,13 +71,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 141bc1bdadc..8d24d1bd6a2 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config" @@ -73,13 +72,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 1d771d9cb6c..0d20391354e 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" @@ -72,13 +71,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index fb7c930cb70..bbddc89444b 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/config" @@ -73,13 +72,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index e796cf59093..d10f4cb4dd6 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" @@ -60,7 +59,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { cfg.Log = &config.Log{ Level: cfg.Commons.Log.Level, @@ -73,13 +72,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index eae5eed508a..4e24303e589 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/thumbnails/pkg/config" @@ -73,16 +72,9 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { - return err - } - return nil } diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 11c6b5ffa55..4d1c6249aeb 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/web/pkg/config" @@ -71,13 +70,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index f2ec6221af7..9df612006fd 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/imdario/mergo" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/webdav/pkg/config" @@ -71,13 +70,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - envCfg := config.Config{} - if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err - } - - // merge environment variable config on top of the current config - if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil { + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { return err } From e3611324352d52dceeab15280ac7d97615eef40a Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 16:58:36 +0100 Subject: [PATCH 49/84] move accounts config sanitazing into config parsing --- accounts/pkg/command/root.go | 7 +++++++ accounts/pkg/command/server.go | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index b8448000767..b2f4740b1c4 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -3,6 +3,7 @@ package command import ( "context" "os" + "strings" "github.com/owncloud/ocis/accounts/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -82,6 +83,12 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) + return nil } diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index aa2c1b0c310..44feb3ffe65 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -2,7 +2,6 @@ package command import ( "context" - "strings" "github.com/oklog/run" "github.com/owncloud/ocis/accounts/pkg/config" @@ -22,16 +21,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "Start ocis accounts service", Description: "uses an LDAP server as the storage backend", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - if err := ParseConfig(ctx, cfg); err != nil { return err } - cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) - return nil }, Action: func(c *cli.Context) error { From 61ff46b29c7d9d3093ea83fca39e03885c8d91f4 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:11:31 +0100 Subject: [PATCH 50/84] fix unit tests --- .../pkg/proto/v0/accounts.pb.micro_test.go | 18 ++++++++++++------ ocis-pkg/crypto/crypto_test.go | 2 +- ocs/pkg/server/http/svc_test.go | 4 ++-- proxy/pkg/proxy/proxy_integration_test.go | 4 +--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index b8e3eeb4d8a..003746f4f1c 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -13,11 +13,10 @@ import ( mgrpcc "github.com/asim/go-micro/plugins/client/grpc/v4" empty "github.com/golang/protobuf/ptypes/empty" "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/logging" "github.com/owncloud/ocis/accounts/pkg/proto/v0" svc "github.com/owncloud/ocis/accounts/pkg/service/v0" - oclog "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/service/grpc" - "github.com/owncloud/ocis/ocis-pkg/shared" settings "github.com/owncloud/ocis/settings/pkg/proto/v0" "github.com/stretchr/testify/assert" "go-micro.dev/v4/client" @@ -83,10 +82,17 @@ func init() { cfg.Repo.Backend = "disk" cfg.Repo.Disk.Path = dataPath cfg.DemoUsersAndGroups = true + cfg.Log = &config.Log{} var hdlr *svc.Service var err error - if hdlr, err = svc.New(svc.Logger(oclog.LoggerFromConfig("accounts", shared.Log(cfg.Log))), svc.Config(cfg), svc.RoleService(buildRoleServiceMock())); err != nil { + hdlr, err = svc.New( + svc.Logger(logging.Configure(cfg.Service.Name, cfg.Log)), + svc.Config(cfg), + svc.RoleService(buildRoleServiceMock()), + ) + + if err != nil { log.Fatalf("Could not create new service") } @@ -494,7 +500,7 @@ func TestUpdateAccount(t *testing.T) { GidNumber: 30001, Mail: "एलिस@उदाहरण.com", }, - merrors.BadRequest(".", "preferred_name 'अद्भुत-एलिस' must be at least the local part of an email"), + merrors.BadRequest("com.owncloud.api.accounts", "preferred_name 'अद्भुत-एलिस' must be at least the local part of an email"), }, { "Update user with empty data values", @@ -506,7 +512,7 @@ func TestUpdateAccount(t *testing.T) { GidNumber: 0, Mail: "", }, - merrors.BadRequest(".", "preferred_name '' must be at least the local part of an email"), + merrors.BadRequest("com.owncloud.api.accounts", "preferred_name '' must be at least the local part of an email"), }, { "Update user with strange data", @@ -518,7 +524,7 @@ func TestUpdateAccount(t *testing.T) { GidNumber: 1000, Mail: "1.2@3.c_@", }, - merrors.BadRequest(".", "mail '1.2@3.c_@' must be a valid email"), + merrors.BadRequest("com.owncloud.api.accounts", "mail '1.2@3.c_@' must be a valid email"), }, } diff --git a/ocis-pkg/crypto/crypto_test.go b/ocis-pkg/crypto/crypto_test.go index 9bfa55274cc..328607ba9e2 100644 --- a/ocis-pkg/crypto/crypto_test.go +++ b/ocis-pkg/crypto/crypto_test.go @@ -16,7 +16,7 @@ var _ = Describe("Crypto", func() { var ( userConfigDir string err error - config = cfg.New() + config = cfg.DefaultConfig() ) BeforeEach(func() { diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 70ee85ff258..b01095589cb 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -563,7 +563,7 @@ func init() { Path: dataPath, }, }, - Log: accountsCfg.Log{ + Log: &accountsCfg.Log{ Level: "info", Pretty: true, Color: true, @@ -710,7 +710,7 @@ func getService() svc.Service { TokenManager: config.TokenManager{ JWTSecret: jwtSecret, }, - Log: config.Log{ + Log: &config.Log{ Level: "debug", }, } diff --git a/proxy/pkg/proxy/proxy_integration_test.go b/proxy/pkg/proxy/proxy_integration_test.go index 9809383a67e..0137b4413e7 100644 --- a/proxy/pkg/proxy/proxy_integration_test.go +++ b/proxy/pkg/proxy/proxy_integration_test.go @@ -10,8 +10,6 @@ import ( "net/url" "testing" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/owncloud/ocis/proxy/pkg/config" ) @@ -215,7 +213,7 @@ func (tc *testCase) expectProxyTo(strURL string) testCase { func testConfig(policy []config.Policy) *config.Config { return &config.Config{ - Log: &shared.Log{}, + Log: &config.Log{}, Debug: config.Debug{}, HTTP: config.HTTP{}, Tracing: config.Tracing{}, From 342da01c9b53151449c2eb3cbe21ae3f028e6ffe Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:19:47 +0100 Subject: [PATCH 51/84] bring back missing commands --- ocis/pkg/command/graph.go | 3 +++ ocis/pkg/command/graphexplorer.go | 3 +++ ocis/pkg/command/storageauthmachine.go | 3 +++ storage/pkg/command/root.go | 1 + 4 files changed, 10 insertions(+) diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index ecc94826caa..1b1ae5553dc 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -1,3 +1,6 @@ +//go:build !simple +// +build !simple + package command import ( diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index 7833206b916..e4dc82e0247 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -1,3 +1,6 @@ +//go:build !simple +// +build !simple + package command import ( diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 18b9d8a183e..9498c7a017a 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -1,3 +1,6 @@ +//go:build !simple +// +build !simple + package command import ( diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 7de4fc5aa56..80e16d0719e 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -35,6 +35,7 @@ func Execute(cfg *config.Config) error { AppProvider(cfg), AuthBasic(cfg), AuthBearer(cfg), + AuthMachine(cfg), Sharing(cfg), StorageUsers(cfg), StorageShares(cfg), From ae565846c2d7b798a24fbed8b84aec0facc0d050 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:40:35 +0100 Subject: [PATCH 52/84] gix graph url --- graph/pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 03ec948bb36..c7fa9e0891f 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -29,7 +29,7 @@ type Config struct { } type Spaces struct { - WebDavBase string `ocisConfig:"webdav_base" env:"GRAPH_SPACES_WEBDAV_BASE"` + WebDavBase string `ocisConfig:"webdav_base" env:"OCIS_URL;GRAPH_SPACES_WEBDAV_BASE"` WebDavPath string `ocisConfig:"webdav_path" env:"GRAPH_SPACES_WEBDAV_PATH"` DefaultQuota string `ocisConfig:"default_quota" env:"GRAPH_SPACES_DEFAULT_QUOTA"` } From 41403d79521f0338e05b3774d792a2857965a9a5 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:59:26 +0100 Subject: [PATCH 53/84] fix some TODOs --- idp/pkg/config/config.go | 18 +++++++++--------- ocis-pkg/indexer/index/cs3/config.go | 1 - proxy/pkg/cs3/client.go | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 426c34dd481..420dc78886e 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -76,23 +76,23 @@ type Settings struct { EncryptionSecretFile string `ocisConfig:"encrypt_secret_file" env:"IDP_ENCRYPTION_SECRET"` - Listen string `ocisConfig:"listen"` //TODO: is this even needed? + Listen string IdentifierClientDisabled bool `ocisConfig:"identifier_client_disabled" env:"IDP_DISABLE_IDENTIFIER_WEBAPP"` IdentifierClientPath string `ocisConfig:"identifier_client_path" env:"IDP_IDENTIFIER_CLIENT_PATH"` IdentifierRegistrationConf string `ocisConfig:"identifier_registration_conf" env:"IDP_IDENTIFIER_REGISTRATION_CONF"` IdentifierScopesConf string `ocisConfig:"identifier_scopes_conf" env:"IDP_IDENTIFIER_SCOPES_CONF"` - IdentifierDefaultBannerLogo string `ocisConfig:"identifier_default_banner_logo"` // TODO: is this even needed? - IdentifierDefaultSignInPageText string `ocisConfig:"identifier_default_sign_in_page_text"` // TODO: is this even needed? - IdentifierDefaultUsernameHintText string `ocisConfig:"identifier_default_username_hint_text"` // TODO: is this even needed? + IdentifierDefaultBannerLogo string + IdentifierDefaultSignInPageText string + IdentifierDefaultUsernameHintText string - SigningKid string `ocisConfig:"sign_in_kid" env:"IDP_SIGNING_KID"` - SigningMethod string `ocisConfig:"sign_in_method" env:"IDP_SIGNING_METHOD"` - SigningPrivateKeyFiles []string `ocisConfig:"sign_in_private_key_files"` // TODO: is this even needed? + SigningKid string `ocisConfig:"signing_kid" env:"IDP_SIGNING_KID"` + SigningMethod string `ocisConfig:"signing_method" env:"IDP_SIGNING_METHOD"` + SigningPrivateKeyFiles []string `ocisConfig:"signing_private_key_files"` // TODO: is this even needed? ValidationKeysPath string `ocisConfig:"validation_keys_path" env:"IDP_VALIDATION_KEYS_PATH"` - CookieBackendURI string `ocisConfig:"cookie_backend_uri"` // TODO: is this even needed? - CookieNames []string `ocisConfig:"cookie_names"` // TODO: is this even needed? + CookieBackendURI string + CookieNames []string AccessTokenDurationSeconds uint64 `ocisConfig:"access_token_duration_seconds" env:"IDP_ACCESS_TOKEN_EXPIRATION"` IDTokenDurationSeconds uint64 `ocisConfig:"id_token_duration_seconds" env:"IDP_ID_TOKEN_EXPIRATION"` diff --git a/ocis-pkg/indexer/index/cs3/config.go b/ocis-pkg/indexer/index/cs3/config.go index 9326de762e8..430927d4c6f 100644 --- a/ocis-pkg/indexer/index/cs3/config.go +++ b/ocis-pkg/indexer/index/cs3/config.go @@ -4,7 +4,6 @@ import ( acccfg "github.com/owncloud/ocis/accounts/pkg/config" ) -//TODO: remove? // Config represents cs3conf. Should be deprecated in favor of config.Config. type Config struct { ProviderAddr string diff --git a/proxy/pkg/cs3/client.go b/proxy/pkg/cs3/client.go index dbaaa03ae9b..bf8d19871d5 100644 --- a/proxy/pkg/cs3/client.go +++ b/proxy/pkg/cs3/client.go @@ -5,12 +5,13 @@ import ( proxytracing "github.com/owncloud/ocis/proxy/pkg/tracing" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) func newConn(endpoint string) (*grpc.ClientConn, error) { conn, err := grpc.Dial( endpoint, - grpc.WithInsecure(), //TODO: depreciated + grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor( otelgrpc.UnaryClientInterceptor( otelgrpc.WithTracerProvider( From 45ec244aecf4ff474240bdeabbd33741672721ad Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 18:07:33 +0100 Subject: [PATCH 54/84] don't expose not used config via env --- glauth/pkg/config/config.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 6292cfc3506..f5a1bc55031 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -30,24 +30,24 @@ type Config struct { // Backend defined the available backend configuration. type Backend struct { - Datastore string `ocisConfig:"datastore" env:"GLAUTH_BACKEND_DATASTORE"` - BaseDN string `ocisConfig:"base_dn" env:"GLAUTH_BACKEND_BASEDN"` - Insecure bool `ocisConfig:"insecure" env:"GLAUTH_BACKEND_INSECURE"` - NameFormat string `ocisConfig:"name_format" env:"GLAUTH_BACKEND_NAME_FORMAT"` - GroupFormat string `ocisConfig:"group_format" env:"GLAUTH_BACKEND_GROUP_FORMAT"` - Servers []string `ocisConfig:"servers"` //TODO: how to configure this via env? - SSHKeyAttr string `ocisConfig:"ssh_key_attr" env:"GLAUTH_BACKEND_SSH_KEY_ATTR"` - UseGraphAPI bool `ocisConfig:"use_graph_api" env:"GLAUTH_BACKEND_USE_GRAPHAPI"` + Datastore string `ocisConfig:"datastore"` + BaseDN string `ocisConfig:"base_dn"` + Insecure bool `ocisConfig:"insecure"` + NameFormat string `ocisConfig:"name_format"` + GroupFormat string `ocisConfig:"group_format"` + Servers []string `ocisConfig:"servers"` + SSHKeyAttr string `ocisConfig:"ssh_key_attr"` + UseGraphAPI bool `ocisConfig:"use_graph_api"` } // FallbackBackend defined the available fallback backend configuration. type FallbackBackend struct { - Datastore string `ocisConfig:"datastore" env:"GLAUTH_FALLBACK_DATASTORE"` - BaseDN string `ocisConfig:"base_dn" env:"GLAUTH_FALLBACK_BASEDN"` - Insecure bool `ocisConfig:"insecure" env:"GLAUTH_FALLBACK_INSECURE"` - NameFormat string `ocisConfig:"name_format" env:"GLAUTH_FALLBACK_NAME_FORMAT"` - GroupFormat string `ocisConfig:"group_format" env:"GLAUTH_FALLBACK_GROUP_FORMAT"` - Servers []string `ocisConfig:"servers"` //TODO: how to configure this via env? - SSHKeyAttr string `ocisConfig:"ssh_key_attr" env:"GLAUTH_FALLBACK_SSH_KEY_ATTR"` - UseGraphAPI bool `ocisConfig:"use_graph_api" env:"GLAUTH_FALLBACK_USE_GRAPHAPI"` + Datastore string `ocisConfig:"datastore"` + BaseDN string `ocisConfig:"base_dn"` + Insecure bool `ocisConfig:"insecure"` + NameFormat string `ocisConfig:"name_format"` + GroupFormat string `ocisConfig:"group_format"` + Servers []string `ocisConfig:"servers"` + SSHKeyAttr string `ocisConfig:"ssh_key_attr"` + UseGraphAPI bool `ocisConfig:"use_graph_api"` } From 412dadac45dd58aa2fa5643cf32d48cc1303ffd5 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 18:09:49 +0100 Subject: [PATCH 55/84] resolve thumbnails TODOs --- thumbnails/pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index b06e4a723e2..51c0972480a 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -36,7 +36,7 @@ type FileSystemSource struct { // Thumbnail defines the available thumbnail related configuration. type Thumbnail struct { - Resolutions []string `ocisConfig:"resolutions"` // TODO: how to configure + Resolutions []string `ocisConfig:"resolutions"` FileSystemStorage FileSystemStorage `ocisConfig:"filesystem_storage"` WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_WEBDAVSOURCE_INSECURE"` CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_CS3SOURCE_INSECURE"` From 21ed07d90b307d49704bce8b0808e2e0b3520088 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 18:27:29 +0100 Subject: [PATCH 56/84] migrate ocis-pkg to envdecode --- ocis-pkg/config/config.go | 113 +--------------------------- ocis-pkg/config/defaultconfig.go | 42 +++++++++++ ocis-pkg/shared/shared_types.go | 22 +++--- ocis/pkg/command/root.go | 13 ++-- ocis/pkg/runtime/service/service.go | 8 +- 5 files changed, 68 insertions(+), 130 deletions(-) create mode 100644 ocis-pkg/config/defaultconfig.go diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index bdd6cd54974..d0cd0e1d2dc 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -18,17 +18,9 @@ import ( webdav "github.com/owncloud/ocis/webdav/pkg/config" ) -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` -} - // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET"` } const ( @@ -43,9 +35,9 @@ type Mode int // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { - Port string `ocisConfig:"port"` - Host string `ocisConfig:"host"` - Extensions string `ocisConfig:"extensions"` + Port string `ocisConfig:"port" env:"OCIS_RUNTIME_PORT"` + Host string `ocisConfig:"host" env:"OCIS_RUNTIME_HOST"` + Extensions string `ocisConfig:"extensions" env:"OCIS_RUN_EXTENSIONS"` } // Config combines all available configuration parts. @@ -77,100 +69,3 @@ type Config struct { Thumbnails *thumbnails.Config `ocisConfig:"thumbnails"` WebDAV *webdav.Config `ocisConfig:"webdav"` } - -func DefaultConfig() *Config { - return &Config{ - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - Runtime: Runtime{ - Port: "9250", - Host: "localhost", - }, - Accounts: accounts.DefaultConfig(), - GLAuth: glauth.DefaultConfig(), - Graph: graph.DefaultConfig(), - IDP: idp.DefaultConfig(), - Proxy: proxy.DefaultConfig(), - GraphExplorer: graphExplorer.DefaultConfig(), - OCS: ocs.DefaultConfig(), - Settings: settings.DefaultConfig(), - Web: web.DefaultConfig(), - Store: store.DefaultConfig(), - Thumbnails: thumbnails.DefaultConfig(), - WebDAV: webdav.DefaultConfig(), - Storage: storage.DefaultConfig(), - } -} - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv() []string { - var r = make([]string, len(structMappings(&Config{}))) - for i := range structMappings(&Config{}) { - r = append(r, structMappings(&Config{})[i].EnvVars...) - } - - return r -} - -// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the -// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets -// us propagate changes easier. -func StructMappings(cfg *Config) []shared.EnvBinding { - return structMappings(cfg) -} - -func structMappings(cfg *Config) []shared.EnvBinding { - return []shared.EnvBinding{ - // TODO: transform this too - { - EnvVars: []string{"OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - { - EnvVars: []string{"OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - { - EnvVars: []string{"OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - { - EnvVars: []string{"OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - { - EnvVars: []string{"OCIS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - { - EnvVars: []string{"OCIS_RUNTIME_PORT"}, - Destination: &cfg.Runtime.Port, - }, - { - EnvVars: []string{"OCIS_RUNTIME_HOST"}, - Destination: &cfg.Runtime.Host, - }, - { - EnvVars: []string{"OCIS_RUN_EXTENSIONS"}, - Destination: &cfg.Runtime.Extensions, - }, - } -} diff --git a/ocis-pkg/config/defaultconfig.go b/ocis-pkg/config/defaultconfig.go new file mode 100644 index 00000000000..21cf14ba050 --- /dev/null +++ b/ocis-pkg/config/defaultconfig.go @@ -0,0 +1,42 @@ +package config + +import ( + accounts "github.com/owncloud/ocis/accounts/pkg/config" + glauth "github.com/owncloud/ocis/glauth/pkg/config" + graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/config" + graph "github.com/owncloud/ocis/graph/pkg/config" + idp "github.com/owncloud/ocis/idp/pkg/config" + ocs "github.com/owncloud/ocis/ocs/pkg/config" + proxy "github.com/owncloud/ocis/proxy/pkg/config" + settings "github.com/owncloud/ocis/settings/pkg/config" + storage "github.com/owncloud/ocis/storage/pkg/config" + store "github.com/owncloud/ocis/store/pkg/config" + thumbnails "github.com/owncloud/ocis/thumbnails/pkg/config" + web "github.com/owncloud/ocis/web/pkg/config" + webdav "github.com/owncloud/ocis/webdav/pkg/config" +) + +func DefaultConfig() *Config { + return &Config{ + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + Runtime: Runtime{ + Port: "9250", + Host: "localhost", + }, + Accounts: accounts.DefaultConfig(), + GLAuth: glauth.DefaultConfig(), + Graph: graph.DefaultConfig(), + IDP: idp.DefaultConfig(), + Proxy: proxy.DefaultConfig(), + GraphExplorer: graphExplorer.DefaultConfig(), + OCS: ocs.DefaultConfig(), + Settings: settings.DefaultConfig(), + Web: web.DefaultConfig(), + Store: store.DefaultConfig(), + Thumbnails: thumbnails.DefaultConfig(), + WebDAV: webdav.DefaultConfig(), + Storage: storage.DefaultConfig(), + } +} diff --git a/ocis-pkg/shared/shared_types.go b/ocis-pkg/shared/shared_types.go index 25aa9626960..268c596b0be 100644 --- a/ocis-pkg/shared/shared_types.go +++ b/ocis-pkg/shared/shared_types.go @@ -10,24 +10,24 @@ type EnvBinding struct { // Log defines the available logging configuration. type Log struct { - Level string `mapstructure:"level"` - Pretty bool `mapstructure:"pretty"` - Color bool `mapstructure:"color"` - File string `mapstructure:"file"` + Level string `ocisConfig:"level" env:"OCIS_LOG_LEVEL"` + Pretty bool `ocisConfig:"pretty" env:"OCIS_LOG_PRETTY"` + Color bool `ocisConfig:"color" env:"OCIS_LOG_COLOR"` + File string `ocisConfig:"file" env:"OCIS_LOG_FILE"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `ocisConfig:"enabled"` - Type string `ocisConfig:"type"` - Endpoint string `ocisConfig:"endpoint"` - Collector string `ocisConfig:"collector"` + Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED"` + Type string `ocisConfig:"type" env:"OCIS_TRACING_TYPE"` + Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT"` + Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR"` } // Commons holds configuration that are common to all extensions. Each extension can then decide whether // to overwrite its values. type Commons struct { - *Log `mapstructure:"log"` - Tracing `mapstrucuture:"log"` - OcisURL string `mapstructure:"ocis_url"` + Log *Log `ocisConfig:"log"` + Tracing *Tracing `ocisConfig:"tracing"` + OcisURL string `ocisConfig:"ocis_url" env:"OCIS_URL"` } diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index ffcbba1b6db..09d7e63fbf3 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -8,6 +8,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" + "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis command. @@ -55,15 +56,15 @@ func Execute() error { // ParseConfig loads ocis configuration. func ParseConfig(c *cli.Context, cfg *config.Config) error { - conf, err := ociscfg.BindSourcesToStructs("ocis", cfg) + _, err := ociscfg.BindSourcesToStructs("ocis", cfg) if err != nil { return err } - // TODO: use envconfig here too - - conf.LoadOSEnv(config.GetEnv(), false) + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { + return err + } - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + return nil } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index c66b07c3fd1..fa7c68586b9 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -168,10 +168,10 @@ func Start(o ...Option) error { s.cfg.Storage.Log = &shared.Log{} } - s.cfg.Storage.Log.Color = s.cfg.Commons.Color - s.cfg.Storage.Log.Level = s.cfg.Commons.Level - s.cfg.Storage.Log.Pretty = s.cfg.Commons.Pretty - s.cfg.Storage.Log.File = s.cfg.Commons.File + s.cfg.Storage.Log.Color = s.cfg.Commons.Log.Color + s.cfg.Storage.Log.Level = s.cfg.Commons.Log.Level + s.cfg.Storage.Log.Pretty = s.cfg.Commons.Log.Pretty + s.cfg.Storage.Log.File = s.cfg.Commons.Log.File if err = rpc.Register(s); err != nil { if s != nil { From 5034e399bb9ba80b32c5631bbf6de478f2d8b5fc Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 21 Dec 2021 10:25:09 +0100 Subject: [PATCH 57/84] maintain envdecode inside ocis-pkg --- accounts/pkg/command/root.go | 2 +- glauth/pkg/command/root.go | 2 +- go.mod | 1 - go.sum | 2 - graph-explorer/pkg/command/root.go | 2 +- graph/pkg/command/root.go | 2 +- idp/pkg/command/root.go | 2 +- ocis-pkg/config/envdecode/LICENSE | 21 + ocis-pkg/config/envdecode/README.md | 88 +++ ocis-pkg/config/envdecode/envdecode.go | 431 +++++++++++ ocis-pkg/config/envdecode/envdecode_test.go | 795 ++++++++++++++++++++ ocis/pkg/command/root.go | 2 +- ocs/pkg/command/root.go | 2 +- proxy/pkg/command/root.go | 2 +- settings/pkg/command/root.go | 2 +- store/pkg/command/root.go | 2 +- thumbnails/pkg/command/root.go | 2 +- web/pkg/command/root.go | 2 +- webdav/pkg/command/root.go | 2 +- 19 files changed, 1348 insertions(+), 16 deletions(-) create mode 100644 ocis-pkg/config/envdecode/LICENSE create mode 100644 ocis-pkg/config/envdecode/README.md create mode 100644 ocis-pkg/config/envdecode/envdecode.go create mode 100644 ocis-pkg/config/envdecode/envdecode_test.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index b2f4740b1c4..c6d70c96dbb 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -7,10 +7,10 @@ import ( "github.com/owncloud/ocis/accounts/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-accounts command. diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index e46b8c014c6..5fe6aefdc94 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -6,10 +6,10 @@ import ( "github.com/owncloud/ocis/glauth/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-glauth command. diff --git a/go.mod b/go.mod index 437bedcc8d7..11d4291d949 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,6 @@ require ( github.com/stretchr/testify v1.7.0 github.com/thejerf/suture/v4 v4.0.1 github.com/urfave/cli/v2 v2.3.0 - github.com/wkloucek/envdecode v0.0.0-20211216135343-360f0d3c2679 go-micro.dev/v4 v4.5.0 go.opencensus.io v0.23.0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0 diff --git a/go.sum b/go.sum index c5a01f9029c..9e230717d1e 100644 --- a/go.sum +++ b/go.sum @@ -1316,8 +1316,6 @@ github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgq github.com/vultr/govultr/v2 v2.0.0/go.mod h1:2PsEeg+gs3p/Fo5Pw8F9mv+DUBEOlrNZ8GmCTGmhOhs= github.com/wk8/go-ordered-map v0.2.0 h1:KlvGyHstD1kkGZkPtHCyCfRYS0cz84uk6rrW/Dnhdtk= github.com/wk8/go-ordered-map v0.2.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= -github.com/wkloucek/envdecode v0.0.0-20211216135343-360f0d3c2679 h1:aFJVdr5Lo6QrfgW4nlmguvATkSp+iOfIg6rcdTfu9eM= -github.com/wkloucek/envdecode v0.0.0-20211216135343-360f0d3c2679/go.mod h1:lEir1NV8XGJ16mCsne3GrW6MbiQyhf5WUk55kvu9rYs= github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= github.com/xanzy/ssh-agent v0.3.1 h1:AmzO1SSWxw73zxFZPRwaMN1MohDw8UyHnmuxyceTEGo= github.com/xanzy/ssh-agent v0.3.1/go.mod h1:QIE4lCeL7nkC25x+yA3LBIYfwCc1TFziCtG7cBAac6w= diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 034fb7ea243..6b0fbedf8fd 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -6,10 +6,10 @@ import ( "github.com/owncloud/ocis/graph-explorer/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the graph-explorer command. diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 5df88df4633..565aa710fb9 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -4,8 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/thejerf/suture/v4" - "github.com/wkloucek/envdecode" "github.com/owncloud/ocis/graph/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 85fda3c5218..c59652ff43d 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -6,10 +6,10 @@ import ( "github.com/owncloud/ocis/idp/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-idp command. diff --git a/ocis-pkg/config/envdecode/LICENSE b/ocis-pkg/config/envdecode/LICENSE new file mode 100644 index 00000000000..5869b24ec6a --- /dev/null +++ b/ocis-pkg/config/envdecode/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Joe Shaw + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ocis-pkg/config/envdecode/README.md b/ocis-pkg/config/envdecode/README.md new file mode 100644 index 00000000000..8e7ae860e27 --- /dev/null +++ b/ocis-pkg/config/envdecode/README.md @@ -0,0 +1,88 @@ +`envdecode` is a Go package for populating structs from environment +variables. It's basically a fork of https://github.com/joeshaw/envdecode, +but changed to support multiple environment variables (precedence). + +`envdecode` uses struct tags to map environment variables to fields, +allowing you you use any names you want for environment variables. +`envdecode` will recurse into nested structs, including pointers to +nested structs, but it will not allocate new pointers to structs. + +## API + +Full API docs are available on +[godoc.org](https://godoc.org/github.com/owncloud/ocis/ocis-pkg/config/envdecode). + +Define a struct with `env` struct tags: + +```go +type Config struct { + Hostname string `env:"SERVER_HOSTNAME,default=localhost"` + Port uint16 `env:"HTTP_PORT;SERVER_PORT,default=8080"` + + AWS struct { + ID string `env:"AWS_ACCESS_KEY_ID"` + Secret string `env:"AWS_SECRET_ACCESS_KEY,required"` + SnsTopics []string `env:"AWS_SNS_TOPICS"` + } + + Timeout time.Duration `env:"TIMEOUT,default=1m,strict"` +} +``` + +Fields _must be exported_ (i.e. begin with a capital letter) in order +for `envdecode` to work with them. An error will be returned if a +struct with no exported fields is decoded (including one that contains +no `env` tags at all). +Default values may be provided by appending ",default=value" to the +struct tag. Required values may be marked by appending ",required" to the +struct tag. Strict values may be marked by appending ",strict" which will +return an error on Decode if there is an error while parsing. + +Then call `envdecode.Decode`: + +```go +var cfg Config +err := envdecode.Decode(&cfg) +``` + +If you want all fields to act `strict`, you may use `envdecode.StrictDecode`: + +```go +var cfg Config +err := envdecode.StrictDecode(&cfg) +``` + +All parse errors will fail fast and return an error in this mode. + +## Supported types + +- Structs (and pointer to structs) +- Slices of below defined types, separated by semicolon +- `bool` +- `float32`, `float64` +- `int`, `int8`, `int16`, `int32`, `int64` +- `uint`, `uint8`, `uint16`, `uint32`, `uint64` +- `string` +- `time.Duration`, using the [`time.ParseDuration()` format](http://golang.org/pkg/time/#ParseDuration) +- `*url.URL`, using [`url.Parse()`](https://godoc.org/net/url#Parse) +- Types those implement a `Decoder` interface + +## Custom `Decoder` + +If you want a field to be decoded with custom behavior, you may implement the interface `Decoder` for the filed type. + +```go +type Config struct { + IPAddr IP `env:"IP_ADDR"` +} + +type IP net.IP + +// Decode implements the interface `envdecode.Decoder` +func (i *IP) Decode(repl string) error { + *i = net.ParseIP(repl) + return nil +} +``` + +`Decoder` is the interface implemented by an object that can decode an environment variable string representation of itself. diff --git a/ocis-pkg/config/envdecode/envdecode.go b/ocis-pkg/config/envdecode/envdecode.go new file mode 100644 index 00000000000..d97d698988e --- /dev/null +++ b/ocis-pkg/config/envdecode/envdecode.go @@ -0,0 +1,431 @@ +// Package envdecode is a package for populating structs from environment +// variables, using struct tags. +package envdecode + +import ( + "encoding" + "errors" + "fmt" + "log" + "net/url" + "os" + "reflect" + "sort" + "strconv" + "strings" + "time" +) + +// ErrInvalidTarget indicates that the target value passed to +// Decode is invalid. Target must be a non-nil pointer to a struct. +var ErrInvalidTarget = errors.New("target must be non-nil pointer to struct that has at least one exported field with a valid env tag.") +var ErrNoTargetFieldsAreSet = errors.New("none of the target fields were set from environment variables") + +// FailureFunc is called when an error is encountered during a MustDecode +// operation. It prints the error and terminates the process. +// +// This variable can be assigned to another function of the user-programmer's +// design, allowing for graceful recovery of the problem, such as loading +// from a backup configuration file. +var FailureFunc = func(err error) { + log.Fatalf("envdecode: an error was encountered while decoding: %v\n", err) +} + +// Decoder is the interface implemented by an object that can decode an +// environment variable string representation of itself. +type Decoder interface { + Decode(string) error +} + +// Decode environment variables into the provided target. The target +// must be a non-nil pointer to a struct. Fields in the struct must +// be exported, and tagged with an "env" struct tag with a value +// containing the name of the environment variable. An error is +// returned if there are no exported members tagged. +// +// Default values may be provided by appending ",default=value" to the +// struct tag. Required values may be marked by appending ",required" +// to the struct tag. It is an error to provide both "default" and +// "required". Strict values may be marked by appending ",strict" which +// will return an error on Decode if there is an error while parsing. +// If everything must be strict, consider using StrictDecode instead. +// +// All primitive types are supported, including bool, floating point, +// signed and unsigned integers, and string. Boolean and numeric +// types are decoded using the standard strconv Parse functions for +// those types. Structs and pointers to structs are decoded +// recursively. time.Duration is supported via the +// time.ParseDuration() function and *url.URL is supported via the +// url.Parse() function. Slices are supported for all above mentioned +// primitive types. Semicolon is used as delimiter in environment variables. +func Decode(target interface{}) error { + nFields, err := decode(target, false) + if err != nil { + return err + } + + // if we didn't do anything - the user probably did something + // wrong like leave all fields unexported. + if nFields == 0 { + return ErrNoTargetFieldsAreSet + } + + return nil +} + +// StrictDecode is similar to Decode except all fields will have an implicit +// ",strict" on all fields. +func StrictDecode(target interface{}) error { + nFields, err := decode(target, true) + if err != nil { + return err + } + + // if we didn't do anything - the user probably did something + // wrong like leave all fields unexported. + if nFields == 0 { + return ErrInvalidTarget + } + + return nil +} + +func decode(target interface{}, strict bool) (int, error) { + s := reflect.ValueOf(target) + if s.Kind() != reflect.Ptr || s.IsNil() { + return 0, ErrInvalidTarget + } + + s = s.Elem() + if s.Kind() != reflect.Struct { + return 0, ErrInvalidTarget + } + + t := s.Type() + setFieldCount := 0 + for i := 0; i < s.NumField(); i++ { + // Localize the umbrella `strict` value to the specific field. + strict := strict + + f := s.Field(i) + + switch f.Kind() { + case reflect.Ptr: + if f.Elem().Kind() != reflect.Struct { + break + } + + f = f.Elem() + fallthrough + + case reflect.Struct: + if !f.Addr().CanInterface() { + continue + } + + ss := f.Addr().Interface() + _, custom := ss.(Decoder) + if custom { + break + } + + n, err := decode(ss, strict) + if err != nil { + return 0, err + } + setFieldCount += n + } + + if !f.CanSet() { + continue + } + + tag := t.Field(i).Tag.Get("env") + if tag == "" { + continue + } + + parts := strings.Split(tag, ",") + overrides := strings.Split(parts[0], `;`) + + var env string + for _, override := range overrides { + v := os.Getenv(override) + if v != "" { + env = v + } + } + + required := false + hasDefault := false + defaultValue := "" + + for _, o := range parts[1:] { + if !required { + required = strings.HasPrefix(o, "required") + } + if strings.HasPrefix(o, "default=") { + hasDefault = true + defaultValue = o[8:] + } + if !strict { + strict = strings.HasPrefix(o, "strict") + } + } + + if required && hasDefault { + panic(`envdecode: "default" and "required" may not be specified in the same annotation`) + } + if env == "" && required { + return 0, fmt.Errorf("the environment variable \"%s\" is missing", parts[0]) + } + if env == "" { + env = defaultValue + } + if env == "" { + continue + } + + setFieldCount++ + + unmarshaler, implementsUnmarshaler := f.Addr().Interface().(encoding.TextUnmarshaler) + decoder, implmentsDecoder := f.Addr().Interface().(Decoder) + if implmentsDecoder { + if err := decoder.Decode(env); err != nil { + return 0, err + } + } else if implementsUnmarshaler { + if err := unmarshaler.UnmarshalText([]byte(env)); err != nil { + return 0, err + } + } else if f.Kind() == reflect.Slice { + decodeSlice(&f, env) + } else { + if err := decodePrimitiveType(&f, env); err != nil && strict { + return 0, err + } + } + } + + return setFieldCount, nil +} + +func decodeSlice(f *reflect.Value, env string) { + parts := strings.Split(env, ";") + + values := parts[:0] + for _, x := range parts { + if x != "" { + values = append(values, strings.TrimSpace(x)) + } + } + + valuesCount := len(values) + slice := reflect.MakeSlice(f.Type(), valuesCount, valuesCount) + if valuesCount > 0 { + for i := 0; i < valuesCount; i++ { + e := slice.Index(i) + decodePrimitiveType(&e, values[i]) + } + } + + f.Set(slice) +} + +func decodePrimitiveType(f *reflect.Value, env string) error { + switch f.Kind() { + case reflect.Bool: + v, err := strconv.ParseBool(env) + if err != nil { + return err + } + f.SetBool(v) + + case reflect.Float32, reflect.Float64: + bits := f.Type().Bits() + v, err := strconv.ParseFloat(env, bits) + if err != nil { + return err + } + f.SetFloat(v) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + if t := f.Type(); t.PkgPath() == "time" && t.Name() == "Duration" { + v, err := time.ParseDuration(env) + if err != nil { + return err + } + f.SetInt(int64(v)) + } else { + bits := f.Type().Bits() + v, err := strconv.ParseInt(env, 0, bits) + if err != nil { + return err + } + f.SetInt(v) + } + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + bits := f.Type().Bits() + v, err := strconv.ParseUint(env, 0, bits) + if err != nil { + return err + } + f.SetUint(v) + + case reflect.String: + f.SetString(env) + + case reflect.Ptr: + if t := f.Type().Elem(); t.Kind() == reflect.Struct && t.PkgPath() == "net/url" && t.Name() == "URL" { + v, err := url.Parse(env) + if err != nil { + return err + } + f.Set(reflect.ValueOf(v)) + } + } + return nil +} + +// MustDecode calls Decode and terminates the process if any errors +// are encountered. +func MustDecode(target interface{}) { + err := Decode(target) + if err != nil { + FailureFunc(err) + } +} + +// MustStrictDecode calls StrictDecode and terminates the process if any errors +// are encountered. +func MustStrictDecode(target interface{}) { + err := StrictDecode(target) + if err != nil { + FailureFunc(err) + } +} + +//// Configuration info for Export + +type ConfigInfo struct { + Field string + EnvVar string + Value string + DefaultValue string + HasDefault bool + Required bool + UsesEnv bool +} + +type ConfigInfoSlice []*ConfigInfo + +func (c ConfigInfoSlice) Less(i, j int) bool { + return c[i].EnvVar < c[j].EnvVar +} +func (c ConfigInfoSlice) Len() int { + return len(c) +} +func (c ConfigInfoSlice) Swap(i, j int) { + c[i], c[j] = c[j], c[i] +} + +// Returns a list of final configuration metadata sorted by envvar name +func Export(target interface{}) ([]*ConfigInfo, error) { + s := reflect.ValueOf(target) + if s.Kind() != reflect.Ptr || s.IsNil() { + return nil, ErrInvalidTarget + } + + cfg := []*ConfigInfo{} + + s = s.Elem() + if s.Kind() != reflect.Struct { + return nil, ErrInvalidTarget + } + + t := s.Type() + for i := 0; i < s.NumField(); i++ { + f := s.Field(i) + fName := t.Field(i).Name + + fElem := f + if f.Kind() == reflect.Ptr { + fElem = f.Elem() + } + if fElem.Kind() == reflect.Struct { + ss := fElem.Addr().Interface() + subCfg, err := Export(ss) + if err != ErrInvalidTarget { + f = fElem + for _, v := range subCfg { + v.Field = fmt.Sprintf("%s.%s", fName, v.Field) + cfg = append(cfg, v) + } + } + } + + tag := t.Field(i).Tag.Get("env") + if tag == "" { + continue + } + + parts := strings.Split(tag, ",") + + ci := &ConfigInfo{ + Field: fName, + EnvVar: parts[0], + UsesEnv: os.Getenv(parts[0]) != "", + } + + for _, o := range parts[1:] { + if strings.HasPrefix(o, "default=") { + ci.HasDefault = true + ci.DefaultValue = o[8:] + } else if strings.HasPrefix(o, "required") { + ci.Required = true + } + } + + if f.Kind() == reflect.Ptr && f.IsNil() { + ci.Value = "" + } else if stringer, ok := f.Interface().(fmt.Stringer); ok { + ci.Value = stringer.String() + } else { + switch f.Kind() { + case reflect.Bool: + ci.Value = strconv.FormatBool(f.Bool()) + + case reflect.Float32, reflect.Float64: + bits := f.Type().Bits() + ci.Value = strconv.FormatFloat(f.Float(), 'f', -1, bits) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + ci.Value = strconv.FormatInt(f.Int(), 10) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + ci.Value = strconv.FormatUint(f.Uint(), 10) + + case reflect.String: + ci.Value = f.String() + + case reflect.Slice: + ci.Value = fmt.Sprintf("%v", f.Interface()) + + default: + // Unable to determine string format for value + return nil, ErrInvalidTarget + } + } + + cfg = append(cfg, ci) + } + + // No configuration tags found, assume invalid input + if len(cfg) == 0 { + return nil, ErrInvalidTarget + } + + sort.Sort(ConfigInfoSlice(cfg)) + + return cfg, nil +} diff --git a/ocis-pkg/config/envdecode/envdecode_test.go b/ocis-pkg/config/envdecode/envdecode_test.go new file mode 100644 index 00000000000..bf6fd3352b1 --- /dev/null +++ b/ocis-pkg/config/envdecode/envdecode_test.go @@ -0,0 +1,795 @@ +package envdecode + +import ( + "encoding/json" + "fmt" + "math" + "net/url" + "os" + "reflect" + "sort" + "strconv" + "sync" + "testing" + "time" +) + +type nested struct { + String string `env:"TEST_STRING"` +} + +type testConfig struct { + String string `env:"TEST_STRING"` + Int64 int64 `env:"TEST_INT64"` + Uint16 uint16 `env:"TEST_UINT16"` + Float64 float64 `env:"TEST_FLOAT64"` + Bool bool `env:"TEST_BOOL"` + Duration time.Duration `env:"TEST_DURATION"` + URL *url.URL `env:"TEST_URL"` + + StringSlice []string `env:"TEST_STRING_SLICE"` + Int64Slice []int64 `env:"TEST_INT64_SLICE"` + Uint16Slice []uint16 `env:"TEST_UINT16_SLICE"` + Float64Slice []float64 `env:"TEST_FLOAT64_SLICE"` + BoolSlice []bool `env:"TEST_BOOL_SLICE"` + DurationSlice []time.Duration `env:"TEST_DURATION_SLICE"` + URLSlice []*url.URL `env:"TEST_URL_SLICE"` + + UnsetString string `env:"TEST_UNSET_STRING"` + UnsetInt64 int64 `env:"TEST_UNSET_INT64"` + UnsetDuration time.Duration `env:"TEST_UNSET_DURATION"` + UnsetURL *url.URL `env:"TEST_UNSET_URL"` + UnsetSlice []string `env:"TEST_UNSET_SLICE"` + + InvalidInt64 int64 `env:"TEST_INVALID_INT64"` + + UnusedField string + unexportedField string + + IgnoredPtr *bool `env:"TEST_BOOL"` + + Nested nested + NestedPtr *nested + + DecoderStruct decoderStruct `env:"TEST_DECODER_STRUCT"` + DecoderStructPtr *decoderStruct `env:"TEST_DECODER_STRUCT_PTR"` + + DecoderString decoderString `env:"TEST_DECODER_STRING"` + + UnmarshalerNumber unmarshalerNumber `env:"TEST_UNMARSHALER_NUMBER"` + + DefaultInt int `env:"TEST_UNSET,asdf=asdf,default=1234"` + DefaultSliceInt []int `env:"TEST_UNSET,asdf=asdf,default=1;2;3"` + DefaultDuration time.Duration `env:"TEST_UNSET,asdf=asdf,default=24h"` + DefaultURL *url.URL `env:"TEST_UNSET,default=http://example.com"` + + cantInterfaceField sync.Mutex +} + +type testConfigNoSet struct { + Some string `env:"TEST_THIS_ENV_WILL_NOT_BE_SET"` +} + +type testConfigRequired struct { + Required string `env:"TEST_REQUIRED,required"` +} + +type testConfigRequiredDefault struct { + RequiredDefault string `env:"TEST_REQUIRED_DEFAULT,required,default=test"` +} + +type testConfigOverride struct { + OverrideString string `env:"TEST_OVERRIDE_A;TEST_OVERRIDE_B,default=override_default"` +} + +type testNoExportedFields struct { + aString string `env:"TEST_STRING"` + anInt64 int64 `env:"TEST_INT64"` + aUint16 uint16 `env:"TEST_UINT16"` + aFloat64 float64 `env:"TEST_FLOAT64"` + aBool bool `env:"TEST_BOOL"` +} + +type testNoTags struct { + String string +} + +type decoderStruct struct { + String string +} + +func (d *decoderStruct) Decode(env string) error { + return json.Unmarshal([]byte(env), &d) +} + +type decoderString string + +func (d *decoderString) Decode(env string) error { + r, l := []rune(env), len(env) + + for i := 0; i < l/2; i++ { + r[i], r[l-1-i] = r[l-1-i], r[i] + } + + *d = decoderString(r) + return nil +} + +type unmarshalerNumber uint8 + +func (o *unmarshalerNumber) UnmarshalText(raw []byte) error { + n, err := strconv.ParseUint(string(raw), 8, 8) // parse text as octal number + if err != nil { + return err + } + *o = unmarshalerNumber(n) + return nil +} + +func TestDecode(t *testing.T) { + int64Val := int64(-(1 << 50)) + int64AsString := fmt.Sprintf("%d", int64Val) + piAsString := fmt.Sprintf("%.48f", math.Pi) + + os.Setenv("TEST_STRING", "foo") + os.Setenv("TEST_INT64", int64AsString) + os.Setenv("TEST_UINT16", "60000") + os.Setenv("TEST_FLOAT64", piAsString) + os.Setenv("TEST_BOOL", "true") + os.Setenv("TEST_DURATION", "10m") + os.Setenv("TEST_URL", "https://example.com") + os.Setenv("TEST_INVALID_INT64", "asdf") + os.Setenv("TEST_STRING_SLICE", "foo;bar") + os.Setenv("TEST_INT64_SLICE", int64AsString+";"+int64AsString) + os.Setenv("TEST_UINT16_SLICE", "60000;50000") + os.Setenv("TEST_FLOAT64_SLICE", piAsString+";"+piAsString) + os.Setenv("TEST_BOOL_SLICE", "true; false; true") + os.Setenv("TEST_DURATION_SLICE", "10m; 20m") + os.Setenv("TEST_URL_SLICE", "https://example.com") + os.Setenv("TEST_DECODER_STRUCT", "{\"string\":\"foo\"}") + os.Setenv("TEST_DECODER_STRUCT_PTR", "{\"string\":\"foo\"}") + os.Setenv("TEST_DECODER_STRING", "oof") + os.Setenv("TEST_UNMARSHALER_NUMBER", "07") + + var tc testConfig + tc.NestedPtr = &nested{} + tc.DecoderStructPtr = &decoderStruct{} + + err := Decode(&tc) + if err != nil { + t.Fatal(err) + } + + if tc.String != "foo" { + t.Fatalf(`Expected "foo", got "%s"`, tc.String) + } + + if tc.Int64 != -(1 << 50) { + t.Fatalf("Expected %d, got %d", -(1 << 50), tc.Int64) + } + + if tc.Uint16 != 60000 { + t.Fatalf("Expected 60000, got %d", tc.Uint16) + } + + if tc.Float64 != math.Pi { + t.Fatalf("Expected %.48f, got %.48f", math.Pi, tc.Float64) + } + + if !tc.Bool { + t.Fatal("Expected true, got false") + } + + duration, _ := time.ParseDuration("10m") + if tc.Duration != duration { + t.Fatalf("Expected %d, got %d", duration, tc.Duration) + } + + if tc.URL == nil { + t.Fatalf("Expected https://example.com, got nil") + } else if tc.URL.String() != "https://example.com" { + t.Fatalf("Expected https://example.com, got %s", tc.URL.String()) + } + + expectedStringSlice := []string{"foo", "bar"} + if !reflect.DeepEqual(tc.StringSlice, expectedStringSlice) { + t.Fatalf("Expected %s, got %s", expectedStringSlice, tc.StringSlice) + } + + expectedInt64Slice := []int64{int64Val, int64Val} + if !reflect.DeepEqual(tc.Int64Slice, expectedInt64Slice) { + t.Fatalf("Expected %#v, got %#v", expectedInt64Slice, tc.Int64Slice) + } + + expectedUint16Slice := []uint16{60000, 50000} + if !reflect.DeepEqual(tc.Uint16Slice, expectedUint16Slice) { + t.Fatalf("Expected %#v, got %#v", expectedUint16Slice, tc.Uint16Slice) + } + + expectedFloat64Slice := []float64{math.Pi, math.Pi} + if !reflect.DeepEqual(tc.Float64Slice, expectedFloat64Slice) { + t.Fatalf("Expected %#v, got %#v", expectedFloat64Slice, tc.Float64Slice) + } + + expectedBoolSlice := []bool{true, false, true} + if !reflect.DeepEqual(tc.BoolSlice, expectedBoolSlice) { + t.Fatalf("Expected %#v, got %#v", expectedBoolSlice, tc.BoolSlice) + } + + duration2, _ := time.ParseDuration("20m") + expectedDurationSlice := []time.Duration{duration, duration2} + if !reflect.DeepEqual(tc.DurationSlice, expectedDurationSlice) { + t.Fatalf("Expected %s, got %s", expectedDurationSlice, tc.DurationSlice) + } + + urlVal, _ := url.Parse("https://example.com") + expectedUrlSlice := []*url.URL{urlVal} + if !reflect.DeepEqual(tc.URLSlice, expectedUrlSlice) { + t.Fatalf("Expected %s, got %s", expectedUrlSlice, tc.URLSlice) + } + + if tc.UnsetString != "" { + t.Fatal("Got non-empty string unexpectedly") + } + + if tc.UnsetInt64 != 0 { + t.Fatal("Got non-zero int unexpectedly") + } + + if tc.UnsetDuration != time.Duration(0) { + t.Fatal("Got non-zero time.Duration unexpectedly") + } + + if tc.UnsetURL != nil { + t.Fatal("Got non-zero *url.URL unexpectedly") + } + + if len(tc.UnsetSlice) > 0 { + t.Fatal("Got not-empty string slice unexpectedly") + } + + if tc.InvalidInt64 != 0 { + t.Fatal("Got non-zero int unexpectedly") + } + + if tc.UnusedField != "" { + t.Fatal("Expected empty field") + } + + if tc.unexportedField != "" { + t.Fatal("Expected empty field") + } + + if tc.IgnoredPtr != nil { + t.Fatal("Expected nil pointer") + } + + if tc.Nested.String != "foo" { + t.Fatalf(`Expected "foo", got "%s"`, tc.Nested.String) + } + + if tc.NestedPtr.String != "foo" { + t.Fatalf(`Expected "foo", got "%s"`, tc.NestedPtr.String) + } + + if tc.DefaultInt != 1234 { + t.Fatalf("Expected 1234, got %d", tc.DefaultInt) + } + + expectedDefaultSlice := []int{1, 2, 3} + if !reflect.DeepEqual(tc.DefaultSliceInt, expectedDefaultSlice) { + t.Fatalf("Expected %d, got %d", expectedDefaultSlice, tc.DefaultSliceInt) + } + + defaultDuration, _ := time.ParseDuration("24h") + if tc.DefaultDuration != defaultDuration { + t.Fatalf("Expected %d, got %d", defaultDuration, tc.DefaultInt) + } + + if tc.DefaultURL.String() != "http://example.com" { + t.Fatalf("Expected http://example.com, got %s", tc.DefaultURL.String()) + } + + if tc.DecoderStruct.String != "foo" { + t.Fatalf("Expected foo, got %s", tc.DecoderStruct.String) + } + + if tc.DecoderStructPtr.String != "foo" { + t.Fatalf("Expected foo, got %s", tc.DecoderStructPtr.String) + } + + if tc.DecoderString != "foo" { + t.Fatalf("Expected foo, got %s", tc.DecoderString) + } + + if tc.UnmarshalerNumber != 07 { + t.Fatalf("Expected 07, got %04o", tc.UnmarshalerNumber) + } + + os.Setenv("TEST_REQUIRED", "required") + var tcr testConfigRequired + + err = Decode(&tcr) + if err != nil { + t.Fatal(err) + } + + if tcr.Required != "required" { + t.Fatalf("Expected \"required\", got %s", tcr.Required) + } + + _, err = Export(&tcr) + if err != nil { + t.Fatal(err) + } + + var tco testConfigOverride + err = Decode(&tco) + if err != nil { + t.Fatal(err) + } + + if tco.OverrideString != "override_default" { + t.Fatalf(`Expected "override_default" but got %s`, tco.OverrideString) + } + + os.Setenv("TEST_OVERRIDE_A", "override_a") + + tco = testConfigOverride{} + err = Decode(&tco) + if err != nil { + t.Fatal(err) + } + + if tco.OverrideString != "override_a" { + t.Fatalf(`Expected "override_a" but got %s`, tco.OverrideString) + } + + os.Setenv("TEST_OVERRIDE_B", "override_b") + + tco = testConfigOverride{} + err = Decode(&tco) + if err != nil { + t.Fatal(err) + } + + if tco.OverrideString != "override_b" { + t.Fatalf(`Expected "override_b" but got %s`, tco.OverrideString) + } +} + +func TestDecodeErrors(t *testing.T) { + var b bool + err := Decode(&b) + if err != ErrInvalidTarget { + t.Fatal("Should have gotten an error decoding into a bool") + } + + var tc testConfig + err = Decode(tc) + if err != ErrInvalidTarget { + t.Fatal("Should have gotten an error decoding into a non-pointer") + } + + var tcp *testConfig + err = Decode(tcp) + if err != ErrInvalidTarget { + t.Fatal("Should have gotten an error decoding to a nil pointer") + } + + var tnt testNoTags + err = Decode(&tnt) + if err != ErrNoTargetFieldsAreSet { + t.Fatal("Should have gotten an error decoding a struct with no tags") + } + + var tcni testNoExportedFields + err = Decode(&tcni) + if err != ErrNoTargetFieldsAreSet { + t.Fatal("Should have gotten an error decoding a struct with no unexported fields") + } + + var tcr testConfigRequired + os.Clearenv() + err = Decode(&tcr) + if err == nil { + t.Fatal("An error was expected but recieved:", err) + } + + var tcns testConfigNoSet + err = Decode(&tcns) + if err != ErrNoTargetFieldsAreSet { + t.Fatal("Should have gotten an error decoding when no env variables are set") + } + + missing := false + FailureFunc = func(err error) { + missing = true + } + MustDecode(&tcr) + if !missing { + t.Fatal("The FailureFunc should have been called but it was not") + } + + var tcrd testConfigRequiredDefault + defer func() { + if r := recover(); r != nil { + } + }() + err = Decode(&tcrd) + t.Fatal("This should not have been reached. A panic should have occured.") +} + +func TestOnlyNested(t *testing.T) { + os.Setenv("TEST_STRING", "foo") + + // No env vars in the outer level are ok, as long as they're + // in the inner struct. + var o struct { + Inner nested + } + if err := Decode(&o); err != nil { + t.Fatalf("Expected no error, got %s", err) + } + + // No env vars in the inner levels are ok, as long as they're + // in the outer struct. + var o2 struct { + Inner noConfig + X string `env:"TEST_STRING"` + } + if err := Decode(&o2); err != nil { + t.Fatalf("Expected no error, got %s", err) + } + + // No env vars in either outer or inner levels should result + // in error + var o3 struct { + Inner noConfig + } + if err := Decode(&o3); err != ErrNoTargetFieldsAreSet { + t.Fatalf("Expected ErrInvalidTarget, got %s", err) + } +} + +func ExampleDecode() { + type Example struct { + // A string field, without any default + String string `env:"EXAMPLE_STRING"` + + // A uint16 field, with a default value of 100 + Uint16 uint16 `env:"EXAMPLE_UINT16,default=100"` + } + + os.Setenv("EXAMPLE_STRING", "an example!") + + var e Example + err := Decode(&e) + if err != nil { + panic(err) + } + + // If TEST_STRING is set, e.String will contain its value + fmt.Println(e.String) + + // If TEST_UINT16 is set, e.Uint16 will contain its value. + // Otherwise, it will contain the default value, 100. + fmt.Println(e.Uint16) + + // Output: + // an example! + // 100 +} + +//// Export tests + +type testConfigExport struct { + String string `env:"TEST_STRING"` + Int64 int64 `env:"TEST_INT64"` + Uint16 uint16 `env:"TEST_UINT16"` + Float64 float64 `env:"TEST_FLOAT64"` + Bool bool `env:"TEST_BOOL"` + Duration time.Duration `env:"TEST_DURATION"` + URL *url.URL `env:"TEST_URL"` + + StringSlice []string `env:"TEST_STRING_SLICE"` + + UnsetString string `env:"TEST_UNSET_STRING"` + UnsetInt64 int64 `env:"TEST_UNSET_INT64"` + UnsetDuration time.Duration `env:"TEST_UNSET_DURATION"` + UnsetURL *url.URL `env:"TEST_UNSET_URL"` + + UnusedField string + unexportedField string + + IgnoredPtr *bool `env:"TEST_IGNORED_POINTER"` + + Nested nestedConfigExport + NestedPtr *nestedConfigExportPointer + NestedPtrUnset *nestedConfigExportPointer + + NestedTwice nestedTwiceConfig + + NoConfig noConfig + NoConfigPtr *noConfig + NoConfigPtrSet *noConfig + + RequiredInt int `env:"TEST_REQUIRED_INT,required"` + + DefaultBool bool `env:"TEST_DEFAULT_BOOL,default=true"` + DefaultInt int `env:"TEST_DEFAULT_INT,default=1234"` + DefaultDuration time.Duration `env:"TEST_DEFAULT_DURATION,default=24h"` + DefaultURL *url.URL `env:"TEST_DEFAULT_URL,default=http://example.com"` + DefaultIntSet int `env:"TEST_DEFAULT_INT_SET,default=99"` + DefaultIntSlice []int `env:"TEST_DEFAULT_INT_SLICE,default=99;33"` +} + +type nestedConfigExport struct { + String string `env:"TEST_NESTED_STRING"` +} + +type nestedConfigExportPointer struct { + String string `env:"TEST_NESTED_STRING_POINTER"` +} + +type noConfig struct { + Int int +} + +type nestedTwiceConfig struct { + Nested nestedConfigInner +} + +type nestedConfigInner struct { + String string `env:"TEST_NESTED_TWICE_STRING"` +} + +type testConfigStrict struct { + InvalidInt64Strict int64 `env:"TEST_INVALID_INT64,strict,default=1"` + InvalidInt64Implicit int64 `env:"TEST_INVALID_INT64_IMPLICIT,default=1"` + + Nested struct { + InvalidInt64Strict int64 `env:"TEST_INVALID_INT64_NESTED,strict,required"` + InvalidInt64Implicit int64 `env:"TEST_INVALID_INT64_NESTED_IMPLICIT,required"` + } +} + +func TestInvalidStrict(t *testing.T) { + cases := []struct { + decoder func(interface{}) error + rootValue string + nestedValue string + rootValueImplicit string + nestedValueImplicit string + pass bool + }{ + {Decode, "1", "1", "1", "1", true}, + {Decode, "1", "1", "1", "asdf", true}, + {Decode, "1", "1", "asdf", "1", true}, + {Decode, "1", "1", "asdf", "asdf", true}, + {Decode, "1", "asdf", "1", "1", false}, + {Decode, "asdf", "1", "1", "1", false}, + {Decode, "asdf", "asdf", "1", "1", false}, + {StrictDecode, "1", "1", "1", "1", true}, + {StrictDecode, "asdf", "1", "1", "1", false}, + {StrictDecode, "1", "asdf", "1", "1", false}, + {StrictDecode, "1", "1", "asdf", "1", false}, + {StrictDecode, "1", "1", "1", "asdf", false}, + {StrictDecode, "asdf", "asdf", "1", "1", false}, + {StrictDecode, "1", "asdf", "asdf", "1", false}, + {StrictDecode, "1", "1", "asdf", "asdf", false}, + {StrictDecode, "1", "asdf", "asdf", "asdf", false}, + {StrictDecode, "asdf", "asdf", "asdf", "asdf", false}, + } + + for _, test := range cases { + os.Setenv("TEST_INVALID_INT64", test.rootValue) + os.Setenv("TEST_INVALID_INT64_NESTED", test.nestedValue) + os.Setenv("TEST_INVALID_INT64_IMPLICIT", test.rootValueImplicit) + os.Setenv("TEST_INVALID_INT64_NESTED_IMPLICIT", test.nestedValueImplicit) + + var tc testConfigStrict + if err := test.decoder(&tc); test.pass != (err == nil) { + t.Fatalf("Have err=%s wanted pass=%v", err, test.pass) + } + } +} + +func TestExport(t *testing.T) { + testFloat64 := fmt.Sprintf("%.48f", math.Pi) + testFloat64Output := strconv.FormatFloat(math.Pi, 'f', -1, 64) + testInt64 := fmt.Sprintf("%d", -(1 << 50)) + + os.Setenv("TEST_STRING", "foo") + os.Setenv("TEST_INT64", testInt64) + os.Setenv("TEST_UINT16", "60000") + os.Setenv("TEST_FLOAT64", testFloat64) + os.Setenv("TEST_BOOL", "true") + os.Setenv("TEST_DURATION", "10m") + os.Setenv("TEST_URL", "https://example.com") + os.Setenv("TEST_STRING_SLICE", "foo;bar") + os.Setenv("TEST_NESTED_STRING", "nest_foo") + os.Setenv("TEST_NESTED_STRING_POINTER", "nest_foo_ptr") + os.Setenv("TEST_NESTED_TWICE_STRING", "nest_twice_foo") + os.Setenv("TEST_REQUIRED_INT", "101") + os.Setenv("TEST_DEFAULT_INT_SET", "102") + os.Setenv("TEST_DEFAULT_INT_SLICE", "1;2;3") + + var tc testConfigExport + tc.NestedPtr = &nestedConfigExportPointer{} + tc.NoConfigPtrSet = &noConfig{} + + err := Decode(&tc) + if err != nil { + t.Fatal(err) + } + + rc, err := Export(&tc) + if err != nil { + t.Fatal(err) + } + + expected := []*ConfigInfo{ + &ConfigInfo{ + Field: "String", + EnvVar: "TEST_STRING", + Value: "foo", + UsesEnv: true, + }, + &ConfigInfo{ + Field: "Int64", + EnvVar: "TEST_INT64", + Value: testInt64, + UsesEnv: true, + }, + &ConfigInfo{ + Field: "Uint16", + EnvVar: "TEST_UINT16", + Value: "60000", + UsesEnv: true, + }, + &ConfigInfo{ + Field: "Float64", + EnvVar: "TEST_FLOAT64", + Value: testFloat64Output, + UsesEnv: true, + }, + &ConfigInfo{ + Field: "Bool", + EnvVar: "TEST_BOOL", + Value: "true", + UsesEnv: true, + }, + &ConfigInfo{ + Field: "Duration", + EnvVar: "TEST_DURATION", + Value: "10m0s", + UsesEnv: true, + }, + &ConfigInfo{ + Field: "URL", + EnvVar: "TEST_URL", + Value: "https://example.com", + UsesEnv: true, + }, + &ConfigInfo{ + Field: "StringSlice", + EnvVar: "TEST_STRING_SLICE", + Value: "[foo bar]", + UsesEnv: true, + }, + + &ConfigInfo{ + Field: "UnsetString", + EnvVar: "TEST_UNSET_STRING", + Value: "", + }, + &ConfigInfo{ + Field: "UnsetInt64", + EnvVar: "TEST_UNSET_INT64", + Value: "0", + }, + &ConfigInfo{ + Field: "UnsetDuration", + EnvVar: "TEST_UNSET_DURATION", + Value: "0s", + }, + &ConfigInfo{ + Field: "UnsetURL", + EnvVar: "TEST_UNSET_URL", + Value: "", + }, + + &ConfigInfo{ + Field: "IgnoredPtr", + EnvVar: "TEST_IGNORED_POINTER", + Value: "", + }, + + &ConfigInfo{ + Field: "Nested.String", + EnvVar: "TEST_NESTED_STRING", + Value: "nest_foo", + UsesEnv: true, + }, + &ConfigInfo{ + Field: "NestedPtr.String", + EnvVar: "TEST_NESTED_STRING_POINTER", + Value: "nest_foo_ptr", + UsesEnv: true, + }, + + &ConfigInfo{ + Field: "NestedTwice.Nested.String", + EnvVar: "TEST_NESTED_TWICE_STRING", + Value: "nest_twice_foo", + UsesEnv: true, + }, + + &ConfigInfo{ + Field: "RequiredInt", + EnvVar: "TEST_REQUIRED_INT", + Value: "101", + UsesEnv: true, + Required: true, + }, + + &ConfigInfo{ + Field: "DefaultBool", + EnvVar: "TEST_DEFAULT_BOOL", + Value: "true", + DefaultValue: "true", + HasDefault: true, + }, + &ConfigInfo{ + Field: "DefaultInt", + EnvVar: "TEST_DEFAULT_INT", + Value: "1234", + DefaultValue: "1234", + HasDefault: true, + }, + &ConfigInfo{ + Field: "DefaultDuration", + EnvVar: "TEST_DEFAULT_DURATION", + Value: "24h0m0s", + DefaultValue: "24h", + HasDefault: true, + }, + &ConfigInfo{ + Field: "DefaultURL", + EnvVar: "TEST_DEFAULT_URL", + Value: "http://example.com", + DefaultValue: "http://example.com", + HasDefault: true, + }, + &ConfigInfo{ + Field: "DefaultIntSet", + EnvVar: "TEST_DEFAULT_INT_SET", + Value: "102", + DefaultValue: "99", + HasDefault: true, + UsesEnv: true, + }, + &ConfigInfo{ + Field: "DefaultIntSlice", + EnvVar: "TEST_DEFAULT_INT_SLICE", + Value: "[1 2 3]", + DefaultValue: "99;33", + HasDefault: true, + UsesEnv: true, + }, + } + + sort.Sort(ConfigInfoSlice(expected)) + + if len(rc) != len(expected) { + t.Fatalf("Have %d results, expected %d", len(rc), len(expected)) + } + + for n, v := range rc { + ci := expected[n] + if *ci != *v { + t.Fatalf("have %+v, expected %+v", v, ci) + } + } +} diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 09d7e63fbf3..232c18ab243 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -5,10 +5,10 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis command. diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 8d24d1bd6a2..994e5e8898c 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -5,11 +5,11 @@ import ( "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-ocs command. diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 0d20391354e..7bd07dfde84 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -5,11 +5,11 @@ import ( "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-proxy command. diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index bbddc89444b..c6091ef905a 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -5,11 +5,11 @@ import ( "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-settings command. diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index d10f4cb4dd6..be613a9f756 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -5,11 +5,11 @@ import ( "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-store command. diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 4e24303e589..4236c1098b8 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -5,11 +5,11 @@ import ( "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/thumbnails/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-thumbnails command. diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 4d1c6249aeb..371c3337e4a 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -5,11 +5,11 @@ import ( "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/web/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the web command. diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 9df612006fd..224823e0196 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -5,11 +5,11 @@ import ( "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/webdav/pkg/config" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" - "github.com/wkloucek/envdecode" ) // Execute is the entry point for the ocis-webdav command. From 6dc2d4d74c95083b049fb7fc5cd6835ac76be273 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 08:15:46 +0100 Subject: [PATCH 58/84] expose proxy debug port only on localhost --- proxy/pkg/config/defaultconfig.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/pkg/config/defaultconfig.go b/proxy/pkg/config/defaultconfig.go index b4101401360..136cf28b980 100644 --- a/proxy/pkg/config/defaultconfig.go +++ b/proxy/pkg/config/defaultconfig.go @@ -9,7 +9,7 @@ import ( func DefaultConfig() *Config { return &Config{ Debug: Debug{ - Addr: "0.0.0.0:9205", + Addr: "127.0.0.1:9205", Token: "", }, HTTP: HTTP{ From a8392882127052a82583d161c168186e1644f395 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 08:22:44 +0100 Subject: [PATCH 59/84] remove supervised flag from configs --- accounts/pkg/config/config.go | 3 +-- glauth/pkg/config/config.go | 3 +-- graph-explorer/pkg/config/config.go | 3 +-- graph/pkg/config/config.go | 3 +-- idp/pkg/config/config.go | 3 +-- ocs/pkg/config/config.go | 3 +-- proxy/pkg/config/config.go | 3 +-- settings/pkg/config/config.go | 3 +-- storage/pkg/config/config.go | 2 +- store/pkg/config/config.go | 3 +-- thumbnails/pkg/config/config.go | 3 +-- web/pkg/config/config.go | 3 +-- webdav/pkg/config/config.go | 3 +-- 13 files changed, 13 insertions(+), 25 deletions(-) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index eb07e2ca592..e2107361615 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -28,8 +28,7 @@ type Config struct { HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY"` DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"` - Context context.Context - Supervised bool + Context context.Context } // Asset defines the available asset configuration. diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index f5a1bc55031..3d687319cdb 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -24,8 +24,7 @@ type Config struct { RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` - Context context.Context - Supervised bool + Context context.Context } // Backend defined the available backend configuration. diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index ea0577b0f9a..d84c239fde2 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -20,8 +20,7 @@ type Config struct { GraphExplorer GraphExplorer `ocisConfig:"graph_explorer"` - Context context.Context - Supervised bool + Context context.Context } // GraphExplorer defines the available graph-explorer configuration. diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index c7fa9e0891f..f5925b75444 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -24,8 +24,7 @@ type Config struct { Spaces Spaces `ocisConfig:"spaces"` Identity Identity `ocisConfig:"identity"` - Context context.Context - Supervised bool + Context context.Context } type Spaces struct { diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 420dc78886e..7c16b9b1bf1 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -22,8 +22,7 @@ type Config struct { IDP Settings `ocisConfig:"idp"` Ldap Ldap `ocisConfig:"ldap"` - Context context.Context - Supervised bool + Context context.Context } // Ldap defines the available LDAP configuration. diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 0171ef7a06f..bfad75d8604 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -27,8 +27,7 @@ type Config struct { StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"` MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"` - Context context.Context - Supervised bool + Context context.Context } // IdentityManagement keeps track of the OIDC address. This is because Reva requisite of uniqueness for users diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 048928e6ac0..5ac9ee84104 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -32,8 +32,7 @@ type Config struct { EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"` InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` - Context context.Context - Supervised bool + Context context.Context } // Policy enables us to use multiple directors. diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 052a07360d4..fce3b34d5f5 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -23,8 +23,7 @@ type Config struct { Asset Asset `ocisConfig:"asset"` TokenManager TokenManager `ocisConfig:"token_manager"` - Context context.Context - Supervised bool + Context context.Context } // Asset defines the available asset configuration. diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index c2d7a4c6264..0acbf11bbdf 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -125,7 +125,7 @@ type Port struct { Context context.Context // Supervised is used when running under an oCIS runtime supervision tree - Supervised bool // deprecated + Supervised bool // deprecated // TODO: delete me } // Users defines the available users configuration. diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index c8b807bdb1e..46855d55da4 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -20,6 +20,5 @@ type Config struct { Datapath string `ocisConfig:"data_path" env:"STORE_DATA_PATH"` - Context context.Context - Supervised bool + Context context.Context } diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 51c0972480a..8ab2d5bfd21 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -20,8 +20,7 @@ type Config struct { Thumbnail Thumbnail `ocisConfig:"thumbnail"` - Context context.Context - Supervised bool + Context context.Context } // FileSystemStorage defines the available filesystem storage configuration. diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index df0f7ab6dde..13f67adfef0 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -22,8 +22,7 @@ type Config struct { File string `ocisConfig:"file" env:"WEB_UI_CONFIG"` // TODO: rename this to a more self explaining string Web Web `ocisConfig:"web"` - Context context.Context - Supervised bool + Context context.Context } // Asset defines the available asset configuration. diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index d8e9ebe7cfc..7c48724c22a 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -22,6 +22,5 @@ type Config struct { WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` //TODO: prevent this cross config RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` - Context context.Context - Supervised bool + Context context.Context } From e89071200fee00b54bba4e9145020f60d0dade7b Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 08:55:22 +0100 Subject: [PATCH 60/84] satisfy linters --- ocis-pkg/config/envdecode/envdecode.go | 20 +++++++----- ocis-pkg/config/envdecode/envdecode_test.go | 35 +++++++++------------ ocis-pkg/indexer/indexer.go | 3 +- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/ocis-pkg/config/envdecode/envdecode.go b/ocis-pkg/config/envdecode/envdecode.go index d97d698988e..0105c1764fd 100644 --- a/ocis-pkg/config/envdecode/envdecode.go +++ b/ocis-pkg/config/envdecode/envdecode.go @@ -18,7 +18,7 @@ import ( // ErrInvalidTarget indicates that the target value passed to // Decode is invalid. Target must be a non-nil pointer to a struct. -var ErrInvalidTarget = errors.New("target must be non-nil pointer to struct that has at least one exported field with a valid env tag.") +var ErrInvalidTarget = errors.New("target must be non-nil pointer to struct that has at least one exported field with a valid env tag") var ErrNoTargetFieldsAreSet = errors.New("none of the target fields were set from environment variables") // FailureFunc is called when an error is encountered during a MustDecode @@ -199,7 +199,9 @@ func decode(target interface{}, strict bool) (int, error) { return 0, err } } else if f.Kind() == reflect.Slice { - decodeSlice(&f, env) + if err := decodeSlice(&f, env); err != nil { + return 0, err + } } else { if err := decodePrimitiveType(&f, env); err != nil && strict { return 0, err @@ -210,7 +212,7 @@ func decode(target interface{}, strict bool) (int, error) { return setFieldCount, nil } -func decodeSlice(f *reflect.Value, env string) { +func decodeSlice(f *reflect.Value, env string) error { parts := strings.Split(env, ";") values := parts[:0] @@ -225,11 +227,15 @@ func decodeSlice(f *reflect.Value, env string) { if valuesCount > 0 { for i := 0; i < valuesCount; i++ { e := slice.Index(i) - decodePrimitiveType(&e, values[i]) + err := decodePrimitiveType(&e, values[i]) + if err != nil { + return err + } } } f.Set(slice) + return nil } func decodePrimitiveType(f *reflect.Value, env string) error { @@ -290,8 +296,7 @@ func decodePrimitiveType(f *reflect.Value, env string) error { // MustDecode calls Decode and terminates the process if any errors // are encountered. func MustDecode(target interface{}) { - err := Decode(target) - if err != nil { + if err := Decode(target); err != nil { FailureFunc(err) } } @@ -299,8 +304,7 @@ func MustDecode(target interface{}) { // MustStrictDecode calls StrictDecode and terminates the process if any errors // are encountered. func MustStrictDecode(target interface{}) { - err := StrictDecode(target) - if err != nil { + if err := StrictDecode(target); err != nil { FailureFunc(err) } } diff --git a/ocis-pkg/config/envdecode/envdecode_test.go b/ocis-pkg/config/envdecode/envdecode_test.go index bf6fd3352b1..54ac86decfd 100644 --- a/ocis-pkg/config/envdecode/envdecode_test.go +++ b/ocis-pkg/config/envdecode/envdecode_test.go @@ -9,7 +9,6 @@ import ( "reflect" "sort" "strconv" - "sync" "testing" "time" ) @@ -62,8 +61,6 @@ type testConfig struct { DefaultSliceInt []int `env:"TEST_UNSET,asdf=asdf,default=1;2;3"` DefaultDuration time.Duration `env:"TEST_UNSET,asdf=asdf,default=24h"` DefaultURL *url.URL `env:"TEST_UNSET,default=http://example.com"` - - cantInterfaceField sync.Mutex } type testConfigNoSet struct { @@ -83,11 +80,12 @@ type testConfigOverride struct { } type testNoExportedFields struct { - aString string `env:"TEST_STRING"` - anInt64 int64 `env:"TEST_INT64"` - aUint16 uint16 `env:"TEST_UINT16"` - aFloat64 float64 `env:"TEST_FLOAT64"` - aBool bool `env:"TEST_BOOL"` + // folowing unexported fields are used for tests + aString string `env:"TEST_STRING"` //nolint:structcheck,unused + anInt64 int64 `env:"TEST_INT64"` //nolint:structcheck,unused + aUint16 uint16 `env:"TEST_UINT16"` //nolint:structcheck,unused + aFloat64 float64 `env:"TEST_FLOAT64"` //nolint:structcheck,unused + aBool bool `env:"TEST_BOOL"` //nolint:structcheck,unused } type testNoTags struct { @@ -223,9 +221,9 @@ func TestDecode(t *testing.T) { } urlVal, _ := url.Parse("https://example.com") - expectedUrlSlice := []*url.URL{urlVal} - if !reflect.DeepEqual(tc.URLSlice, expectedUrlSlice) { - t.Fatalf("Expected %s, got %s", expectedUrlSlice, tc.URLSlice) + expectedURLSlice := []*url.URL{urlVal} + if !reflect.DeepEqual(tc.URLSlice, expectedURLSlice) { + t.Fatalf("Expected %s, got %s", expectedURLSlice, tc.URLSlice) } if tc.UnsetString != "" { @@ -366,7 +364,7 @@ func TestDecodeErrors(t *testing.T) { } var tc testConfig - err = Decode(tc) + err = Decode(tc) //nolint:govet if err != ErrInvalidTarget { t.Fatal("Should have gotten an error decoding into a non-pointer") } @@ -413,10 +411,9 @@ func TestDecodeErrors(t *testing.T) { var tcrd testConfigRequiredDefault defer func() { - if r := recover(); r != nil { - } + recover() }() - err = Decode(&tcrd) + _ = Decode(&tcrd) t.Fatal("This should not have been reached. A panic should have occured.") } @@ -464,8 +461,7 @@ func ExampleDecode() { os.Setenv("EXAMPLE_STRING", "an example!") var e Example - err := Decode(&e) - if err != nil { + if err := Decode(&e); err != nil { panic(err) } @@ -500,7 +496,7 @@ type testConfigExport struct { UnsetURL *url.URL `env:"TEST_UNSET_URL"` UnusedField string - unexportedField string + unexportedField string //nolint:structcheck,unused IgnoredPtr *bool `env:"TEST_IGNORED_POINTER"` @@ -619,8 +615,7 @@ func TestExport(t *testing.T) { tc.NestedPtr = &nestedConfigExportPointer{} tc.NoConfigPtrSet = &noConfig{} - err := Decode(&tc) - if err != nil { + if err := Decode(&tc); err != nil { t.Fatal(err) } diff --git a/ocis-pkg/indexer/indexer.go b/ocis-pkg/indexer/indexer.go index 2a42a56f7d1..84189be0add 100644 --- a/ocis-pkg/indexer/indexer.go +++ b/ocis-pkg/indexer/indexer.go @@ -215,12 +215,11 @@ func (i *Indexer) FindByPartial(t interface{}, field string, pattern string) ([] // Update updates all indexes on a value to a value . func (i *Indexer) Update(from, to interface{}) error { typeNameFrom := getTypeFQN(from) - typeNameTo := getTypeFQN(to) i.mu.Lock(typeNameFrom) defer i.mu.Unlock(typeNameFrom) - if typeNameFrom != typeNameTo { + if typeNameTo := getTypeFQN(to); typeNameFrom != typeNameTo { return fmt.Errorf("update types do not match: from %v to %v", typeNameFrom, typeNameTo) } From 6a03c4acba6e55af7c3595d39aa662db3e4c833f Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 09:43:42 +0100 Subject: [PATCH 61/84] improve envdecode error handling --- accounts/pkg/command/root.go | 8 ++++++-- glauth/pkg/command/root.go | 8 ++++++-- graph-explorer/pkg/command/root.go | 8 ++++++-- graph/pkg/command/root.go | 8 ++++++-- idp/pkg/command/root.go | 8 ++++++-- ocis-pkg/config/envdecode/envdecode_test.go | 2 +- ocis/pkg/command/root.go | 8 ++++++-- ocs/pkg/command/root.go | 8 ++++++-- proxy/pkg/command/root.go | 8 ++++++-- settings/pkg/command/root.go | 8 ++++++-- store/pkg/command/root.go | 8 ++++++-- thumbnails/pkg/command/root.go | 8 ++++++-- web/pkg/command/root.go | 8 ++++++-- webdav/pkg/command/root.go | 8 ++++++-- 14 files changed, 79 insertions(+), 27 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index c6d70c96dbb..05b3e835105 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "strings" @@ -79,8 +80,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } // sanitize config diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 5fe6aefdc94..f72d940c1bc 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/glauth/pkg/config" @@ -70,8 +71,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 6b0fbedf8fd..6a4ae2bbe92 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/graph-explorer/pkg/config" @@ -68,8 +69,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 565aa710fb9..41b72393097 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -69,8 +70,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index c59652ff43d..e346e4b1f29 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/idp/pkg/config" @@ -71,8 +72,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/ocis-pkg/config/envdecode/envdecode_test.go b/ocis-pkg/config/envdecode/envdecode_test.go index 54ac86decfd..d8cec54c932 100644 --- a/ocis-pkg/config/envdecode/envdecode_test.go +++ b/ocis-pkg/config/envdecode/envdecode_test.go @@ -411,7 +411,7 @@ func TestDecodeErrors(t *testing.T) { var tcrd testConfigRequiredDefault defer func() { - recover() + _ = recover() }() _ = Decode(&tcrd) t.Fatal("This should not have been reached. A panic should have occured.") diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 232c18ab243..034061824b4 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -1,6 +1,7 @@ package command import ( + "errors" "os" "github.com/owncloud/ocis/ocis-pkg/config" @@ -62,8 +63,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 994e5e8898c..3f17fb049ef 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 7bd07dfde84..02ab99c5847 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -71,8 +72,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index c6091ef905a..9ee08aef210 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index be613a9f756..ca3d05bb2bd 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 4236c1098b8..fbaaeba51d9 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil } diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 371c3337e4a..b56960a86a7 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -70,8 +71,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 224823e0196..e39d64cd0d6 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -70,8 +71,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil From 5b70d46213c6b97102c1ce5fcb3c27ffcb1bed96 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 11:10:33 +0100 Subject: [PATCH 62/84] remove build flags, add debug server to accounts --- accounts/pkg/command/server.go | 13 +++++ accounts/pkg/config/debug.go | 1 - accounts/pkg/config/defaultconfig.go | 6 +++ accounts/pkg/server/debug/option.go | 50 ++++++++++++++++++ accounts/pkg/server/debug/server.go | 63 +++++++++++++++++++++++ glauth/pkg/server/debug/server.go | 6 +-- graph-explorer/pkg/server/debug/server.go | 14 +++-- graph/pkg/server/debug/server.go | 14 +++-- idp/pkg/server/debug/server.go | 12 +++-- ocis-pkg/config/config.go | 2 +- ocis/pkg/command/graph.go | 3 -- ocis/pkg/command/graphexplorer.go | 3 -- ocis/pkg/command/root.go | 16 +++++- ocis/pkg/command/server.go | 1 + ocis/pkg/command/storageauthmachine.go | 3 -- ocis/pkg/command/store.go | 2 + ocs/pkg/server/debug/server.go | 12 +++-- proxy/pkg/server/debug/server.go | 12 +++-- settings/pkg/server/debug/server.go | 18 +++++-- storage/pkg/server/debug/server.go | 14 +++-- store/pkg/server/debug/server.go | 16 ++++-- thumbnails/pkg/server/debug/server.go | 16 +++++- web/pkg/server/debug/server.go | 14 +++-- webdav/pkg/server/debug/server.go | 12 +++-- 24 files changed, 260 insertions(+), 63 deletions(-) create mode 100644 accounts/pkg/server/debug/option.go create mode 100644 accounts/pkg/server/debug/server.go diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 44feb3ffe65..d0cd905a05b 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -7,6 +7,7 @@ import ( "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/logging" "github.com/owncloud/ocis/accounts/pkg/metrics" + "github.com/owncloud/ocis/accounts/pkg/server/debug" "github.com/owncloud/ocis/accounts/pkg/server/grpc" "github.com/owncloud/ocis/accounts/pkg/server/http" svc "github.com/owncloud/ocis/accounts/pkg/service/v0" @@ -75,6 +76,18 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) + // prepare a debug server and add it to the group run. + debugServer, err := debug.Server(debug.Logger(logger), debug.Context(ctx), debug.Config(cfg)) + if err != nil { + logger.Error().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) + cancel() + }) + return gr.Run() }, } diff --git a/accounts/pkg/config/debug.go b/accounts/pkg/config/debug.go index c95ef3a2666..539b8fababf 100644 --- a/accounts/pkg/config/debug.go +++ b/accounts/pkg/config/debug.go @@ -1,6 +1,5 @@ package config -//TODO: use debug config // Debug defines the available debug configuration. type Debug struct { Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"` diff --git a/accounts/pkg/config/defaultconfig.go b/accounts/pkg/config/defaultconfig.go index 5b027a54598..2c69305bb9a 100644 --- a/accounts/pkg/config/defaultconfig.go +++ b/accounts/pkg/config/defaultconfig.go @@ -8,6 +8,12 @@ import ( func DefaultConfig() *Config { return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9182", + Token: "", + Pprof: false, + Zpages: false, + }, HTTP: HTTP{ Addr: "127.0.0.1:9181", Namespace: "com.owncloud.web", diff --git a/accounts/pkg/server/debug/option.go b/accounts/pkg/server/debug/option.go new file mode 100644 index 00000000000..0fd139d248f --- /dev/null +++ b/accounts/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/accounts/pkg/server/debug/server.go b/accounts/pkg/server/debug/server.go new file mode 100644 index 00000000000..cabc144644d --- /dev/null +++ b/accounts/pkg/server/debug/server.go @@ -0,0 +1,63 @@ +package debug + +import ( + "io" + "net/http" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.String), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(health(options.Config)), + debug.Ready(ready(options.Config)), + debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), + debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), + debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), + debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), + ), nil +} + +// health implements the health check. +func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + + // TODO: check if services are up and running + + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } + } +} + +// ready implements the ready check. +func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + + // TODO: check if services are up and running + + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } + } +} diff --git a/glauth/pkg/server/debug/server.go b/glauth/pkg/server/debug/server.go index d6373ba1ec7..5cc9fab7b36 100644 --- a/glauth/pkg/server/debug/server.go +++ b/glauth/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("glauth"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,7 +32,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running _, err := io.WriteString(w, http.StatusText(http.StatusOK)) // io.WriteString should not fail but if it does we want to know. @@ -48,7 +48,7 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running _, err := io.WriteString(w, http.StatusText(http.StatusOK)) // io.WriteString should not fail but if it does we want to know. diff --git a/graph-explorer/pkg/server/debug/server.go b/graph-explorer/pkg/server/debug/server.go index 5717db3c7cd..1165097394c 100644 --- a/graph-explorer/pkg/server/debug/server.go +++ b/graph-explorer/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("graph-explorer"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -46,9 +48,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } diff --git a/graph/pkg/server/debug/server.go b/graph/pkg/server/debug/server.go index fe979c8ee20..240b1f93626 100644 --- a/graph/pkg/server/debug/server.go +++ b/graph/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("graph"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -46,9 +48,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } diff --git a/idp/pkg/server/debug/server.go b/idp/pkg/server/debug/server.go index f05038d95a3..bdfe9208373 100644 --- a/idp/pkg/server/debug/server.go +++ b/idp/pkg/server/debug/server.go @@ -31,9 +31,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -45,9 +47,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index d0cd0e1d2dc..1f3e3c0d2cb 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -45,7 +45,7 @@ type Config struct { *shared.Commons `ocisConfig:"shared"` Tracing shared.Tracing `ocisConfig:"tracing"` - Log shared.Log `ocisConfig:"log"` + Log *shared.Log `ocisConfig:"log"` Mode Mode // DEPRECATED File string diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 1b1ae5553dc..ecc94826caa 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index e4dc82e0247..7833206b916 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 034061824b4..51ff2189ba8 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -5,8 +5,8 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/config" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" @@ -57,11 +57,23 @@ func Execute() error { // ParseConfig loads ocis configuration. func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs("ocis", cfg) + _, err := config.BindSourcesToStructs("ocis", cfg) if err != nil { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &shared.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &shared.Log{} + } + // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index c9262144d5c..67cde41954d 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -18,6 +18,7 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { + // what to do //cfg.Commons = &shared.Commons{ // Log: &cfg.Log, //} diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 9498c7a017a..18b9d8a183e 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 5629abac378..cec0e2e028c 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -23,11 +23,13 @@ func StoreCommand(cfg *config.Config) *cli.Command { return err } + // TODO: what to do //globalLog = cfg.Log return nil }, Action: func(c *cli.Context) error { + // TODO: what to do // if accounts logging is empty in ocis.yaml //if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) { // // we can safely inherit the global logging values. diff --git a/ocs/pkg/server/debug/server.go b/ocs/pkg/server/debug/server.go index 7c704840e0b..214c4a9c196 100644 --- a/ocs/pkg/server/debug/server.go +++ b/ocs/pkg/server/debug/server.go @@ -35,9 +35,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -49,9 +51,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index b4106f2a8c4..5c4b3804625 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -33,9 +33,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -47,9 +49,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } diff --git a/settings/pkg/server/debug/server.go b/settings/pkg/server/debug/server.go index 36bf1411eaa..81f41de18b5 100644 --- a/settings/pkg/server/debug/server.go +++ b/settings/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("settings"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -36,9 +36,13 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } } } @@ -48,8 +52,12 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } } } diff --git a/storage/pkg/server/debug/server.go b/storage/pkg/server/debug/server.go index 4a3fa24b3a8..29ea57b0a70 100644 --- a/storage/pkg/server/debug/server.go +++ b/storage/pkg/server/debug/server.go @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -46,10 +48,12 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } -} +} \ No newline at end of file diff --git a/store/pkg/server/debug/server.go b/store/pkg/server/debug/server.go index e3812b25df1..975974c5cc9 100644 --- a/store/pkg/server/debug/server.go +++ b/store/pkg/server/debug/server.go @@ -31,9 +31,13 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } } } @@ -43,8 +47,12 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } } } diff --git a/thumbnails/pkg/server/debug/server.go b/thumbnails/pkg/server/debug/server.go index b78261d5fe2..24fdee22c1b 100644 --- a/thumbnails/pkg/server/debug/server.go +++ b/thumbnails/pkg/server/debug/server.go @@ -25,21 +25,33 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } +// health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + + // TODO: check if services are up and running + + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } } +// ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + + // TODO: check if services are up and running + + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } diff --git a/web/pkg/server/debug/server.go b/web/pkg/server/debug/server.go index 43c45036bd3..d4d7e302e6a 100644 --- a/web/pkg/server/debug/server.go +++ b/web/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("web"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -46,9 +48,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } diff --git a/webdav/pkg/server/debug/server.go b/webdav/pkg/server/debug/server.go index f79a0538f81..ad9568b6041 100644 --- a/webdav/pkg/server/debug/server.go +++ b/webdav/pkg/server/debug/server.go @@ -35,9 +35,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } @@ -49,9 +51,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { panic(err) } } From 23e7a8ffabbbe17180913ae50201d43407495c9b Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 13:53:27 +0100 Subject: [PATCH 63/84] simplify commands and version handling --- accounts/pkg/command/root.go | 55 ++-- accounts/pkg/command/version.go | 13 +- glauth/pkg/command/root.go | 41 ++- glauth/pkg/command/version.go | 18 +- graph-explorer/pkg/command/root.go | 41 +-- graph-explorer/pkg/command/version.go | 16 +- graph/pkg/command/root.go | 40 +-- graph/pkg/command/version.go | 16 +- graph/pkg/config/config.go | 1 - idp/pkg/command/root.go | 42 ++- idp/pkg/command/version.go | 16 +- ocis-pkg/clihelper/app.go | 26 ++ ocis/pkg/command/accounts.go | 13 +- ocis/pkg/command/glauth.go | 5 +- ocis/pkg/command/graph.go | 10 +- ocis/pkg/command/graphexplorer.go | 10 +- ocis/pkg/command/idp.go | 12 +- ocis/pkg/command/ocs.go | 8 +- ocis/pkg/command/proxy.go | 8 +- ocis/pkg/command/root.go | 25 +- ocis/pkg/command/settings.go | 8 +- ocis/pkg/command/store.go | 21 +- ocis/pkg/command/thumbnails.go | 4 +- ocis/pkg/command/version.go | 5 + ocis/pkg/command/web.go | 5 +- ocis/pkg/command/webdav.go | 8 +- ocs/pkg/command/root.go | 43 ++- ocs/pkg/command/version.go | 16 +- proxy/pkg/command/root.go | 42 ++- proxy/pkg/command/version.go | 16 +- settings/pkg/command/root.go | 43 ++- settings/pkg/command/version.go | 16 +- storage/pkg/command/root.go | 60 ++-- storage/pkg/config/defaultconfig.go | 436 ++++++++++++++++++++++++++ store/pkg/command/root.go | 43 ++- store/pkg/command/version.go | 16 +- thumbnails/pkg/command/root.go | 43 ++- thumbnails/pkg/command/version.go | 16 +- web/pkg/command/root.go | 42 +-- web/pkg/command/version.go | 16 +- webdav/pkg/command/root.go | 43 ++- webdav/pkg/command/version.go | 16 +- 42 files changed, 874 insertions(+), 500 deletions(-) create mode 100644 ocis-pkg/clihelper/app.go create mode 100644 storage/pkg/config/defaultconfig.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 05b3e835105..5122954234a 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -14,49 +15,45 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + AddAccount(cfg), + UpdateAccount(cfg), + ListAccounts(cfg), + InspectAccount(cfg), + RemoveAccount(cfg), + RebuildIndex(cfg), + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-accounts command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-accounts", - Version: version.String, - Usage: "Provide accounts and groups for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-accounts", + Usage: "Provide accounts and groups for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - AddAccount(cfg), - UpdateAccount(cfg), - ListAccounts(cfg), - InspectAccount(cfg), - RemoveAccount(cfg), - RebuildIndex(cfg), - - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index 7e7fc0f571d..6d3ec843f99 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -5,27 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get accounts services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running accounts service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index f72d940c1bc..120791317a6 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -6,6 +6,7 @@ import ( "os" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,41 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-glauth command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-glauth", - Version: version.String, - Usage: "Serve GLAuth API for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-glauth", + Usage: "Serve GLAuth API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/glauth/pkg/command/version.go b/glauth/pkg/command/version.go index b9be475ab49..c3d2e4ffd39 100644 --- a/glauth/pkg/command/version.go +++ b/glauth/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/glauth/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Ldaps.Namespace + "." + cfg.Service.Name) + services, err := reg.GetService(cfg.Ldap.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get glauth services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running glauth service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 6a4ae2bbe92..4e3fecc58bf 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -6,6 +6,7 @@ import ( "os" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,38 +14,38 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the graph-explorer command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "graph-explorer", - Version: version.String, - Usage: "Serve Graph-Explorer for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "graph-explorer", + Usage: "Serve Graph-Explorer for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) + cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } return app.Run(os.Args) } diff --git a/graph-explorer/pkg/command/version.go b/graph-explorer/pkg/command/version.go index 2fde4e337ea..400c0bf1043 100644 --- a/graph-explorer/pkg/command/version.go +++ b/graph-explorer/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/graph-explorer/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get graph services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running graph service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 41b72393097..af4f264f17e 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/thejerf/suture/v4" @@ -14,38 +15,37 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-graph command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-graph", - Version: version.String, - Usage: "Serve Graph API for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-graph", + Usage: "Serve Graph API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } return app.Run(os.Args) } diff --git a/graph/pkg/command/version.go b/graph/pkg/command/version.go index 3eeaff740cf..8ced4ad48a5 100644 --- a/graph/pkg/command/version.go +++ b/graph/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/graph/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get graph services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running graph service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index f5925b75444..523bcfdb045 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -33,7 +33,6 @@ type Spaces struct { DefaultQuota string `ocisConfig:"default_quota" env:"GRAPH_SPACES_DEFAULT_QUOTA"` } -// TODO: do we really need a ldap backend if CS3 also does LDAP!? type LDAP struct { URI string `ocisConfig:"uri" env:"GRAPH_LDAP_URI"` BindDN string `ocisConfig:"bind_dn" env:"GRAPH_LDAP_BIND_DN"` diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index e346e4b1f29..bcb8e4ea1fe 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -6,6 +6,7 @@ import ( "os" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,42 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-idp command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-idp", - Version: version.String, - Usage: "Serve IDP API for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-idp", + Usage: "Serve IDP API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/idp/pkg/command/version.go b/idp/pkg/command/version.go index 30a54513947..f9cbcd574ed 100644 --- a/idp/pkg/command/version.go +++ b/idp/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/idp/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get idp services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running idp service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/ocis-pkg/clihelper/app.go b/ocis-pkg/clihelper/app.go new file mode 100644 index 00000000000..4ea39ace310 --- /dev/null +++ b/ocis-pkg/clihelper/app.go @@ -0,0 +1,26 @@ +package clihelper + +import ( + "github.com/owncloud/ocis/ocis-pkg/version" + "github.com/urfave/cli/v2" +) + +func DefaultApp(app *cli.App) *cli.App { + // version info + app.Version = version.String + app.Compiled = version.Compiled() + + // author info + app.Authors = []*cli.Author{ + { + Name: "ownCloud GmbH", + Email: "support@owncloud.com", + }, + } + + // disable global version flag + // instead we provide the version command + app.HideVersion = true + + return app +} diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 1c3db45c0da..62efe82eaac 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -13,14 +13,6 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Name: "accounts", Usage: "Start accounts server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.ListAccounts(cfg.Accounts), - command.AddAccount(cfg.Accounts), - command.UpdateAccount(cfg.Accounts), - command.RemoveAccount(cfg.Accounts), - command.InspectAccount(cfg.Accounts), - command.PrintVersion(cfg.Accounts), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -32,10 +24,7 @@ func AccountsCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Accounts) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Accounts), } } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index c6baacfdeb5..1f9da764d0d 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -24,10 +24,7 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.GLAuth) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.GLAuth), } } diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index ecc94826caa..92e5b532c23 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -19,18 +19,12 @@ func GraphCommand(cfg *config.Config) *cli.Command { } if cfg.Commons != nil { - cfg.Graph.Commons = cfg.Commons + cfg.Accounts.Commons = cfg.Commons } return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Graph) - return handleOriginalAction(c, origCmd) - }, - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Graph), - }, + Subcommands: command.GetCommands(cfg.Graph), } } diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index 7833206b916..f02ad25b756 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -19,18 +19,12 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { } if cfg.Commons != nil { - cfg.Graph.Commons = cfg.Commons + cfg.GraphExplorer.Commons = cfg.Commons } return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.GraphExplorer) - return handleOriginalAction(c, origCmd) - }, - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.GraphExplorer), - }, + Subcommands: command.GetCommands(cfg.GraphExplorer), } } diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 7b35c15ba89..62d929cbe13 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -13,9 +13,6 @@ func IDPCommand(cfg *config.Config) *cli.Command { Name: "idp", Usage: "Start idp server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.IDP), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -27,14 +24,7 @@ func IDPCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - idpCommand := command.Server(cfg.IDP) - if err := idpCommand.Before(c); err != nil { - return err - } - - return cli.HandleAction(idpCommand.Action, c) - }, + Subcommands: command.GetCommands(cfg.IDP), } } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 243c27696f5..dd010e71f35 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -24,13 +24,7 @@ func OCSCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.OCS) - return handleOriginalAction(c, origCmd) - }, - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.OCS), - }, + Subcommands: command.GetCommands(cfg.OCS), } } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 7458a80d669..2554573a284 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -13,9 +13,6 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Name: "proxy", Usage: "Start proxy server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Proxy), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -27,10 +24,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Proxy) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Proxy), } } diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 51ff2189ba8..163adebc80d 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -4,10 +4,10 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -16,24 +16,16 @@ import ( func Execute() error { cfg := config.DefaultConfig() - app := &cli.App{ - Name: "ocis", - Version: version.String, - Usage: "ownCloud Infinite Scale Stack", - Compiled: version.Compiled(), + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis", + Usage: "ownCloud Infinite Scale Stack", Before: func(c *cli.Context) error { + // TODO: what do do? //cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, - } + }) for _, fn := range register.Commands { app.Commands = append( @@ -47,11 +39,6 @@ func Execute() error { Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 90bdafc304f..ae1fec6c607 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -13,9 +13,6 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Name: "settings", Usage: "Start settings server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Settings), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -27,10 +24,7 @@ func SettingsCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Settings) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Settings), } } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index cec0e2e028c..6fda33d5ebb 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -9,36 +9,23 @@ import ( // StoreCommand is the entrypoint for the ocs command. func StoreCommand(cfg *config.Config) *cli.Command { - //var globalLog shared.Log return &cli.Command{ Name: "store", Usage: "Start a go-micro store", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Store), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err } - // TODO: what to do - //globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Store.Commons = cfg.Commons + } return nil }, - Action: func(c *cli.Context) error { - // TODO: what to do - // if accounts logging is empty in ocis.yaml - //if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // // we can safely inherit the global logging values. - // cfg.Store.Log = globalLog - //} - - origCmd := command.Server(cfg.Store) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Store), } } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index f671358e779..add5b668458 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -13,9 +13,6 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { Name: "thumbnails", Usage: "Start thumbnails server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Thumbnails), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -31,6 +28,7 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { origCmd := command.Server(cfg.Thumbnails) return handleOriginalAction(c, origCmd) }, + Subcommands: command.GetCommands(cfg.Thumbnails), } } diff --git a/ocis/pkg/command/version.go b/ocis/pkg/command/version.go index 21d762b5916..f693406832c 100644 --- a/ocis/pkg/command/version.go +++ b/ocis/pkg/command/version.go @@ -7,6 +7,7 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" mreg "go-micro.dev/v4/registry" @@ -19,6 +20,10 @@ func VersionCommand(cfg *config.Config) *cli.Command { Usage: "Lists running services with version", Category: "Runtime", Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() serviceList, err := reg.ListServices() if err != nil { diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index c3f2df2eafe..e1f66f8eef4 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -24,10 +24,7 @@ func WebCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Web) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Web), } } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 31cb2c52856..ea7f518225d 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -14,9 +14,6 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { Name: "webdav", Usage: "Start webdav server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.WebDAV), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -28,10 +25,7 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.WebDAV) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.WebDAV), } } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 3f17fb049ef..2b143d547aa 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-ocs command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-ocs", - Version: version.String, - Usage: "Serve OCS API for oCIS", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-ocs", + Usage: "Serve OCS API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/ocs/pkg/command/version.go b/ocs/pkg/command/version.go index dac137c15cd..116c081df6e 100644 --- a/ocs/pkg/command/version.go +++ b/ocs/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/ocs/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get ocs services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running ocs service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 02ab99c5847..283e85246a4 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,42 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-proxy command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-proxy", - Version: version.String, - Usage: "proxy for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-proxy", + Usage: "proxy for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/proxy/pkg/command/version.go b/proxy/pkg/command/version.go index bd9cd671792..7545db5d42d 100644 --- a/proxy/pkg/command/version.go +++ b/proxy/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get proxy services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running proxy service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 9ee08aef210..03340bb1af6 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-settings command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-settings", - Version: version.String, - Usage: "Provide settings and permissions for oCIS", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-settings", + Usage: "Provide settings and permissions for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/settings/pkg/command/version.go b/settings/pkg/command/version.go index 55091cf81a1..15c3901363b 100644 --- a/settings/pkg/command/version.go +++ b/settings/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/settings/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get settings services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running settings service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 80e16d0719e..29c5b6a384e 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -3,58 +3,50 @@ package command import ( "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + Frontend(cfg), + Gateway(cfg), + Users(cfg), + Groups(cfg), + AppProvider(cfg), + AuthBasic(cfg), + AuthBearer(cfg), + AuthMachine(cfg), + Sharing(cfg), + StoragePublicLink(cfg), + StorageShares(cfg), + StorageUsers(cfg), + StorageMetadata(cfg), + Health(cfg), + } +} + // Execute is the entry point for the storage command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "storage", - Version: version.String, - Usage: "Storage service for oCIS", - Compiled: version.Compiled(), + app := clihelper.DefaultApp(&cli.App{ + Name: "storage", + Usage: "Storage service for oCIS", - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage") }, - Commands: []*cli.Command{ - Frontend(cfg), - Gateway(cfg), - Users(cfg), - Groups(cfg), - AppProvider(cfg), - AuthBasic(cfg), - AuthBearer(cfg), - AuthMachine(cfg), - Sharing(cfg), - StorageUsers(cfg), - StorageShares(cfg), - StoragePublicLink(cfg), - StorageMetadata(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/storage/pkg/config/defaultconfig.go b/storage/pkg/config/defaultconfig.go new file mode 100644 index 00000000000..00e0dba3633 --- /dev/null +++ b/storage/pkg/config/defaultconfig.go @@ -0,0 +1,436 @@ +package config + +import ( + "os" + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + // log is inherited + Debug: Debug{ + Addr: "127.0.0.1:9109", + }, + Reva: Reva{ + JWTSecret: "Pive-Fumkiu4", + SkipUserGroupsInToken: false, + TransferSecret: "replace-me-with-a-transfer-secret", + TransferExpires: 24 * 60 * 60, + OIDC: OIDC{ + Issuer: "https://localhost:9200", + Insecure: false, + IDClaim: "preferred_username", + }, + LDAP: LDAP{ + Hostname: "localhost", + Port: 9126, + CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Insecure: false, + BaseDN: "dc=ocis,dc=test", + LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", + UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", + UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", + GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", + GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", + BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", + BindPassword: "reva", + IDP: "https://localhost:9200", + UserSchema: LDAPUserSchema{ + UID: "ownclouduuid", + Mail: "mail", + DisplayName: "displayname", + CN: "cn", + UIDNumber: "uidnumber", + GIDNumber: "gidnumber", + }, + GroupSchema: LDAPGroupSchema{ + GID: "cn", + Mail: "mail", + DisplayName: "cn", + CN: "cn", + GIDNumber: "gidnumber", + }, + }, + UserGroupRest: UserGroupRest{ + RedisAddress: "localhost:6379", + }, + UserOwnCloudSQL: UserOwnCloudSQL{ + DBUsername: "owncloud", + DBPassword: "secret", + DBHost: "mysql", + DBPort: 3306, + DBName: "owncloud", + Idp: "https://localhost:9200", + Nobody: 90, + JoinUsername: false, + JoinOwnCloudUUID: false, + EnableMedialSearch: false, + }, + OCDav: OCDav{ + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + DavFilesNamespace: "/users/{{.Id.OpaqueId}}", + }, + Archiver: Archiver{ + MaxNumFiles: 10000, + MaxSize: 1073741824, + ArchiverURL: "/archiver", + }, + UserStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + }, + ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") + UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + OwnCloud: DriverOwnCloud{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + Redis: ":6379", + Scan: true, + }, + OwnCloudSQL: DriverOwnCloudSQL{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + DBUsername: "owncloud", + DBPassword: "owncloud", + DBHost: "", + DBPort: 3306, + DBName: "owncloud", + }, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + MetadataStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + EnableHome: false, + }, + ShadowNamespace: "", + UploadsNamespace: "", + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + GrpcURI: "", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + EnableLogging: false, + ShowHiddenSysFiles: false, + ForceSingleUserMode: false, + UseKeytab: false, + SecProtocol: "", + Keytab: "", + SingleUsername: "", + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), + }, + OwnCloud: DriverOwnCloud{}, + OwnCloudSQL: DriverOwnCloudSQL{}, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + Frontend: FrontendPort{ + Port: Port{ + MaxCPUs: "", + LogLevel: "", + GRPCNetwork: "", + GRPCAddr: "", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9140", + Protocol: "", + Endpoint: "", + DebugAddr: "127.0.0.1:9141", + Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, + Config: nil, + Context: nil, + Supervised: false, + }, + AppProviderInsecure: false, + AppProviderPrefix: "", + ArchiverInsecure: false, + ArchiverPrefix: "archiver", + DatagatewayPrefix: "data", + Favorites: false, + OCDavInsecure: false, + OCDavPrefix: "", + OCSPrefix: "ocs", + OCSSharePrefix: "/Shares", + OCSHomeNamespace: "/users/{{.Id.OpaqueId}}", + PublicURL: "https://localhost:9200", + OCSCacheWarmupDriver: "", + OCSAdditionalInfoAttribute: "{{.Mail}}", + OCSResourceInfoCacheTTL: 0, + Middleware: Middleware{}, + }, + DataGateway: DataGatewayPort{ + Port: Port{}, + PublicURL: "", + }, + Gateway: Gateway{ + Port: Port{ + Endpoint: "127.0.0.1:9142", + DebugAddr: "127.0.0.1:9143", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9142", + }, + CommitShareToStorageGrant: true, + CommitShareToStorageRef: true, + DisableHomeCreationOnLogin: false, + ShareFolder: "Shares", + LinkGrants: "", + HomeMapping: "", + EtagCacheTTL: 0, + }, + StorageRegistry: StorageRegistry{ + Driver: "spaces", + HomeProvider: "/home", + JSON: "", + }, + AppRegistry: AppRegistry{ + Driver: "static", + MimetypesJSON: "", + }, + Users: Users{ + Port: Port{ + Endpoint: "localhost:9144", + DebugAddr: "127.0.0.1:9145", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9144", + Services: []string{"userprovider"}, + }, + Driver: "ldap", + UserGroupsCacheExpiration: 5, + }, + Groups: Groups{ + Port: Port{ + Endpoint: "localhost:9160", + DebugAddr: "127.0.0.1:9161", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9160", + Services: []string{"groupprovider"}, + }, + Driver: "ldap", + GroupMembersCacheExpiration: 5, + }, + AuthProvider: Users{ + Port: Port{}, + Driver: "ldap", + UserGroupsCacheExpiration: 0, + }, + AuthBasic: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9146", + DebugAddr: "127.0.0.1:9147", + Services: []string{"authprovider"}, + Endpoint: "localhost:9146", + }, + AuthBearer: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9148", + DebugAddr: "127.0.0.1:9149", + Services: []string{"authprovider"}, + Endpoint: "localhost:9148", + }, + AuthMachine: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9166", + DebugAddr: "127.0.0.1:9167", + Services: []string{"authprovider"}, + Endpoint: "localhost:9166", + }, + AuthMachineConfig: AuthMachineConfig{ + MachineAuthAPIKey: "change-me-please", + }, + Sharing: Sharing{ + Port: Port{ + Endpoint: "localhost:9150", + DebugAddr: "127.0.0.1:9151", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9150", + Services: []string{"usershareprovider", "publicshareprovider"}, + }, + UserDriver: "json", + UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), + UserSQLUsername: "", + UserSQLPassword: "", + UserSQLHost: "", + UserSQLPort: 1433, + UserSQLName: "", + PublicDriver: "json", + PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), + PublicPasswordHashCost: 11, + PublicEnableExpiredSharesCleanup: true, + PublicJanitorRunInterval: 60, + UserStorageMountID: "", + }, + StorageShares: StoragePort{ + Port: Port{ + Endpoint: "localhost:9154", + DebugAddr: "127.0.0.1:9156", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9154", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9155", + }, + ReadOnly: false, + AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + }, + StorageUsers: StoragePort{ + Port: Port{ + Endpoint: "localhost:9157", + DebugAddr: "127.0.0.1:9159", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9157", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9158", + }, + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + Driver: "ocis", + DataServerURL: "http://localhost:9158/data", + HTTPPrefix: "data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), + }, + StoragePublicLink: PublicStorage{ + StoragePort: StoragePort{ + Port: Port{ + Endpoint: "localhost:9178", + DebugAddr: "127.0.0.1:9179", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9178", + }, + MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", + }, + PublicShareProviderAddr: "", + UserProviderAddr: "", + }, + StorageMetadata: StoragePort{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9215", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9216", + DebugAddr: "127.0.0.1:9217", + }, + Driver: "ocis", + ExposeDataServer: false, + DataServerURL: "http://localhost:9216/data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), + DataProvider: DataProvider{}, + }, + AppProvider: AppProvider{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9164", + DebugAddr: "127.0.0.1:9165", + Endpoint: "localhost:9164", + Services: []string{"appprovider"}, + }, + ExternalAddr: "127.0.0.1:9164", + WopiDriver: WopiDriver{}, + AppsURL: "/app/list", + OpenURL: "/app/open", + NewURL: "/app/new", + }, + Configs: nil, + UploadMaxChunkSize: 1e+8, + UploadHTTPMethodOverride: "", + ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, + ChecksumPreferredUploadType: "", + DefaultUploadProtocol: "tus", + }, + Tracing: Tracing{ + Service: "storage", + Type: "jaeger", + }, + Asset: Asset{}, + } +} diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index ca3d05bb2bd..c32c0c45f34 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-store command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-store", - Version: version.String, - Usage: "Service to store values for ocis extensions", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-store", + Usage: "Service to store values for ocis extensions", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/store/pkg/command/version.go b/store/pkg/command/version.go index 588e45b6465..91554c791a7 100644 --- a/store/pkg/command/version.go +++ b/store/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/store/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get store services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running store service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index fbaaeba51d9..ad18155e752 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-thumbnails command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-thumbnails", - Version: version.String, - Usage: "Example usage", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-thumbnails", + Usage: "Example usage", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/thumbnails/pkg/command/version.go b/thumbnails/pkg/command/version.go index d3dfb245916..45030313a34 100644 --- a/thumbnails/pkg/command/version.go +++ b/thumbnails/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/thumbnails/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get thumbnails services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running thumbnails service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index b56960a86a7..38c8ea330df 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,46 +14,45 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the web command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "web", - Version: version.String, - Usage: "Serve ownCloud Web for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "web", + Usage: "Serve ownCloud Web for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { + // TODO: remove cli.Context _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err diff --git a/web/pkg/command/version.go b/web/pkg/command/version.go index 94a87b49665..7b76bdcfe93 100644 --- a/web/pkg/command/version.go +++ b/web/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/web/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get web services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running web service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index e39d64cd0d6..2846715b329 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,41 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + // start this service + Server(cfg), + + // interaction with this service + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-webdav command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "webdav", - Version: version.String, - Usage: "Serve WebDAV API for oCIS", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "webdav", + Usage: "Serve WebDAV API for oCIS", + Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/webdav/pkg/command/version.go b/webdav/pkg/command/version.go index a0ab763f591..f6649a41a70 100644 --- a/webdav/pkg/command/version.go +++ b/webdav/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/webdav/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get webdav services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running webdav service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } From b9f2b6b91e9d4ae40879fdf5175405458e68d6a1 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 15:21:56 +0100 Subject: [PATCH 64/84] move config parsing in separate package for each service --- accounts/pkg/command/health.go | 3 +- accounts/pkg/command/root.go | 46 +------------------- accounts/pkg/command/server.go | 3 +- accounts/pkg/config/parser/parse.go | 47 +++++++++++++++++++++ glauth/pkg/command/health.go | 3 +- glauth/pkg/command/root.go | 39 +---------------- glauth/pkg/command/server.go | 3 +- glauth/pkg/config/parser/parse.go | 42 +++++++++++++++++++ graph-explorer/pkg/command/health.go | 3 +- graph-explorer/pkg/command/root.go | 39 +---------------- graph-explorer/pkg/command/server.go | 8 +--- graph-explorer/pkg/config/parser/parse.go | 46 ++++++++++++++++++++ graph/pkg/command/health.go | 3 +- graph/pkg/command/root.go | 39 +---------------- graph/pkg/command/server.go | 7 +--- graph/pkg/config/parser/parse.go | 46 ++++++++++++++++++++ idp/pkg/command/health.go | 3 +- idp/pkg/command/root.go | 39 +---------------- idp/pkg/command/server.go | 8 +--- idp/pkg/config/parser/parse.go | 46 ++++++++++++++++++++ ocis-pkg/config/parser/parse.go | 39 +++++++++++++++++ ocis/pkg/command/accounts.go | 3 +- ocis/pkg/command/glauth.go | 3 +- ocis/pkg/command/graph.go | 3 +- ocis/pkg/command/graphexplorer.go | 3 +- ocis/pkg/command/idp.go | 3 +- ocis/pkg/command/ocs.go | 3 +- ocis/pkg/command/proxy.go | 3 +- ocis/pkg/command/root.go | 39 +---------------- ocis/pkg/command/server.go | 11 ++--- ocis/pkg/command/settings.go | 3 +- ocis/pkg/command/store.go | 3 +- ocis/pkg/command/thumbnails.go | 3 +- ocis/pkg/command/util.go | 3 +- ocis/pkg/command/web.go | 3 +- ocis/pkg/command/webdav.go | 3 +- ocs/pkg/command/health.go | 3 +- ocs/pkg/command/root.go | 39 +---------------- ocs/pkg/command/server.go | 8 +--- ocs/pkg/config/parser/parse.go | 46 ++++++++++++++++++++ proxy/pkg/command/root.go | 39 +---------------- proxy/pkg/command/server.go | 50 ++-------------------- proxy/pkg/config/config.go | 22 +++------- proxy/pkg/config/parser/parse.go | 51 +++++++++++++++++++++++ proxy/pkg/config/reva.go | 6 +++ settings/pkg/command/health.go | 3 +- settings/pkg/command/root.go | 39 +---------------- settings/pkg/command/server.go | 8 +--- settings/pkg/config/parser/parse.go | 46 ++++++++++++++++++++ store/pkg/command/health.go | 3 +- store/pkg/command/root.go | 39 +---------------- store/pkg/command/server.go | 9 ++-- store/pkg/config/parser/parse.go | 42 +++++++++++++++++++ thumbnails/pkg/command/health.go | 3 +- thumbnails/pkg/command/root.go | 38 +---------------- thumbnails/pkg/command/server.go | 3 +- thumbnails/pkg/config/parser/parse.go | 42 +++++++++++++++++++ web/pkg/command/health.go | 3 +- web/pkg/command/root.go | 40 +----------------- web/pkg/command/server.go | 3 +- web/pkg/config/defaultconfig.go | 5 ++- web/pkg/config/parser/parse.go | 42 +++++++++++++++++++ webdav/pkg/command/health.go | 3 +- webdav/pkg/command/root.go | 39 +---------------- webdav/pkg/command/server.go | 7 +--- webdav/pkg/config/parser/parse.go | 46 ++++++++++++++++++++ 66 files changed, 705 insertions(+), 623 deletions(-) create mode 100644 accounts/pkg/config/parser/parse.go create mode 100644 glauth/pkg/config/parser/parse.go create mode 100644 graph-explorer/pkg/config/parser/parse.go create mode 100644 graph/pkg/config/parser/parse.go create mode 100644 idp/pkg/config/parser/parse.go create mode 100644 ocis-pkg/config/parser/parse.go create mode 100644 ocs/pkg/config/parser/parse.go create mode 100644 proxy/pkg/config/parser/parse.go create mode 100644 proxy/pkg/config/reva.go create mode 100644 settings/pkg/config/parser/parse.go create mode 100644 store/pkg/config/parser/parse.go create mode 100644 thumbnails/pkg/config/parser/parse.go create mode 100644 web/pkg/config/parser/parse.go create mode 100644 webdav/pkg/config/parser/parse.go diff --git a/accounts/pkg/command/health.go b/accounts/pkg/command/health.go index 5a4d79cef2e..2fadae8ef72 100644 --- a/accounts/pkg/command/health.go +++ b/accounts/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/config/parser" "github.com/owncloud/ocis/accounts/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 5122954234a..a0d264fde47 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -2,15 +2,12 @@ package command import ( "context" - "errors" "os" - "strings" "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -40,12 +37,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-accounts", Usage: "Provide accounts and groups for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -57,42 +51,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads accounts configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) - - return nil -} - // SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index d0cd905a05b..906dd75b64b 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -5,6 +5,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/config/parser" "github.com/owncloud/ocis/accounts/pkg/logging" "github.com/owncloud/ocis/accounts/pkg/metrics" "github.com/owncloud/ocis/accounts/pkg/server/debug" @@ -22,7 +23,7 @@ func Server(cfg *config.Config) *cli.Command { Usage: "Start ocis accounts service", Description: "uses an LDAP server as the storage backend", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/accounts/pkg/config/parser/parse.go b/accounts/pkg/config/parser/parse.go new file mode 100644 index 00000000000..dee2dc13b75 --- /dev/null +++ b/accounts/pkg/config/parser/parse.go @@ -0,0 +1,47 @@ +package parser + +import ( + "errors" + "strings" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) + + return nil +} diff --git a/glauth/pkg/command/health.go b/glauth/pkg/command/health.go index 1cd0eac23cd..215018b291c 100644 --- a/glauth/pkg/command/health.go +++ b/glauth/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/config/parser" "github.com/owncloud/ocis/glauth/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 120791317a6..4ba8e95be32 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-glauth", Usage: "Serve GLAuth API for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads glauth configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the glauth command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index e5f88b39486..db5222db916 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -7,6 +7,7 @@ import ( "github.com/oklog/run" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/config/parser" "github.com/owncloud/ocis/glauth/pkg/logging" "github.com/owncloud/ocis/glauth/pkg/metrics" "github.com/owncloud/ocis/glauth/pkg/server/debug" @@ -24,7 +25,7 @@ func Server(cfg *config.Config) *cli.Command { Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/glauth/pkg/config/parser/parse.go b/glauth/pkg/config/parser/parse.go new file mode 100644 index 00000000000..b2a18b2a90a --- /dev/null +++ b/glauth/pkg/config/parser/parse.go @@ -0,0 +1,42 @@ +package parser + +import ( + "errors" + + "github.com/owncloud/ocis/glauth/pkg/config" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + + return nil +} diff --git a/graph-explorer/pkg/command/health.go b/graph-explorer/pkg/command/health.go index 54ad47fe99c..6719e960af9 100644 --- a/graph-explorer/pkg/command/health.go +++ b/graph-explorer/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/config/parser" "github.com/owncloud/ocis/graph-explorer/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig( cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 4e3fecc58bf..92097b27998 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "graph-explorer", Usage: "Serve Graph-Explorer for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads graph configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the graph-explorer command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index 6b9f80129bd..b16ec1150bc 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -2,10 +2,10 @@ package command import ( "context" - "strings" "github.com/oklog/run" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/config/parser" "github.com/owncloud/ocis/graph-explorer/pkg/logging" "github.com/owncloud/ocis/graph-explorer/pkg/metrics" "github.com/owncloud/ocis/graph-explorer/pkg/server/debug" @@ -20,11 +20,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - - return ParseConfig(ctx, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/graph-explorer/pkg/config/parser/parse.go b/graph-explorer/pkg/config/parser/parse.go new file mode 100644 index 00000000000..be113e45980 --- /dev/null +++ b/graph-explorer/pkg/config/parser/parse.go @@ -0,0 +1,46 @@ +package parser + +import ( + "errors" + "strings" + + "github.com/owncloud/ocis/graph-explorer/pkg/config" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + + return nil +} diff --git a/graph/pkg/command/health.go b/graph/pkg/command/health.go index 18cc12baef9..5e2a31ecbef 100644 --- a/graph/pkg/command/health.go +++ b/graph/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/config/parser" "github.com/owncloud/ocis/graph/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index af4f264f17e..2318c610b7f 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -2,16 +2,14 @@ package command import ( "context" - "errors" "os" + "github.com/owncloud/ocis/graph/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/thejerf/suture/v4" "github.com/owncloud/ocis/graph/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/urfave/cli/v2" ) @@ -34,12 +32,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-graph", Usage: "Serve Graph API for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) cli.HelpFlag = &cli.BoolFlag{ @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads graph configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the graph command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index 6a62b1daceb..27bb58b13d3 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -2,10 +2,10 @@ package command import ( "context" - "strings" "github.com/oklog/run" "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/config/parser" "github.com/owncloud/ocis/graph/pkg/logging" "github.com/owncloud/ocis/graph/pkg/metrics" "github.com/owncloud/ocis/graph/pkg/server/debug" @@ -20,11 +20,8 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/graph/pkg/config/parser/parse.go b/graph/pkg/config/parser/parse.go new file mode 100644 index 00000000000..8856821543f --- /dev/null +++ b/graph/pkg/config/parser/parse.go @@ -0,0 +1,46 @@ +package parser + +import ( + "errors" + "strings" + + "github.com/owncloud/ocis/graph/pkg/config" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + + return nil +} diff --git a/idp/pkg/command/health.go b/idp/pkg/command/health.go index fcb337253bc..a668eaf4cd7 100644 --- a/idp/pkg/command/health.go +++ b/idp/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/idp/pkg/config/parser" "github.com/owncloud/ocis/idp/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index bcb8e4ea1fe..9bb2df16e07 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/idp/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-idp", Usage: "Serve IDP API for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads idp configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the idp command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index 0c91b4b5b22..e955731c2bc 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -2,10 +2,10 @@ package command import ( "context" - "strings" "github.com/oklog/run" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/idp/pkg/config/parser" "github.com/owncloud/ocis/idp/pkg/logging" "github.com/owncloud/ocis/idp/pkg/metrics" "github.com/owncloud/ocis/idp/pkg/server/debug" @@ -20,14 +20,10 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - return nil }, Action: func(c *cli.Context) error { diff --git a/idp/pkg/config/parser/parse.go b/idp/pkg/config/parser/parse.go new file mode 100644 index 00000000000..de98f42d689 --- /dev/null +++ b/idp/pkg/config/parser/parse.go @@ -0,0 +1,46 @@ +package parser + +import ( + "errors" + "strings" + + "github.com/owncloud/ocis/idp/pkg/config" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + + return nil +} diff --git a/ocis-pkg/config/parser/parse.go b/ocis-pkg/config/parser/parse.go new file mode 100644 index 00000000000..a0870d17c72 --- /dev/null +++ b/ocis-pkg/config/parser/parse.go @@ -0,0 +1,39 @@ +package parser + +import ( + "errors" + + "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" + "github.com/owncloud/ocis/ocis-pkg/shared" +) + +// ParseConfig loads ocis configuration. +func ParseConfig(cfg *config.Config) error { + _, err := config.BindSourcesToStructs("ocis", cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &shared.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &shared.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + return nil +} diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 62efe82eaac..719b08062c6 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/accounts/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -14,7 +15,7 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Usage: "Start accounts server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 1f9da764d0d..23b45f9dbfb 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/glauth/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -14,7 +15,7 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Usage: "Start glauth server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 92e5b532c23..0e1d4e2955a 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/graph/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -14,7 +15,7 @@ func GraphCommand(cfg *config.Config) *cli.Command { Usage: "Start graph server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index f02ad25b756..db65c6b1d69 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/graph-explorer/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -14,7 +15,7 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { Usage: "Start graph-explorer server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 62d929cbe13..8f996f493e3 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/idp/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -14,7 +15,7 @@ func IDPCommand(cfg *config.Config) *cli.Command { Usage: "Start idp server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index dd010e71f35..eb29b3d25f4 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocs/pkg/command" "github.com/urfave/cli/v2" @@ -14,7 +15,7 @@ func OCSCommand(cfg *config.Config) *cli.Command { Usage: "Start ocs server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 2554573a284..423794d91a0 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/proxy/pkg/command" "github.com/urfave/cli/v2" @@ -14,7 +15,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Usage: "Start proxy server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 163adebc80d..e0c77c0f69e 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -1,13 +1,11 @@ package command import ( - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -19,11 +17,8 @@ func Execute() error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis", Usage: "ownCloud Infinite Scale Stack", - Before: func(c *cli.Context) error { - // TODO: what do do? - //cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, }) @@ -41,33 +36,3 @@ func Execute() error { return app.Run(os.Args) } - -// ParseConfig loads ocis configuration. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := config.BindSourcesToStructs("ocis", cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &shared.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &shared.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 67cde41954d..ac24c1c6489 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -2,6 +2,8 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocis/pkg/runtime" "github.com/urfave/cli/v2" @@ -14,14 +16,13 @@ func Server(cfg *config.Config) *cli.Command { Usage: "Start fullstack server", Category: "Fullstack", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { - // what to do - //cfg.Commons = &shared.Commons{ - // Log: &cfg.Log, - //} + cfg.Commons = &shared.Commons{ + Log: cfg.Log, + } r := runtime.New(cfg) return r.Start() diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index ae1fec6c607..0cf950c4cb4 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/settings/pkg/command" "github.com/urfave/cli/v2" @@ -14,7 +15,7 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Usage: "Start settings server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 6fda33d5ebb..71ecb35d947 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/store/pkg/command" "github.com/urfave/cli/v2" @@ -15,7 +16,7 @@ func StoreCommand(cfg *config.Config) *cli.Command { Usage: "Start a go-micro store", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index add5b668458..171b781431b 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/thumbnails/pkg/command" "github.com/urfave/cli/v2" @@ -14,7 +15,7 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { Usage: "Start thumbnails server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/util.go b/ocis/pkg/command/util.go index a2e9b1abc0e..914c5a37c11 100644 --- a/ocis/pkg/command/util.go +++ b/ocis/pkg/command/util.go @@ -2,12 +2,13 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/urfave/cli/v2" ) func ParseStorageCommon(ctx *cli.Context, cfg *config.Config) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index e1f66f8eef4..a95cc94aec3 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/web/pkg/command" "github.com/urfave/cli/v2" @@ -14,7 +15,7 @@ func WebCommand(cfg *config.Config) *cli.Command { Usage: "Start web server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index ea7f518225d..2b7ed2dea4e 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -2,6 +2,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/webdav/pkg/command" "github.com/urfave/cli/v2" @@ -15,7 +16,7 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { Usage: "Start webdav server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocs/pkg/command/health.go b/ocs/pkg/command/health.go index b1d2249e260..834390b9e12 100644 --- a/ocs/pkg/command/health.go +++ b/ocs/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/ocs/pkg/config" + "github.com/owncloud/ocis/ocs/pkg/config/parser" "github.com/owncloud/ocis/ocs/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 2b143d547aa..1d10a9847f2 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config" + "github.com/owncloud/ocis/ocs/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-ocs", Usage: "Serve OCS API for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads idp configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the ocs command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 406e0221cc1..807a7786a40 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -2,8 +2,8 @@ package command import ( "context" - "strings" + "github.com/owncloud/ocis/ocs/pkg/config/parser" "github.com/owncloud/ocis/ocs/pkg/logging" "github.com/owncloud/ocis/ocs/pkg/tracing" @@ -21,11 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/ocs/pkg/config/parser/parse.go b/ocs/pkg/config/parser/parse.go new file mode 100644 index 00000000000..9a50e535b30 --- /dev/null +++ b/ocs/pkg/config/parser/parse.go @@ -0,0 +1,46 @@ +package parser + +import ( + "errors" + "strings" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocs/pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + + return nil +} diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 283e85246a4..b2c82bf0a74 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-proxy", Usage: "proxy for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads accounts configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index a99060d8b2c..501305bcefd 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -3,9 +3,7 @@ package command import ( "context" "crypto/tls" - "fmt" "net/http" - "strings" "time" "github.com/coreos/go-oidc/v3/oidc" @@ -14,11 +12,11 @@ import ( "github.com/justinas/alice" "github.com/oklog/run" acc "github.com/owncloud/ocis/accounts/pkg/proto/v0" - "github.com/owncloud/ocis/ocis-pkg/conversions" "github.com/owncloud/ocis/ocis-pkg/log" pkgmiddleware "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/service/grpc" "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config/parser" "github.com/owncloud/ocis/proxy/pkg/cs3" "github.com/owncloud/ocis/proxy/pkg/logging" "github.com/owncloud/ocis/proxy/pkg/metrics" @@ -40,26 +38,9 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } - - if cfg.Policies == nil { - cfg.Policies = config.DefaultPolicies() - } - - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - - if len(ctx.StringSlice("presignedurl-allow-method")) > 0 { - cfg.PreSignedURL.AllowedHTTPMethods = ctx.StringSlice("presignedurl-allow-method") - } - - if err := loadUserAgent(ctx, cfg); err != nil { - return err - } - return nil }, Action: func(c *cli.Context) error { @@ -218,7 +199,7 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config) middleware.OIDCIss(cfg.OIDC.Issuer), middleware.UserOIDCClaim(cfg.UserOIDCClaim), middleware.UserCS3Claim(cfg.UserCS3Claim), - middleware.CredentialsByUserAgent(cfg.Reva.Middleware.Auth.CredentialsByUserAgent), + middleware.CredentialsByUserAgent(cfg.AuthMiddleware.CredentialsByUserAgent), ), middleware.SignedURLAuth( middleware.Logger(logger), @@ -253,28 +234,3 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config) ), ) } - -// loadUserAgent reads the proxy-user-agent-lock-in, since it is a string flag, and attempts to construct a map of -// "user-agent":"challenge" locks in for Reva. -// Modifies cfg. Spaces don't need to be trimmed as urfavecli takes care of it. User agents with spaces are valid. i.e: -// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0 -// This function works by relying in our format of specifying [user-agent:challenge] and the fact that the user agent -// might contain ":" (colon), so the original string is reversed, split in two parts, by the time it is split we -// have the indexes reversed and the tuple is in the format of [challenge:user-agent], then the same process is applied -// in reverse for each individual part -func loadUserAgent(c *cli.Context, cfg *config.Config) error { - cfg.Reva.Middleware.Auth.CredentialsByUserAgent = make(map[string]string) - locks := c.StringSlice("proxy-user-agent-lock-in") - - for _, v := range locks { - vv := conversions.Reverse(v) - parts := strings.SplitN(vv, ":", 2) - if len(parts) != 2 { - return fmt.Errorf("unexpected config value for user-agent lock-in: %v, expected format is user-agent:challenge", v) - } - - cfg.Reva.Middleware.Auth.CredentialsByUserAgent[conversions.Reverse(parts[1])] = conversions.Reverse(parts[0]) - } - - return nil -} diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 5ac9ee84104..c525421e808 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -18,11 +18,12 @@ type Config struct { HTTP HTTP `ocisConfig:"http"` + Reva Reva `ocisConfig:"reva"` + Policies []Policy `ocisConfig:"policies"` OIDC OIDC `ocisConfig:"oidc"` TokenManager TokenManager `ocisConfig:"token_manager"` PolicySelector *PolicySelector `ocisConfig:"policy_selector"` - Reva Reva `ocisConfig:"reva"` PreSignedURL PreSignedURL `ocisConfig:"pre_signed_url"` AccountBackend string `ocisConfig:"account_backend" env:"PROXY_ACCOUNT_BACKEND_TYPE"` UserOIDCClaim string `ocisConfig:"user_oidc_claim" env:"PROXY_USER_OIDC_CLAIM"` @@ -31,6 +32,7 @@ type Config struct { AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts" env:"PROXY_AUTOPROVISION_ACCOUNTS"` EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"` InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` + AuthMiddleware AuthMiddleware `ocisConfig:"auth_middleware"` Context context.Context } @@ -68,21 +70,9 @@ var ( RouteTypes = []RouteType{QueryRoute, RegexRoute, PrefixRoute} ) -// TODO: use reva config here -// Reva defines all available REVA configuration. -type Reva struct { - Address string `ocisConfig:"address" env:"REVA_GATEWAY"` - Middleware Middleware `ocisConfig:"middleware"` -} - -// Middleware configures proxy middlewares. -type Middleware struct { - Auth Auth `ocisConfig:"middleware"` -} - -// Auth configures proxy http auth middleware. -type Auth struct { - CredentialsByUserAgent map[string]string `ocisConfig:""` +// AuthMiddleware configures the proxy http auth middleware. +type AuthMiddleware struct { + CredentialsByUserAgent map[string]string `ocisConfig:"credentials_by_user_agent"` } // OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request diff --git a/proxy/pkg/config/parser/parse.go b/proxy/pkg/config/parser/parse.go new file mode 100644 index 00000000000..65921b31cff --- /dev/null +++ b/proxy/pkg/config/parser/parse.go @@ -0,0 +1,51 @@ +package parser + +import ( + "errors" + "strings" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + + if cfg.Policies == nil { + cfg.Policies = config.DefaultPolicies() + } + + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + + return nil +} diff --git a/proxy/pkg/config/reva.go b/proxy/pkg/config/reva.go new file mode 100644 index 00000000000..2b299a0f651 --- /dev/null +++ b/proxy/pkg/config/reva.go @@ -0,0 +1,6 @@ +package config + +// Reva defines all available REVA configuration. +type Reva struct { + Address string `ocisConfig:"address" env:"REVA_GATEWAY"` +} diff --git a/settings/pkg/command/health.go b/settings/pkg/command/health.go index e561b84e082..a8e15f8cfd6 100644 --- a/settings/pkg/command/health.go +++ b/settings/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/config/parser" "github.com/owncloud/ocis/settings/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 03340bb1af6..938a3f26be5 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-settings", Usage: "Provide settings and permissions for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads idp configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index a6e51c93044..c26623a86d3 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -2,10 +2,10 @@ package command import ( "context" - "strings" "github.com/oklog/run" "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/config/parser" "github.com/owncloud/ocis/settings/pkg/logging" "github.com/owncloud/ocis/settings/pkg/metrics" "github.com/owncloud/ocis/settings/pkg/server/debug" @@ -21,11 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/settings/pkg/config/parser/parse.go b/settings/pkg/config/parser/parse.go new file mode 100644 index 00000000000..551d44108c3 --- /dev/null +++ b/settings/pkg/config/parser/parse.go @@ -0,0 +1,46 @@ +package parser + +import ( + "errors" + "strings" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/settings/pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + + return nil +} diff --git a/store/pkg/command/health.go b/store/pkg/command/health.go index b280d8b0e45..bc0b77b3449 100644 --- a/store/pkg/command/health.go +++ b/store/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/store/pkg/config" + "github.com/owncloud/ocis/store/pkg/config/parser" "github.com/owncloud/ocis/store/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index c32c0c45f34..6586d0947ca 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" + "github.com/owncloud/ocis/store/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-store", Usage: "Service to store values for ocis extensions", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads accounts configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the store command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index add4beaef64..c4ebd5e9aba 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,14 +3,15 @@ package command import ( "context" - "github.com/owncloud/ocis/store/pkg/logging" - "github.com/owncloud/ocis/store/pkg/tracing" - "github.com/oklog/run" + "github.com/owncloud/ocis/store/pkg/config" + "github.com/owncloud/ocis/store/pkg/config/parser" + "github.com/owncloud/ocis/store/pkg/logging" "github.com/owncloud/ocis/store/pkg/metrics" "github.com/owncloud/ocis/store/pkg/server/debug" "github.com/owncloud/ocis/store/pkg/server/grpc" + "github.com/owncloud/ocis/store/pkg/tracing" "github.com/urfave/cli/v2" ) @@ -20,7 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/store/pkg/config/parser/parse.go b/store/pkg/config/parser/parse.go new file mode 100644 index 00000000000..f3789eecbf4 --- /dev/null +++ b/store/pkg/config/parser/parse.go @@ -0,0 +1,42 @@ +package parser + +import ( + "errors" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/store/pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + + return nil +} diff --git a/thumbnails/pkg/command/health.go b/thumbnails/pkg/command/health.go index 1ba961d62ca..5b232dc9e11 100644 --- a/thumbnails/pkg/command/health.go +++ b/thumbnails/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/config/parser" "github.com/owncloud/ocis/thumbnails/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index ad18155e752..1cdb5c49447 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis-thumbnails", Usage: "Example usage", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,35 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads accounts configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - return nil -} - // SutureService allows for the thumbnails command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 42531f4d86a..990c549e354 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/config/parser" "github.com/owncloud/ocis/thumbnails/pkg/logging" "github.com/owncloud/ocis/thumbnails/pkg/metrics" "github.com/owncloud/ocis/thumbnails/pkg/server/debug" @@ -20,7 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } return nil diff --git a/thumbnails/pkg/config/parser/parse.go b/thumbnails/pkg/config/parser/parse.go new file mode 100644 index 00000000000..3591aea8a53 --- /dev/null +++ b/thumbnails/pkg/config/parser/parse.go @@ -0,0 +1,42 @@ +package parser + +import ( + "errors" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + + return nil +} diff --git a/web/pkg/command/health.go b/web/pkg/command/health.go index d780d4058e4..5ab5887ea09 100644 --- a/web/pkg/command/health.go +++ b/web/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/config/parser" "github.com/owncloud/ocis/web/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 38c8ea330df..2c22ed570df 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "web", Usage: "Serve ownCloud Web for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,37 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads accounts configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - // TODO: remove cli.Context - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the web command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index 6b3b1f9ad2a..fbacd1cccb6 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -8,6 +8,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/config/parser" "github.com/owncloud/ocis/web/pkg/logging" "github.com/owncloud/ocis/web/pkg/metrics" "github.com/owncloud/ocis/web/pkg/server/debug" @@ -26,7 +27,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") } - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/web/pkg/config/defaultconfig.go b/web/pkg/config/defaultconfig.go index 42f22beda3d..cf518a9def3 100644 --- a/web/pkg/config/defaultconfig.go +++ b/web/pkg/config/defaultconfig.go @@ -1,5 +1,7 @@ package config +import "github.com/owncloud/ocis/ocis-pkg/version" + func DefaultConfig() *Config { return &Config{ Debug: Debug{ @@ -15,7 +17,8 @@ func DefaultConfig() *Config { CacheTTL: 604800, // 7 days }, Service: Service{ - Name: "web", + Name: "web", + Version: version.String, // TODO: ensure everywhere or remove }, Tracing: Tracing{ Enabled: false, diff --git a/web/pkg/config/parser/parse.go b/web/pkg/config/parser/parse.go new file mode 100644 index 00000000000..ed22078282d --- /dev/null +++ b/web/pkg/config/parser/parse.go @@ -0,0 +1,42 @@ +package parser + +import ( + "errors" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/web/pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + + return nil +} diff --git a/webdav/pkg/command/health.go b/webdav/pkg/command/health.go index e1f2be33e62..0a8e62486bc 100644 --- a/webdav/pkg/command/health.go +++ b/webdav/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/config/parser" "github.com/owncloud/ocis/webdav/pkg/logging" "github.com/urfave/cli/v2" ) @@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command { Name: "health", Usage: "Check health status", Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 2846715b329..45e25649212 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -2,14 +2,12 @@ package command import ( "context" - "errors" "os" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/envdecode" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ Name: "webdav", Usage: "Serve WebDAV API for oCIS", - Before: func(c *cli.Context) error { - cfg.Service.Version = version.String - return ParseConfig(c, cfg) + return parser.ParseConfig(cfg) }, - Commands: GetCommands(cfg), }) @@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// ParseConfig loads graph configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) - if err != nil { - return err - } - - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil && cfg.Commons == nil { - cfg.Log = &config.Log{} - } - - // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil { - // no environment variable set for this config is an expected "error" - if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { - return err - } - } - - return nil -} - // SutureService allows for the webdav command to be embedded and supervised by a suture supervisor tree. type SutureService struct { cfg *config.Config diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 7732f04bb75..073a8eb805e 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -2,10 +2,10 @@ package command import ( "context" - "strings" "github.com/oklog/run" "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/config/parser" "github.com/owncloud/ocis/webdav/pkg/logging" "github.com/owncloud/ocis/webdav/pkg/metrics" "github.com/owncloud/ocis/webdav/pkg/server/debug" @@ -20,11 +20,8 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - if err := ParseConfig(ctx, cfg); err != nil { + if err := parser.ParseConfig(cfg); err != nil { return err } diff --git a/webdav/pkg/config/parser/parse.go b/webdav/pkg/config/parser/parse.go new file mode 100644 index 00000000000..66341b0992b --- /dev/null +++ b/webdav/pkg/config/parser/parse.go @@ -0,0 +1,46 @@ +package parser + +import ( + "errors" + "strings" + + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/webdav/pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/config/envdecode" +) + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(cfg *config.Config) error { + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + if err != nil { + return err + } + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &config.Log{} + } + + // load all env variables relevant to the config in the current context. + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } + } + + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + + return nil +} From adc7b3b3d2e0aa41e9cd6ea59c841c77b4dc2bbf Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 16:24:39 +0100 Subject: [PATCH 65/84] remove version from service config --- accounts/pkg/command/server.go | 3 ++- accounts/pkg/config/service.go | 3 +-- accounts/pkg/server/grpc/server.go | 3 ++- accounts/pkg/server/http/server.go | 2 +- glauth/pkg/command/server.go | 3 ++- glauth/pkg/config/service.go | 3 +-- graph-explorer/pkg/command/server.go | 3 ++- graph-explorer/pkg/config/service.go | 3 +-- graph/pkg/command/server.go | 3 ++- graph/pkg/config/service.go | 3 +-- idp/pkg/command/server.go | 3 ++- idp/pkg/config/service.go | 3 +-- idp/pkg/server/debug/server.go | 3 ++- idp/pkg/server/http/server.go | 5 +++-- ocs/pkg/command/server.go | 3 ++- ocs/pkg/config/service.go | 3 +-- ocs/pkg/server/debug/server.go | 3 ++- ocs/pkg/server/http/server.go | 8 ++++++-- proxy/pkg/command/server.go | 3 ++- proxy/pkg/config/service.go | 3 +-- proxy/pkg/server/debug/server.go | 3 ++- proxy/pkg/server/http/server.go | 3 ++- settings/pkg/command/server.go | 3 ++- settings/pkg/config/service.go | 3 +-- settings/pkg/server/grpc/server.go | 3 ++- settings/pkg/server/http/server.go | 2 +- store/pkg/command/server.go | 3 ++- store/pkg/config/service.go | 3 +-- store/pkg/server/debug/server.go | 3 ++- store/pkg/server/grpc/server.go | 3 ++- thumbnails/pkg/command/server.go | 3 ++- thumbnails/pkg/config/service.go | 3 +-- thumbnails/pkg/server/debug/server.go | 3 ++- thumbnails/pkg/server/grpc/server.go | 2 +- web/pkg/config/defaultconfig.go | 5 +---- web/pkg/config/service.go | 3 +-- webdav/pkg/command/server.go | 3 ++- webdav/pkg/config/service.go | 3 +-- webdav/pkg/server/debug/server.go | 3 ++- webdav/pkg/server/http/server.go | 5 +++-- 40 files changed, 70 insertions(+), 58 deletions(-) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 906dd75b64b..e9452870242 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -13,6 +13,7 @@ import ( "github.com/owncloud/ocis/accounts/pkg/server/http" svc "github.com/owncloud/ocis/accounts/pkg/service/v0" "github.com/owncloud/ocis/accounts/pkg/tracing" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/urfave/cli/v2" ) @@ -41,7 +42,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + mtrcs.BuildInfo.WithLabelValues(version.String).Set(1) handler, err := svc.New(svc.Logger(logger), svc.Config(cfg)) if err != nil { diff --git a/accounts/pkg/config/service.go b/accounts/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/accounts/pkg/config/service.go +++ b/accounts/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/accounts/pkg/server/grpc/server.go b/accounts/pkg/server/grpc/server.go index d063eda4743..8670c5a5ca1 100644 --- a/accounts/pkg/server/grpc/server.go +++ b/accounts/pkg/server/grpc/server.go @@ -3,6 +3,7 @@ package grpc import ( "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/owncloud/ocis/ocis-pkg/service/grpc" + "github.com/owncloud/ocis/ocis-pkg/version" ) // Server initializes a new go-micro service ready to run @@ -17,7 +18,7 @@ func Server(opts ...Option) grpc.Service { grpc.Namespace(options.Config.GRPC.Namespace), grpc.Logger(options.Logger), grpc.Flags(options.Flags...), - grpc.Version(options.Config.Service.Version), + grpc.Version(version.String), ) if err := proto.RegisterAccountsServiceHandler(service.Server(), handler); err != nil { diff --git a/accounts/pkg/server/http/server.go b/accounts/pkg/server/http/server.go index 306fa9347ff..4fb764fcba1 100644 --- a/accounts/pkg/server/http/server.go +++ b/accounts/pkg/server/http/server.go @@ -21,7 +21,7 @@ func Server(opts ...Option) http.Service { service := http.NewService( http.Logger(options.Logger), http.Name(options.Name), - http.Version(options.Config.Service.Version), + http.Version(version.String), http.Address(options.Config.HTTP.Addr), http.Namespace(options.Config.HTTP.Namespace), http.Context(options.Context), diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index db5222db916..459d8a0eb51 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -15,6 +15,7 @@ import ( "github.com/owncloud/ocis/glauth/pkg/tracing" pkgcrypto "github.com/owncloud/ocis/ocis-pkg/crypto" "github.com/owncloud/ocis/ocis-pkg/service/grpc" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/urfave/cli/v2" ) @@ -49,7 +50,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + metrics.BuildInfo.WithLabelValues(version.String).Set(1) { diff --git a/glauth/pkg/config/service.go b/glauth/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/glauth/pkg/config/service.go +++ b/glauth/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index b16ec1150bc..7f753b3ccbd 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -11,6 +11,7 @@ import ( "github.com/owncloud/ocis/graph-explorer/pkg/server/debug" "github.com/owncloud/ocis/graph-explorer/pkg/server/http" "github.com/owncloud/ocis/graph-explorer/pkg/tracing" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/urfave/cli/v2" ) @@ -41,7 +42,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + mtrcs.BuildInfo.WithLabelValues(version.String).Set(1) { server, err := http.Server( diff --git a/graph-explorer/pkg/config/service.go b/graph-explorer/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/graph-explorer/pkg/config/service.go +++ b/graph-explorer/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index 27bb58b13d3..8c9276cffb5 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -11,6 +11,7 @@ import ( "github.com/owncloud/ocis/graph/pkg/server/debug" "github.com/owncloud/ocis/graph/pkg/server/http" "github.com/owncloud/ocis/graph/pkg/tracing" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/urfave/cli/v2" ) @@ -45,7 +46,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + mtrcs.BuildInfo.WithLabelValues(version.String).Set(1) { server, err := http.Server( diff --git a/graph/pkg/config/service.go b/graph/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/graph/pkg/config/service.go +++ b/graph/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index e955731c2bc..d8072891147 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -11,6 +11,7 @@ import ( "github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/http" "github.com/owncloud/ocis/idp/pkg/tracing" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/urfave/cli/v2" ) @@ -45,7 +46,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + metrics.BuildInfo.WithLabelValues(version.String).Set(1) { server, err := http.Server( diff --git a/idp/pkg/config/service.go b/idp/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/idp/pkg/config/service.go +++ b/idp/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/idp/pkg/server/debug/server.go b/idp/pkg/server/debug/server.go index bdfe9208373..9da10444fed 100644 --- a/idp/pkg/server/debug/server.go +++ b/idp/pkg/server/debug/server.go @@ -6,6 +6,7 @@ import ( "github.com/owncloud/ocis/idp/pkg/config" "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" ) // Server initializes the debug service and server. @@ -15,7 +16,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), - debug.Version(options.Config.Service.Version), + debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), diff --git a/idp/pkg/server/http/server.go b/idp/pkg/server/http/server.go index 0d9cf8b2f5e..08a1c550ce3 100644 --- a/idp/pkg/server/http/server.go +++ b/idp/pkg/server/http/server.go @@ -9,6 +9,7 @@ import ( pkgcrypto "github.com/owncloud/ocis/ocis-pkg/crypto" "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/service/http" + "github.com/owncloud/ocis/ocis-pkg/version" "go-micro.dev/v4" ) @@ -42,7 +43,7 @@ func Server(opts ...Option) (http.Service, error) { http.Logger(options.Logger), http.Namespace(options.Config.HTTP.Namespace), http.Name(options.Config.Service.Name), - http.Version(options.Config.Service.Version), + http.Version(version.String), http.Address(options.Config.HTTP.Addr), http.Context(options.Context), http.Flags(options.Flags...), @@ -60,7 +61,7 @@ func Server(opts ...Option) (http.Service, error) { middleware.Secure, middleware.Version( options.Config.Service.Name, - options.Config.Service.Version, + version.String, ), middleware.Logger( options.Logger, diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 807a7786a40..a5081a3cfb6 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -3,6 +3,7 @@ package command import ( "context" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config/parser" "github.com/owncloud/ocis/ocs/pkg/logging" "github.com/owncloud/ocis/ocs/pkg/tracing" @@ -47,7 +48,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + metrics.BuildInfo.WithLabelValues(version.String).Set(1) { server, err := http.Server( diff --git a/ocs/pkg/config/service.go b/ocs/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/ocs/pkg/config/service.go +++ b/ocs/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/ocs/pkg/server/debug/server.go b/ocs/pkg/server/debug/server.go index 214c4a9c196..7a7b69d80dd 100644 --- a/ocs/pkg/server/debug/server.go +++ b/ocs/pkg/server/debug/server.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config" ) @@ -15,7 +16,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), - debug.Version(options.Config.Service.Version), + debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), diff --git a/ocs/pkg/server/http/server.go b/ocs/pkg/server/http/server.go index 27c4e7e7fb8..06d38018429 100644 --- a/ocs/pkg/server/http/server.go +++ b/ocs/pkg/server/http/server.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/cors" "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/service/http" + "github.com/owncloud/ocis/ocis-pkg/version" ocsmw "github.com/owncloud/ocis/ocs/pkg/middleware" svc "github.com/owncloud/ocis/ocs/pkg/service/v0" "go-micro.dev/v4" @@ -17,7 +18,7 @@ func Server(opts ...Option) (http.Service, error) { service := http.NewService( http.Logger(options.Logger), http.Name(options.Config.Service.Name), - http.Version(options.Config.Service.Version), + http.Version(version.String), http.Namespace(options.Config.HTTP.Namespace), http.Address(options.Config.HTTP.Addr), http.Context(options.Context), @@ -39,7 +40,10 @@ func Server(opts ...Option) (http.Service, error) { cors.AllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), middleware.Secure, - middleware.Version(options.Config.Service.Name, options.Config.Service.Version), + middleware.Version( + options.Config.Service.Name, + version.String, + ), middleware.Logger(options.Logger), ocsmw.LogTrace, ), diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 501305bcefd..8d8045ab905 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -15,6 +15,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" pkgmiddleware "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/service/grpc" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/owncloud/ocis/proxy/pkg/config/parser" "github.com/owncloud/ocis/proxy/pkg/cs3" @@ -64,7 +65,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - m.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + m.BuildInfo.WithLabelValues(version.String).Set(1) rp := proxy.NewMultiHostReverseProxy( proxy.Logger(logger), diff --git a/proxy/pkg/config/service.go b/proxy/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/proxy/pkg/config/service.go +++ b/proxy/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index 5c4b3804625..9158a697d82 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" ) @@ -16,7 +17,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), - debug.Version(options.Config.Service.Version), + debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), diff --git a/proxy/pkg/server/http/server.go b/proxy/pkg/server/http/server.go index 4ae43d82460..14b377434ba 100644 --- a/proxy/pkg/server/http/server.go +++ b/proxy/pkg/server/http/server.go @@ -6,6 +6,7 @@ import ( pkgcrypto "github.com/owncloud/ocis/ocis-pkg/crypto" svc "github.com/owncloud/ocis/ocis-pkg/service/http" + "github.com/owncloud/ocis/ocis-pkg/version" "go-micro.dev/v4" ) @@ -43,7 +44,7 @@ func Server(opts ...Option) (svc.Service, error) { service := svc.NewService( svc.Name(options.Config.Service.Name), - svc.Version(options.Config.Service.Version), + svc.Version(version.String), svc.TLSConfig(tlsConfig), svc.Logger(options.Logger), svc.Address(options.Config.HTTP.Addr), diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index c26623a86d3..0728ef2921e 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -4,6 +4,7 @@ import ( "context" "github.com/oklog/run" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/config" "github.com/owncloud/ocis/settings/pkg/config/parser" "github.com/owncloud/ocis/settings/pkg/logging" @@ -44,7 +45,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() mtrcs := metrics.New() - mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + mtrcs.BuildInfo.WithLabelValues(version.String).Set(1) // prepare an HTTP server and add it to the group run. httpServer := http.Server( diff --git a/settings/pkg/config/service.go b/settings/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/settings/pkg/config/service.go +++ b/settings/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/settings/pkg/server/grpc/server.go b/settings/pkg/server/grpc/server.go index a2b5d1f1d6e..a3a2bde3bda 100644 --- a/settings/pkg/server/grpc/server.go +++ b/settings/pkg/server/grpc/server.go @@ -2,6 +2,7 @@ package grpc import ( "github.com/owncloud/ocis/ocis-pkg/service/grpc" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/proto/v0" svc "github.com/owncloud/ocis/settings/pkg/service/v0" ) @@ -13,7 +14,7 @@ func Server(opts ...Option) grpc.Service { service := grpc.NewService( grpc.Logger(options.Logger), grpc.Name(options.Name), - grpc.Version(options.Config.Service.Version), + grpc.Version(version.String), grpc.Address(options.Config.GRPC.Addr), grpc.Namespace(options.Config.GRPC.Namespace), grpc.Context(options.Context), diff --git a/settings/pkg/server/http/server.go b/settings/pkg/server/http/server.go index cb63ac5ec63..29795d78f95 100644 --- a/settings/pkg/server/http/server.go +++ b/settings/pkg/server/http/server.go @@ -21,7 +21,7 @@ func Server(opts ...Option) http.Service { service := http.NewService( http.Logger(options.Logger), http.Name(options.Name), - http.Version(options.Config.Service.Version), + http.Version(version.String), http.Address(options.Config.HTTP.Addr), http.Namespace(options.Config.HTTP.Namespace), http.Context(options.Context), diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index c4ebd5e9aba..cf9a4ad20b7 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -5,6 +5,7 @@ import ( "github.com/oklog/run" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" "github.com/owncloud/ocis/store/pkg/config/parser" "github.com/owncloud/ocis/store/pkg/logging" @@ -47,7 +48,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + metrics.BuildInfo.WithLabelValues(version.String).Set(1) { server := grpc.Server( diff --git a/store/pkg/config/service.go b/store/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/store/pkg/config/service.go +++ b/store/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/store/pkg/server/debug/server.go b/store/pkg/server/debug/server.go index 975974c5cc9..874071c714b 100644 --- a/store/pkg/server/debug/server.go +++ b/store/pkg/server/debug/server.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" ) @@ -15,7 +16,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), - debug.Version(options.Config.Service.Version), + debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), diff --git a/store/pkg/server/grpc/server.go b/store/pkg/server/grpc/server.go index 46ba11de8f0..632505486f7 100644 --- a/store/pkg/server/grpc/server.go +++ b/store/pkg/server/grpc/server.go @@ -2,6 +2,7 @@ package grpc import ( "github.com/owncloud/ocis/ocis-pkg/service/grpc" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/proto/v0" svc "github.com/owncloud/ocis/store/pkg/service/v0" ) @@ -13,7 +14,7 @@ func Server(opts ...Option) grpc.Service { service := grpc.NewService( grpc.Namespace(options.Config.GRPC.Namespace), grpc.Name(options.Config.Service.Name), - grpc.Version(options.Config.Service.Version), + grpc.Version(version.String), grpc.Context(options.Context), grpc.Address(options.Config.GRPC.Addr), grpc.Logger(options.Logger), diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 990c549e354..4b7444c6556 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/oklog/run" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/thumbnails/pkg/config" "github.com/owncloud/ocis/thumbnails/pkg/config/parser" "github.com/owncloud/ocis/thumbnails/pkg/logging" @@ -46,7 +47,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + metrics.BuildInfo.WithLabelValues(version.String).Set(1) service := grpc.NewService( grpc.Logger(logger), diff --git a/thumbnails/pkg/config/service.go b/thumbnails/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/thumbnails/pkg/config/service.go +++ b/thumbnails/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/thumbnails/pkg/server/debug/server.go b/thumbnails/pkg/server/debug/server.go index 24fdee22c1b..dd7b40a1fcd 100644 --- a/thumbnails/pkg/server/debug/server.go +++ b/thumbnails/pkg/server/debug/server.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/thumbnails/pkg/config" ) @@ -15,7 +16,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), - debug.Version(options.Config.Service.Version), + debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), diff --git a/thumbnails/pkg/server/grpc/server.go b/thumbnails/pkg/server/grpc/server.go index efa6ed85a32..b90dc699e77 100644 --- a/thumbnails/pkg/server/grpc/server.go +++ b/thumbnails/pkg/server/grpc/server.go @@ -22,7 +22,7 @@ func NewService(opts ...Option) grpc.Service { grpc.Address(options.Address), grpc.Context(options.Context), grpc.Flags(options.Flags...), - grpc.Version(options.Config.Service.Version), + grpc.Version(version.String), ) tconf := options.Config.Thumbnail gc, err := pool.GetGatewayServiceClient(tconf.RevaGateway) diff --git a/web/pkg/config/defaultconfig.go b/web/pkg/config/defaultconfig.go index cf518a9def3..42f22beda3d 100644 --- a/web/pkg/config/defaultconfig.go +++ b/web/pkg/config/defaultconfig.go @@ -1,7 +1,5 @@ package config -import "github.com/owncloud/ocis/ocis-pkg/version" - func DefaultConfig() *Config { return &Config{ Debug: Debug{ @@ -17,8 +15,7 @@ func DefaultConfig() *Config { CacheTTL: 604800, // 7 days }, Service: Service{ - Name: "web", - Version: version.String, // TODO: ensure everywhere or remove + Name: "web", }, Tracing: Tracing{ Enabled: false, diff --git a/web/pkg/config/service.go b/web/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/web/pkg/config/service.go +++ b/web/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 073a8eb805e..720729efbcc 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -4,6 +4,7 @@ import ( "context" "github.com/oklog/run" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/webdav/pkg/config" "github.com/owncloud/ocis/webdav/pkg/config/parser" "github.com/owncloud/ocis/webdav/pkg/logging" @@ -47,7 +48,7 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() - metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) + metrics.BuildInfo.WithLabelValues(version.String).Set(1) { server, err := http.Server( diff --git a/webdav/pkg/config/service.go b/webdav/pkg/config/service.go index c12faf34442..f98aa3d27e5 100644 --- a/webdav/pkg/config/service.go +++ b/webdav/pkg/config/service.go @@ -2,6 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string - Version string + Name string } diff --git a/webdav/pkg/server/debug/server.go b/webdav/pkg/server/debug/server.go index ad9568b6041..ff0ee6b4fe3 100644 --- a/webdav/pkg/server/debug/server.go +++ b/webdav/pkg/server/debug/server.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/webdav/pkg/config" ) @@ -15,7 +16,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), - debug.Version(options.Config.Service.Version), + debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), diff --git a/webdav/pkg/server/http/server.go b/webdav/pkg/server/http/server.go index e3217294971..029245bbacb 100644 --- a/webdav/pkg/server/http/server.go +++ b/webdav/pkg/server/http/server.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/cors" "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/service/http" + "github.com/owncloud/ocis/ocis-pkg/version" svc "github.com/owncloud/ocis/webdav/pkg/service/v0" "go-micro.dev/v4" ) @@ -17,7 +18,7 @@ func Server(opts ...Option) (http.Service, error) { http.Logger(options.Logger), http.Namespace(options.Config.HTTP.Namespace), http.Name(options.Config.Service.Name), - http.Version(options.Config.Service.Version), + http.Version(version.String), http.Address(options.Config.HTTP.Addr), http.Context(options.Context), http.Flags(options.Flags...), @@ -40,7 +41,7 @@ func Server(opts ...Option) (http.Service, error) { middleware.Secure, middleware.Version( options.Config.Service.Name, - options.Config.Service.Version, + version.String, ), middleware.Logger( options.Logger, From 5b56920128e1cc6a3c675748368b366fa0eef56f Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 17:19:10 +0100 Subject: [PATCH 66/84] add missing commons in supervised mode --- graph-explorer/pkg/command/root.go | 2 +- store/pkg/command/root.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 92097b27998..cf997cc6f09 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -52,7 +52,7 @@ type SutureService struct { // NewSutureService creates a new graph-explorer.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - //cfg.GraphExplorer.Log = cfg.Log + cfg.GraphExplorer.Commons = cfg.Commons return SutureService{ cfg: cfg.GraphExplorer, } diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 6586d0947ca..44451c48beb 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -52,6 +52,7 @@ type SutureService struct { // NewSutureService creates a new store.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + cfg.Store.Commons = cfg.Commons return SutureService{ cfg: cfg.Store, } From 1dc63cbce1e5a12dc9937bc3b63c3410cd221a12 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 19:08:11 +0100 Subject: [PATCH 67/84] ensure, that each config is only parsed once --- accounts/pkg/command/root.go | 8 ++------ accounts/pkg/command/server.go | 8 ++------ glauth/pkg/command/root.go | 8 ++------ glauth/pkg/command/server.go | 9 ++------- graph-explorer/pkg/command/root.go | 8 ++------ graph/pkg/command/root.go | 8 ++------ graph/pkg/command/server.go | 9 ++------- idp/pkg/command/root.go | 8 ++------ idp/pkg/command/server.go | 8 ++------ ocis/pkg/command/accounts.go | 10 +--------- ocis/pkg/command/glauth.go | 10 +--------- ocis/pkg/command/graph.go | 10 +--------- ocis/pkg/command/graphexplorer.go | 10 +--------- ocis/pkg/command/idp.go | 10 +--------- ocis/pkg/command/ocs.go | 10 +--------- ocis/pkg/command/proxy.go | 10 +--------- ocis/pkg/command/root.go | 4 ---- ocis/pkg/command/settings.go | 10 +--------- ocis/pkg/command/store.go | 10 +--------- ocis/pkg/command/thumbnails.go | 10 +--------- ocis/pkg/command/web.go | 10 +--------- ocis/pkg/command/webdav.go | 10 +--------- ocs/pkg/command/root.go | 8 ++------ ocs/pkg/command/server.go | 8 ++------ proxy/pkg/command/health.go | 5 ++++- proxy/pkg/command/root.go | 8 ++------ proxy/pkg/command/server.go | 7 ++----- settings/pkg/command/root.go | 8 ++------ settings/pkg/command/server.go | 8 ++------ store/pkg/command/root.go | 8 ++------ store/pkg/command/server.go | 8 ++------ thumbnails/pkg/command/root.go | 8 ++------ thumbnails/pkg/command/server.go | 7 ++----- web/pkg/command/root.go | 8 ++------ web/pkg/command/server.go | 18 ++---------------- web/pkg/config/parser/parse.go | 8 ++++++++ webdav/pkg/command/root.go | 8 ++------ webdav/pkg/command/server.go | 9 ++------- 38 files changed, 70 insertions(+), 262 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index a0d264fde47..fb0bf288315 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -5,7 +5,6 @@ import ( "os" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/thejerf/suture/v4" @@ -35,11 +34,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-accounts command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-accounts", - Usage: "Provide accounts and groups for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-accounts", + Usage: "Provide accounts and groups for oCIS", Commands: GetCommands(cfg), }) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index e9452870242..7c8f3832e48 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -23,12 +23,8 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start ocis accounts service", Description: "uses an LDAP server as the storage backend", - Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 4ba8e95be32..7b1dc51d9cc 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -5,7 +5,6 @@ import ( "os" "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/glauth/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/thejerf/suture/v4" @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-glauth command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-glauth", - Usage: "Serve GLAuth API for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-glauth", + Usage: "Serve GLAuth API for oCIS", Commands: GetCommands(cfg), }) diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index 459d8a0eb51..08f1879e02f 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -24,13 +24,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index cf997cc6f09..f2acd3460ae 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -5,7 +5,6 @@ import ( "os" "github.com/owncloud/ocis/graph-explorer/pkg/config" - "github.com/owncloud/ocis/graph-explorer/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/thejerf/suture/v4" @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the graph-explorer command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "graph-explorer", - Usage: "Serve Graph-Explorer for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "graph-explorer", + Usage: "Serve Graph-Explorer for oCIS", Commands: GetCommands(cfg), }) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 2318c610b7f..60c389880d4 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/owncloud/ocis/graph/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/thejerf/suture/v4" @@ -30,11 +29,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-graph command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-graph", - Usage: "Serve Graph API for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-graph", + Usage: "Serve Graph API for oCIS", Commands: GetCommands(cfg), }) cli.HelpFlag = &cli.BoolFlag{ diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index 8c9276cffb5..c246b23e415 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -20,13 +20,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 9bb2df16e07..787381c7e84 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -5,7 +5,6 @@ import ( "os" "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/idp/pkg/config/parser" "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/thejerf/suture/v4" @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-idp command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-idp", - Usage: "Serve IDP API for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-idp", + Usage: "Serve IDP API for oCIS", Commands: GetCommands(cfg), }) diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index d8072891147..a5be7abcce7 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -20,12 +20,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 719b08062c6..672dcd6a32b 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -15,15 +15,7 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Usage: "Start accounts server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.Accounts.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.Accounts), } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 23b45f9dbfb..3e58bbeefb7 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -15,15 +15,7 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Usage: "Start glauth server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.GLAuth.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.GLAuth), } diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 0e1d4e2955a..a482ef68133 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -15,15 +15,7 @@ func GraphCommand(cfg *config.Config) *cli.Command { Usage: "Start graph server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.Accounts.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.Graph), } diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index db65c6b1d69..fa2eee4c3dd 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -15,15 +15,7 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { Usage: "Start graph-explorer server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.GraphExplorer.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.GraphExplorer), } diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 8f996f493e3..d71e5743830 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -15,15 +15,7 @@ func IDPCommand(cfg *config.Config) *cli.Command { Usage: "Start idp server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.IDP.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.IDP), } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index eb29b3d25f4..657bc2969d9 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -15,15 +15,7 @@ func OCSCommand(cfg *config.Config) *cli.Command { Usage: "Start ocs server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.OCS.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.OCS), } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 423794d91a0..d52e667b4e3 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -15,15 +15,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Usage: "Start proxy server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.Proxy.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.Proxy), } diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index e0c77c0f69e..7fb3551afd1 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -5,7 +5,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -17,9 +16,6 @@ func Execute() error { app := clihelper.DefaultApp(&cli.App{ Name: "ocis", Usage: "ownCloud Infinite Scale Stack", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, }) for _, fn := range register.Commands { diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 0cf950c4cb4..2803c13983a 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -15,15 +15,7 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Usage: "Start settings server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.Settings.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.Settings), } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 71ecb35d947..a12412c95ff 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -16,15 +16,7 @@ func StoreCommand(cfg *config.Config) *cli.Command { Usage: "Start a go-micro store", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.Store.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.Store), } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 171b781431b..140b6a1c570 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -15,15 +15,7 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { Usage: "Start thumbnails server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.Thumbnails.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { origCmd := command.Server(cfg.Thumbnails) diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index a95cc94aec3..6ef8a2095fe 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -15,15 +15,7 @@ func WebCommand(cfg *config.Config) *cli.Command { Usage: "Start web server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.Web.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.Web), } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 2b7ed2dea4e..fb171ad1451 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -16,15 +16,7 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { Usage: "Start webdav server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - if cfg.Commons != nil { - cfg.WebDAV.Commons = cfg.Commons - } - - return nil + return parser.ParseConfig(cfg) }, Subcommands: command.GetCommands(cfg.WebDAV), } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 1d10a9847f2..cac620e67a6 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocs/pkg/config" - "github.com/owncloud/ocis/ocs/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-ocs command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-ocs", - Usage: "Serve OCS API for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-ocs", + Usage: "Serve OCS API for oCIS", Commands: GetCommands(cfg), }) diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index a5081a3cfb6..4126133a111 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -21,12 +21,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/proxy/pkg/command/health.go b/proxy/pkg/command/health.go index 3f904bda1b2..0d10d16ecef 100644 --- a/proxy/pkg/command/health.go +++ b/proxy/pkg/command/health.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config/parser" "github.com/owncloud/ocis/proxy/pkg/logging" "github.com/urfave/cli/v2" ) @@ -14,7 +15,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - //Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) + }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index b2c82bf0a74..cfc2afa6299 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/proxy/pkg/config" - "github.com/owncloud/ocis/proxy/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-proxy command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-proxy", - Usage: "proxy for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-proxy", + Usage: "proxy for oCIS", Commands: GetCommands(cfg), }) diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 8d8045ab905..9f992d6d7d6 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -38,11 +38,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 938a3f26be5..4e65d6391c2 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/settings/pkg/config" - "github.com/owncloud/ocis/settings/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-settings command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-settings", - Usage: "Provide settings and permissions for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-settings", + Usage: "Provide settings and permissions for oCIS", Commands: GetCommands(cfg), }) diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index 0728ef2921e..9c08299f1e1 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -21,12 +21,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 44451c48beb..add49da6f18 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/store/pkg/config" - "github.com/owncloud/ocis/store/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-store command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-store", - Usage: "Service to store values for ocis extensions", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-store", + Usage: "Service to store values for ocis extensions", Commands: GetCommands(cfg), }) diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index cf9a4ad20b7..77df9d87bb2 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -21,12 +21,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 1cdb5c49447..83b31119677 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/thumbnails/pkg/config" - "github.com/owncloud/ocis/thumbnails/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-thumbnails command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "ocis-thumbnails", - Usage: "Example usage", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "ocis-thumbnails", + Usage: "Example usage", Commands: GetCommands(cfg), }) diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 4b7444c6556..c475057053f 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -21,11 +21,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - return err - } - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 2c22ed570df..2dbe61c1b3a 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/web/pkg/config" - "github.com/owncloud/ocis/web/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the web command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "web", - Usage: "Serve ownCloud Web for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "web", + Usage: "Serve ownCloud Web for oCIS", Commands: GetCommands(cfg), }) diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index fbacd1cccb6..016246d1e8f 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "io/ioutil" - "strings" "github.com/oklog/run" "github.com/owncloud/ocis/web/pkg/config" @@ -22,21 +21,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") - } - - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - // build well known openid-configuration endpoint if it is not set - if cfg.Web.Config.OpenIDConnect.MetadataURL == "" { - cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/web/pkg/config/parser/parse.go b/web/pkg/config/parser/parse.go index ed22078282d..71870c8ce69 100644 --- a/web/pkg/config/parser/parse.go +++ b/web/pkg/config/parser/parse.go @@ -2,6 +2,7 @@ package parser import ( "errors" + "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/web/pkg/config" @@ -37,6 +38,13 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") + } + // build well known openid-configuration endpoint if it is not set + if cfg.Web.Config.OpenIDConnect.MetadataURL == "" { + cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" + } return nil } diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 45e25649212..3a3a3432bd9 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/webdav/pkg/config" - "github.com/owncloud/ocis/webdav/pkg/config/parser" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -29,11 +28,8 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the ocis-webdav command. func Execute(cfg *config.Config) error { app := clihelper.DefaultApp(&cli.App{ - Name: "webdav", - Usage: "Serve WebDAV API for oCIS", - Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "webdav", + Usage: "Serve WebDAV API for oCIS", Commands: GetCommands(cfg), }) diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 720729efbcc..10dd88abf88 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -20,13 +20,8 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Before: func(ctx *cli.Context) error { - - if err := parser.ParseConfig(cfg); err != nil { - return err - } - - return nil + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) From e31d0a8a35fdb5580f6f92fb46357838f31687c8 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 4 Jan 2022 10:40:35 +0100 Subject: [PATCH 68/84] remove reference to flags --- docs/ocis/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ocis/config.md b/docs/ocis/config.md index aa6a367bf8f..02df18b9f17 100644 --- a/docs/ocis/config.md +++ b/docs/ocis/config.md @@ -19,7 +19,7 @@ In order to simplify deployments and development the configuration model from oC ## In-depth configuration -Since we include a set of predefined extensions within the single binary, configuring an extension can be done in a variety of ways. Since we work with complex types, having as many cli per config value scales poorly, so we limited the options to config files and environment variables, leaving cli flags for common values, such as logging (`--log-level`, `--log-pretty`, `--log-file` or `--log-color`). +Since we include a set of predefined extensions within the single binary, configuring an extension can be done in a variety of ways. Since we work with complex types, having as many cli per config value scales poorly, so we limited the options to config files and environment variables. The hierarchy is clear enough, leaving us with: From c92dca658a1f2256ee2d7ae54b27efdd657a2312 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 4 Jan 2022 12:33:56 +0100 Subject: [PATCH 69/84] add changelog --- .../unreleased/change-unify-configuration-and-commands.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/change-unify-configuration-and-commands.md diff --git a/changelog/unreleased/change-unify-configuration-and-commands.md b/changelog/unreleased/change-unify-configuration-and-commands.md new file mode 100644 index 00000000000..0447d54877f --- /dev/null +++ b/changelog/unreleased/change-unify-configuration-and-commands.md @@ -0,0 +1,7 @@ +Change: Unify configuration and commands + +We've unified the configuration and commands of all non storage services. This also +includes the change, that environment variables are now defined on the config struct +as tags instead in a separate mapping. + +https://github.com/owncloud/ocis/pull/2818 From 1e38150276b03ca31ad1e58d0b6b11fa7258bdc5 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 7 Jan 2022 13:19:39 +0100 Subject: [PATCH 70/84] improve command description --- accounts/pkg/command/add_account.go | 9 +++++---- accounts/pkg/command/health.go | 5 +++-- accounts/pkg/command/inspect_account.go | 3 ++- accounts/pkg/command/list_accounts.go | 9 +++++---- accounts/pkg/command/rebuild_index.go | 7 ++++--- accounts/pkg/command/remove_account.go | 3 ++- accounts/pkg/command/server.go | 7 ++++--- accounts/pkg/command/update_account.go | 1 + accounts/pkg/command/version.go | 5 +++-- glauth/pkg/command/health.go | 5 +++-- glauth/pkg/command/server.go | 6 ++++-- glauth/pkg/command/version.go | 5 +++-- graph-explorer/pkg/command/health.go | 7 ++++--- graph-explorer/pkg/command/server.go | 6 ++++-- graph-explorer/pkg/command/version.go | 5 +++-- graph/pkg/command/health.go | 5 +++-- graph/pkg/command/server.go | 6 ++++-- graph/pkg/command/version.go | 5 +++-- idp/pkg/command/health.go | 5 +++-- idp/pkg/command/server.go | 6 ++++-- idp/pkg/command/version.go | 5 +++-- ocis/pkg/command/accounts.go | 6 +++--- ocis/pkg/command/common.go | 10 +++++++++- ocis/pkg/command/glauth.go | 6 +++--- ocis/pkg/command/graph.go | 6 +++--- ocis/pkg/command/graphexplorer.go | 6 +++--- ocis/pkg/command/idp.go | 6 +++--- ocis/pkg/command/kill.go | 4 ++-- ocis/pkg/command/list.go | 4 ++-- ocis/pkg/command/ocs.go | 6 +++--- ocis/pkg/command/proxy.go | 6 +++--- ocis/pkg/command/run.go | 4 ++-- ocis/pkg/command/server.go | 4 ++-- ocis/pkg/command/settings.go | 6 +++--- ocis/pkg/command/storageappprovider.go | 4 ++-- ocis/pkg/command/storageauthbasic.go | 4 ++-- ocis/pkg/command/storageauthbearer.go | 2 +- ocis/pkg/command/storageauthmachine.go | 4 ++-- ocis/pkg/command/storagefrontend.go | 4 ++-- ocis/pkg/command/storagegateway.go | 4 ++-- ocis/pkg/command/storagegroupprovider.go | 4 ++-- ocis/pkg/command/storagemetadata.go | 4 ++-- ocis/pkg/command/storagepubliclink.go | 4 ++-- ocis/pkg/command/storageshares.go | 4 ++-- ocis/pkg/command/storagesharing.go | 4 ++-- ocis/pkg/command/storageuserprovider.go | 4 ++-- ocis/pkg/command/storageusers.go | 4 ++-- ocis/pkg/command/store.go | 6 +++--- ocis/pkg/command/thumbnails.go | 10 +++------- ocis/pkg/command/version.go | 4 ++-- ocis/pkg/command/web.go | 6 +++--- ocis/pkg/command/webdav.go | 6 +++--- ocs/pkg/command/health.go | 5 +++-- ocs/pkg/command/server.go | 6 ++++-- ocs/pkg/command/version.go | 5 +++-- proxy/pkg/command/health.go | 5 +++-- proxy/pkg/command/server.go | 6 ++++-- proxy/pkg/command/version.go | 5 +++-- settings/pkg/command/server.go | 6 ++++-- settings/pkg/command/version.go | 5 +++-- storage/pkg/command/appprovider.go | 2 +- storage/pkg/command/authbasic.go | 2 +- storage/pkg/command/authbearer.go | 2 +- storage/pkg/command/authmachine.go | 2 +- storage/pkg/command/frontend.go | 2 +- storage/pkg/command/gateway.go | 2 +- storage/pkg/command/groups.go | 2 +- storage/pkg/command/health.go | 5 +++-- storage/pkg/command/sharing.go | 2 +- storage/pkg/command/storagemetadata.go | 4 ++-- storage/pkg/command/storagepubliclink.go | 4 ++-- storage/pkg/command/storageshares.go | 2 +- storage/pkg/command/storageusers.go | 2 +- storage/pkg/command/users.go | 2 +- store/pkg/command/health.go | 5 +++-- store/pkg/command/server.go | 6 ++++-- store/pkg/command/version.go | 5 +++-- thumbnails/pkg/command/health.go | 5 +++-- thumbnails/pkg/command/server.go | 5 +++-- thumbnails/pkg/command/version.go | 5 +++-- web/pkg/command/health.go | 5 +++-- web/pkg/command/server.go | 6 ++++-- web/pkg/command/version.go | 5 +++-- webdav/pkg/command/health.go | 5 +++-- webdav/pkg/command/server.go | 6 ++++-- webdav/pkg/command/version.go | 5 +++-- 86 files changed, 234 insertions(+), 178 deletions(-) diff --git a/accounts/pkg/command/add_account.go b/accounts/pkg/command/add_account.go index 07d18f1a824..1e904c5b80b 100644 --- a/accounts/pkg/command/add_account.go +++ b/accounts/pkg/command/add_account.go @@ -16,10 +16,11 @@ func AddAccount(cfg *config.Config) *cli.Command { PasswordProfile: &accounts.PasswordProfile{}, } return &cli.Command{ - Name: "add", - Usage: "Create a new account", - Aliases: []string{"create", "a"}, - Flags: flagset.AddAccountWithConfig(cfg, a), + Name: "add", + Usage: "create a new account", + Category: "account management", + Aliases: []string{"create", "a"}, + Flags: flagset.AddAccountWithConfig(cfg, a), Before: func(c *cli.Context) error { // Write value of username to the flags beneath, as preferred name // and on-premises-sam-account-name is probably confusing for users. diff --git a/accounts/pkg/command/health.go b/accounts/pkg/command/health.go index 2fadae8ef72..0e908b60e60 100644 --- a/accounts/pkg/command/health.go +++ b/accounts/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index 7124b0da4a8..5e2009497ec 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -18,7 +18,8 @@ import ( func InspectAccount(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "inspect", - Usage: "Show detailed data on an existing account", + Usage: "show detailed data on an existing account", + Category: "account management", ArgsUsage: "id", Flags: flagset.InspectAccountWithConfig(cfg), Action: func(c *cli.Context) error { diff --git a/accounts/pkg/command/list_accounts.go b/accounts/pkg/command/list_accounts.go index bf35626b1a2..3c15a127516 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -17,10 +17,11 @@ import ( // ListAccounts command lists all accounts func ListAccounts(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "list", - Usage: "List existing accounts", - Aliases: []string{"ls"}, - Flags: flagset.ListAccountsWithConfig(cfg), + Name: "list", + Usage: "list existing accounts", + Category: "account management", + Aliases: []string{"ls"}, + Flags: flagset.ListAccountsWithConfig(cfg), Action: func(c *cli.Context) error { accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) diff --git a/accounts/pkg/command/rebuild_index.go b/accounts/pkg/command/rebuild_index.go index b643ec04e3f..d2eb1d2de7f 100644 --- a/accounts/pkg/command/rebuild_index.go +++ b/accounts/pkg/command/rebuild_index.go @@ -14,9 +14,10 @@ import ( // RebuildIndex rebuilds the entire configured index. func RebuildIndex(cdf *config.Config) *cli.Command { return &cli.Command{ - Name: "rebuildIndex", - Usage: "Rebuilds the service's index, i.e. deleting and then re-adding all existing documents", - Aliases: []string{"rebuild", "ri"}, + Name: "rebuildIndex", + Usage: "rebuilds the service's index, i.e. deleting and then re-adding all existing documents", + Category: "account management", + Aliases: []string{"rebuild", "ri"}, Action: func(ctx *cli.Context) error { idxSvcID := "com.owncloud.api.accounts" idxSvc := index.NewIndexService(idxSvcID, grpc.NewClient()) diff --git a/accounts/pkg/command/remove_account.go b/accounts/pkg/command/remove_account.go index c51c1abe318..ee18eede46a 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -16,7 +16,8 @@ import ( func RemoveAccount(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "remove", - Usage: "Removes an existing account", + Usage: "removes an existing account", + Category: "account management", ArgsUsage: "id", Aliases: []string{"rm"}, Flags: flagset.RemoveAccountWithConfig(cfg), diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 7c8f3832e48..52fd784ee98 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/oklog/run" "github.com/owncloud/ocis/accounts/pkg/config" @@ -20,9 +21,9 @@ import ( // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start ocis accounts service", - Description: "uses an LDAP server as the storage backend", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/accounts/pkg/command/update_account.go b/accounts/pkg/command/update_account.go index 1b9b91ca485..cf2e68950f9 100644 --- a/accounts/pkg/command/update_account.go +++ b/accounts/pkg/command/update_account.go @@ -21,6 +21,7 @@ func UpdateAccount(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "update", Usage: "Make changes to an existing account", + Category: "account management", ArgsUsage: "id", Flags: flagset.UpdateAccountWithConfig(cfg, a), Before: func(c *cli.Context) error { diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index 6d3ec843f99..a776689373b 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/glauth/pkg/command/health.go b/glauth/pkg/command/health.go index 215018b291c..ef15ee650c8 100644 --- a/glauth/pkg/command/health.go +++ b/glauth/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index 08f1879e02f..75a27f8463c 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" glauthcfg "github.com/glauth/glauth/v2/pkg/config" "github.com/oklog/run" @@ -22,8 +23,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/glauth/pkg/command/version.go b/glauth/pkg/command/version.go index c3d2e4ffd39..c8e149daf5a 100644 --- a/glauth/pkg/command/version.go +++ b/glauth/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/graph-explorer/pkg/command/health.go b/graph-explorer/pkg/command/health.go index 6719e960af9..cf0a9a660f1 100644 --- a/graph-explorer/pkg/command/health.go +++ b/graph-explorer/pkg/command/health.go @@ -13,10 +13,11 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { - return parser.ParseConfig( cfg) + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index 7f753b3ccbd..711ae3a0b83 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/oklog/run" "github.com/owncloud/ocis/graph-explorer/pkg/config" @@ -18,8 +19,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/graph-explorer/pkg/command/version.go b/graph-explorer/pkg/command/version.go index 400c0bf1043..39b1cadb442 100644 --- a/graph-explorer/pkg/command/version.go +++ b/graph-explorer/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/graph/pkg/command/health.go b/graph/pkg/command/health.go index 5e2a31ecbef..b40b65a178f 100644 --- a/graph/pkg/command/health.go +++ b/graph/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index c246b23e415..38c012a20c2 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/oklog/run" "github.com/owncloud/ocis/graph/pkg/config" @@ -18,8 +19,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/graph/pkg/command/version.go b/graph/pkg/command/version.go index 8ced4ad48a5..8e85a27dd3f 100644 --- a/graph/pkg/command/version.go +++ b/graph/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/idp/pkg/command/health.go b/idp/pkg/command/health.go index a668eaf4cd7..af3e6ccbc23 100644 --- a/idp/pkg/command/health.go +++ b/idp/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index a5be7abcce7..c3bdfec70e7 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/oklog/run" "github.com/owncloud/ocis/idp/pkg/config" @@ -18,8 +19,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/idp/pkg/command/version.go b/idp/pkg/command/version.go index f9cbcd574ed..22d4f4ce6dc 100644 --- a/idp/pkg/command/version.go +++ b/idp/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 672dcd6a32b..5671fa9b6d9 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -11,9 +11,9 @@ import ( // AccountsCommand is the entrypoint for the accounts command. func AccountsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "accounts", - Usage: "Start accounts server", - Category: "Extensions", + Name: cfg.Accounts.Service.Name, + Usage: subcommandDescription(cfg.Accounts.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/common.go b/ocis/pkg/command/common.go index 60af3e22ab9..77bfa381ed3 100644 --- a/ocis/pkg/command/common.go +++ b/ocis/pkg/command/common.go @@ -1,6 +1,10 @@ package command -import "github.com/urfave/cli/v2" +import ( + "fmt" + + "github.com/urfave/cli/v2" +) func handleOriginalAction(c *cli.Context, cmd *cli.Command) error { @@ -12,3 +16,7 @@ func handleOriginalAction(c *cli.Context, cmd *cli.Command) error { return cli.HandleAction(cmd.Action, c) } + +func subcommandDescription(serviceName string) string { + return fmt.Sprintf("%s extension commands", serviceName) +} diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 3e58bbeefb7..9d7b09b0211 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -11,9 +11,9 @@ import ( // GLAuthCommand is the entrypoint for the glauth command. func GLAuthCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "glauth", - Usage: "Start glauth server", - Category: "Extensions", + Name: cfg.GLAuth.Service.Name, + Usage: subcommandDescription(cfg.GLAuth.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index a482ef68133..0a663e6db31 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -11,9 +11,9 @@ import ( // GraphCommand is the entrypoint for the graph command. func GraphCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "graph", - Usage: "Start graph server", - Category: "Extensions", + Name: cfg.Graph.Service.Name, + Usage: subcommandDescription(cfg.Graph.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index fa2eee4c3dd..d88135d0b95 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -11,9 +11,9 @@ import ( // GraphExplorerCommand is the entrypoint for the graph-explorer command. func GraphExplorerCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "graph-explorer", - Usage: "Start graph-explorer server", - Category: "Extensions", + Name: cfg.GraphExplorer.Service.Name, + Usage: subcommandDescription(cfg.GraphExplorer.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index d71e5743830..8e64daee71b 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -11,9 +11,9 @@ import ( // IDPCommand is the entrypoint for the idp command. func IDPCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "idp", - Usage: "Start idp server", - Category: "Extensions", + Name: cfg.IDP.Service.Name, + Usage: subcommandDescription(cfg.IDP.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/kill.go b/ocis/pkg/command/kill.go index 70530f98afb..853acdd715d 100644 --- a/ocis/pkg/command/kill.go +++ b/ocis/pkg/command/kill.go @@ -16,8 +16,8 @@ import ( func KillCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "kill", - Usage: "Kill an extension by name", - Category: "Runtime", + Usage: "kill an extension by name in the runtime (supervised mode)", + Category: "runtime", Flags: []cli.Flag{ &cli.StringFlag{ Name: "hostname", diff --git a/ocis/pkg/command/list.go b/ocis/pkg/command/list.go index 7d277e8bfdc..c7fd1558710 100644 --- a/ocis/pkg/command/list.go +++ b/ocis/pkg/command/list.go @@ -15,8 +15,8 @@ import ( func ListCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "list", - Usage: "Lists running ocis extensions", - Category: "Runtime", + Usage: "list oCIS extensions running in the runtime (supervised mode)", + Category: "runtime", Flags: []cli.Flag{ &cli.StringFlag{ Name: "hostname", diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 657bc2969d9..2570f2a3832 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -11,9 +11,9 @@ import ( // OCSCommand is the entrypoint for the ocs command. func OCSCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "ocs", - Usage: "Start ocs server", - Category: "Extensions", + Name: cfg.OCS.Service.Name, + Usage: subcommandDescription(cfg.OCS.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index d52e667b4e3..cd59c609047 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -11,9 +11,9 @@ import ( // ProxyCommand is the entry point for the proxy command. func ProxyCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "proxy", - Usage: "Start proxy server", - Category: "Extensions", + Name: cfg.Proxy.Service.Name, + Usage: subcommandDescription(cfg.Proxy.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/run.go b/ocis/pkg/command/run.go index 398bb39e101..1cab47a0d37 100644 --- a/ocis/pkg/command/run.go +++ b/ocis/pkg/command/run.go @@ -17,8 +17,8 @@ import ( func RunCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "run", - Usage: "Runs an extension", - Category: "Runtime", + Usage: "run an extension by name in the runtime (supervised mode)", + Category: "runtime", Flags: []cli.Flag{ &cli.StringFlag{ Name: "hostname", diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index ac24c1c6489..00b9c89da31 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -13,8 +13,8 @@ import ( func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", - Usage: "Start fullstack server", - Category: "Fullstack", + Usage: "start a fullstack server (runtime and all extensions in supervised mode)", + Category: "fullstack", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 2803c13983a..d489ccc80fd 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -11,9 +11,9 @@ import ( // SettingsCommand is the entry point for the settings command. func SettingsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "settings", - Usage: "Start settings server", - Category: "Extensions", + Name: cfg.Settings.Service.Name, + Usage: subcommandDescription(cfg.Settings.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/storageappprovider.go b/ocis/pkg/command/storageappprovider.go index 03d886f3bc5..48744bff509 100644 --- a/ocis/pkg/command/storageappprovider.go +++ b/ocis/pkg/command/storageappprovider.go @@ -11,8 +11,8 @@ import ( func StorageAppProviderCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-app-provider", - Usage: "Start storage app-provider service", - Category: "Extensions", + Usage: "start storage app-provider service", + Category: "extensions", //Flags: flagset.AppProviderWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storageauthbasic.go b/ocis/pkg/command/storageauthbasic.go index 1bfe109dbb8..3523c40b7b0 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -11,8 +11,8 @@ import ( func StorageAuthBasicCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-auth-basic", - Usage: "Start storage auth-basic service", - Category: "Extensions", + Usage: "start storage auth-basic service", + Category: "extensions", //Flags: flagset.AuthBasicWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storageauthbearer.go b/ocis/pkg/command/storageauthbearer.go index 8b87968e0ba..8486373a8fb 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -12,7 +12,7 @@ func StorageAuthBearerCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-auth-bearer", Usage: "Start storage auth-bearer service", - Category: "Extensions", + Category: "extensions", //Flags: flagset.AuthBearerWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 18b9d8a183e..2f3392caf5e 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -11,8 +11,8 @@ import ( func StorageAuthMachineCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-auth-machine", - Usage: "Start storage auth-machine service", - Category: "Extensions", + Usage: "start storage auth-machine service", + Category: "extensions", //Flags: flagset.AuthMachineWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storagefrontend.go b/ocis/pkg/command/storagefrontend.go index 5fe8ef78c51..9079e268cef 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -11,8 +11,8 @@ import ( func StorageFrontendCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-frontend", - Usage: "Start storage frontend", - Category: "Extensions", + Usage: "start storage frontend", + Category: "extensions", //Flags: flagset.FrontendWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storagegateway.go b/ocis/pkg/command/storagegateway.go index 937305d8105..615490fdd54 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -11,8 +11,8 @@ import ( func StorageGatewayCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-gateway", - Usage: "Start storage gateway", - Category: "Extensions", + Usage: "start storage gateway", + Category: "extensions", //Flags: flagset.GatewayWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storagegroupprovider.go b/ocis/pkg/command/storagegroupprovider.go index 6519772a12d..ed7907f4ed6 100644 --- a/ocis/pkg/command/storagegroupprovider.go +++ b/ocis/pkg/command/storagegroupprovider.go @@ -11,8 +11,8 @@ import ( func StorageGroupProviderCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-groupprovider", - Usage: "Start storage groupprovider service", - Category: "Extensions", + Usage: "start storage groupprovider service", + Category: "extensions", //Flags: flagset.GroupsWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storagemetadata.go b/ocis/pkg/command/storagemetadata.go index 59598a2459e..cab4a7a08f8 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -11,8 +11,8 @@ import ( func StorageMetadataCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-metadata", - Usage: "Start storage and data service for metadata", - Category: "Extensions", + Usage: "start storage and data service for metadata", + Category: "extensions", Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index 97057ed0089..653d7baf6b0 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -11,8 +11,8 @@ import ( func StoragePublicLinkCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-public-link", - Usage: "Start storage public link storage", - Category: "Extensions", + Usage: "start storage public link storage", + Category: "extensions", //Flags: flagset.StoragePublicLink(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storageshares.go b/ocis/pkg/command/storageshares.go index 7e94fd9e327..1ae1c2a5e56 100644 --- a/ocis/pkg/command/storageshares.go +++ b/ocis/pkg/command/storageshares.go @@ -11,8 +11,8 @@ import ( func StorageSharesCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-shares", - Usage: "Start storage and data provider for /home/Shares mount", - Category: "Extensions", + Usage: "start storage and data provider for shares jail", + Category: "extensions", Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagesharing.go b/ocis/pkg/command/storagesharing.go index d5d479c5cfa..1a2e5f7914a 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -11,8 +11,8 @@ import ( func StorageSharingCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-sharing", - Usage: "Start storage sharing service", - Category: "Extensions", + Usage: "start storage sharing service", + Category: "extensions", //Flags: flagset.SharingWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storageuserprovider.go b/ocis/pkg/command/storageuserprovider.go index 984d7e86a9b..61159245253 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -11,8 +11,8 @@ import ( func StorageUserProviderCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-userprovider", - Usage: "Start storage userprovider service", - Category: "Extensions", + Usage: "start storage userprovider service", + Category: "extensions", //Flags: flagset.UsersWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/storageusers.go b/ocis/pkg/command/storageusers.go index fbcd1d40a59..a6b57ceffe6 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -11,8 +11,8 @@ import ( func StorageUsersCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-users", - Usage: "Start storage and data provider for /users mount", - Category: "Extensions", + Usage: "start storage and data provider for /users mount", + Category: "extensions", //Flags: flagset.StorageUsersWithConfig(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index a12412c95ff..7e10d3628b7 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -12,9 +12,9 @@ import ( func StoreCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "store", - Usage: "Start a go-micro store", - Category: "Extensions", + Name: cfg.Store.Service.Name, + Usage: subcommandDescription(cfg.Store.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 140b6a1c570..f2c2284b9af 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -11,16 +11,12 @@ import ( // ThumbnailsCommand is the entrypoint for the thumbnails command. func ThumbnailsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "thumbnails", - Usage: "Start thumbnails server", - Category: "Extensions", + Name: cfg.Thumbnails.Service.Name, + Usage: subcommandDescription(cfg.Thumbnails.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Thumbnails) - return handleOriginalAction(c, origCmd) - }, Subcommands: command.GetCommands(cfg.Thumbnails), } } diff --git a/ocis/pkg/command/version.go b/ocis/pkg/command/version.go index f693406832c..4254a46df4a 100644 --- a/ocis/pkg/command/version.go +++ b/ocis/pkg/command/version.go @@ -17,8 +17,8 @@ import ( func VersionCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", - Usage: "Lists running services with version", - Category: "Runtime", + Usage: "print the version of this binary and all running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 6ef8a2095fe..d5b2a91333b 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -11,9 +11,9 @@ import ( // WebCommand is the entrypoint for the web command. func WebCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "web", - Usage: "Start web server", - Category: "Extensions", + Name: cfg.Web.Service.Name, + Usage: subcommandDescription(cfg.Web.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index fb171ad1451..f09b59a13cf 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -12,9 +12,9 @@ import ( func WebDAVCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "webdav", - Usage: "Start webdav server", - Category: "Extensions", + Name: cfg.WebDAV.Service.Name, + Usage: subcommandDescription(cfg.WebDAV.Service.Name), + Category: "extensions", Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocs/pkg/command/health.go b/ocs/pkg/command/health.go index 834390b9e12..319efcd39ce 100644 --- a/ocs/pkg/command/health.go +++ b/ocs/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 4126133a111..d8d0acfe42c 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config/parser" @@ -19,8 +20,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocs/pkg/command/version.go b/ocs/pkg/command/version.go index 116c081df6e..e00e7b98054 100644 --- a/ocs/pkg/command/version.go +++ b/ocs/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/proxy/pkg/command/health.go b/proxy/pkg/command/health.go index 0d10d16ecef..41359d0c7bf 100644 --- a/proxy/pkg/command/health.go +++ b/proxy/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 9f992d6d7d6..7f1767ae2c2 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -3,6 +3,7 @@ package command import ( "context" "crypto/tls" + "fmt" "net/http" "time" @@ -36,8 +37,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/proxy/pkg/command/version.go b/proxy/pkg/command/version.go index 7545db5d42d..e8b907dcadb 100644 --- a/proxy/pkg/command/version.go +++ b/proxy/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "Print the version of this binary and the running extension instances", + Category: "Version", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index 9c08299f1e1..c2c773d0a70 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/version" @@ -19,8 +20,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/settings/pkg/command/version.go b/settings/pkg/command/version.go index 15c3901363b..20df41a1e39 100644 --- a/settings/pkg/command/version.go +++ b/settings/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 80c8c523bac..591fc78136a 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -22,7 +22,7 @@ import ( func AppProvider(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "app-provider", - Usage: "Start appprovider for providing apps", + Usage: "start appprovider for providing apps", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-app-provider") }, diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 10268754a14..8528cb6c170 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -23,7 +23,7 @@ import ( func AuthBasic(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-basic", - Usage: "Start authprovider for basic auth", + Usage: "start authprovider for basic auth", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-auth-basic") }, diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index af60ccbdac7..aff1c2a5f38 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -22,7 +22,7 @@ import ( func AuthBearer(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-bearer", - Usage: "Start authprovider for bearer auth", + Usage: "start authprovider for bearer auth", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-auth-bearer") }, diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index eaaa97cbf61..46e0fa9490a 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -22,7 +22,7 @@ import ( func AuthMachine(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-machine", - Usage: "Start authprovider for machine auth", + Usage: "start authprovider for machine auth", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-auth-machine") }, diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index c3e92788ded..1be21b4ce2f 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -26,7 +26,7 @@ import ( func Frontend(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "frontend", - Usage: "Start frontend service", + Usage: "start frontend service", Before: func(c *cli.Context) error { if err := loadUserAgent(c, cfg); err != nil { return err diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 0dff38512bb..d7cdc5f2dec 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -30,7 +30,7 @@ import ( func Gateway(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "gateway", - Usage: "Start gateway", + Usage: "start gateway", Before: func(c *cli.Context) error { if err := ParseConfig(c, cfg, "storage-gateway"); err != nil { return err diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 043c96fdcdc..b7195143142 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -23,7 +23,7 @@ import ( func Groups(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "groups", - Usage: "Start groups service", + Usage: "start groups service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-groups") }, diff --git a/storage/pkg/command/health.go b/storage/pkg/command/health.go index a3c3791a99c..2a81dee7ca6 100644 --- a/storage/pkg/command/health.go +++ b/storage/pkg/command/health.go @@ -11,8 +11,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage") }, diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index abace4d50b2..52735f32b37 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -25,7 +25,7 @@ import ( func Sharing(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "sharing", - Usage: "Start sharing service", + Usage: "start sharing service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-sharing") }, diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index f77d1eca32e..8ca9d415320 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -28,11 +28,11 @@ import ( func StorageMetadata(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-metadata", - Usage: "Start storage-metadata service", + Usage: "start storage-metadata service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-metadata") }, - Category: "Extensions", + Category: "extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) tracing.Configure(cfg, logger) diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index 0e3966b7d1f..ed2a2394233 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -22,11 +22,11 @@ import ( func StoragePublicLink(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-public-link", - Usage: "Start storage-public-link service", + Usage: "start storage-public-link service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-public-link") }, - Category: "Extensions", + Category: "extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) tracing.Configure(cfg, logger) diff --git a/storage/pkg/command/storageshares.go b/storage/pkg/command/storageshares.go index a239170a21c..e701878d68a 100644 --- a/storage/pkg/command/storageshares.go +++ b/storage/pkg/command/storageshares.go @@ -23,7 +23,7 @@ import ( func StorageShares(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-shares", - Usage: "Start storage-shares service", + Usage: "start storage-shares service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-shares") }, diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 9d671949a23..8aef59396ed 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -23,7 +23,7 @@ import ( func StorageUsers(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-users", - Usage: "Start storage-users service", + Usage: "start storage-users service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-userprovider") }, diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 34aee1d7c03..c71a674b7f6 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -23,7 +23,7 @@ import ( func Users(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "users", - Usage: "Start users service", + Usage: "start users service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-users") }, diff --git a/store/pkg/command/health.go b/store/pkg/command/health.go index bc0b77b3449..7b62857a352 100644 --- a/store/pkg/command/health.go +++ b/store/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 77df9d87bb2..eb0b7f8d61e 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/oklog/run" @@ -19,8 +20,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/store/pkg/command/version.go b/store/pkg/command/version.go index 91554c791a7..e976ef727d8 100644 --- a/store/pkg/command/version.go +++ b/store/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/thumbnails/pkg/command/health.go b/thumbnails/pkg/command/health.go index 5b232dc9e11..3ac49f6b6a2 100644 --- a/thumbnails/pkg/command/health.go +++ b/thumbnails/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index c475057053f..f44b230d36c 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -19,8 +19,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/thumbnails/pkg/command/version.go b/thumbnails/pkg/command/version.go index 45030313a34..b909db37dae 100644 --- a/thumbnails/pkg/command/version.go +++ b/thumbnails/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/web/pkg/command/health.go b/web/pkg/command/health.go index 5ab5887ea09..c3c38ec4f76 100644 --- a/web/pkg/command/health.go +++ b/web/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index 016246d1e8f..f68d16a5dcf 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -3,6 +3,7 @@ package command import ( "context" "encoding/json" + "fmt" "io/ioutil" "github.com/oklog/run" @@ -19,8 +20,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/web/pkg/command/version.go b/web/pkg/command/version.go index 7b76bdcfe93..783dd284e3a 100644 --- a/web/pkg/command/version.go +++ b/web/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) diff --git a/webdav/pkg/command/health.go b/webdav/pkg/command/health.go index 0a8e62486bc..f4485c6c1bc 100644 --- a/webdav/pkg/command/health.go +++ b/webdav/pkg/command/health.go @@ -13,8 +13,9 @@ import ( // Health is the entrypoint for the health command. func Health(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "health", - Usage: "Check health status", + Name: "health", + Usage: "check health status", + Category: "info", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 10dd88abf88..3511d326c89 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -2,6 +2,7 @@ package command import ( "context" + "fmt" "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/version" @@ -18,8 +19,9 @@ import ( // Server is the entrypoint for the server command. func Server(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "server", - Usage: "Start integrated server", + Name: "server", + Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), + Category: "server", Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/webdav/pkg/command/version.go b/webdav/pkg/command/version.go index f6649a41a70..71b5b0d4525 100644 --- a/webdav/pkg/command/version.go +++ b/webdav/pkg/command/version.go @@ -15,8 +15,9 @@ import ( // Version prints the service versions of all running instances. func Version(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "Print the versions of the running instances", + Name: "version", + Usage: "print the version of this binary and the running extension instances", + Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.String) fmt.Printf("Compiled: %s\n", version.Compiled()) From 6de48a8cd43c47f2b08e86fe1d9fb8a83f290bae Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 7 Jan 2022 13:21:14 +0100 Subject: [PATCH 71/84] switch to http.StatusOK instead of 200 --- accounts/pkg/command/health.go | 2 +- glauth/pkg/command/health.go | 2 +- graph-explorer/pkg/command/health.go | 2 +- graph/pkg/command/health.go | 2 +- idp/pkg/command/health.go | 2 +- ocs/pkg/command/health.go | 2 +- proxy/pkg/command/health.go | 2 +- settings/pkg/command/health.go | 2 +- storage/pkg/command/health.go | 2 +- store/pkg/command/health.go | 2 +- thumbnails/pkg/command/health.go | 2 +- web/pkg/command/health.go | 2 +- webdav/pkg/command/health.go | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/accounts/pkg/command/health.go b/accounts/pkg/command/health.go index 0e908b60e60..bba020b88e5 100644 --- a/accounts/pkg/command/health.go +++ b/accounts/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/glauth/pkg/command/health.go b/glauth/pkg/command/health.go index ef15ee650c8..edc25b50ac6 100644 --- a/glauth/pkg/command/health.go +++ b/glauth/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/graph-explorer/pkg/command/health.go b/graph-explorer/pkg/command/health.go index cf0a9a660f1..b25e795c262 100644 --- a/graph-explorer/pkg/command/health.go +++ b/graph-explorer/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/graph/pkg/command/health.go b/graph/pkg/command/health.go index b40b65a178f..27c8ef9e9a5 100644 --- a/graph/pkg/command/health.go +++ b/graph/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/idp/pkg/command/health.go b/idp/pkg/command/health.go index af3e6ccbc23..d1da86af79a 100644 --- a/idp/pkg/command/health.go +++ b/idp/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/ocs/pkg/command/health.go b/ocs/pkg/command/health.go index 319efcd39ce..b49d3b41ab4 100644 --- a/ocs/pkg/command/health.go +++ b/ocs/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/proxy/pkg/command/health.go b/proxy/pkg/command/health.go index 41359d0c7bf..ff004eae4b5 100644 --- a/proxy/pkg/command/health.go +++ b/proxy/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/settings/pkg/command/health.go b/settings/pkg/command/health.go index a8e15f8cfd6..3475fceabc6 100644 --- a/settings/pkg/command/health.go +++ b/settings/pkg/command/health.go @@ -36,7 +36,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/storage/pkg/command/health.go b/storage/pkg/command/health.go index 2a81dee7ca6..7ba232a1c07 100644 --- a/storage/pkg/command/health.go +++ b/storage/pkg/command/health.go @@ -35,7 +35,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/store/pkg/command/health.go b/store/pkg/command/health.go index 7b62857a352..fafc60e027b 100644 --- a/store/pkg/command/health.go +++ b/store/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/thumbnails/pkg/command/health.go b/thumbnails/pkg/command/health.go index 3ac49f6b6a2..7eb46247503 100644 --- a/thumbnails/pkg/command/health.go +++ b/thumbnails/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/web/pkg/command/health.go b/web/pkg/command/health.go index c3c38ec4f76..38713676abb 100644 --- a/web/pkg/command/health.go +++ b/web/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") diff --git a/webdav/pkg/command/health.go b/webdav/pkg/command/health.go index f4485c6c1bc..94741b29a71 100644 --- a/webdav/pkg/command/health.go +++ b/webdav/pkg/command/health.go @@ -37,7 +37,7 @@ func Health(cfg *config.Config) *cli.Command { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { logger.Fatal(). Int("code", resp.StatusCode). Msg("Health seems to be in bad state") From d08c805179de248cc79962a7eb76cafc0dade627 Mon Sep 17 00:00:00 2001 From: Willy Kloucek <34452982+wkloucek@users.noreply.github.com> Date: Fri, 7 Jan 2022 12:50:07 +0000 Subject: [PATCH 72/84] Automated changelog update [skip ci] --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b3b0f90420..ba674e78689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The following sections list the changes for unreleased. * Bugfix - Add `ocis storage-auth-machine` subcommand: [#2910](https://github.com/owncloud/ocis/pull/2910) * Bugfix - Fix configuration for space membership endpoint: [#2893](https://github.com/owncloud/ocis/pull/2893) +* Change - Unify configuration and commands: [#2818](https://github.com/owncloud/ocis/pull/2818) * Change - Update the graph api: [#2885](https://github.com/owncloud/ocis/pull/2885) * Change - Update libre-graph-api to v0.3.0: [#2858](https://github.com/owncloud/ocis/pull/2858) * Change - Return not found when updating non existent space: [#2869](https://github.com/cs3org/reva/pull/2869) @@ -31,6 +32,14 @@ The following sections list the changes for unreleased. https://github.com/owncloud/ocis/pull/2893 +* Change - Unify configuration and commands: [#2818](https://github.com/owncloud/ocis/pull/2818) + + We've unified the configuration and commands of all non storage services. This also includes + the change, that environment variables are now defined on the config struct as tags instead in a + separate mapping. + + https://github.com/owncloud/ocis/pull/2818 + * Change - Update the graph api: [#2885](https://github.com/owncloud/ocis/pull/2885) GraphApi has been updated to version 0.4.1 and the existing dependency was removed From 191b3de60a6a3a37475d6ec07f94ccdd44c38745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Jan 2022 19:58:42 +0000 Subject: [PATCH 73/84] fix merge and rebase dance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- storage/pkg/command/frontend.go | 2 +- storage/pkg/command/gateway.go | 11 +- storage/pkg/command/storageshares.go | 2 +- storage/pkg/config/config.go | 439 --------------------------- storage/pkg/config/defaultconfig.go | 8 +- 5 files changed, 7 insertions(+), 455 deletions(-) diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 1be21b4ce2f..e96d2c1477d 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -201,7 +201,7 @@ func frontendConfigFromStruct(c *cli.Context, cfg *config.Config, filesCfg map[s "resource_info_cache_ttl": cfg.Reva.Frontend.OCSResourceInfoCacheTTL, "prefix": cfg.Reva.Frontend.OCSPrefix, "additional_info_attribute": cfg.Reva.Frontend.OCSAdditionalInfoAttribute, - "machine_auth_apikey": "change-me-please", // FIXME make configurable + "machine_auth_apikey": cfg.Reva.AuthMachineConfig.MachineAuthAPIKey, "cache_warmup_driver": cfg.Reva.Frontend.OCSCacheWarmupDriver, "cache_warmup_drivers": map[string]interface{}{ "cbox": map[string]interface{}{ diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index d7cdc5f2dec..0de42d2b918 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -180,8 +180,7 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg "driver": cfg.Reva.StorageRegistry.Driver, "drivers": map[string]interface{}{ "spaces": map[string]interface{}{ - "home_template": cfg.Reva.StorageRegistry.HomeProvider, - "providers": spacesProviders(cfg, logger), + "providers": spacesProviders(cfg, logger), }, }, }, @@ -234,14 +233,6 @@ func spacesProviders(cfg *config.Config, logger log.Logger) map[string]map[strin }, cfg.Reva.StorageShares.Endpoint: { "spaces": map[string]interface{}{ - /* - "share": map[string]interface{}{ - // The jail needs to be filled with mount points - // .Space.Name is a path relative to the mount point - "mount_point": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", - "path_template": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares/{{.Space.Name}}", - }, - */ "virtual": map[string]interface{}{ // The root of the share jail is mounted here "mount_point": "/users/{{.CurrentUser.Id.OpaqueId}}/Shares", diff --git a/storage/pkg/command/storageshares.go b/storage/pkg/command/storageshares.go index e701878d68a..ea0d0c91722 100644 --- a/storage/pkg/command/storageshares.go +++ b/storage/pkg/command/storageshares.go @@ -117,7 +117,7 @@ func storageSharesConfigFromStruct(c *cli.Context, cfg *config.Config) map[strin return rcfg } -// StorageSharesSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree. +// StorageSharesSutureService allows for the storage-shares command to be embedded and supervised by a suture supervisor tree. type StorageSharesSutureService struct { cfg *config.Config } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 0acbf11bbdf..6cd62c35d61 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -2,10 +2,6 @@ package config import ( "context" - "os" - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/shared" ) @@ -520,441 +516,6 @@ func New() *Config { return &Config{} } -func DefaultConfig() *Config { - return &Config{ - // log is inherited - Debug: Debug{ - Addr: "127.0.0.1:9109", - }, - Reva: Reva{ - JWTSecret: "Pive-Fumkiu4", - SkipUserGroupsInToken: false, - TransferSecret: "replace-me-with-a-transfer-secret", - TransferExpires: 24 * 60 * 60, - OIDC: OIDC{ - Issuer: "https://localhost:9200", - Insecure: false, - IDClaim: "preferred_username", - }, - LDAP: LDAP{ - Hostname: "localhost", - Port: 9126, - CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), - Insecure: false, - BaseDN: "dc=ocis,dc=test", - LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", - UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", - UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", - UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", - GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", - GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", - GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", - BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", - BindPassword: "reva", - IDP: "https://localhost:9200", - UserSchema: LDAPUserSchema{ - UID: "ownclouduuid", - Mail: "mail", - DisplayName: "displayname", - CN: "cn", - UIDNumber: "uidnumber", - GIDNumber: "gidnumber", - }, - GroupSchema: LDAPGroupSchema{ - GID: "cn", - Mail: "mail", - DisplayName: "cn", - CN: "cn", - GIDNumber: "gidnumber", - }, - }, - UserGroupRest: UserGroupRest{ - RedisAddress: "localhost:6379", - }, - UserOwnCloudSQL: UserOwnCloudSQL{ - DBUsername: "owncloud", - DBPassword: "secret", - DBHost: "mysql", - DBPort: 3306, - DBName: "owncloud", - Idp: "https://localhost:9200", - Nobody: 90, - JoinUsername: false, - JoinOwnCloudUUID: false, - EnableMedialSearch: false, - }, - OCDav: OCDav{ - WebdavNamespace: "/home/", - DavFilesNamespace: "/users/", - }, - Archiver: Archiver{ - MaxNumFiles: 10000, - MaxSize: 1073741824, - ArchiverURL: "/archiver", - }, - UserStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ - Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", - UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", - }, - ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") - UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") - EosBinary: "/usr/bin/eos", - XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - CacheDirectory: os.TempDir(), - GatewaySVC: "127.0.0.1:9142", - }, - Local: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Username}}", - EnableHome: false, - }, - OwnCloud: DriverOwnCloud{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), - Redis: ":6379", - Scan: true, - }, - OwnCloudSQL: DriverOwnCloudSQL{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Username}}", - EnableHome: false, - }, - UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), - DBUsername: "owncloud", - DBPassword: "owncloud", - DBHost: "", - DBPort: 3306, - DBName: "owncloud", - }, - S3: DriverS3{ - DriverCommon: DriverCommon{}, - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - }, - }, - MetadataStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ - Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", - UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", - EnableHome: false, - }, - ShadowNamespace: "", - UploadsNamespace: "", - EosBinary: "/usr/bin/eos", - XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - GrpcURI: "", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", - CacheDirectory: os.TempDir(), - EnableLogging: false, - ShowHiddenSysFiles: false, - ForceSingleUserMode: false, - UseKeytab: false, - SecProtocol: "", - Keytab: "", - SingleUsername: "", - GatewaySVC: "127.0.0.1:9142", - }, - Local: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), - }, - OwnCloud: DriverOwnCloud{}, - OwnCloudSQL: DriverOwnCloudSQL{}, - S3: DriverS3{ - DriverCommon: DriverCommon{}, - Region: "default", - }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), - ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Region: "default", - AccessKey: "", - SecretKey: "", - Endpoint: "", - Bucket: "", - }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ - Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), - ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", - EnableHome: false, - }, - ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - }, - }, - Frontend: FrontendPort{ - Port: Port{ - MaxCPUs: "", - LogLevel: "", - GRPCNetwork: "", - GRPCAddr: "", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9140", - Protocol: "", - Endpoint: "", - DebugAddr: "127.0.0.1:9141", - Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, - Config: nil, - Context: nil, - Supervised: false, - }, - AppProviderInsecure: false, - AppProviderPrefix: "", - ArchiverInsecure: false, - ArchiverPrefix: "archiver", - DatagatewayPrefix: "data", - Favorites: false, - OCDavInsecure: false, - OCDavPrefix: "", - OCSPrefix: "ocs", - OCSSharePrefix: "/Shares", - OCSHomeNamespace: "/home", - PublicURL: "https://localhost:9200", - OCSCacheWarmupDriver: "", - OCSAdditionalInfoAttribute: "{{.Mail}}", - OCSResourceInfoCacheTTL: 0, - Middleware: Middleware{}, - }, - DataGateway: DataGatewayPort{ - Port: Port{}, - PublicURL: "", - }, - Gateway: Gateway{ - Port: Port{ - Endpoint: "127.0.0.1:9142", - DebugAddr: "127.0.0.1:9143", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9142", - }, - CommitShareToStorageGrant: true, - CommitShareToStorageRef: true, - DisableHomeCreationOnLogin: false, - ShareFolder: "Shares", - LinkGrants: "", - HomeMapping: "", - EtagCacheTTL: 0, - }, - StorageRegistry: StorageRegistry{ - Driver: "static", - HomeProvider: "/home", - JSON: "", - }, - AppRegistry: AppRegistry{ - Driver: "static", - MimetypesJSON: "", - }, - Users: Users{ - Port: Port{ - Endpoint: "localhost:9144", - DebugAddr: "127.0.0.1:9145", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9144", - Services: []string{"userprovider"}, - }, - Driver: "ldap", - UserGroupsCacheExpiration: 5, - }, - Groups: Groups{ - Port: Port{ - Endpoint: "localhost:9160", - DebugAddr: "127.0.0.1:9161", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9160", - Services: []string{"groupprovider"}, - }, - Driver: "ldap", - GroupMembersCacheExpiration: 5, - }, - AuthProvider: Users{ - Port: Port{}, - Driver: "ldap", - UserGroupsCacheExpiration: 0, - }, - AuthBasic: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9146", - DebugAddr: "127.0.0.1:9147", - Services: []string{"authprovider"}, - Endpoint: "localhost:9146", - }, - AuthBearer: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9148", - DebugAddr: "127.0.0.1:9149", - Services: []string{"authprovider"}, - Endpoint: "localhost:9148", - }, - AuthMachine: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9166", - DebugAddr: "127.0.0.1:9167", - Services: []string{"authprovider"}, - Endpoint: "localhost:9166", - }, - AuthMachineConfig: AuthMachineConfig{ - MachineAuthAPIKey: "change-me-please", - }, - Sharing: Sharing{ - Port: Port{ - Endpoint: "localhost:9150", - DebugAddr: "127.0.0.1:9151", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9150", - Services: []string{"usershareprovider", "publicshareprovider"}, - }, - UserDriver: "json", - UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), - UserSQLUsername: "", - UserSQLPassword: "", - UserSQLHost: "", - UserSQLPort: 1433, - UserSQLName: "", - PublicDriver: "json", - PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), - PublicPasswordHashCost: 11, - PublicEnableExpiredSharesCleanup: true, - PublicJanitorRunInterval: 60, - UserStorageMountID: "", - }, - StorageHome: StoragePort{ - Port: Port{ - Endpoint: "localhost:9154", - DebugAddr: "127.0.0.1:9156", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9154", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9155", - }, - Driver: "ocis", - ReadOnly: false, - MountPath: "/home", - AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", - MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - DataServerURL: "http://localhost:9155/data", - HTTPPrefix: "data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "home"), - }, - StorageUsers: StoragePort{ - Port: Port{ - Endpoint: "localhost:9157", - DebugAddr: "127.0.0.1:9159", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9157", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9158", - }, - MountPath: "/users", - MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", - Driver: "ocis", - DataServerURL: "http://localhost:9158/data", - HTTPPrefix: "data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), - }, - StoragePublicLink: PublicStorage{ - StoragePort: StoragePort{ - Port: Port{ - Endpoint: "localhost:9178", - DebugAddr: "127.0.0.1:9179", - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9178", - }, - MountPath: "/public", - MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", - }, - PublicShareProviderAddr: "", - UserProviderAddr: "", - }, - StorageMetadata: StoragePort{ - Port: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9215", - HTTPNetwork: "tcp", - HTTPAddr: "127.0.0.1:9216", - DebugAddr: "127.0.0.1:9217", - }, - Driver: "ocis", - ExposeDataServer: false, - DataServerURL: "http://localhost:9216/data", - TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), - DataProvider: DataProvider{}, - }, - AppProvider: AppProvider{ - Port: Port{ - GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9164", - DebugAddr: "127.0.0.1:9165", - Endpoint: "localhost:9164", - Services: []string{"appprovider"}, - }, - ExternalAddr: "127.0.0.1:9164", - WopiDriver: WopiDriver{}, - AppsURL: "/app/list", - OpenURL: "/app/open", - NewURL: "/app/new", - }, - Configs: nil, - UploadMaxChunkSize: 1e+8, - UploadHTTPMethodOverride: "", - ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, - ChecksumPreferredUploadType: "", - DefaultUploadProtocol: "tus", - }, - Tracing: Tracing{ - Service: "storage", - Type: "jaeger", - }, - Asset: Asset{}, - } -} - // StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the // Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets // us propagate changes easier. diff --git a/storage/pkg/config/defaultconfig.go b/storage/pkg/config/defaultconfig.go index 00e0dba3633..0f266d4d650 100644 --- a/storage/pkg/config/defaultconfig.go +++ b/storage/pkg/config/defaultconfig.go @@ -33,7 +33,7 @@ func DefaultConfig() *Config { UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", - UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", + UserGroupFilter: "(&(objectclass=posixGroup)(cn={{.}}*))", // FIXME (&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*)) in reva the template is executed with a string. IIRC rhaferkamp mentioned this GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", @@ -239,7 +239,7 @@ func DefaultConfig() *Config { ArchiverPrefix: "archiver", DatagatewayPrefix: "data", Favorites: false, - OCDavInsecure: false, + OCDavInsecure: false, // true? OCDavPrefix: "", OCSPrefix: "ocs", OCSSharePrefix: "/Shares", @@ -271,7 +271,7 @@ func DefaultConfig() *Config { }, StorageRegistry: StorageRegistry{ Driver: "spaces", - HomeProvider: "/home", + HomeProvider: "/home", // unused for spaces, static currently not supported JSON: "", }, AppRegistry: AppRegistry{ @@ -387,7 +387,7 @@ func DefaultConfig() *Config { GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9178", }, - MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", + MountID: "7993447f-687f-490d-875c-ac95e89a62a4", }, PublicShareProviderAddr: "", UserProviderAddr: "", From 2eeb017342c7b62d6342e055181ee3e5cc5f8fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Jan 2022 20:07:13 +0000 Subject: [PATCH 74/84] revert .drone.env change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .drone.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.env b/.drone.env index 35d1a715497..895c99c0615 100644 --- a/.drone.env +++ b/.drone.env @@ -1,5 +1,5 @@ # The test runner source for API tests -CORE_COMMITID=a37efb60db92923398de7efef1abb173d13a9afb +CORE_COMMITID=09d584745d6cbd6aebc557d9b78f6130e9b99e2b CORE_BRANCH=master # The test runner source for UI tests From 2dd3f18d7e1f694cedd0350a18d1da53c7bf78d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Jan 2022 20:14:21 +0000 Subject: [PATCH 75/84] remove unused user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- thumbnails/pkg/service/v0/service.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/thumbnails/pkg/service/v0/service.go b/thumbnails/pkg/service/v0/service.go index 82ca913901c..28a0d4045fd 100644 --- a/thumbnails/pkg/service/v0/service.go +++ b/thumbnails/pkg/service/v0/service.go @@ -8,7 +8,6 @@ import ( "strings" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" - userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" revactx "github.com/cs3org/reva/pkg/ctx" @@ -99,7 +98,7 @@ func (g Thumbnail) GetThumbnail(ctx context.Context, req *v0proto.GetThumbnailRe func (g Thumbnail) handleCS3Source(ctx context.Context, req *v0proto.GetThumbnailRequest, encoder thumbnail.Encoder) ([]byte, error) { src := req.GetCs3Source() - sRes, err := g.stat(src.Path, src.Authorization, nil) + sRes, err := g.stat(src.Path, src.Authorization) if err != nil { return nil, err } @@ -143,10 +142,7 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *v0proto.GetThumb return nil, errors.Wrap(err, "source url is invalid") } - var ( - auth, statPath string - user *userv1beta1.User - ) + var auth, statPath string if src.IsPublicLink { q := imgURL.Query() @@ -174,14 +170,12 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *v0proto.GetThumb return nil, merrors.InternalServerError(g.serviceID, "could not authenticate: %s", err.Error()) } auth = rsp.Token - user = rsp.User statPath = path.Join("/public", src.PublicLinkToken, req.Filepath) } else { auth = src.RevaAuthorization statPath = req.Filepath - user = revactx.ContextMustGetUser(ctx) } - sRes, err := g.stat(statPath, auth, user) + sRes, err := g.stat(statPath, auth) if err != nil { return nil, err } @@ -219,7 +213,7 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *v0proto.GetThumb return thumb, nil } -func (g Thumbnail) stat(path, auth string, user *userv1beta1.User) (*provider.StatResponse, error) { +func (g Thumbnail) stat(path, auth string) (*provider.StatResponse, error) { ctx := metadata.AppendToOutgoingContext(context.Background(), revactx.TokenHeader, auth) req := &provider.StatRequest{ From c2ce38ce6b165830bc68a3d881ac6d14466016a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Jan 2022 20:45:23 +0000 Subject: [PATCH 76/84] remove unexepected success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- tests/acceptance/expected-failures-API-on-OCIS-storage.md | 6 ------ .../expected-failures-localAPI-on-OCIS-storage.md | 4 ---- 2 files changed, 10 deletions(-) diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index 389456b7c7e..565002e2ec8 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -581,11 +581,6 @@ _getting and setting quota_ - [apiWebdavProperties1/getQuota.feature:27](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties1/getQuota.feature#L27) - [apiWebdavProperties1/getQuota.feature:28](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties1/getQuota.feature#L28) - -#### [cannot get share-types webdav property](https://github.com/owncloud/ocis/issues/567) -- [apiWebdavProperties2/getFileProperties.feature:174](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature#L174) -- [apiWebdavProperties2/getFileProperties.feature:175](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature#L175) - #### [Private link support](https://github.com/owncloud/product/issues/201) #### [oc:privatelink property not returned in webdav responses](https://github.com/owncloud/product/issues/262) - [apiWebdavProperties2/getFileProperties.feature:232](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature#L232) @@ -1428,7 +1423,6 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers - [apiSharePublicLink2/allowGroupToCreatePublicLinks.feature:91](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink2/allowGroupToCreatePublicLinks.feature#L91) ### [Cannot download preview of shared received file after the shareowner has changed the file content](https://github.com/owncloud/ocis/issues/2538) -- [apiWebdavPreviews/previews.feature:196](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavPreviews/previews.feature#L196) - [apiWebdavPreviews/previews.feature:217](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavPreviews/previews.feature#L217) - [apiWebdavPreviews/previews.feature:233](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavPreviews/previews.feature#L233) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index e7f8deb0447..3ec4a5f35cc 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -1,9 +1,5 @@ ## Scenarios from OCIS API tests that are expected to fail with OCIS storage -#### [downloading the /Shares folder using the archiver endpoint does not work](https://github.com/owncloud/ocis/issues/2751) -- [apiArchiver/downloadById.feature:134](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadById.feature#L134) -- [apiArchiver/downloadById.feature:135](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadById.feature#L135) - #### [downloading an archive with invalid path returns HTTP/500](https://github.com/owncloud/ocis/issues/2768) - [apiArchiver/downloadByPath.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L69) From b68a9c53465737df2531205763c31d3d6fe4c632 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Mon, 10 Jan 2022 15:46:37 +0100 Subject: [PATCH 77/84] use newest reva version Signed-off-by: jkoberg --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 11d4291d949..2d87537b490 100644 --- a/go.mod +++ b/go.mod @@ -246,4 +246,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20220107152324-c05e07489406 +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20220110143148-0b50ca9ddb6e diff --git a/go.sum b/go.sum index 9e230717d1e..d9389859460 100644 --- a/go.sum +++ b/go.sum @@ -324,8 +324,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8 h1:PqOprF37OvwCbAN5W23znknGk6N/LMayqLAeP904FHE= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20220107152324-c05e07489406 h1:pmt68Syo7St30SztB5ce761x5P6/XNX7CXL+rnOPLrI= -github.com/cs3org/reva v1.16.1-0.20220107152324-c05e07489406/go.mod h1:WqO2/NkAmx1qes09G92lGPxxyroQgnZetJrCPItCcDo= +github.com/cs3org/reva v1.16.1-0.20220110143148-0b50ca9ddb6e h1:mV27x2ADeJgmPC+HBDtFeZFAp3tZIo65h9yiFf1jBrU= +github.com/cs3org/reva v1.16.1-0.20220110143148-0b50ca9ddb6e/go.mod h1:WqO2/NkAmx1qes09G92lGPxxyroQgnZetJrCPItCcDo= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= From f6739402ec2f63c13c960a2538d947bc8ef8058f Mon Sep 17 00:00:00 2001 From: jkoberg Date: Mon, 10 Jan 2022 16:00:26 +0100 Subject: [PATCH 78/84] add /home/ tests to expected failures Signed-off-by: jkoberg --- .../expected-failures-localAPI-on-OCIS-storage.md | 14 ++++++++++++-- .../features/apiArchiver/downloadById.feature | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 3ec4a5f35cc..34f1a905aa6 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -1,10 +1,20 @@ ## Scenarios from OCIS API tests that are expected to fail with OCIS storage #### [downloading an archive with invalid path returns HTTP/500](https://github.com/owncloud/ocis/issues/2768) +- [apiArchiver/downloadByPath.feature:69] + +#### [Hardcoded call to /home/..., but /home no longer exists](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L26) +- [apiArchiver/downloadByPath.feature:26](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L26) +- [apiArchiver/downloadByPath.feature:27](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L27) +- [apiArchiver/downloadByPath.feature:44](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L44) +- [apiArchiver/downloadByPath.feature:45](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L45) +- [apiArchiver/downloadByPath.feature:48](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L48) - [apiArchiver/downloadByPath.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L69) +- [apiArchiver/downloadByPath.feature:74](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L74) +- [apiArchiver/downloadByPath.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L132) +- [apiArchiver/downloadByPath.feature:133](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L133) -#### [downloading an archive with non existing / accessible id returns HTTP/500](https://github.com/owncloud/ocis/issues/2795) -- [apiArchiver/downloadById.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L69) #### [Overwriting a file in the space within the allowed quota does not work](https://github.com/owncloud/ocis/issues/2829) - [apiSpaces/quota.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/quota.feature#L56) + diff --git a/tests/acceptance/features/apiArchiver/downloadById.feature b/tests/acceptance/features/apiArchiver/downloadById.feature index 1437a97639b..fef3847928b 100644 --- a/tests/acceptance/features/apiArchiver/downloadById.feature +++ b/tests/acceptance/features/apiArchiver/downloadById.feature @@ -70,7 +70,7 @@ Feature: download multiple resources bundled into an archive Given user "Brian" has been created with default attributes and without skeleton files And user "Alice" has uploaded file with content "some data" to "/textfile0.txt" When user "Brian" downloads the archive of "/textfile0.txt" of user "Alice" using the resource id - Then the HTTP status code should be "400" + Then the HTTP status code should be "404" Scenario: download multiple shared items as share receiver From 64471d02cb07a7ecfca4d94676a2e1f879ab852b Mon Sep 17 00:00:00 2001 From: jkoberg Date: Mon, 10 Jan 2022 17:36:14 +0100 Subject: [PATCH 79/84] bump reva and update expected failures Signed-off-by: jkoberg --- go.mod | 2 +- go.sum | 4 ++-- .../acceptance/expected-failures-localAPI-on-OCIS-storage.md | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2d87537b490..5447d5cd6ad 100644 --- a/go.mod +++ b/go.mod @@ -246,4 +246,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20220110143148-0b50ca9ddb6e +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20220110163001-3d6605476745 diff --git a/go.sum b/go.sum index d9389859460..e54f2622752 100644 --- a/go.sum +++ b/go.sum @@ -324,8 +324,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8 h1:PqOprF37OvwCbAN5W23znknGk6N/LMayqLAeP904FHE= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20220110143148-0b50ca9ddb6e h1:mV27x2ADeJgmPC+HBDtFeZFAp3tZIo65h9yiFf1jBrU= -github.com/cs3org/reva v1.16.1-0.20220110143148-0b50ca9ddb6e/go.mod h1:WqO2/NkAmx1qes09G92lGPxxyroQgnZetJrCPItCcDo= +github.com/cs3org/reva v1.16.1-0.20220110163001-3d6605476745 h1:t//I0DOXvmXjWD1PcxHIUYueu8wv838ye4rPltDXvF8= +github.com/cs3org/reva v1.16.1-0.20220110163001-3d6605476745/go.mod h1:WqO2/NkAmx1qes09G92lGPxxyroQgnZetJrCPItCcDo= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 34f1a905aa6..e572e083932 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -14,6 +14,9 @@ - [apiArchiver/downloadByPath.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L132) - [apiArchiver/downloadByPath.feature:133](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L133) +#### Another users space literally does not exist because it is not listed as a space for him, 404 seems correct, expects 403 +- [apiAuthWebDav/webDavPUTAuth.feature:40] + #### [Overwriting a file in the space within the allowed quota does not work](https://github.com/owncloud/ocis/issues/2829) - [apiSpaces/quota.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/quota.feature#L56) From 39d5f9eb2a5a506e35ee5f027bb966c813ebc17d Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 11 Jan 2022 10:46:07 +0100 Subject: [PATCH 80/84] add test to expected failures for real Signed-off-by: jkoberg --- .../expected-failures-API-on-OCIS-storage.md | 13 ++++++----- ...ected-failures-localAPI-on-OCIS-storage.md | 22 ++++++++----------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index 565002e2ec8..f566358786e 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -1049,6 +1049,9 @@ _ocdav: api compatibility, return correct status code_ _ocdav: api compatibility, return correct status code_ - [apiAuthWebDav/webDavPOSTAuth.feature:40](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPOSTAuth.feature#L40) Scenario: send POST requests to another user's webDav endpoints as normal user +#### Another users space literally does not exist because it is not listed as a space for him, 404 seems correct, expects 403 +- [apiAuthWebDav/webDavPUTAuth.feature:40](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPUTAuth.feature#L40) + #### [Using double slash in URL to access a folder gives 501 and other status codes](https://github.com/owncloud/ocis/issues/1667) - [apiAuthWebDav/webDavSpecialURLs.feature:13](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavSpecialURLs.feature#L13) - [apiAuthWebDav/webDavSpecialURLs.feature:24](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavSpecialURLs.feature#L24) @@ -1418,18 +1421,18 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers - [apiWebdavUpload1/uploadFileToBlacklistedName.feature:66](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFileToBlacklistedName.feature#L66) - [apiWebdavUpload1/uploadFileToBlacklistedName.feature:67](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFileToBlacklistedName.feature#L67) -### [Allow public link sharing only for certain groups feature not implemented] +#### [Allow public link sharing only for certain groups feature not implemented] - [apiSharePublicLink2/allowGroupToCreatePublicLinks.feature:35](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink2/allowGroupToCreatePublicLinks.feature#L35) - [apiSharePublicLink2/allowGroupToCreatePublicLinks.feature:91](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiSharePublicLink2/allowGroupToCreatePublicLinks.feature#L91) -### [Cannot download preview of shared received file after the shareowner has changed the file content](https://github.com/owncloud/ocis/issues/2538) +#### [Cannot download preview of shared received file after the shareowner has changed the file content](https://github.com/owncloud/ocis/issues/2538) - [apiWebdavPreviews/previews.feature:217](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavPreviews/previews.feature#L217) - [apiWebdavPreviews/previews.feature:233](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavPreviews/previews.feature#L233) -### [Preview of text file with UTF content does not render correctly](https://github.com/owncloud/ocis/issues/2570) +#### [Preview of text file with UTF content does not render correctly](https://github.com/owncloud/ocis/issues/2570) - [apiWebdavPreviews/previews.feature:208](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavPreviews/previews.feature#L208) -### [Share path in the response is different between share states](https://github.com/owncloud/ocis/issues/2540) +#### [Share path in the response is different between share states](https://github.com/owncloud/ocis/issues/2540) - [apiShareManagementToShares/acceptShares.feature:65](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L65) - [apiShareManagementToShares/acceptShares.feature:93](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L93) - [apiShareManagementToShares/acceptShares.feature:228](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L228) @@ -1441,6 +1444,6 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers - [apiShareOperationsToShares2/shareAccessByID.feature:124](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L124) - [apiShareOperationsToShares2/shareAccessByID.feature:125](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L125) -### [Content-type is not multipart/byteranges when downloading file with Range Header](https://github.com/owncloud/ocis/issues/2677) +#### [Content-type is not multipart/byteranges when downloading file with Range Header](https://github.com/owncloud/ocis/issues/2677) - [apiWebdavOperations/downloadFile.feature:169](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavOperations/downloadFile.feature#L169) - [apiWebdavOperations/downloadFile.feature:170](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavOperations/downloadFile.feature#L170) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index e572e083932..8aa81007f0e 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -4,19 +4,15 @@ - [apiArchiver/downloadByPath.feature:69] #### [Hardcoded call to /home/..., but /home no longer exists](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L26) -- [apiArchiver/downloadByPath.feature:26](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L26) -- [apiArchiver/downloadByPath.feature:27](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L27) -- [apiArchiver/downloadByPath.feature:44](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L44) -- [apiArchiver/downloadByPath.feature:45](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L45) -- [apiArchiver/downloadByPath.feature:48](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L48) -- [apiArchiver/downloadByPath.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L69) -- [apiArchiver/downloadByPath.feature:74](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L74) -- [apiArchiver/downloadByPath.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L132) -- [apiArchiver/downloadByPath.feature:133](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/apiArchiver/downloadByPath.feature#L133) - -#### Another users space literally does not exist because it is not listed as a space for him, 404 seems correct, expects 403 -- [apiAuthWebDav/webDavPUTAuth.feature:40] - +- [apiArchiver/downloadByPath.feature:26](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L26) +- [apiArchiver/downloadByPath.feature:27](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L27) +- [apiArchiver/downloadByPath.feature:44](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L44) +- [apiArchiver/downloadByPath.feature:45](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L45) +- [apiArchiver/downloadByPath.feature:48](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L48) +- [apiArchiver/downloadByPath.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L69) +- [apiArchiver/downloadByPath.feature:74](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L74) +- [apiArchiver/downloadByPath.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L132) +- [apiArchiver/downloadByPath.feature:133](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L133) #### [Overwriting a file in the space within the allowed quota does not work](https://github.com/owncloud/ocis/issues/2829) - [apiSpaces/quota.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/quota.feature#L56) From f542e58f773d946ab9a020e75c61b0a7efd09a09 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 11 Jan 2022 12:48:49 +0100 Subject: [PATCH 81/84] add web tests to expected failures Signed-off-by: jkoberg --- tests/acceptance/expected-failures-webUI-on-OCIS-storage.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md b/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md index 657b0b7d9e1..5833e4e5884 100644 --- a/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md @@ -510,3 +510,7 @@ Other free text and markdown formatting can be used elsewhere in the document if ### [shares are not listed with full paths](https://github.com/owncloud/ocis/issues/2462) - [webUISharingPublicBasic/publicLinkCreate.feature:88](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUISharingPublicBasic/publicLinkCreate.feature#L88) + +### Shares folder cannot be deleted and is always visible +- [webUIDeleteFilesFolders/deleteFilesFolders.feature:77](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIDeleteFilesFolders/deleteFilesFolders.feature#L77) +- [webUIDeleteFilesFolders/deleteFilesFolders.feature:89](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIDeleteFilesFolders/deleteFilesFolders.feature#L89) From f08c1615544c69858f2b4ef3d2d3b32111df872c Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 11 Jan 2022 13:14:34 +0100 Subject: [PATCH 82/84] more expected failures ... and unexpected successes! Signed-off-by: jkoberg --- tests/acceptance/expected-failures-webUI-on-OCIS-storage.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md b/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md index 5833e4e5884..47611a95a8f 100644 --- a/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md @@ -122,8 +122,6 @@ Other free text and markdown formatting can be used elsewhere in the document if - [webUIRestrictSharing/restrictSharing.feature:56](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature#L56) ### [First request with a recreated user returns a 401 error](https://github.com/owncloud/ocis/issues/1675) -- [webUISharingAutocompletion/shareAutocompletion.feature:56](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUISharingAutocompletion/shareAutocompletion.feature#L56) -- [webUISharingAutocompletion/shareAutocompletion.feature:66](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUISharingAutocompletion/shareAutocompletion.feature#L66) - [webUISharingAutocompletion/shareAutocompletion.feature:128](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUISharingAutocompletion/shareAutocompletion.feature#L128) - [webUISharingAutocompletion/shareAutocompletion.feature:141](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUISharingAutocompletion/shareAutocompletion.feature#L141) @@ -514,3 +512,7 @@ Other free text and markdown formatting can be used elsewhere in the document if ### Shares folder cannot be deleted and is always visible - [webUIDeleteFilesFolders/deleteFilesFolders.feature:77](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIDeleteFilesFolders/deleteFilesFolders.feature#L77) - [webUIDeleteFilesFolders/deleteFilesFolders.feature:89](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIDeleteFilesFolders/deleteFilesFolders.feature#L89) +- [webUISharingAcceptShares/acceptShares.feature:72](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature#L72) + +### [web config update is not properly reflected after the ocis start](https://github.com/owncloud/ocis/issues/2944) +- [webUIFiles/breadcrumb.feature:50](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIFiles/breadcrumb.feature#L50) From 5c7427f0901e7b9c8ab02d9606bdb2edbcdbb656 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 11 Jan 2022 16:07:14 +0100 Subject: [PATCH 83/84] bump reva Signed-off-by: jkoberg --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5447d5cd6ad..d28bb821b00 100644 --- a/go.mod +++ b/go.mod @@ -246,4 +246,4 @@ require ( //replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20211208164450-3abd76eecf8b //replace github.com/cs3org/reva => ../reva -replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20220110163001-3d6605476745 +replace github.com/cs3org/reva => github.com/cs3org/reva v1.16.1-0.20220111150347-1b21aefbf8db diff --git a/go.sum b/go.sum index e54f2622752..eefeacae186 100644 --- a/go.sum +++ b/go.sum @@ -324,8 +324,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8 h1:PqOprF37OvwCbAN5W23znknGk6N/LMayqLAeP904FHE= github.com/cs3org/go-cs3apis v0.0.0-20211214102047-7ce3134d7bf8/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20220110163001-3d6605476745 h1:t//I0DOXvmXjWD1PcxHIUYueu8wv838ye4rPltDXvF8= -github.com/cs3org/reva v1.16.1-0.20220110163001-3d6605476745/go.mod h1:WqO2/NkAmx1qes09G92lGPxxyroQgnZetJrCPItCcDo= +github.com/cs3org/reva v1.16.1-0.20220111150347-1b21aefbf8db h1:YCzbz8N0OHkO6AcA2SfXHCc02Y/DqSkO+hm8Pj+eDZ4= +github.com/cs3org/reva v1.16.1-0.20220111150347-1b21aefbf8db/go.mod h1:WqO2/NkAmx1qes09G92lGPxxyroQgnZetJrCPItCcDo= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= From 1129d3c53d57a110c6a633839df9460b26f08873 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 11 Jan 2022 16:39:12 +0100 Subject: [PATCH 84/84] even more expected failures Signed-off-by: jkoberg --- .../acceptance/expected-failures-localAPI-on-OCIS-storage.md | 4 ++++ tests/acceptance/expected-failures-webUI-on-OCIS-storage.md | 2 ++ 2 files changed, 6 insertions(+) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 8aa81007f0e..591c12dcf54 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -14,6 +14,10 @@ - [apiArchiver/downloadByPath.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L132) - [apiArchiver/downloadByPath.feature:133](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L133) +### Tries to download /Shares/ folder but it cannot be downloaded any more directly +- [apiArchiver/downloadById.feature:134](https://github.com/owncloud/web/blob/master/tests/acceptance/features/apiArchiver/downloadById.feature#L134) +- [apiArchiver/downloadById.feature:135](https://github.com/owncloud/web/blob/master/tests/acceptance/features/apiArchiver/downloadById.feature#L135) + #### [Overwriting a file in the space within the allowed quota does not work](https://github.com/owncloud/ocis/issues/2829) - [apiSpaces/quota.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/quota.feature#L56) diff --git a/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md b/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md index 47611a95a8f..fb3233908f4 100644 --- a/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-webUI-on-OCIS-storage.md @@ -513,6 +513,8 @@ Other free text and markdown formatting can be used elsewhere in the document if - [webUIDeleteFilesFolders/deleteFilesFolders.feature:77](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIDeleteFilesFolders/deleteFilesFolders.feature#L77) - [webUIDeleteFilesFolders/deleteFilesFolders.feature:89](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIDeleteFilesFolders/deleteFilesFolders.feature#L89) - [webUISharingAcceptShares/acceptShares.feature:72](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature#L72) +- [webUIOperationsWithFolderShares/accessToSharesFolder.feature:14](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIOperationsWithFolderShares/accessToSharesFolder.feature#L14) ### [web config update is not properly reflected after the ocis start](https://github.com/owncloud/ocis/issues/2944) - [webUIFiles/breadcrumb.feature:50](https://github.com/owncloud/web/blob/master/tests/acceptance/features/webUIFiles/breadcrumb.feature#L50) +