Skip to content

Commit 070e80a

Browse files
authored
feat: Adds support for empty collection and DatabaseName for CustomDBRole (#1341)
1 parent 650a4b4 commit 070e80a

File tree

9 files changed

+80
-17
lines changed

9 files changed

+80
-17
lines changed

cfn-resources/custom-db-role/cmd/resource/config.go

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

cfn-resources/custom-db-role/cmd/resource/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ func (r Resource) toAtlasResource() admin.DatabasePermittedNamespaceResource {
249249
out := admin.DatabasePermittedNamespaceResource{
250250
Cluster: false,
251251
}
252-
if util.IsStringPresent(r.Collection) {
252+
if r.Collection != nil {
253253
out.Collection = *r.Collection
254254
}
255255

256-
if util.IsStringPresent(r.DB) {
256+
if r.DB != nil {
257257
out.Db = *r.DB
258258
}
259259

cfn-resources/custom-db-role/docs/resource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy
2828

2929
#### Collection
3030

31-
Human-readable label that identifies the collection on which you grant the action to one MongoDB user. If you don't set this parameter, you grant the action to all collections in the database specified in the actions.resources.db parameter. If you set "actions.resources.cluster" : true, MongoDB Cloud ignores this parameter.
31+
Human-readable label that identifies the collection on which you grant the action to one MongoDB user. If you don't set this parameter, you grant the action to all collections in the database specified in the actions.resources.db parameter. If you set "actions.resources.cluster" : true, MongoDB Cloud ignores this parameter. Use the empty string ("") to allow an action on all collections.
3232

3333
_Required_: No
3434

@@ -38,7 +38,7 @@ _Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormati
3838

3939
#### DB
4040

41-
Human-readable label that identifies the database on which you grant the action to one MongoDB user. If you set "actions.resources.cluster" : true, MongoDB Cloud ignores this parameter.
41+
Human-readable label that identifies the database on which you grant the action to one MongoDB user. If you set "actions.resources.cluster" : true, MongoDB Cloud ignores this parameter. Use the empty string ("") to allow an action on all databases.
4242

4343
_Required_: No
4444

cfn-resources/custom-db-role/mongodb-atlas-customdbrole.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
"properties": {
2121
"Collection": {
2222
"type": "string",
23-
"description": "Human-readable label that identifies the collection on which you grant the action to one MongoDB user. If you don't set this parameter, you grant the action to all collections in the database specified in the actions.resources.db parameter. If you set \"actions.resources.cluster\" : true, MongoDB Cloud ignores this parameter."
23+
"description": "Human-readable label that identifies the collection on which you grant the action to one MongoDB user. If you don't set this parameter, you grant the action to all collections in the database specified in the actions.resources.db parameter. If you set \"actions.resources.cluster\" : true, MongoDB Cloud ignores this parameter. Use the empty string (\"\") to allow an action on all collections."
2424
},
2525
"DB": {
2626
"type": "string",
27-
"description": "Human-readable label that identifies the database on which you grant the action to one MongoDB user. If you set \"actions.resources.cluster\" : true, MongoDB Cloud ignores this parameter."
27+
"description": "Human-readable label that identifies the database on which you grant the action to one MongoDB user. If you set \"actions.resources.cluster\" : true, MongoDB Cloud ignores this parameter. Use the empty string (\"\") to allow an action on all databases."
2828
},
2929
"Cluster": {
3030
"type": "boolean",

cfn-resources/custom-db-role/test/cfn-test-create-inputs.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ rm -rf inputs
1919
mkdir inputs
2020

2121
projectName="${1}"
22+
MONGODB_ATLAS_PROFILE=${MONGODB_ATLAS_PROFILE:-"default"}
2223
projectId=$(atlas projects list --output json | jq --arg NAME "${projectName}" -r '.results[] | select(.name==$NAME) | .id')
2324
if [ -z "$projectId" ]; then
2425
projectId=$(atlas projects create "${projectName}" --output=json | jq -r '.id')
@@ -30,10 +31,12 @@ fi
3031

3132
echo "Created project \"${projectName}\" with id: ${projectId}"
3233

33-
jq --arg projectId "$projectId" \
34-
'.ProjectId?|=$projectId ' \
35-
"$(dirname "$0")/inputs_1_create.template.json" >"inputs/inputs_1_create.json"
36-
37-
jq --arg projectId "$projectId" \
38-
'.ProjectId?|=$projectId ' \
39-
"$(dirname "$0")/inputs_1_update.template.json" >"inputs/inputs_1_update.json"
34+
cd "$(dirname "$0")" || exit
35+
WORDTOREMOVE="template."
36+
for inputFile in inputs_*; do
37+
outputFile=${inputFile//$WORDTOREMOVE/}
38+
jq --arg ProjectId "$projectId" --arg Profile "${MONGODB_ATLAS_PROFILE}" \
39+
'.ProjectId?|=$ProjectId | .Profile?|=$Profile' \
40+
"$inputFile" >"../inputs/$outputFile"
41+
done
42+
cd ..

cfn-resources/custom-db-role/test/inputs_1_create.template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"ProjectId": "",
2+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
33
"Actions": [
44
{
55
"Action": "FIND",
@@ -12,5 +12,5 @@
1212
}
1313
],
1414
"RoleName": "testcreate",
15-
"Profile": "default"
15+
"Profile": "${MONGODB_ATLAS_PROFILE}"
1616
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"ProjectId": "",
2+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
33
"Actions": [
44
{
55
"Action": "FIND",
@@ -9,8 +9,17 @@
99
"DB": "sample_airbnb"
1010
}
1111
]
12+
},
13+
{
14+
"Action": "INSERT",
15+
"Resources": [
16+
{
17+
"Collection": "listingsAndReviews",
18+
"DB": "sample_airbnb"
19+
}
20+
]
1221
}
1322
],
1423
"RoleName": "testcreate",
15-
"Profile": "default"
24+
"Profile": "${MONGODB_ATLAS_PROFILE}"
1625
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
3+
"Actions": [
4+
{
5+
"Action": "FIND",
6+
"Resources": [
7+
{
8+
"Collection": "",
9+
"DB": ""
10+
}
11+
]
12+
}
13+
],
14+
"RoleName": "testcreate-cfn-empty-db",
15+
"Profile": "${MONGODB_ATLAS_PROFILE}"
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
3+
"Actions": [
4+
{
5+
"Action": "INSERT",
6+
"Resources": [
7+
{
8+
"Collection": "",
9+
"DB": ""
10+
}
11+
]
12+
}
13+
],
14+
"RoleName": "testcreate-cfn-empty-db",
15+
"Profile": "${MONGODB_ATLAS_PROFILE}"
16+
}

0 commit comments

Comments
 (0)