Skip to content

Conversation

@andreaangiolillo
Copy link
Collaborator

@andreaangiolillo andreaangiolillo commented Mar 11, 2025

Proposed changes

Jira ticket: CLOUDP-305822

Bug

The atlas dbusers update [USER] --password [PASS] sets the roles and scope array to empty.

Fix

Set the roles and scope in the request body only when the user provides their flags.

Testing

Before

atlas dbusers get Quickstart-1635259359 -P dev -o dev
{
  "awsIAMType": "NONE",
  "databaseName": "admin",
  "groupId": "5e4e593f70dfbf1010295836",
  "labels": [],
  "ldapAuthType": "NONE",
  "links": [
    {
      "href": "https://cloud-dev.mongodb.com/api/atlas/v2/groups/5e4e593f70dfbf1010295836/databaseUsers/admin/Quickstart-1635259359",
      "rel": "self"
    }
  ],
  "oidcAuthType": "NONE",
  "roles": [
    {
      "databaseName": "admin",
      "roleName": "atlasAdmin"
    }
  ],
  "scopes": [],
  "username": "Quickstart-1635259359",
  "x509Type": "NONE"
}
atlas dbusers update Quickstart-1635259359  --password 'test' -P dev -o json                                                                              
{
  "awsIAMType": "NONE",
  "databaseName": "admin",
  "groupId": "5e4e593f70dfbf1010295836",
  "labels": [],
  "ldapAuthType": "NONE",
  "links": [
    {
      "href": "https://cloud-dev.mongodb.com/api/atlas/v2/groups/5e4e593f70dfbf1010295836/databaseUsers/admin/Quickstart-1635259359",
      "rel": "self"
    }
  ],
  "oidcAuthType": "NONE",
  "roles": [],
  "scopes": [],
  "username": "Quickstart-1635259359",
  "x509Type": "NONE"
}

After the fix

./bin/atlas dbusers update thirdUser --password 'test' -P dev -o json                                                                                    
{
  "awsIAMType": "NONE",
  "databaseName": "admin",
  "groupId": "5e4e593f70dfbf1010295836",
  "labels": [],
  "ldapAuthType": "NONE",
  "links": [
    {
      "href": "https://cloud-dev.mongodb.com/api/atlas/v2/groups/5e4e593f70dfbf1010295836/databaseUsers/admin/thirdUser",
      "rel": "self"
    }
  ],
  "oidcAuthType": "NONE",
  "roles": [
    {
      "databaseName": "admin",
      "roleName": "readWriteAnyDatabase"
    },
    {
      "databaseName": "admin",
      "roleName": "clusterMonitor"
    }
  ],
  "scopes": [],
  "username": "thirdUser",
  "x509Type": "NONE"
}

@andreaangiolillo andreaangiolillo marked this pull request as ready for review March 11, 2025 09:57
@andreaangiolillo andreaangiolillo requested a review from a team as a code owner March 11, 2025 09:57
@github-actions
Copy link
Contributor

Coverage Report 📈

Branch Commit Coverage
master 415526a 37.9%
CLOUDP-305822 039ddaf 37.9%
Difference 0%

@andreaangiolillo andreaangiolillo merged commit 82d2d94 into master Mar 11, 2025
22 of 24 checks passed
@andreaangiolillo andreaangiolillo deleted the CLOUDP-305822 branch March 11, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants