Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/cloudcredential/openstack/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions cmd/project/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
),
Expand Down
12 changes: 12 additions & 0 deletions cmd/user/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
}
}
77 changes: 77 additions & 0 deletions cmd/user/notifications/notifications.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
10 changes: 10 additions & 0 deletions cmd/user/test_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading