Skip to content

Commit

Permalink
fix: dbaas user creation pre-check
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrondier committed Jan 9, 2025
1 parent a7af867 commit 136b25c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/dbaas_database_create_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c dbaasDatabaseCreateCmd) createMysql(cmd *cobra.Command, _ []string) erro
return err
}

if s.State != "running" {
if len(s.Databases) == 0 {
return fmt.Errorf("service %q is not ready for database creation", c.Name)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/dbaas_database_create_pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c dbaasDatabaseCreateCmd) createPg(cmd *cobra.Command, _ []string) error {
return err
}

if s.State != "running" {
if len(s.Databases) == 0 {
return fmt.Errorf("service %q is not ready for database creation", c.Name)
}

Expand Down
9 changes: 9 additions & 0 deletions cmd/dbaas_user_create_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ func (c *dbaasUserCreateCmd) createKafka(cmd *cobra.Command, _ []string) error {
return err
}

s, err := client.GetDBAASServicePG(ctx, c.Name)
if err != nil {
return err
}

if len(s.Users) == 0 {
return fmt.Errorf("service %q is not ready for user creation", c.Name)
}

req := v3.CreateDBAASKafkaUserRequest{Username: v3.DBAASUserUsername(c.Username)}

op, err := client.CreateDBAASKafkaUser(ctx, c.Name, req)
Expand Down
9 changes: 9 additions & 0 deletions cmd/dbaas_user_create_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ func (c *dbaasUserCreateCmd) createMysql(cmd *cobra.Command, _ []string) error {
return err
}

s, err := client.GetDBAASServiceMysql(ctx, c.Name)
if err != nil {
return err
}

if len(s.Users) == 0 {
return fmt.Errorf("service %q is not ready for user creation", c.Name)
}

req := v3.CreateDBAASMysqlUserRequest{Username: v3.DBAASUserUsername(c.Username)}
if c.MysqlAuthenticationMethod != "" {
req.Authentication = v3.EnumMysqlAuthenticationPlugin(c.MysqlAuthenticationMethod)
Expand Down
9 changes: 9 additions & 0 deletions cmd/dbaas_user_create_opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ func (c *dbaasUserCreateCmd) createOpensearch(cmd *cobra.Command, _ []string) er
return err
}

s, err := client.GetDBAASServiceOpensearch(ctx, c.Name)
if err != nil {
return err
}

if len(s.Users) == 0 {
return fmt.Errorf("service %q is not ready for user creation", c.Name)
}

req := v3.CreateDBAASOpensearchUserRequest{Username: v3.DBAASUserUsername(c.Username)}

op, err := client.CreateDBAASOpensearchUser(ctx, c.Name, req)
Expand Down
9 changes: 9 additions & 0 deletions cmd/dbaas_user_create_pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ func (c *dbaasUserCreateCmd) createPg(cmd *cobra.Command, _ []string) error {
return err
}

s, err := client.GetDBAASServicePG(ctx, c.Name)
if err != nil {
return err
}

if len(s.Users) == 0 {
return fmt.Errorf("service %q is not ready for user creation", c.Name)
}

req := v3.CreateDBAASPostgresUserRequest{Username: v3.DBAASUserUsername(c.Username), AllowReplication: &c.PostgresAllowReplication}

op, err := client.CreateDBAASPostgresUser(ctx, c.Name, req)
Expand Down

0 comments on commit 136b25c

Please sign in to comment.