Skip to content

Commit

Permalink
CLOUDP-289992: [AtlasCLI] add --description in the "atlas dbusers cre…
Browse files Browse the repository at this point in the history
…ate" command (#3467)
  • Loading branch information
andreaangiolillo authored Dec 14, 2024
1 parent 5255685 commit c0fd95c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
4 changes: 4 additions & 0 deletions docs/command/atlas-dbusers-create.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Options
- string
- false
- Timestamp in ISO 8601 in UTC after which Atlas deletes the user.
* - --desc
- string
- false
- Description of this database user.
* - -h, --help
-
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-dbusers-update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Options
- string
- false
- Authentication database name. If the user authenticates with AWS IAM, x.509, or LDAP, this value should be $external. If the user authenticates with SCRAM-SHA, this value should be admin.
* - --desc
- string
- false
- Description of this database user.
* - -h, --help
-
- false
Expand Down
6 changes: 6 additions & 0 deletions internal/cli/dbusers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type CreateOpts struct {
ldapType string
oidcType string
deleteAfter string
description string
roles []string
scopes []string
store store.DatabaseUserCreator
Expand Down Expand Up @@ -140,6 +141,10 @@ func (opts *CreateOpts) newDatabaseUser() *atlasv2.CloudDatabaseUser {
u.OidcAuthType = &opts.oidcType
}

if opts.description != "" {
u.Description = &opts.description
}

return u
}

Expand Down Expand Up @@ -239,6 +244,7 @@ func CreateBuilder() *cobra.Command {
cmd.Flags().StringVarP(&opts.username, flag.Username, flag.UsernameShort, "", usage.DBUsername)
cmd.Flags().StringVarP(&opts.password, flag.Password, flag.PasswordShort, "", usage.DBUserPassword)
cmd.Flags().StringVar(&opts.deleteAfter, flag.DeleteAfter, "", usage.BDUsersDeleteAfter)
cmd.Flags().StringVar(&opts.description, flag.Description, "", usage.DBUserDescription)
cmd.Flags().StringSliceVar(&opts.roles, flag.Role, []string{}, usage.RolesExtended)
cmd.Flags().StringSliceVar(&opts.scopes, flag.Scope, []string{}, usage.Scopes)
cmd.Flags().StringVar(&opts.x509Type, flag.X509Type, none, usage.X509Type)
Expand Down
50 changes: 27 additions & 23 deletions internal/cli/dbusers/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ func TestDBUserCreateOpts_Run(t *testing.T) {

func TestCreateOpts_validate(t *testing.T) {
type fields struct {
x509Type string
awsIamType string
oidcType string
ldapType string
password string
roles []string
x509Type string
awsIamType string
oidcType string
ldapType string
password string
description string
roles []string
}
tests := []struct {
name string
Expand Down Expand Up @@ -113,23 +114,25 @@ func TestCreateOpts_validate(t *testing.T) {
{
name: "awsIamType and password",
fields: fields{
roles: []string{"test"},
awsIamType: user,
ldapType: none,
oidcType: none,
x509Type: none,
password: "password",
roles: []string{"test"},
awsIamType: user,
ldapType: none,
oidcType: none,
x509Type: none,
description: "test",
password: "password",
},
wantErr: true,
},
{
name: "no external auth",
fields: fields{
roles: []string{"test"},
awsIamType: none,
ldapType: none,
x509Type: none,
oidcType: none,
roles: []string{"test"},
awsIamType: none,
ldapType: none,
x509Type: none,
description: "test",
oidcType: none,
},
wantErr: false,
},
Expand Down Expand Up @@ -163,12 +166,13 @@ func TestCreateOpts_validate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
opts := &CreateOpts{
x509Type: fields.x509Type,
awsIamType: fields.awsIamType,
ldapType: fields.ldapType,
oidcType: fields.oidcType,
roles: fields.roles,
password: fields.password,
x509Type: fields.x509Type,
awsIamType: fields.awsIamType,
ldapType: fields.ldapType,
oidcType: fields.oidcType,
roles: fields.roles,
password: fields.password,
description: fields.description,
}
if err := opts.validate(); (err != nil) != wantErr {
t.Errorf("validate() error = %v, wantErr %v", err, wantErr)
Expand Down
8 changes: 7 additions & 1 deletion internal/cli/dbusers/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type UpdateOpts struct {
currentUsername string
password string
authDB string
x509Type string
description string
roles []string
scopes []string
x509Type string
store store.DatabaseUserUpdater
}

Expand Down Expand Up @@ -82,6 +83,10 @@ func (opts *UpdateOpts) update(out *admin.CloudDatabaseUser) {
out.Password = &opts.password
}

if opts.description != "" {
out.Description = &opts.description
}

roles := convert.BuildAtlasRoles(opts.roles)
out.Roles = &roles
scopes := convert.BuildAtlasScopes(opts.scopes)
Expand Down Expand Up @@ -136,6 +141,7 @@ func UpdateBuilder() *cobra.Command {

cmd.Flags().StringVarP(&opts.username, flag.Username, flag.UsernameShort, "", usage.DBUsername)
cmd.Flags().StringVarP(&opts.password, flag.Password, flag.PasswordShort, "", usage.DBUserPassword)
cmd.Flags().StringVar(&opts.description, flag.Description, "", usage.DBUserDescription)
cmd.Flags().StringVar(&opts.authDB, flag.AuthDB, "", usage.AtlasAuthDB)
cmd.Flags().StringSliceVar(&opts.roles, flag.Role, []string{}, usage.Roles+usage.UpdateWarning)
cmd.Flags().StringSliceVar(&opts.scopes, flag.Scope, []string{}, usage.Scopes+usage.UpdateWarning)
Expand Down
1 change: 1 addition & 0 deletions internal/cli/dbusers/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestDBUserUpdate_Run(t *testing.T) {
currentUsername: "test4",
password: "US",
roles: []string{"admin@admin"},
description: "test",
store: mockStore,
}

Expand Down
1 change: 1 addition & 0 deletions internal/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
Username = "Name that identifies the user. You must specify a valid email address."
TeamUsername = "Comma-separated list that contains the valid usernames of the MongoDB users to add to the new team. A team must have at least one user. New users must accept the invitation to join an organization before you can add them to a team."
DBUsername = "Username for authenticating to MongoDB."
DBUserDescription = "Description of this database user."
TeamName = "Label that identifies the team."
UserID = "Unique 24-digit identifier of the user."
LDAPHostname = "Hostname or IP address of the LDAP server."
Expand Down

0 comments on commit c0fd95c

Please sign in to comment.