Skip to content

Commit 650a4b4

Browse files
authored
feat: Adds Description to MongoDB::Atlas::DatabaseUser (#1337)
1 parent 03c0700 commit 650a4b4

File tree

10 files changed

+85
-51
lines changed

10 files changed

+85
-51
lines changed

cfn-resources/database-user/cmd/resource/model.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/database-user/cmd/resource/resource.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
2727
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
2828
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
29-
"go.mongodb.org/atlas-sdk/v20231115014/admin"
29+
"go.mongodb.org/atlas-sdk/v20250312002/admin"
3030
)
3131

3232
var CreateRequiredFields = []string{constants.DatabaseName, constants.ProjectID, constants.Roles, constants.Username}
@@ -68,7 +68,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
6868

6969
groupID := *currentModel.ProjectId
7070

71-
_, resp, err := client.Atlas20231115014.DatabaseUsersApi.CreateDatabaseUser(context.Background(), groupID, dbUser).Execute()
71+
_, resp, err := client.AtlasSDK.DatabaseUsersApi.CreateDatabaseUser(context.Background(), groupID, dbUser).Execute()
7272
if err != nil {
7373
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
7474
}
@@ -99,13 +99,14 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
9999
groupID := *currentModel.ProjectId
100100
username := *currentModel.Username
101101
dbName := *currentModel.DatabaseName
102-
databaseUser, resp, err := client.Atlas20231115014.DatabaseUsersApi.GetDatabaseUser(context.Background(), groupID, dbName, username).Execute()
102+
databaseUser, resp, err := client.AtlasSDK.DatabaseUsersApi.GetDatabaseUser(context.Background(), groupID, dbName, username).Execute()
103103
if err != nil {
104104
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
105105
}
106106

107107
_, _ = logger.Debugf("databaseUser:%+v", databaseUser)
108108
currentModel.DatabaseName = &databaseUser.DatabaseName
109+
currentModel.Description = databaseUser.Description
109110
currentModel.LdapAuthType = databaseUser.LdapAuthType
110111
currentModel.AWSIAMType = databaseUser.AwsIAMType
111112
currentModel.X509Type = databaseUser.X509Type
@@ -176,7 +177,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
176177

177178
groupID := *currentModel.ProjectId
178179

179-
_, resp, err := client.Atlas20231115014.DatabaseUsersApi.UpdateDatabaseUser(context.Background(), groupID, *currentModel.DatabaseName, *currentModel.Username, dbUser).Execute()
180+
_, resp, err := client.AtlasSDK.DatabaseUsersApi.UpdateDatabaseUser(context.Background(), groupID, *currentModel.DatabaseName, *currentModel.Username, dbUser).Execute()
180181
if err != nil {
181182
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
182183
}
@@ -208,7 +209,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
208209
groupID := *currentModel.ProjectId
209210
databaseName := *currentModel.DatabaseName
210211
username := *currentModel.Username
211-
_, resp, err := client.Atlas20231115014.DatabaseUsersApi.DeleteDatabaseUser(context.Background(), groupID, databaseName, username).Execute()
212+
resp, err := client.AtlasSDK.DatabaseUsersApi.DeleteDatabaseUser(context.Background(), groupID, databaseName, username).Execute()
212213
if err != nil {
213214
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
214215
}
@@ -239,7 +240,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
239240

240241
dbUserModels := make([]interface{}, 0)
241242

