From ad4fb0e0f9a30d552deed525c0123c42fae3f4b5 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 19:37:15 +0100 Subject: [PATCH] attempt to revert to the old status. Just triggering a CI run --- accounts/pkg/command/inspect_account.go | 2 +- accounts/pkg/command/list_accounts.go | 2 +- accounts/pkg/command/remove_account.go | 5 +- accounts/pkg/command/version.go | 3 - accounts/pkg/flagset/flagset.go | 212 ++++++++++++++---------- 5 files changed, 129 insertions(+), 95 deletions(-) diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index baa3cb4b10..1ea262c31d 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -20,7 +20,7 @@ func InspectAccount(cfg *config.Config) *cli.Command { Name: "inspect", Usage: "Show detailed data on an existing account", ArgsUsage: "id", - Flags: flagset.Root(cfg), + Flags: flagset.InspectAccountWithConfig(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 de352367f6..87727b5762 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -20,7 +20,7 @@ func ListAccounts(cfg *config.Config) *cli.Command { Name: "list", Usage: "List existing accounts", Aliases: []string{"ls"}, - Flags: flagset.Root(cfg), + Flags: flagset.ListAccountsWithConfig(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 884244ed69..dfb723db9c 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -19,10 +19,7 @@ func RemoveAccount(cfg *config.Config) *cli.Command { Usage: "Removes an existing account", ArgsUsage: "id", Aliases: []string{"rm"}, - Flags: flagset.Root(cfg), - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, + Flags: flagset.RemoveAccountWithConfig(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 66867b6552..e61530d16b 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -16,9 +16,6 @@ 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.GRPC.Namespace + "." + cfg.Server.Name) diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 69b33a957c..3815f0784a 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -7,6 +7,90 @@ 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 { @@ -95,92 +179,48 @@ func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { } } -// 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, - }, - } -} - -// Root applies remove command flags to cfg -func Root(cfg *config.Config) []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",