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 80e16d071..29c5b6a38 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -3,58 +3,50 @@ package command import ( "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + Frontend(cfg), + Gateway(cfg), + Users(cfg), + Groups(cfg), + AppProvider(cfg), + AuthBasic(cfg), + AuthBearer(cfg), + AuthMachine(cfg), + Sharing(cfg), + StoragePublicLink(cfg), + StorageShares(cfg), + StorageUsers(cfg), + StorageMetadata(cfg), + Health(cfg), + } +} + // Execute is the entry point for the storage command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "storage", - Version: version.String, - Usage: "Storage service for oCIS", - Compiled: version.Compiled(), + app := clihelper.DefaultApp(&cli.App{ + Name: "storage", + Usage: "Storage service for oCIS", - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage") }, - Commands: []*cli.Command{ - Frontend(cfg), - Gateway(cfg), - Users(cfg), - Groups(cfg), - AppProvider(cfg), - AuthBasic(cfg), - AuthBearer(cfg), - AuthMachine(cfg), - Sharing(cfg), - StorageUsers(cfg), - StorageShares(cfg), - StoragePublicLink(cfg), - StorageMetadata(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/storage/pkg/config/defaultconfig.go b/storage/pkg/config/defaultconfig.go new file mode 100644 index 000000000..00e0dba36 --- /dev/null +++ b/storage/pkg/config/defaultconfig.go @@ -0,0 +1,436 @@ +package config + +import ( + "os" + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func DefaultConfig() *Config { + return &Config{ + // log is inherited + Debug: Debug{ + Addr: "127.0.0.1:9109", + }, + Reva: Reva{ + JWTSecret: "Pive-Fumkiu4", + SkipUserGroupsInToken: false, + TransferSecret: "replace-me-with-a-transfer-secret", + TransferExpires: 24 * 60 * 60, + OIDC: OIDC{ + Issuer: "https://localhost:9200", + Insecure: false, + IDClaim: "preferred_username", + }, + LDAP: LDAP{ + Hostname: "localhost", + Port: 9126, + CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Insecure: false, + BaseDN: "dc=ocis,dc=test", + LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", + UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", + UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", + GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", + GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", + BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", + BindPassword: "reva", + IDP: "https://localhost:9200", + UserSchema: LDAPUserSchema{ + UID: "ownclouduuid", + Mail: "mail", + DisplayName: "displayname", + CN: "cn", + UIDNumber: "uidnumber", + GIDNumber: "gidnumber", + }, + GroupSchema: LDAPGroupSchema{ + GID: "cn", + Mail: "mail", + DisplayName: "cn", + CN: "cn", + GIDNumber: "gidnumber", + }, + }, + UserGroupRest: UserGroupRest{ + RedisAddress: "localhost:6379", + }, + UserOwnCloudSQL: UserOwnCloudSQL{ + DBUsername: "owncloud", + DBPassword: "secret", + DBHost: "mysql", + DBPort: 3306, + DBName: "owncloud", + Idp: "https://localhost:9200", + Nobody: 90, + JoinUsername: false, + JoinOwnCloudUUID: false, + EnableMedialSearch: false, + }, + OCDav: OCDav{ + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + DavFilesNamespace: "/users/{{.Id.OpaqueId}}", + }, + Archiver: Archiver{ + MaxNumFiles: 10000, + MaxSize: 1073741824, + ArchiverURL: "/archiver", + }, + UserStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + }, + ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") + UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + OwnCloud: DriverOwnCloud{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + Redis: ":6379", + Scan: true, + }, + OwnCloudSQL: DriverOwnCloudSQL{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + DBUsername: "owncloud", + DBPassword: "owncloud", + DBHost: "", + DBPort: 3306, + DBName: "owncloud", + }, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + MetadataStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + EnableHome: false, + }, + ShadowNamespace: "", + UploadsNamespace: "", + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + GrpcURI: "", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + EnableLogging: false, + ShowHiddenSysFiles: false, + ForceSingleUserMode: false, + UseKeytab: false, + SecProtocol: "", + Keytab: "", + SingleUsername: "", + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), + }, + OwnCloud: DriverOwnCloud{}, + OwnCloudSQL: DriverOwnCloudSQL{}, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + Frontend: FrontendPort{ + Port: Port{ + MaxCPUs: "", + LogLevel: "", + GRPCNetwork: "", + GRPCAddr: "", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9140", + Protocol: "", + Endpoint: "", + DebugAddr: "127.0.0.1:9141", + Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, + Config: nil, + Context: nil, + Supervised: false, + }, + AppProviderInsecure: false, + AppProviderPrefix: "", + ArchiverInsecure: false, + ArchiverPrefix: "archiver", + DatagatewayPrefix: "data", + Favorites: false, + OCDavInsecure: false, + OCDavPrefix: "", + OCSPrefix: "ocs", + OCSSharePrefix: "/Shares", + OCSHomeNamespace: "/users/{{.Id.OpaqueId}}", + PublicURL: "https://localhost:9200", + OCSCacheWarmupDriver: "", + OCSAdditionalInfoAttribute: "{{.Mail}}", + OCSResourceInfoCacheTTL: 0, + Middleware: Middleware{}, + }, + DataGateway: DataGatewayPort{ + Port: Port{}, + PublicURL: "", + }, + Gateway: Gateway{ + Port: Port{ + Endpoint: "127.0.0.1:9142", + DebugAddr: "127.0.0.1:9143", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9142", + }, + CommitShareToStorageGrant: true, + CommitShareToStorageRef: true, + DisableHomeCreationOnLogin: false, + ShareFolder: "Shares", + LinkGrants: "", + HomeMapping: "", + EtagCacheTTL: 0, + }, + StorageRegistry: StorageRegistry{ + Driver: "spaces", + HomeProvider: "/home", + JSON: "", + }, + AppRegistry: AppRegistry{ + Driver: "static", + MimetypesJSON: "", + }, + Users: Users{ + Port: Port{ + Endpoint: "localhost:9144", + DebugAddr: "127.0.0.1:9145", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9144", + Services: []string{"userprovider"}, + }, + Driver: "ldap", + UserGroupsCacheExpiration: 5, + }, + Groups: Groups{ + Port: Port{ + Endpoint: "localhost:9160", + DebugAddr: "127.0.0.1:9161", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9160", + Services: []string{"groupprovider"}, + }, + Driver: "ldap", + GroupMembersCacheExpiration: 5, + }, + AuthProvider: Users{ + Port: Port{}, + Driver: "ldap", + UserGroupsCacheExpiration: 0, + }, + AuthBasic: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9146", + DebugAddr: "127.0.0.1:9147", + Services: []string{"authprovider"}, + Endpoint: "localhost:9146", + }, + AuthBearer: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9148", + DebugAddr: "127.0.0.1:9149", + Services: []string{"authprovider"}, + Endpoint: "localhost:9148", + }, + AuthMachine: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9166", + DebugAddr: "127.0.0.1:9167", + Services: []string{"authprovider"}, + Endpoint: "localhost:9166", + }, + AuthMachineConfig: AuthMachineConfig{ + MachineAuthAPIKey: "change-me-please", + }, + Sharing: Sharing{ + Port: Port{ + Endpoint: "localhost:9150", + DebugAddr: "127.0.0.1:9151", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9150", + Services: []string{"usershareprovider", "publicshareprovider"}, + }, + UserDriver: "json", + UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), + UserSQLUsername: "", + UserSQLPassword: "", + UserSQLHost: "", + UserSQLPort: 1433, + UserSQLName: "", + PublicDriver: "json", + PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), + PublicPasswordHashCost: 11, + PublicEnableExpiredSharesCleanup: true, + PublicJanitorRunInterval: 60, + UserStorageMountID: "", + }, + StorageShares: StoragePort{ + Port: Port{ + Endpoint: "localhost:9154", + DebugAddr: "127.0.0.1:9156", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9154", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9155", + }, + ReadOnly: false, + AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + }, + StorageUsers: StoragePort{ + Port: Port{ + Endpoint: "localhost:9157", + DebugAddr: "127.0.0.1:9159", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9157", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9158", + }, + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + Driver: "ocis", + DataServerURL: "http://localhost:9158/data", + HTTPPrefix: "data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), + }, + StoragePublicLink: PublicStorage{ + StoragePort: StoragePort{ + Port: Port{ + Endpoint: "localhost:9178", + DebugAddr: "127.0.0.1:9179", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9178", + }, + MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", + }, + PublicShareProviderAddr: "", + UserProviderAddr: "", + }, + StorageMetadata: StoragePort{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9215", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9216", + DebugAddr: "127.0.0.1:9217", + }, + Driver: "ocis", + ExposeDataServer: false, + DataServerURL: "http://localhost:9216/data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), + DataProvider: DataProvider{}, + }, + AppProvider: AppProvider{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9164", + DebugAddr: "127.0.0.1:9165", + Endpoint: "localhost:9164", + Services: []string{"appprovider"}, + }, + ExternalAddr: "127.0.0.1:9164", + WopiDriver: WopiDriver{}, + AppsURL: "/app/list", + OpenURL: "/app/open", + NewURL: "/app/new", + }, + Configs: nil, + UploadMaxChunkSize: 1e+8, + UploadHTTPMethodOverride: "", + ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, + ChecksumPreferredUploadType: "", + DefaultUploadProtocol: "tus", + }, + Tracing: Tracing{ + Service: "storage", + Type: "jaeger", + }, + Asset: Asset{}, + } +} diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 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 }