diff --git a/accounts/pkg/command/add_account.go b/accounts/pkg/command/add_account.go index 4003c46eed..386cb48648 100644 --- a/accounts/pkg/command/add_account.go +++ b/accounts/pkg/command/add_account.go @@ -21,6 +21,10 @@ func AddAccount(cfg *config.Config) *cli.Command { Aliases: []string{"create", "a"}, Flags: flagset.AddAccountWithConfig(cfg, a), Before: func(c *cli.Context) error { + if err := ParseConfig(c, cfg); err != nil { + return err + } + // Write value of username to the flags beneath, as preferred name // and on-premises-sam-account-name is probably confusing for users. if username := c.String("username"); username != "" { diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index 6769cf0f82..ece3932d5e 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -8,7 +8,6 @@ import ( "github.com/asim/go-micro/plugins/client/grpc/v4" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/urfave/cli/v2" ) @@ -19,7 +18,9 @@ func InspectAccount(cfg *config.Config) *cli.Command { Name: "inspect", Usage: "Show detailed data on an existing account", ArgsUsage: "id", - Flags: flagset.InspectAccountWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name if c.NArg() != 1 { diff --git a/accounts/pkg/command/list_accounts.go b/accounts/pkg/command/list_accounts.go index 0ad3747612..fedac44c47 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -8,7 +8,6 @@ import ( "github.com/asim/go-micro/plugins/client/grpc/v4" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/urfave/cli/v2" ) @@ -19,7 +18,9 @@ func ListAccounts(cfg *config.Config) *cli.Command { Name: "list", Usage: "List existing accounts", Aliases: []string{"ls"}, - Flags: flagset.ListAccountsWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) diff --git a/accounts/pkg/command/remove_account.go b/accounts/pkg/command/remove_account.go index 086e50554e..88a18110cf 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -6,7 +6,6 @@ import ( "github.com/asim/go-micro/plugins/client/grpc/v4" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/urfave/cli/v2" ) @@ -18,7 +17,9 @@ func RemoveAccount(cfg *config.Config) *cli.Command { Usage: "Removes an existing account", ArgsUsage: "id", Aliases: []string{"rm"}, - Flags: flagset.RemoveAccountWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name if c.NArg() != 1 { diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index c89358db52..66867b6552 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListAccountsWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Server.Name) diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 3815f0784a..c633f11164 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -7,90 +7,6 @@ import ( "github.com/urfave/cli/v2" ) -// UpdateAccountWithConfig applies update command flags to cfg -func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { - if a.PasswordProfile == nil { - a.PasswordProfile = &accounts.PasswordProfile{} - } - - return []cli.Flag{ - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.GRPC.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - &cli.BoolFlag{ - Name: "enabled", - Usage: "Enable the account", - Destination: &a.AccountEnabled, - }, - &cli.StringFlag{ - Name: "displayname", - Usage: "Set the displayname for the account", - Destination: &a.DisplayName, - }, - &cli.StringFlag{ - Name: "preferred-name", - Usage: "Set the preferred-name for the account", - Destination: &a.PreferredName, - }, - &cli.StringFlag{ - Name: "on-premises-sam-account-name", - Usage: "Set the on-premises-sam-account-name", - Destination: &a.OnPremisesSamAccountName, - }, - &cli.Int64Flag{ - Name: "uidnumber", - Usage: "Set the uidnumber for the account", - Destination: &a.UidNumber, - }, - &cli.Int64Flag{ - Name: "gidnumber", - Usage: "Set the gidnumber for the account", - Destination: &a.GidNumber, - }, - &cli.StringFlag{ - Name: "mail", - Usage: "Set the mail for the account", - Destination: &a.Mail, - }, - &cli.StringFlag{ - Name: "description", - Usage: "Set the description for the account", - Destination: &a.Description, - }, - &cli.StringFlag{ - Name: "password", - Usage: "Set the password for the account", - Destination: &a.PasswordProfile.Password, - // TODO read password from ENV? - }, - &cli.StringSliceFlag{ - Name: "password-policies", - Usage: "Possible policies: DisableStrongPassword, DisablePasswordExpiration", - }, - &cli.BoolFlag{ - Name: "force-password-change", - Usage: "Force password change on next sign-in", - Destination: &a.PasswordProfile.ForceChangePasswordNextSignIn, - }, - &cli.BoolFlag{ - Name: "force-password-change-mfa", - Usage: "Force password change on next sign-in with mfa", - Destination: &a.PasswordProfile.ForceChangePasswordNextSignInWithMfa, - }, - } -} - // AddAccountWithConfig applies create command flags to cfg func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { if a.PasswordProfile == nil { @@ -178,63 +94,3 @@ func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { }, } } - -// ListAccountsWithConfig applies list command flags to cfg -func ListAccountsWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.GRPC.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - } -} - -// RemoveAccountWithConfig applies remove command flags to cfg -func RemoveAccountWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.GRPC.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - } -} - -// InspectAccountWithConfig applies inspect command flags to cfg -func InspectAccountWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.GRPC.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - } -} diff --git a/ocis/pkg/command/health.go b/ocis/pkg/command/health.go index c65e295829..f293dbf8fa 100644 --- a/ocis/pkg/command/health.go +++ b/ocis/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis/pkg/flagset" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -15,7 +14,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/ocis/pkg/flagset/flagset.go b/ocis/pkg/flagset/flagset.go deleted file mode 100644 index 1450838fca..0000000000 --- a/ocis/pkg/flagset/flagset.go +++ /dev/null @@ -1,19 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/urfave/cli/v2" -) - -// HealthWithConfig applies cfg to the root flag-set. -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: "127.0.0.1:9010", - Usage: "Address to debug endpoint", - EnvVars: []string{"OCIS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -}