diff --git a/cmd/cloudcredential/openstack/check/check.go b/cmd/cloudcredential/openstack/check/check.go index 6fb9858d..b2859e21 100644 --- a/cmd/cloudcredential/openstack/check/check.go +++ b/cmd/cloudcredential/openstack/check/check.go @@ -3,13 +3,14 @@ package check import ( "context" "fmt" + "strings" + "github.com/itera-io/taikun-cli/cmd/cmderr" "github.com/itera-io/taikun-cli/cmd/cmdutils" "github.com/itera-io/taikun-cli/utils/out" tk "github.com/itera-io/taikungoclient" taikuncore "github.com/itera-io/taikungoclient/client" "github.com/spf13/cobra" - "strings" ) type CheckOptions struct { @@ -74,7 +75,7 @@ func checkRun(opts *CheckOptions) (err error) { // Execute a query into the API + graceful exit myRequest := myApiClient.Client.CheckerAPI.CheckerOpenstack(context.TODO()).CheckOpenstackCommand(body) - response, err := myRequest.Execute() + _, response, err := myRequest.Execute() if err == nil { out.PrintCheckSuccess("OpenStack cloud credential") diff --git a/cmd/project/info/info.go b/cmd/project/info/info.go index 1651e1ee..5c2cdf4b 100644 --- a/cmd/project/info/info.go +++ b/cmd/project/info/info.go @@ -2,6 +2,7 @@ package info import ( "context" + "github.com/itera-io/taikun-cli/cmd/cmderr" "github.com/itera-io/taikun-cli/cmd/cmdutils" "github.com/itera-io/taikun-cli/utils/out" @@ -38,6 +39,9 @@ var infoFields = fields.New( field.NewVisible( "ACCESS-PROFILE-ID", "accessProfileId", ), + field.NewVisible( + "ACCESS-IP", "accessIp", + ), field.NewVisibleWithToStringFunc( "CLOUD", "cloudType", out.FormatCloudType, ), diff --git a/cmd/user/info/info.go b/cmd/user/info/info.go index b65cdfd0..2e9dd688 100644 --- a/cmd/user/info/info.go +++ b/cmd/user/info/info.go @@ -2,10 +2,12 @@ package info import ( "context" + "github.com/itera-io/taikun-cli/cmd/cmderr" "github.com/itera-io/taikun-cli/cmd/user/complete" "github.com/itera-io/taikun-cli/cmd/user/list" "github.com/itera-io/taikun-cli/utils/out" + "github.com/itera-io/taikun-cli/utils/out/fields" tk "github.com/itera-io/taikungoclient" "github.com/spf13/cobra" ) @@ -38,6 +40,7 @@ func NewCmdInfo() *cobra.Command { // myInfoRun calls the API and gets the info about the current user func myInfoRun() (err error) { + showNotificationField(infoFields) myApiClient := tk.NewClient() data, response, err := myApiClient.Client.UsersAPI.UsersUserInfo(context.TODO()).Execute() if err != nil { @@ -62,3 +65,12 @@ func listRun(userID string) (err error) { return out.PrintResult(data.Data[0], infoFields) } + +func showNotificationField(infoFields fields.Fields) { + for _, infoField := range infoFields.AllFields() { + if infoField.NameMatches("EMAIL-NOTIFICATIONS") { + infoField.Show() + return + } + } +} diff --git a/cmd/user/notifications/notifications.go b/cmd/user/notifications/notifications.go new file mode 100644 index 00000000..67becde7 --- /dev/null +++ b/cmd/user/notifications/notifications.go @@ -0,0 +1,77 @@ +package notifications + +import ( + "context" + "fmt" + "strings" + + "github.com/itera-io/taikun-cli/cmd/cmdutils" + "github.com/itera-io/taikun-cli/utils/out" + tk "github.com/itera-io/taikungoclient" + taikuncore "github.com/itera-io/taikungoclient/client" + "github.com/spf13/cobra" +) + +type NotificationsOptions struct { + Mode string +} + +func NewCmdNotifications() *cobra.Command { + var opts NotificationsOptions + + cmd := cobra.Command{ + Use: "notifications [enable|disable]", + Short: "Toggle notification mode", + Args: cobra.MaximumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) == 1 { + if opts.Mode != "" { + return fmt.Errorf("provide mode either as argument or --mode, not both") + } + opts.Mode = args[0] + } + return notificationsRun(&opts) + }, + } + + cmd.Flags().StringVarP(&opts.Mode, "mode", "m", "", "Notification mode (enable|disable)") + cmdutils.SetFlagCompletionValues(&cmd, "mode", "enable", "disable") + + return &cmd +} + +func notificationsRun(opts *NotificationsOptions) (err error) { + mode, err := normalizeMode(opts.Mode) + if err != nil { + return err + } + + myApiClient := tk.NewClient() + body := taikuncore.ToggleNotificationModeCommand{} + body.SetMode(mode) + + response, err := myApiClient.Client.UsersAPI.UsersToggleNotificationMode(context.TODO()). + ToggleNotificationModeCommand(body). + Execute() + if err != nil { + return tk.CreateError(response, err) + } + + out.PrintStandardSuccess() + return +} + +func normalizeMode(mode string) (string, error) { + if mode == "" { + return "", fmt.Errorf("mode is required (enable|disable)") + } + + switch strings.ToLower(mode) { + case "enable", "enabled", "on", "true", "1": + return "enable", nil + case "disable", "disabled", "off", "false", "0": + return "disable", nil + default: + return "", fmt.Errorf("invalid mode %q (enable|disable)", mode) + } +} diff --git a/cmd/user/test_spec.sh b/cmd/user/test_spec.sh index 727d4ef2..22a5e3e5 100644 --- a/cmd/user/test_spec.sh +++ b/cmd/user/test_spec.sh @@ -47,6 +47,16 @@ Context 'user' The stderr should include "${username}@mailinator.com" End + Example 'toggle notification mode' + When call taikun user notifications enable + The status should equal 0 + The output should include 'Operation was successful.' + + When call taikun user notifications disable + The status should equal 0 + The output should include 'Operation was successful.' + End + Context bind() { taikun user project bind "$uid" --project-id "$pid" -q diff --git a/cmd/user/user.go b/cmd/user/user.go index 2f0a763c..757542fe 100644 --- a/cmd/user/user.go +++ b/cmd/user/user.go @@ -4,6 +4,7 @@ import ( "github.com/itera-io/taikun-cli/cmd/user/add" "github.com/itera-io/taikun-cli/cmd/user/info" "github.com/itera-io/taikun-cli/cmd/user/list" + "github.com/itera-io/taikun-cli/cmd/user/notifications" "github.com/itera-io/taikun-cli/cmd/user/project" "github.com/itera-io/taikun-cli/cmd/user/remove" "github.com/spf13/cobra" @@ -18,6 +19,7 @@ func NewCmdUser() *cobra.Command { cmd.AddCommand(add.NewCmdAdd()) cmd.AddCommand(info.NewCmdInfo()) cmd.AddCommand(list.NewCmdList()) + cmd.AddCommand(notifications.NewCmdNotifications()) cmd.AddCommand(project.NewCmdProject()) cmd.AddCommand(remove.NewCmdDelete()) diff --git a/go.mod b/go.mod index bb1d2cd8..6cb8d35d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.24.0 require ( github.com/go-openapi/strfmt v0.24.0 - github.com/itera-io/taikungoclient v0.0.0-20251014100817-e7578ebb929f + github.com/itera-io/taikungoclient v0.0.0-20260205161035-a02b3cbc1f7f github.com/jedib0t/go-pretty/v6 v6.6.8 github.com/spf13/cobra v1.10.1 ) diff --git a/go.sum b/go.sum index c390d790..e08359bb 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/itera-io/taikungoclient v0.0.0-20251014100817-e7578ebb929f h1:Uvg6hvkj1RjqY53++YEbwHFZEk3nESmOQmzLlL966oY= -github.com/itera-io/taikungoclient v0.0.0-20251014100817-e7578ebb929f/go.mod h1:VEIUQxLg9qNq20j4KELD2XBKak/M/d1OEdEaaCI0olo= +github.com/itera-io/taikungoclient v0.0.0-20260205161035-a02b3cbc1f7f h1:STUedHD+owXvNm8V3I8gF82yL0NzLHgorsp/cGcL/Nk= +github.com/itera-io/taikungoclient v0.0.0-20260205161035-a02b3cbc1f7f/go.mod h1:VEIUQxLg9qNq20j4KELD2XBKak/M/d1OEdEaaCI0olo= github.com/jedib0t/go-pretty/v6 v6.6.8 h1:JnnzQeRz2bACBobIaa/r+nqjvws4yEhcmaZ4n1QzsEc= github.com/jedib0t/go-pretty/v6 v6.6.8/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=