From 6206fe23983ce2d1a7b5fa6f55b0fc47a55a5873 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 24 Nov 2021 18:30:20 +0100 Subject: [PATCH] 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 4003c46eed..07d18f1a82 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 1ea262c31d..7124b0da4a 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 87727b5762..bf35626b1a 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 dfb723db9c..c51c1abe31 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 19eae93b2f..948ff2e4a1 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 e4e6f92e68..3475532434 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 71f8c2c661..1b9b91ca48 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 e61530d16b..7e7fc0f571 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 21bcd3dc25..63844a2ccc 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 00b13818b4..b61d93bc27 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 3815f0784a..d661508e2d 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 89cf6c346b..562fad5894 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 216b13e2e9..d063eda474 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 21487a2d61..306fa9347f 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 805f06c376..d7425dce37 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 477369b663..f339855f32 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 cfea0f2209..d9118ad42a 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 e6017cfef5..77270bf417 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 d9cbb5f1c0..6dcad7f036 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 0000000000..b9be475ab4 --- /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 d547180d7c..c3b55c7720 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 2f5f679a4c..d1c0e0ff68 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 86dabfe32f..c606f1d7cd 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 0000000000..2fde4e337e --- /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 c25d415de5..1acf398e87 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 20d07c88ea..3e61b387a9 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 32cd2a4aba..bcb9f3dcfb 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 0000000000..3eeaff740c --- /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 0cf4a47359..1cba3b4a24 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 7408d59f61..30a5451394 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 ffb7e781e4..54f1ff1d9a 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 68383fe5c7..6e316eaba8 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 cab4554b3d..107643e336 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 0000000000..1b1ae5553d --- /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 0000000000..e4dc82e024 --- /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 573266ca9d..9498c7a017 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 2c1b64e0e7..dac137c15c 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 01f2d65bbd..882c6364ee 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 2aab7b910c..7fe449dd54 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 4df5fbbddb..27c4e7e7fb 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 469abc6efe..bd9cd67179 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 bd21ee1e32..5193d5a653 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 582e391b4e..1bb038a263 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 a403f630d2..4ae43d8246 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 4d91088b96..113beb8cb1 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 0fd5a9f2d6..da12fcfa6d 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 4ac235e8cc..18400c6b75 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 b5bfef3b26..588e45b646 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 a39cae29b5..3131492b61 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 62eea4e71e..189f293ec5 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 148de47ad8..46ba11de8f 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 c1a5cc98d9..b86033f1d3 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 5136f0df0c..30dc5c53ba 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 fc7ec10a62..f76645ba86 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 df3c0230f0..d3dfb24591 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 5126a2d60d..3270e2e587 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 6f6ef0d2fa..d26a276030 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 4db1f72367..b78261d5fe 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 0c905c06e5..efa6ed85a3 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 8914aebbce..3c1e456db2 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 0000000000..94a87b4966 --- /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 0054c9331a..210b52918d 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 813cc1c08c..a0ab763f59 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 c08c8ea0f9..158ee88593 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 7fa86211ef..7e5fcb8088 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 1b183af5ed..a541071b2d 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),