Skip to content

Commit

Permalink
Show user on creation, reset
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrondier committed Dec 2, 2024
1 parent dede9b9 commit d2a2288
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 85 deletions.
12 changes: 7 additions & 5 deletions cmd/dbaas_user_create_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,10 +35,13 @@ func (c *dbaasUserCreateCmd) createKafka(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceKafka(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))

return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showKafka(ctx))

}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_create_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,10 +38,11 @@ func (c *dbaasUserCreateCmd) createMysql(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceMysql(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showMysql(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_create_opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,10 +35,11 @@ func (c *dbaasUserCreateCmd) createOpensearch(cmd *cobra.Command, _ []string) er
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceOpensearch(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showOpensearch(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_create_pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,10 +35,11 @@ func (c *dbaasUserCreateCmd) createPg(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServicePG(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showPG(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_create_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,10 +35,11 @@ func (c *dbaasUserCreateCmd) createRedis(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceRedis(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showRedis(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_reset_grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,10 +38,11 @@ func (c *dbaasUserResetCmd) resetGrafana(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceGrafana(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showGrafana(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_reset_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,10 +38,11 @@ func (c *dbaasUserResetCmd) resetKafka(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceKafka(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showKafka(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_reset_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -43,10 +42,11 @@ func (c *dbaasUserResetCmd) resetMysql(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceMysql(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showMysql(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_reset_opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,10 +38,11 @@ func (c *dbaasUserResetCmd) resetOpensearch(cmd *cobra.Command, _ []string) erro
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceOpensearch(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showOpensearch(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_reset_pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,10 +38,11 @@ func (c *dbaasUserResetCmd) resetPG(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServicePG(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showPG(ctx))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/dbaas_user_reset_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,10 +38,11 @@ func (c *dbaasUserResetCmd) resetRedis(cmd *cobra.Command, _ []string) error {
}

if !globalstate.Quiet {
return c.outputFunc((&dbaasServiceShowCmd{
Name: c.Name,
Zone: c.Zone,
}).showDatabaseServiceRedis(exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))))
return c.outputFunc((&dbaasUserShowCmd{
Name: c.Name,
Zone: c.Zone,
Username: c.Username,
}).showRedis(ctx))
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions cmd/dbaas_user_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ func (c *dbaasUserShowCmd) cmdRun(cmd *cobra.Command, args []string) error {

switch db.Type {
case "mysql":
return c.outputFunc(c.showMysql(cmd, args))
return c.outputFunc(c.showMysql(ctx))
case "kafka":
return c.outputFunc(c.showKafka(cmd, args))
return c.outputFunc(c.showKafka(ctx))
case "pg":
return c.outputFunc(c.showPG(cmd, args))
return c.outputFunc(c.showPG(ctx))
case "opensearch":
return c.outputFunc(c.showOpensearch(cmd, args))
return c.outputFunc(c.showOpensearch(ctx))
case "redis":
return c.outputFunc(c.showRedis(cmd, args))
return c.outputFunc(c.showRedis(ctx))
case "grafana":
return c.outputFunc(c.showGrafana(cmd, args))
return c.outputFunc(c.showGrafana(ctx))
default:
return fmt.Errorf("Listing users unsupported for service of type %q", db.Type)

Expand Down
6 changes: 2 additions & 4 deletions cmd/dbaas_user_show_grafana.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package cmd

import (
"context"
"fmt"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

func (c *dbaasUserShowCmd) showGrafana(cmd *cobra.Command, _ []string) (output.Outputter, error) {

ctx := gContext
func (c *dbaasUserShowCmd) showGrafana(ctx context.Context) (output.Outputter, error) {

client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions cmd/dbaas_user_show_kafka.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"time"

Expand All @@ -9,7 +10,6 @@ import (
"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/table"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

type dbaasKafkaUserShowOutput struct {
Expand All @@ -24,9 +24,7 @@ func (o *dbaasKafkaUserShowOutput) formatUser(t *table.Table) {
t.Append([]string{"Access Cert Expiry", o.AccessCertExpiry.String()})
}

func (c *dbaasUserShowCmd) showKafka(cmd *cobra.Command, _ []string) (output.Outputter, error) {

ctx := gContext
func (c *dbaasUserShowCmd) showKafka(ctx context.Context) (output.Outputter, error) {

client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions cmd/dbaas_user_show_mysql.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cmd

import (
"context"
"fmt"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/table"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

type dbaasMysqlUserShowOutput struct {
Expand All @@ -19,9 +19,7 @@ func (o *dbaasMysqlUserShowOutput) formatUser(t *table.Table) {
t.Append([]string{"Authentication", o.Authentication})
}

func (c *dbaasUserShowCmd) showMysql(cmd *cobra.Command, _ []string) (output.Outputter, error) {

ctx := gContext
func (c *dbaasUserShowCmd) showMysql(ctx context.Context) (output.Outputter, error) {

client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions cmd/dbaas_user_show_opensearch.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package cmd

import (
"context"
"fmt"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

func (c *dbaasUserShowCmd) showOpensearch(cmd *cobra.Command, _ []string) (output.Outputter, error) {

ctx := gContext
func (c *dbaasUserShowCmd) showOpensearch(ctx context.Context) (output.Outputter, error) {

client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
Expand Down
Loading

0 comments on commit d2a2288

Please sign in to comment.