From 6206fe23983ce2d1a7b5fa6f55b0fc47a55a5873 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 24 Nov 2021 18:30:20 +0100 Subject: [PATCH 01/41] 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 | 2 +- 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, 515 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 4003c46ee..07d18f1a8 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 1ea262c31..7124b0da4 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 87727b576..bf35626b1 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 dfb723db9..c51c1abe3 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 19eae93b2..948ff2e4a 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 e4e6f92e6..347553243 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 71f8c2c66..1b9b91ca4 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 e61530d16..7e7fc0f57 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 21bcd3dc2..63844a2cc 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 00b13818b..b61d93bc2 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 3815f0784..d661508e2 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 89cf6c346..562fad589 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 216b13e2e..d063eda47 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 21487a2d6..306fa9347 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 805f06c37..d7425dce3 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 477369b66..f339855f3 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 cfea0f220..d9118ad42 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 e6017cfef..77270bf41 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 d9cbb5f1c..6dcad7f03 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 000000000..b9be475ab --- /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 d547180d7..c3b55c772 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 2f5f679a4..d1c0e0ff6 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 86dabfe32..c606f1d7c 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 000000000..2fde4e337 --- /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 c25d415de..1acf398e8 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 20d07c88e..3e61b387a 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 32cd2a4ab..bcb9f3dcf 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 000000000..3eeaff740 --- /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 0cf4a4735..1cba3b4a2 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 7408d59f6..30a545139 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 ffb7e781e..54f1ff1d9 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 68383fe5c..6e316eaba 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 cab4554b3..107643e33 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 000000000..1b1ae5553 --- /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 000000000..e4dc82e02 --- /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 573266ca9..9498c7a01 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 2c1b64e0e..dac137c15 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 01f2d65bb..882c6364e 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 2aab7b910..7fe449dd5 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 4df5fbbdd..27c4e7e7f 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 469abc6ef..bd9cd6717 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 bd21ee1e3..5193d5a65 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 582e391b4..1bb038a26 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 a403f630d..4ae43d824 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 4d91088b9..113beb8cb 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 0fd5a9f2d..da12fcfa6 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 4ac235e8c..18400c6b7 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), StorageHome(cfg), StorageUsers(cfg), diff --git a/store/pkg/command/version.go b/store/pkg/command/version.go index b5bfef3b2..588e45b64 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 a39cae29b..3131492b6 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 62eea4e71..189f293ec 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 148de47ad..46ba11de8 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 c1a5cc98d..b86033f1d 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 5136f0df0..30dc5c53b 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 fc7ec10a6..f76645ba8 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 df3c0230f..d3dfb2459 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 5126a2d60..3270e2e58 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"` @@ -82,10 +87,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 6f6ef0d2f..d26a27603 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 4db1f7236..b78261d5f 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 0c905c06e..efa6ed85a 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 8914aebbc..3c1e456db 100644 --- a/thumbnails/pkg/service/v0/service.go +++ b/thumbnails/pkg/service/v0/service.go @@ -30,7 +30,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, + serviceID: options.Config.GRPC.Namespace + "." + options.Config.Service.Name, webdavNamespace: options.Config.Thumbnail.WebdavNamespace, manager: thumbnail.NewSimpleManager( resolutions, diff --git a/web/pkg/command/version.go b/web/pkg/command/version.go new file mode 100644 index 000000000..94a87b496 --- /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 0054c9331..210b52918 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 813cc1c08..a0ab763f5 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 c08c8ea0f..158ee8859 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. @@ -76,8 +76,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"}, @@ -85,6 +86,9 @@ func DefaultConfig() *Config { AllowCredentials: true, }, }, + Service: Service{ + Name: "webdav", + }, Tracing: Tracing{ Enabled: false, Type: "jaeger", @@ -92,10 +96,6 @@ func DefaultConfig() *Config { Collector: "", Service: "webdav", }, - Service: Service{ - Name: "webdav", - Namespace: "com.owncloud.web", - }, OcisPublicURL: "https://127.0.0.1:9200", WebdavNamespace: "/home", } diff --git a/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go index 7fa86211e..7e5fcb808 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 1b183af5e..a541071b2 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 af6cbdaf282fb72f539228cc20bef405914f48bd Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 10:56:28 +0100 Subject: [PATCH 02/41] 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 b61d93bc2..d50464d1e 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 a99f20f8b068db8621faf9252ea7c7ac88ab8381 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 10:56:37 +0100 Subject: [PATCH 03/41] 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 3469715c0..ec5185b86 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 19aac6991..c539ed817 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 dd2be4da7..ec11d218f 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 4386238ec..e8cd83e62 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 996262072..aed2b45f4 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 53b8ca154..06a5e7a45 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 1cb1cf0a2..e9d0b4f6e 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 2f4f3bec0e70bf1ac6f5ecd4f0f89c400947a232 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 11:18:59 +0100 Subject: [PATCH 04/41] 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 0e432054b..3a0e54035 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -542,9 +542,7 @@ func init() { ) c := &accountsCfg.Config{ - Server: accountsCfg.Server{ - DemoUsersAndGroups: true, - }, + DemoUsersAndGroups: true, Repo: accountsCfg.Repo{ Backend: "disk", Disk: accountsCfg.Disk{ From f7b949a4458250723380c1ed8d5f3dce5ffebb77 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 14:59:55 +0100 Subject: [PATCH 05/41] 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 d50464d1e..fdcdbcecd 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 6e316eaba..c5b01cf74 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 7fe449dd5..b32177739 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 1bb038a26..101d9a70d 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 da12fcfa6..d4910269c 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 189f293ec..9d883ca23 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 d26a27603..3cc0699bf 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 7e5fcb808..a4a417d5a 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 6bf467127bde5055b0f7784ca2633b1b2dfea923 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 16:51:18 +0100 Subject: [PATCH 06/41] 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 948ff2e4a..6b646b4f2 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 347553243..e28e8373c 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 63844a2cc..bc4996081 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 fdcdbcecd..000000000 --- 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 d9118ad42..957f5a50c 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 286676e52..8a244315e 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,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 @@ -55,6 +56,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 @@ -149,7 +151,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 eb11ff38c..c760f7926 100644 --- a/go.sum +++ b/go.sum @@ -1306,6 +1306,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 f89cdc5dd..7da572a35 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 1cacd70d0..40acb44ef 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 a35c472be397307f125f98128d17234feb2c1d05 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 17:39:00 +0100 Subject: [PATCH 07/41] 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 562fad589..85bb16a5d 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 d0030ab5559aff031cef89c7caf1502c9a8d6e99 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 18:53:06 +0100 Subject: [PATCH 08/41] 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 6b646b4f2..502ddb74a 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 e28e8373c..2f68df37c 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 000000000..9b09b128e --- /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 85bb16a5d..d15b0ab2d 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 c3b55c772..f5dd39401 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 1acf398e8..0fcacecf4 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 1cba3b4a2..5a113d20d 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 54f1ff1d9..510f06e6b 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 19c53801c..a74c904a7 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 d72e96216..406e0221c 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 882c6364e..6c25c3017 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 b32177739..000000000 --- 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 000000000..355ab6c0d --- /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 3a0e54035..7f641022b 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" @@ -549,7 +547,7 @@ func init() { Path: dataPath, }, }, - Log: &shared.Log{ + Log: accountsCfg.Log{ Level: "info", Pretty: true, Color: true, @@ -560,7 +558,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 { @@ -696,7 +694,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 113beb8cb..4b46a8da8 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 6691edda4..f01a049d8 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -508,7 +508,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 3131492b6..cdb9d23be 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 210b52918..222c93cd2 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 4067ae9493876f6534052fbee3ee1d78700579ae Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 19:24:07 +0100 Subject: [PATCH 09/41] 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 502ddb74a..298aa399a 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 1ee1362ec..1cd0eac23 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 77270bf41..7fdf54a1f 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 6dcad7f03..e5f88b394 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 f5dd39401..19850fdc3 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 4867fc9ea..000000000 --- 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 000000000..2dd2f1cd4 --- /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 0fcacecf4..f03e4f83e 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 5a113d20d..d7b233f52 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 a74c904a7..be8d34ea1 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 5193d5a65..f9f93cc02 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 4b46a8da8..d07229723 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 cdb9d23be..a804e7faf 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 3270e2e58..16b2fa6d1 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 222c93cd2..0cfd317fc 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 158ee8859..9614439d6 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 30656c5a32f71ad2b33225785f2493dbfd5129e8 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 16 Dec 2021 19:40:23 +0100 Subject: [PATCH 10/41] 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 | 79 +++++++++------- graph/pkg/config/mappings.go | 179 ----------------------------------- graph/pkg/logging/logging.go | 17 ++++ ocs/pkg/command/root.go | 2 +- 8 files changed, 92 insertions(+), 235 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 298aa399a..4b0eb6a43 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 7fdf54a1f..c90a6c850 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 3e61b387a..04906877a 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 bcb9f3dcf..6a62b1dac 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 d7b233f52..5185a6fed 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"` + 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"` - 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"` + 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"` - GroupSearchScope string `ocisConfig:"group_search_scope"` - GroupFilter string `ocisConfig:"group_filter"` - GroupNameAttribute string `ocisConfig:"group_name_attribute"` - GroupIDAttribute string `ocisConfig:"group_id_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 6798e8068..000000000 --- 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 000000000..07f8b4450 --- /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 be8d34ea1..26c27151b 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 ee57288309f9d89f74a1d872635d8c34caf76db9 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 10:44:57 +0100 Subject: [PATCH 11/41] 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/storagehome.go | 3 - ocis/pkg/command/storagepubliclink.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/storagehome.go | 3 +- storage/pkg/command/storagemetadata.go | 3 +- storage/pkg/command/storagepubliclink.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 | 45 ++-- 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 | 70 ++--- thumbnails/pkg/config/mappings.go | 115 --------- thumbnails/pkg/logging/logging.go | 17 ++ .../pkg/proto/v0/thumbnails.pb.micro_test.go | 14 +- 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 | 59 +++-- webdav/pkg/config/mappings.go | 103 -------- webdav/pkg/logging/logging.go | 17 ++ 115 files changed, 1023 insertions(+), 1989 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 4b0eb6a43..97088ea20 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 2f68df37c..aa2c1b0c3 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 bc4996081..5c138ad78 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 d15b0ab2d..b8e3eeb4d 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 f339855f3..0cb477468 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 f2abd5e20..6a2a83249 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 c90a6c850..b7b5fef7c 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 19850fdc3..4876413f6 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 60f4cc925..54ad47fe9 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 d1c0e0ff6..621958d00 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 c606f1d7c..6b9f80129 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 f03e4f83e..9a76da101 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 85014e61b..000000000 --- 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 000000000..8d3175cbf --- /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 c43db0993..ec85f2371 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 509146e3f..18cc12bae 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 04906877a..7168eb16a 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 5185a6fed..c3d22789a 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 813470bd4..fcb337253 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 e0d5ba775..77c740592 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 d3b62034f..0c91b4b5b 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 510f06e6b..6793294e6 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 c5b01cf74..000000000 --- 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 000000000..cbcc64833 --- /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 71f29be2c..38e302005 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 107643e33..0d9cf8b2f 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 d5098e2fe..f3dfab793 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 0f949a91a..24fb3132d 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 e73c9d07e..40436f6fa 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 40acb44ef..cb3bdc620 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 1b1ae5553..ecc94826c 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 e4dc82e02..7833206b9 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 17f2d927e..243c27696 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 321298689..7458a80d6 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 7272c357f..ffcbba1b6 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 c750340e8..c9262144d 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 adb37be5b..90bdafc30 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 520295965..03d886f3b 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 62cddc5c8..1bfe109db 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 329e64467..8b87968e0 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 9498c7a01..18b9d8a18 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 29fb13ee2..5fe8ef78c 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 4f24f3e49..937305d81 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 530e8148c..6519772a1 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/storagehome.go b/ocis/pkg/command/storagehome.go index bae5c1c67..f3db32088 100644 --- a/ocis/pkg/command/storagehome.go +++ b/ocis/pkg/command/storagehome.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 e4d9dc750..97057ed00 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/storagesharing.go b/ocis/pkg/command/storagesharing.go index 3a15d90ee..d5d479c5c 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 fc423737a..984d7e86a 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 a7978fb69..fbcd1d40a 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 639462117..5629abac3 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 0562b5d61..01cdae6fc 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 a2e9b1abc..c49fb2c12 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 c3f2df2ea..5d63587c2 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 0502642bb..31cb2c528 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 2def6c6f5..603183284 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 51474a3da..b1d2249e2 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 26c27151b..01d18eb58 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 6c25c3017..c1d7145ad 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 adb3f0a77..3f904bda1 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 13ea25e99..9801fe65a 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 ed8e2d9c0..a99060d8b 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 f9f93cc02..9afd1cc72 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 101d9a70d..000000000 --- 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 68f52d2d7..dbaaa03ae 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 000000000..b2626eb74 --- /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 9b475f5e7..e561b84e0 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 74c09626e..24d5b3619 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 bd430f263..a6e51c930 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 d07229723..fadd6722c 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 d4910269c..000000000 --- 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 000000000..147d07e7c --- /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 786b6ffaf..ec15d60a7 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 cf81638b9..ccd0fe011 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 80c8c523b..3ac4f71d4 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 10268754a..40bd71ed1 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 af60ccbda..4424a6ef2 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 eaaa97cbf..80c70f832 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 f3b3d9f6f..db0135387 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 63f158da1..687e52ebb 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()) @@ -388,16 +388,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 043c96fdc..625a23177 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 a3c3791a9..244ce713d 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 18400c6b7..ee8aa9f4f 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 abace4d50..1d8c032c8 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/storagehome.go b/storage/pkg/command/storagehome.go index bbeca4d70..516eda4ac 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.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" @@ -29,7 +30,7 @@ func StorageHome(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-home") }, 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 1c84313a3..8ba574a27 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 edd73c9ad..9bd908799 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/storageusers.go b/storage/pkg/command/storageusers.go index 7bb7aa6c0..266eb2dfb 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 34aee1d7c..b7205a542 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 f01a049d8..23e8f4794 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"` @@ -508,16 +514,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"` -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{} + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + Reva Reva `ocisConfig:"reva"` + + 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 000000000..c9d443321 --- /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 38461c9ac..b280d8b0e 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 49584e63c..5c63f8a3e 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 } - // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(), false) + // 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{} + //} - bindings := config.StructMappings(cfg) - return ociscfg.BindEnv(conf, bindings) + // 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 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 4bc9b35b9..add4beaef 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 a804e7faf..c96271fbd 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 9d883ca23..000000000 --- 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 000000000..e6183eb18 --- /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 6b5c84939..1ba961d62 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 30dc5c53b..57428daac 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 f76645ba8..42531f4d8 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 16b2fa6d1..1e3d5608b 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"` - 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"` + Tracing Tracing `ocisConfig:"tracing"` + Log Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + + 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,18 +72,13 @@ 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"` - WebdavNamespace string `ocisConfig:"webdav_namespace"` - 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"` + WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` + 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 3cc0699bf..000000000 --- a/thumbnails/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_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, - }, - { - EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, - Destination: &cfg.Thumbnail.WebdavNamespace, - }, - } -} diff --git a/thumbnails/pkg/logging/logging.go b/thumbnails/pkg/logging/logging.go new file mode 100644 index 000000000..e097814b2 --- /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 d3298d62c..a435cdf36 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/web/pkg/command/health.go b/web/pkg/command/health.go index 97206879b..d780d4058 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 8c99ecad6..0a7e731c6 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 } - 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 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 c8b8fd107..6b3b1f9ad 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 0cfd317fc..345ae8aec 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"` - 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"` + 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 } -// 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 3957c225e..000000000 --- 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 000000000..6510b8c21 --- /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 58aca1e1d..e1f2be33e 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 f221de832..15d0db369 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 d3f68efcf..7732f04bb 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 9614439d6..2fcfd9a78 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,49 +24,54 @@ 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"` + 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 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 a4a417d5a..000000000 --- a/webdav/pkg/config/mappings.go +++ /dev/null @@ -1,103 +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, - }, - } -} diff --git a/webdav/pkg/logging/logging.go b/webdav/pkg/logging/logging.go new file mode 100644 index 000000000..11c8f85aa --- /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 9aae5392fc2c5fed972c5feecb6087025bccd0f2 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 11:47:18 +0100 Subject: [PATCH 12/41] 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 | 148 +------ 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/storagehome.go | 2 +- storage/pkg/command/storagemetadata.go | 2 +- storage/pkg/command/storagepubliclink.go | 2 +- storage/pkg/command/storageusers.go | 2 +- storage/pkg/command/users.go | 2 +- storage/pkg/config/config.go | 490 +-------------------- storage/pkg/config/debug.go | 9 + storage/pkg/config/defaultconfig.go | 443 +++++++++++++++++++ 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 | 79 +--- thumbnails/pkg/config/debug.go | 9 + thumbnails/pkg/config/defaultconfig.go | 42 ++ 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 | 87 +--- webdav/pkg/config/debug.go | 9 + webdav/pkg/config/defaultconfig.go | 35 ++ 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, 2056 insertions(+), 1947 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 5c138ad78..e10f6a932 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 000000000..c95ef3a26 --- /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 000000000..8e7caa101 --- /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 000000000..f16de42f2 --- /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 000000000..c8c7ab628 --- /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 000000000..6ada8a7dd --- /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 000000000..c12faf344 --- /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 000000000..3547373fb --- /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 4876413f6..c13d732ea 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 000000000..1d612c88d --- /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 000000000..23c12f844 --- /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 000000000..b0780084a --- /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 000000000..2c09f2530 --- /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 000000000..2ce88369b --- /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 000000000..c12faf344 --- /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 000000000..3caca2705 --- /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 9a76da101..9e11dd8e7 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 000000000..3dfc27f7b --- /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 000000000..b44927243 --- /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 000000000..8990a455e --- /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 000000000..7c9c0f538 --- /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 000000000..c12faf344 --- /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 000000000..cf4214eb4 --- /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 c3d22789a..e2cc81c47 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"` -} +// 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:"GRAPH_HTTP_ADDR"` - Namespace string - Root string `ocisConfig:"root" env:"GRAPH_HTTP_ROOT"` -} + 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;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? -} + Reva Reva `ocisConfig:"reva"` + TokenManager TokenManager `ocisConfig:"token_manager"` -// 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"` -} + Spaces Spaces `ocisConfig:"spaces"` + Identity Identity `ocisConfig:"identity"` -// 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;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 000000000..c1284be91 --- /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 000000000..b5d09a9d2 --- /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 000000000..64351105b --- /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 000000000..3f1f84603 --- /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 000000000..31f48fbb6 --- /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 000000000..c12faf344 --- /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 000000000..457edb0fd --- /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 6793294e6..cc1e3b538 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" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// 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"` -} +// 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:"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"` -} + 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"` + + Asset Asset `ocisConfig:"asset"` + IDP Settings `ocisConfig:"idp"` + Ldap Ldap `ocisConfig:"ldap"` + + 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 000000000..f713bc341 --- /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 000000000..dbaa3ba57 --- /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 000000000..4d528e027 --- /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 000000000..39ba2d9e5 --- /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 000000000..c12faf344 --- /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 000000000..8cb1d9db6 --- /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 430927d4c..9326de762 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 c6baacfde..d6adfa74a 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 ecc94826c..162416d24 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 7833206b9..ede47b9c8 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 7b35c15ba..399b9339a 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 243c27696..40c79fd32 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 7458a80d6..6b3dc5b95 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 90bdafc30..7980f9d0b 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 31cb2c528..ad95e8498 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 c1d7145ad..b8554f887 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 000000000..baef37488 --- /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 000000000..428b254a4 --- /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 000000000..b965e78b3 --- /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 000000000..4f235f1ca --- /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 000000000..31f48fbb6 --- /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 000000000..c12faf344 --- /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 000000000..f627ec382 --- /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 9afd1cc72..4408550b7 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" -) +// Config combines all available configuration parts. +type Config struct { + Service Service -// 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"` -} + 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:"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 HTTP `ocisConfig:"http"` -// 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"` -} + 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"` -// 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;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 000000000..1c450cc4d --- /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 000000000..ea1940a57 --- /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 000000000..8ab553063 --- /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 000000000..54612fc20 --- /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 000000000..c12faf344 --- /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 000000000..914726759 --- /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 fadd6722c..18284a56c 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 000000000..5cec3b97b --- /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 000000000..100c1e80f --- /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 000000000..016b61fa9 --- /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 000000000..f2099febf --- /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 000000000..48247bd17 --- /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 000000000..5427747df --- /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 000000000..c12faf344 --- /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 000000000..543298663 --- /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 3ac4f71d4..86ccac4f0 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 40bd71ed1..1d57341f1 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 4424a6ef2..7c2e23a84 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 80c70f832..9bce040bf 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 db0135387..c3394f84b 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -339,7 +339,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 687e52ebb..a2128c77b 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -352,7 +352,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 625a23177..0d37c4149 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 1d8c032c8..7229b7f28 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/storagehome.go b/storage/pkg/command/storagehome.go index 516eda4ac..c3a2a312a 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -147,7 +147,7 @@ type StorageHomeSutureService struct { // NewStorageHomeSutureService creates a new storage.StorageHomeSutureService func NewStorageHome(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Commons = cfg.Commons + //cfg.Storage.Commons = cfg.Commons return StorageHomeSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 8ba574a27..6ff7a2819 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -167,7 +167,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 9bd908799..f61b32a78 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -127,7 +127,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/storageusers.go b/storage/pkg/command/storageusers.go index 266eb2dfb..0d61415d1 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -147,7 +147,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 b7205a542..908865ae7 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 23e8f4794..35d544a98 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. @@ -496,470 +483,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)(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 new file mode 100644 index 000000000..f9283a9b2 --- /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 000000000..95cc57c1a --- /dev/null +++ b/storage/pkg/config/defaultconfig.go @@ -0,0 +1,443 @@ +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: "/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{}, + } +} diff --git a/storage/pkg/config/grpc.go b/storage/pkg/config/grpc.go new file mode 100644 index 000000000..016b61fa9 --- /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 000000000..f2099febf --- /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 000000000..eb14a82e8 --- /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 000000000..5427747df --- /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 000000000..c12faf344 --- /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 000000000..b5c955444 --- /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 c96271fbd..bb79327e8 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 000000000..a168ce846 --- /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 000000000..4ba99550c --- /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 000000000..ed87112dd --- /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 000000000..a00934bb2 --- /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 000000000..c12faf344 --- /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 000000000..a54001c94 --- /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 1e3d5608b..30c225fac 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,42 +36,7 @@ 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 WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` 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", - WebdavNamespace: "/home", - CS3AllowInsecure: false, - }, - } -} diff --git a/thumbnails/pkg/config/debug.go b/thumbnails/pkg/config/debug.go new file mode 100644 index 000000000..f1f3a01e1 --- /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 000000000..bc7bd36fa --- /dev/null +++ b/thumbnails/pkg/config/defaultconfig.go @@ -0,0 +1,42 @@ +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", + WebdavNamespace: "/home", + CS3AllowInsecure: false, + }, + } +} diff --git a/thumbnails/pkg/config/grpc.go b/thumbnails/pkg/config/grpc.go new file mode 100644 index 000000000..9682ed12c --- /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 000000000..a9b19f070 --- /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 000000000..c12faf344 --- /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 000000000..e118e1530 --- /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 345ae8aec..6a1ef7eab 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 000000000..d4dda707d --- /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 000000000..a41d1af4d --- /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 000000000..317b93497 --- /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 000000000..1a3310728 --- /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 000000000..c12faf344 --- /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 000000000..c6bb6569a --- /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 2fcfd9a78..9003f946e 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"` @@ -71,37 +20,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: "/home", - } -} diff --git a/webdav/pkg/config/debug.go b/webdav/pkg/config/debug.go new file mode 100644 index 000000000..2551ce17a --- /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 000000000..6d0e82310 --- /dev/null +++ b/webdav/pkg/config/defaultconfig.go @@ -0,0 +1,35 @@ +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: "/home", + } +} diff --git a/webdav/pkg/config/http.go b/webdav/pkg/config/http.go new file mode 100644 index 000000000..4ce2f2dcd --- /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 000000000..211aad1a4 --- /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 000000000..c12faf344 --- /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 000000000..f63b2480d --- /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 a77c8ac8dd98647e4428c7c3ecffb363b022b072 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 15:14:01 +0100 Subject: [PATCH 13/41] 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 000000000..5a4d79cef --- /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 97088ea20..5854e0f60 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 7abcf96ea84a384cd5b0d4bde2e2ed62f0ebe55e Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 16:30:57 +0100 Subject: [PATCH 14/41] 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/storagehome.go | 5 +- storage/pkg/command/storagemetadata.go | 5 +- storage/pkg/command/storagepubliclink.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 | 443 ------------------- 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(+), 882 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 5854e0f60..366abad0f 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 e10f6a932..eb07e2ca5 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 8e7caa101..5b027a545 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 3547373fb..fc673f824 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 9b09b128e..4836eaec4 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 957f5a50c..18703e805 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 4da38009f..5f9bd3b65 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 b7b5fef7c..3b16d07a2 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 c13d732ea..6292cfc35 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 23c12f844..becff0bb9 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 3caca2705..52733d097 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 2dd2f1cd4..5282014a6 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 a02161687..734fd1d52 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 621958d00..f99e3eaf3 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 9e11dd8e7..ea0577b0f 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 b44927243..7ea490819 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 cf4214eb4..db55ec8c5 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 8d3175cbf..24a2567a1 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 b7fe7a3f6..73b4c863c 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 7168eb16a..2492597ef 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 e2cc81c47..03ec948bb 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 b5d09a9d2..5879b9487 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 457edb0fd..077a4819a 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 07f8b4450..daf29f40b 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 5e67b08eb..3f2d775a5 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 77c740592..ec61ab260 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 cc1e3b538..426c34dd4 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 dbaa3ba57..21e59a339 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 8cb1d9db6..c149f9da1 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 cbcc64833..97eb83fcd 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 eb116d6ce..756b6210c 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 40436f6fa..bdd6cd549 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 42ae508f8..f2ab74e12 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 fc655e73d..25aa96269 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 cb3bdc620..1c3db45c0 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 d6adfa74a..c6baacfde 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 162416d24..ecc94826c 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 ede47b9c8..7833206b9 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 399b9339a..7b35c15ba 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 40c79fd32..243c27696 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 6b3dc5b95..7458a80d6 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 7980f9d0b..90bdafc30 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 01cdae6fc..f671358e7 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 c49fb2c12..a2e9b1abc 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 5d63587c2..c3f2df2ea 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 ad95e8498..31cb2c528 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 603183284..2def6c6f5 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 01d18eb58..141bc1bda 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 b8554f887..0171ef7a0 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 428b254a4..59cbfb8f1 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 f627ec382..310462e90 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 355ab6c0d..80350b0d0 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 d79ef622f..bd4873036 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 9801fe65a..1d771d9cb 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 4408550b7..048928e6a 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 ea1940a57..b41014013 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 914726759..79429ee5c 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 b2626eb74..dfaeabd24 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 e3b3aa50c..5ab072223 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 24d5b3619..fb7c930cb 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 18284a56c..052a07360 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 100c1e80f..a667c0c25 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 543298663..7197a69f3 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 147d07e7c..aba0cbe82 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 09d85008b..620d261cc 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 86ccac4f0..80c8c523b 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 1d57341f1..10268754a 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 7c2e23a84..af60ccbda 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 9bce040bf..eaaa97cbf 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 c3394f84b..f3b3d9f6f 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) @@ -339,7 +338,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 a2128c77b..63f158da1 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()) @@ -352,7 +352,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, } @@ -388,16 +388,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 0d37c4149..043c96fdc 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 244ce713d..a3c3791a9 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 ee8aa9f4f..4ac235e8c 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), StorageHome(cfg), StorageUsers(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 7229b7f28..abace4d50 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/storagehome.go b/storage/pkg/command/storagehome.go index c3a2a312a..bbeca4d70 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.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" @@ -30,7 +29,7 @@ func StorageHome(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg, "storage-home") }, Action: func(c *cli.Context) error { - logger := logging.Configure(cfg.Service.Name, cfg.Log) + logger := NewLogger(cfg) tracing.Configure(cfg, logger) @@ -147,7 +146,7 @@ type StorageHomeSutureService struct { // NewStorageHomeSutureService creates a new storage.StorageHomeSutureService func NewStorageHome(cfg *ociscfg.Config) suture.Service { - //cfg.Storage.Commons = cfg.Commons + cfg.Storage.Commons = cfg.Commons return StorageHomeSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 6ff7a2819..1c84313a3 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{} @@ -167,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 f61b32a78..edd73c9ad 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()) @@ -127,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/storageusers.go b/storage/pkg/command/storageusers.go index 0d61415d1..7bb7aa6c0 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) @@ -147,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 908865ae7..34aee1d7c 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 35d544a98..6691edda4 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 +// 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"` - - Reva Reva `ocisConfig:"reva"` - - 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. @@ -483,11 +490,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 f9283a9b2..000000000 --- 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 95cc57c1a..000000000 --- a/storage/pkg/config/defaultconfig.go +++ /dev/null @@ -1,443 +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: "/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{}, - } -} diff --git a/storage/pkg/config/grpc.go b/storage/pkg/config/grpc.go deleted file mode 100644 index 016b61fa9..000000000 --- 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 f2099febf..000000000 --- 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 eb14a82e8..000000000 --- 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 5427747df..000000000 --- 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 c12faf344..000000000 --- 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 b5c955444..000000000 --- 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 c9d443321..000000000 --- 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 5c63f8a3e..e796cf590 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 bb79327e8..c8b807bdb 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 4ba99550c..66e44044d 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 a54001c94..7e1ba1821 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 e6183eb18..c5c6d4520 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 b6f66479f..54eef8ca3 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 57428daac..eae5eed50 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 30c225fac..ddc024d54 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 bc7bd36fa..7da4bac4f 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 e118e1530..bbb13435c 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 e097814b2..41d558326 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 6bbd7afc8..16db3bb6f 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 0a7e731c6..11c6b5ffa 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 6a1ef7eab..df0f7ab6d 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 a41d1af4d..42f22beda 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 c6bb6569a..6c54223d6 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 6510b8c21..57616a43b 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 1bd7caf66..cebc588bd 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 15d0db369..f2ec6221a 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 9003f946e..9739198d3 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 6d0e82310..5edb962c4 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: "/home", diff --git a/webdav/pkg/config/tracing.go b/webdav/pkg/config/tracing.go index f63b2480d..311e5fbc0 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 11c8f85aa..ff82b1f6b 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 f3efeecd0..8a2c53929 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 2bcd4f5a176a6eecbf633cc5bebc986141dbeeb5 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 16:54:26 +0100 Subject: [PATCH 15/41] 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 366abad0f..b84480007 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 3b16d07a2..e46b8c014 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 8a244315e..92a89c6e9 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,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 @@ -151,6 +150,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 f99e3eaf3..034fb7ea2 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 2492597ef..5df88df46 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 ec61ab260..85fda3c52 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 141bc1bda..8d24d1bd6 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 1d771d9cb..0d2039135 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 fb7c930cb..bbddc8944 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 e796cf590..d10f4cb4d 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 eae5eed50..4e24303e5 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 11c6b5ffa..4d1c6249a 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 f2ec6221a..9df612006 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 b70cbd26ee1bc8bf08a599aa10d2ac56664499dd Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 16:58:36 +0100 Subject: [PATCH 16/41] 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 b84480007..b2f4740b1 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 aa2c1b0c3..44feb3ffe 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 d5e8ac077197591fdd2b0ca976e11fdef7e741ba Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:11:31 +0100 Subject: [PATCH 17/41] 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 b8e3eeb4d..003746f4f 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 9bfa55274..328607ba9 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 7f641022b..faffe9e46 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -547,7 +547,7 @@ func init() { Path: dataPath, }, }, - Log: accountsCfg.Log{ + Log: &accountsCfg.Log{ Level: "info", Pretty: true, Color: true, @@ -694,7 +694,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 9809383a6..0137b4413 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 0f491977b2ee94065b7714321d759e60117ca02d Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:19:47 +0100 Subject: [PATCH 18/41] 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 ecc94826c..1b1ae5553 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 7833206b9..e4dc82e02 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 18b9d8a18..9498c7a01 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 4ac235e8c..18400c6b7 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), StorageHome(cfg), StorageUsers(cfg), From dcc01ca2a39180447ea968e00c8f5eb2b7bea999 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:40:35 +0100 Subject: [PATCH 19/41] 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 03ec948bb..c7fa9e089 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 d5504093e8a5e7547a51baaf333044812aec575f Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 17:59:26 +0100 Subject: [PATCH 20/41] fix some TODOs --- idp/pkg/config/config.go | 18 +++++++++--------- ocis-pkg/indexer/index/cs3/config.go | 1 - proxy/pkg/cs3/client.go | 3 ++- webdav/pkg/config/config.go | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 426c34dd4..420dc7888 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 9326de762..430927d4c 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 dbaaa03ae..bf8d19871 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( diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 9739198d3..3a6bdb87c 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -19,7 +19,7 @@ type Config struct { 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 + WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` Context context.Context Supervised bool From 9c1cf9b0a51f319ae9697f19e0546eb4e7348d1a Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 18:07:33 +0100 Subject: [PATCH 21/41] 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 6292cfc35..f5a1bc550 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 e5e8c390b14e84477974068c3da7581c1f3be7a3 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 18:09:49 +0100 Subject: [PATCH 22/41] resolve thumbnails TODOs --- thumbnails/pkg/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index ddc024d54..4617b07fc 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -36,11 +36,11 @@ 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"` - RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` //TODO: use REVA config + RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` FontMapFile string `ocisConfig:"font_map_file" env:"THUMBNAILS_TXT_FONTMAP_FILE"` } From fe1672a000d79aa7f64108a83f9af329cb0e7246 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 17 Dec 2021 18:27:29 +0100 Subject: [PATCH 23/41] 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 bdd6cd549..d0cd0e1d2 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 000000000..21cf14ba0 --- /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 25aa96269..268c596b0 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 ffcbba1b6..09d7e63fb 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 + // 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 + } - conf.LoadOSEnv(config.GetEnv(), false) - - 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 2def6c6f5..04f68d24b 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 e3bfb66df1e0f8e2bb739072aafbcb909eec96de Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 21 Dec 2021 10:25:09 +0100 Subject: [PATCH 24/41] 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 b2f4740b1..c6d70c96d 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 e46b8c014..5fe6aefdc 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 92a89c6e9..286676e52 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,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 c760f7926..eb11ff38c 100644 --- a/go.sum +++ b/go.sum @@ -1306,8 +1306,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 034fb7ea2..6b0fbedf8 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 5df88df46..565aa710f 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 85fda3c52..c59652ff4 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 000000000..5869b24ec --- /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 000000000..8e7ae860e --- /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 000000000..d97d69898 --- /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 000000000..bf6fd3352 --- /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 09d7e63fb..232c18ab2 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 8d24d1bd6..994e5e889 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 0d2039135..7bd07dfde 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 bbddc8944..c6091ef90 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 d10f4cb4d..be613a9f7 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 4e24303e5..4236c1098 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 4d1c6249a..371c3337e 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 9df612006..224823e01 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 c9ee77955d13e187b3e434e8c0a0d132a405e86e Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 08:15:46 +0100 Subject: [PATCH 25/41] 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 b41014013..136cf28b9 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 7ffe93ba3b419c92abe9b1649c1aceece5a8dbc9 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 08:22:44 +0100 Subject: [PATCH 26/41] 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 eb07e2ca5..e21073616 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 f5a1bc550..3d687319c 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 ea0577b0f..d84c239fd 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 c7fa9e089..f5925b754 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 420dc7888..7c16b9b1b 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 0171ef7a0..bfad75d86 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 048928e6a..5ac9ee841 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 052a07360..fce3b34d5 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 6691edda4..ac042a47d 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 c8b807bdb..46855d55d 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 4617b07fc..43071171e 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 df0f7ab6d..13f67adfe 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 3a6bdb87c..8b817f7f7 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -21,6 +21,5 @@ type Config struct { OcisPublicURL string `ocisConfig:"ocis_public_url" env:"OCIS_URL;OCIS_PUBLIC_URL"` WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` - Context context.Context - Supervised bool + Context context.Context } From ea5dd756059701f28d247a260415a53d598c43b4 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 08:55:22 +0100 Subject: [PATCH 27/41] 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 d97d69898..0105c1764 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 bf6fd3352..54ac86dec 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 2a42a56f7..84189be0a 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 6d0b754a860197c8c3bfc76ac179f46653b20539 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 09:43:42 +0100 Subject: [PATCH 28/41] 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 c6d70c96d..05b3e8351 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 5fe6aefdc..f72d940c1 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 6b0fbedf8..6a4ae2bbe 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 565aa710f..41b723930 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 c59652ff4..e346e4b1f 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 54ac86dec..d8cec54c9 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 232c18ab2..034061824 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 994e5e889..3f17fb049 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 7bd07dfde..02ab99c58 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 c6091ef90..9ee08aef2 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 be613a9f7..ca3d05bb2 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 4236c1098..fbaaeba51 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 371c3337e..b56960a86 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 224823e01..e39d64cd0 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 eee0d0c4c88f19422a9711182a3a6ce786071c33 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 11:10:33 +0100 Subject: [PATCH 29/41] 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 44feb3ffe..d0cd905a0 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 c95ef3a26..539b8faba 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 5b027a545..2c69305bb 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 000000000..0fd139d24 --- /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 000000000..cabc14464 --- /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 d6373ba1e..5cc9fab7b 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 5717db3c7..116509739 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 fe979c8ee..240b1f936 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 f05038d95..bdfe92083 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 d0cd0e1d2..1f3e3c0d2 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 1b1ae5553..ecc94826c 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 e4dc82e02..7833206b9 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 034061824..51ff2189b 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 c9262144d..67cde4195 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 9498c7a01..18b9d8a18 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 5629abac3..cec0e2e02 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 7c704840e..214c4a9c1 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 b4106f2a8..5c4b38046 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 36bf1411e..81f41de18 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 4a3fa24b3..29ea57b0a 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 e3812b25d..975974c5c 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 b78261d5f..24fdee22c 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 43c45036b..d4d7e302e 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 f79a0538f..ad9568b60 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 e0656daaa01807b3d30f981cf86a7c63c91cbd59 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 13:53:27 +0100 Subject: [PATCH 30/41] 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 ++++++++++++--------------- 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 | 41 +++++++++--------- webdav/pkg/command/version.go | 16 +++---- 41 files changed, 437 insertions(+), 499 deletions(-) create mode 100644 ocis-pkg/clihelper/app.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 05b3e8351..512295423 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 7e7fc0f57..6d3ec843f 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 f72d940c1..120791317 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 b9be475ab..c3d2e4ffd 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 6a4ae2bbe..4e3fecc58 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 2fde4e337..400c0bf10 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 41b723930..af4f264f1 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 3eeaff740..8ced4ad48 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 f5925b754..523bcfdb0 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 e346e4b1f..bcb8e4ea1 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 30a545139..f9cbcd574 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 000000000..4ea39ace3 --- /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 1c3db45c0..62efe82ea 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 c6baacfde..1f9da764d 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 ecc94826c..92e5b532c 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 7833206b9..f02ad25b7 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 7b35c15ba..62d929cbe 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 243c27696..dd010e71f 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 7458a80d6..2554573a2 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 51ff2189b..163adebc8 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 90bdafc30..ae1fec6c6 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 cec0e2e02..6fda33d5e 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 f671358e7..add5b6684 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 21d762b59..f69340683 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 c3f2df2ea..e1f66f8ee 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 31cb2c528..ea7f51822 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 3f17fb049..2b143d547 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 dac137c15..116c081df 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 02ab99c58..283e85246 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 bd9cd6717..7545db5d4 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 9ee08aef2..03340bb1a 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 55091cf81..15c390136 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 18400c6b7..477ec1df1 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), + StorageHome(cfg), + StorageUsers(cfg), + StoragePublicLink(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), - StorageHome(cfg), - StorageUsers(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/store/pkg/command/root.go b/store/pkg/command/root.go index ca3d05bb2..c32c0c45f 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 588e45b64..91554c791 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 fbaaeba51..ad18155e7 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 d3dfb2459..45030313a 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 b56960a86..38c8ea330 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 94a87b496..7b76bdcfe 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 e39d64cd0..2846715b3 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(), + app := clihelper.DefaultApp(&cli.App{ + Name: "webdav", + Usage: "Serve WebDAV API for oCIS", - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - 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), - }, - } + 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 a0ab763f5..f6649a41a 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 55bf175bea5b82633f49accb6f80a17015ab94de Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 15:21:56 +0100 Subject: [PATCH 31/41] 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 5a4d79cef..2fadae8ef 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 512295423..a0d264fde 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 d0cd905a0..906dd75b6 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 000000000..dee2dc13b --- /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 1cd0eac23..215018b29 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 120791317..4ba8e95be 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 e5f88b394..db5222db9 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 000000000..b2a18b2a9 --- /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 54ad47fe9..6719e960a 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 4e3fecc58..92097b279 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 6b9f80129..b16ec1150 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 000000000..be113e459 --- /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 18cc12bae..5e2a31ecb 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 af4f264f1..2318c610b 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 6a62b1dac..27bb58b13 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 000000000..885682154 --- /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 fcb337253..a668eaf4c 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 bcb8e4ea1..9bb2df16e 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 0c91b4b5b..e955731c2 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 000000000..de98f42d6 --- /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 000000000..a0870d17c --- /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 62efe82ea..719b08062 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 1f9da764d..23b45f9db 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 92e5b532c..0e1d4e295 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 f02ad25b7..db65c6b1d 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 62d929cbe..8f996f493 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 dd010e71f..eb29b3d25 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 2554573a2..423794d91 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 163adebc8..e0c77c0f6 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 67cde4195..ac24c1c64 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 ae1fec6c6..0cf950c4c 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 6fda33d5e..71ecb35d9 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 add5b6684..171b78143 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 a2e9b1abc..914c5a37c 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 e1f66f8ee..a95cc94ae 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 ea7f51822..2b7ed2dea 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 b1d2249e2..834390b9e 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 2b143d547..1d10a9847 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 406e0221c..807a7786a 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 000000000..9a50e535b --- /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 283e85246..b2c82bf0a 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 a99060d8b..501305bce 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 5ac9ee841..c525421e8 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 000000000..65921b31c --- /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 000000000..2b299a0f6 --- /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 e561b84e0..a8e15f8cf 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 03340bb1a..938a3f26b 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 a6e51c930..c26623a86 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 000000000..551d44108 --- /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 b280d8b0e..bc0b77b34 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 c32c0c45f..6586d0947 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 add4beaef..c4ebd5e9a 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 000000000..f3789eecb --- /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 1ba961d62..5b232dc9e 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 ad18155e7..1cdb5c494 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 42531f4d8..990c549e3 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 000000000..3591aea8a --- /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 d780d4058..5ab5887ea 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 38c8ea330..2c22ed570 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 6b3b1f9ad..fbacd1ccc 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 42f22beda..cf518a9de 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 000000000..ed2207828 --- /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 e1f2be33e..0a8e62486 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 2846715b3..45e256492 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 7732f04bb..073a8eb80 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 000000000..66341b099 --- /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 3d4df5796a079af0e506c04595d0f924218dd3be Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 16:24:39 +0100 Subject: [PATCH 32/41] 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 906dd75b6..e94528702 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 c12faf344..f98aa3d27 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 d063eda47..8670c5a5c 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 306fa9347..4fb764fcb 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 db5222db9..459d8a0eb 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 c12faf344..f98aa3d27 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 b16ec1150..7f753b3cc 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 c12faf344..f98aa3d27 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 27bb58b13..8c9276cff 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 c12faf344..f98aa3d27 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 e955731c2..d80728911 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 c12faf344..f98aa3d27 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 bdfe92083..9da10444f 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 0d9cf8b2f..08a1c550c 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 807a7786a..a5081a3cf 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 c12faf344..f98aa3d27 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 214c4a9c1..7a7b69d80 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 27c4e7e7f..06d380184 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 501305bce..8d8045ab9 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 c12faf344..f98aa3d27 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 5c4b38046..9158a697d 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 4ae43d824..14b377434 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 c26623a86..0728ef292 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 c12faf344..f98aa3d27 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 a2b5d1f1d..a3a2bde3b 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 cb63ac5ec..29795d78f 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 c4ebd5e9a..cf9a4ad20 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 c12faf344..f98aa3d27 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 975974c5c..874071c71 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 46ba11de8..632505486 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 990c549e3..4b7444c65 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 c12faf344..f98aa3d27 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 24fdee22c..dd7b40a1f 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 efa6ed85a..b90dc699e 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 cf518a9de..42f22beda 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 c12faf344..f98aa3d27 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 073a8eb80..720729efb 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 c12faf344..f98aa3d27 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 ad9568b60..ff0ee6b4f 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 a541071b2..bf962961b 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 e37eff7dc86e52537fb8536d4522dcfe6dfb6600 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 17:19:10 +0100 Subject: [PATCH 33/41] 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 92097b279..cf997cc6f 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 6586d0947..44451c48b 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 11466c5f9ae8940a9687586cdcd52d95d882ec65 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 19:08:11 +0100 Subject: [PATCH 34/41] 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 a0d264fde..fb0bf2883 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 e94528702..7c8f3832e 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 4ba8e95be..7b1dc51d9 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 459d8a0eb..08f1879e0 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 cf997cc6f..f2acd3460 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 2318c610b..60c389880 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 8c9276cff..c246b23e4 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 9bb2df16e..787381c7e 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 d80728911..a5be7abcc 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 719b08062..672dcd6a3 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 23b45f9db..3e58bbeef 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 0e1d4e295..a482ef681 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 db65c6b1d..fa2eee4c3 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 8f996f493..d71e57438 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 eb29b3d25..657bc2969 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 423794d91..d52e667b4 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 e0c77c0f6..7fb3551af 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 0cf950c4c..2803c1398 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 71ecb35d9..a12412c95 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 171b78143..140b6a1c5 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 a95cc94ae..6ef8a2095 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 2b7ed2dea..fb171ad14 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 1d10a9847..cac620e67 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 a5081a3cf..4126133a1 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 3f904bda1..0d10d16ec 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 b2c82bf0a..cfc2afa62 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 8d8045ab9..9f992d6d7 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 938a3f26b..4e65d6391 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 0728ef292..9c08299f1 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 44451c48b..add49da6f 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 cf9a4ad20..77df9d87b 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 1cdb5c494..83b311196 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 4b7444c65..c47505705 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 2c22ed570..2dbe61c1b 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 fbacd1ccc..016246d1e 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 ed2207828..71870c8ce 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 45e256492..3a3a3432b 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 720729efb..10dd88abf 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 94bcc7adbcbba1d430c6db4608c0f9da9fa0370d Mon Sep 17 00:00:00 2001 From: pwengerter Date: Tue, 4 Jan 2022 10:14:28 +0100 Subject: [PATCH 35/41] 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 000000000..07de8e5dc --- /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 000000000..06a4b3fb5 --- /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 b3dde1fff459b8a9a540d22c80a4af56e9a87144 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 4 Jan 2022 10:40:35 +0100 Subject: [PATCH 36/41] 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 aa6a367bf..02df18b9f 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 f9176919967d7718e9bd1a39ce0951cef8dba874 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 4 Jan 2022 12:33:56 +0100 Subject: [PATCH 37/41] 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 000000000..0447d5487 --- /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 f288d6a3ab1ceec9ecc506bae566e4d47b861b3b 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 38/41] 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 35d1a7154..895c99c06 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 10473f88c..4cf034f92 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 d9744ebda7223596926702ada4fd5ebf482bce28 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 7 Jan 2022 13:19:39 +0100 Subject: [PATCH 39/41] 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/storagehome.go | 4 ++-- ocis/pkg/command/storagemetadata.go | 4 ++-- ocis/pkg/command/storagepubliclink.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/storagehome.go | 2 +- storage/pkg/command/storagemetadata.go | 4 ++-- storage/pkg/command/storagepubliclink.go | 4 ++-- 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 07d18f1a8..1e904c5b8 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 2fadae8ef..0e908b60e 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 7124b0da4..5e2009497 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 bf35626b1..3c15a1275 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 b643ec04e..d2eb1d2de 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 c51c1abe3..ee18eede4 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 7c8f3832e..52fd784ee 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 1b9b91ca4..cf2e68950 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 6d3ec843f..a77668937 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 215018b29..ef15ee650 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 08f1879e0..75a27f846 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 c3d2e4ffd..c8e149daf 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 6719e960a..cf0a9a660 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 7f753b3cc..711ae3a0b 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 400c0bf10..39b1cadb4 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 5e2a31ecb..b40b65a17 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 c246b23e4..38c012a20 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 8ced4ad48..8e85a27dd 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 a668eaf4c..af3e6ccbc 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 a5be7abcc..c3bdfec70 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 f9cbcd574..22d4f4ce6 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 672dcd6a3..5671fa9b6 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 60af3e22a..77bfa381e 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 3e58bbeef..9d7b09b02 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 a482ef681..0a663e6db 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 fa2eee4c3..d88135d0b 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 d71e57438..8e64daee7 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 70530f98a..853acdd71 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 7d277e8bf..c7fd15587 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 657bc2969..2570f2a38 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 d52e667b4..cd59c6090 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 398bb39e1..1cab47a0d 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 ac24c1c64..00b9c89da 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 2803c1398..d489ccc80 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 03d886f3b..48744bff5 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 1bfe109db..3523c40b7 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 8b87968e0..8486373a8 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 18b9d8a18..2f3392caf 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 5fe8ef78c..9079e268c 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 937305d81..615490fdd 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 6519772a1..ed7907f4e 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/storagehome.go b/ocis/pkg/command/storagehome.go index f3db32088..14cf7ad91 100644 --- a/ocis/pkg/command/storagehome.go +++ b/ocis/pkg/command/storagehome.go @@ -11,8 +11,8 @@ import ( func StorageHomeCommand(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-home", - Usage: "Start storage and data provider for /home mount", - Category: "Extensions", + Usage: "start storage and data provider for /home mount", + Category: "extensions", //Flags: flagset.StorageHomeWithConfig(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 59598a245..cab4a7a08 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 97057ed00..653d7baf6 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/storagesharing.go b/ocis/pkg/command/storagesharing.go index d5d479c5c..1a2e5f791 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 984d7e86a..611592452 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 fbcd1d40a..a6b57ceff 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 a12412c95..7e10d3628 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 140b6a1c5..f2c2284b9 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 f69340683..4254a46df 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 6ef8a2095..d5b2a9133 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 fb171ad14..f09b59a13 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 834390b9e..319efcd39 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 4126133a1..d8d0acfe4 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 116c081df..e00e7b980 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 0d10d16ec..41359d0c7 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 9f992d6d7..7f1767ae2 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 7545db5d4..e8b907dca 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 9c08299f1..c2c773d0a 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 15c390136..20df41a1e 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 80c8c523b..591fc7813 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 10268754a..8528cb6c1 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 af60ccbda..aff1c2a5f 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 eaaa97cbf..46e0fa949 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 f3b3d9f6f..26d5bbc5e 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 63f158da1..5570c959b 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 043c96fdc..b71951431 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 a3c3791a9..2a81dee7c 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 abace4d50..52735f32b 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/storagehome.go b/storage/pkg/command/storagehome.go index bbeca4d70..8964e0887 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -24,7 +24,7 @@ import ( func StorageHome(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-home", - Usage: "Start storage-home service", + Usage: "start storage-home service", Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-home") }, diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 1c84313a3..cb84b9ac8 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 edd73c9ad..261539813 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/storageusers.go b/storage/pkg/command/storageusers.go index 7bb7aa6c0..7a2be81e8 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 34aee1d7c..c71a674b7 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 bc0b77b34..7b62857a3 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 77df9d87b..eb0b7f8d6 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 91554c791..e976ef727 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 5b232dc9e..3ac49f6b6 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 c47505705..f44b230d3 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 45030313a..b909db37d 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 5ab5887ea..c3c38ec4f 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 016246d1e..f68d16a5d 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 7b76bdcfe..783dd284e 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 0a8e62486..f4485c6c1 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 10dd88abf..3511d326c 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 f6649a41a..71b5b0d45 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 62dbd893b7adcfc960005c65ad9bb9c64d0f9466 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Fri, 7 Jan 2022 13:21:14 +0100 Subject: [PATCH 40/41] 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 0e908b60e..bba020b88 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 ef15ee650..edc25b50a 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 cf0a9a660..b25e795c2 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 b40b65a17..27c8ef9e9 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 af3e6ccbc..d1da86af7 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 319efcd39..b49d3b41a 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 41359d0c7..ff004eae4 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 a8e15f8cf..3475fceab 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 2a81dee7c..7ba232a1c 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 7b62857a3..fafc60e02 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 3ac49f6b6..7eb462475 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 c3c38ec4f..38713676a 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 f4485c6c1..94741b29a 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 4cf0befcdb555e8aa61ba8c18576eb7ed9991ac8 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 41/41] Automated changelog update [skip ci] --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b3b0f904..ba674e786 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