242-
databaseUsers, resp, err := client.Atlas20231115014.DatabaseUsersApi.ListDatabaseUsers(context.Background(), groupID).Execute()
243+
databaseUsers, resp, err := client.AtlasSDK.DatabaseUsersApi.ListDatabaseUsers(context.Background(), groupID).Execute()
243244
if err != nil {
244245
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
245246
}
@@ -249,6 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
249250
databaseUser := dbUserResults[i]
250251
var model = Model{
251252
DatabaseName: &databaseUser.DatabaseName,
253+
Description: databaseUser.Description,
252254
LdapAuthType: databaseUser.LdapAuthType,
253255
X509Type: databaseUser.X509Type,
254256
Username: &databaseUser.Username,
@@ -363,6 +365,7 @@ func setModel(currentModel *Model) (*admin.CloudDatabaseUser, error) {
363365
AwsIAMType: currentModel.AWSIAMType,
364366
X509Type: currentModel.X509Type,
365367
DeleteAfterDate: util.StringPtrToTimePtr(currentModel.DeleteAfterDate),
368+
Description: currentModel.Description,
366369
}
367370

368371
if util.IsStringPresent(currentModel.Password) {

cfn-resources/database-user/docs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy
1515
"<a href="#deleteafterdate" title="DeleteAfterDate">DeleteAfterDate</a>" : <i>String</i>,
1616
"<a href="#awsiamtype" title="AWSIAMType">AWSIAMType</a>" : <i>String</i>,
1717
"<a href="#databasename" title="DatabaseName">DatabaseName</a>" : <i>String</i>,
18+
"<a href="#description" title="Description">Description</a>" : <i>String</i>,
1819
"<a href="#labels" title="Labels">Labels</a>" : <i>[ <a href="labeldefinition.md">labelDefinition</a>, ... ]</i>,
1920
"<a href="#ldapauthtype" title="LdapAuthType">LdapAuthType</a>" : <i>String</i>,
2021
"<a href="#x509type" title="X509Type">X509Type</a>" : <i>String</i>,
@@ -36,6 +37,7 @@ Properties:
3637
<a href="#deleteafterdate" title="DeleteAfterDate">DeleteAfterDate</a>: <i>String</i>
3738
<a href="#awsiamtype" title="AWSIAMType">AWSIAMType</a>: <i>String</i>
3839
<a href="#databasename" title="DatabaseName">DatabaseName</a>: <i>String</i>
40+
<a href="#description" title="Description">Description</a>: <i>String</i>
3941
<a href="#labels" title="Labels">Labels</a>: <i>
4042
- <a href="labeldefinition.md">labelDefinition</a></i>
4143
<a href="#ldapauthtype" title="LdapAuthType">LdapAuthType</a>: <i>String</i>
@@ -84,6 +86,16 @@ _Type_: String
8486

8587
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
8688

89+
#### Description
90+
91+
Description of this database user.
92+
93+
_Required_: No
94+
95+
_Type_: String
96+
97+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
98+
8799
#### Labels
88100

89101
List that contains the key-value pairs for tagging and categorizing the MongoDB database user. The labels that you define do not appear in the console.

cfn-resources/database-user/mongodb-atlas-databaseuser.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
"description": "MongoDB database against which the MongoDB database user authenticates. MongoDB database users must provide both a username and authentication database to log into MongoDB. Default value is `admin`.",
9090
"type": "string"
9191
},
92+
"Description": {
93+
"description": "Description of this database user.",
94+
"type": "string"
95+
},
9296
"Labels": {
9397
"description": "List that contains the key-value pairs for tagging and categorizing the MongoDB database user. The labels that you define do not appear in the console.",
9498
"items": {

cfn-resources/database-user/test/cfn-test-create-inputs.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rm -rf inputs
1818
mkdir inputs
1919

2020
projectName="${1}"
21+
MONGODB_ATLAS_PROFILE=${MONGODB_ATLAS_PROFILE:-"default"}
2122
projectId=$(atlas projects list --output json | jq --arg NAME "${projectName}" -r '.results[] | select(.name==$NAME) | .id')
2223
if [ -z "$projectId" ]; then
2324
projectId=$(atlas projects create "${projectName}" --output=json | jq -r '.id')
@@ -32,8 +33,8 @@ echo "Check if a project is created $projectId"
3233
cd "$(dirname "$0")" || exit
3334
for inputFile in inputs_*; do
3435
outputFile=${inputFile//$WORDTOREMOVE/}
35-
jq --arg ProjectId "$projectId" \
36-
'.ProjectId?|=$ProjectId' \
36+
jq --arg ProjectId "$projectId" --arg Profile "${MONGODB_ATLAS_PROFILE}" \
37+
'.ProjectId?|=$ProjectId | .Profile?|=$Profile' \
3738
"$inputFile" >"../inputs/$outputFile"
3839
done
3940
cd ..
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
2-
"Username" : "DataUser1",
3-
"Password" : "MongoDB12345%",
4-
"ProjectId" : "ProjectId",
5-
"Profile" : "default",
6-
"DatabaseName": "admin",
7-
"Roles": [
8-
{ "RoleName": "readWrite",
9-
"DatabaseName": "testdb",
10-
"CollectionName": "col1"
11-
}
12-
],
13-
"Scopes": [
14-
{ "Type": "CLUSTER",
15-
"Name": "testdb"
16-
}
17-
]
18-
19-
20-
}
2+
"Username": "DataUser1",
3+
"Password": "MongoDB12345%",
4+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
5+
"Profile": "${MONGODB_ATLAS_PROFILE}",
6+
"DatabaseName": "admin",
7+
"Description": "Desc 1",
8+
"Roles": [
9+
{
10+
"RoleName": "readWrite",
11+
"DatabaseName": "testdb",
12+
"CollectionName": "col1"
13+
}
14+
],
15+
"Scopes": [
16+
{
17+
"Type": "CLUSTER",
18+
"Name": "testdb"
19+
}
20+
]
21+
}
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
{
2-
"Username" : "DataUser1",
3-
"Password" : "MongoDB12345%",
4-
"ProjectId" : "ProjectId",
5-
"Profile" : "default",
2+
"Username": "DataUser1",
3+
"Password": "MongoDB12345%",
4+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
5+
"Description": "Desc 2",
6+
"Profile": "${MONGODB_ATLAS_PROFILE}",
67
"DatabaseName": "admin",
7-
"Roles": [
8-
{ "RoleName": "readWrite",
9-
"DatabaseName": "testdb",
10-
"CollectionName": "col1"
11-
},
12-
{ "RoleName": "read",
13-
"DatabaseName": "proddb",
14-
"CollectionName": "col1"
15-
}
16-
],
17-
"Scopes": [
18-
{ "Type": "CLUSTER",
19-
"Name": "testdb"
20-
}
21-
]
22-
}
8+
"Roles": [
9+
{
10+
"RoleName": "readWrite",
11+
"DatabaseName": "testdb",
12+
"CollectionName": "col1"
13+
},
14+
{
15+
"RoleName": "read",
16+
"DatabaseName": "proddb",
17+
"CollectionName": "col1"
18+
}
19+
],
20+
"Scopes": [
21+
{
22+
"Type": "CLUSTER",
23+
"Name": "testdb"
24+
}
25+
]
26+
}

cfn-resources/database-user/test/inputs_2_create.template.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"Username": "arn:aws:iam::111111967292:role/cfn-admin",
33
"AWSIAMType": "ROLE",
4-
"ProjectId": "ProjectId",
5-
"Profile": "default",
4+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
5+
"Profile": "${MONGODB_ATLAS_PROFILE}",
66
"DatabaseName": "$external",
7+
"Description": "Desc 1",
78
"Roles": [
89
{
910
"RoleName": "readWrite",

cfn-resources/database-user/test/inputs_2_update.template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Username": "arn:aws:iam::111111967292:role/cfn-admin",
33
"AWSIAMType": "ROLE",
4-
"ProjectId": "ProjectId",
5-
"Profile": "default",
4+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
5+
"Profile": "${MONGODB_ATLAS_PROFILE}",
66
"DatabaseName": "$external",
77
"Roles": [
88
{

examples/database-user/scramUser.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"Type": "String",
2525
"NoEcho": "true",
2626
"Description": "Alphanumeric string that authenticates this database user against the database specified in databaseName. To authenticate with SCRAM-SHA, you must specify this parameter"
27+
},
28+
"Description": {
29+
"Type": "String",
30+
"Description": "Description of this database user."
2731
}
2832
},
2933
"Mappings": {},
@@ -49,6 +53,9 @@
4953
"DatabaseName": {
5054
"Ref": "DatabaseName"
5155
},
56+
"Description": {
57+
"Ref": "Description"
58+
},
5259
"Roles": [
5360
{
5461
"RoleName": "atlasAdmin",

0 commit comments

Comments
 (0)