Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cfn-resources/custom-db-role/cmd/resource/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cfn-resources/custom-db-role/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ func (r Resource) toAtlasResource() admin.DatabasePermittedNamespaceResource {
out := admin.DatabasePermittedNamespaceResource{
Cluster: false,
}
if util.IsStringPresent(r.Collection) {
if r.Collection != nil {
out.Collection = *r.Collection
}

if util.IsStringPresent(r.DB) {
if r.DB != nil {
out.Db = *r.DB
}

Expand Down
4 changes: 2 additions & 2 deletions cfn-resources/custom-db-role/docs/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy

#### Collection

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.
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.

_Required_: No

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

#### DB

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.
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.

_Required_: No

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"properties": {
"Collection": {
"type": "string",
"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."
"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."
},
"DB": {
"type": "string",
"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."
"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."
},
"Cluster": {
"type": "boolean",
Expand Down
17 changes: 10 additions & 7 deletions cfn-resources/custom-db-role/test/cfn-test-create-inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rm -rf inputs
mkdir inputs

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

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

jq --arg projectId "$projectId" \
'.ProjectId?|=$projectId ' \
"$(dirname "$0")/inputs_1_create.template.json" >"inputs/inputs_1_create.json"

jq --arg projectId "$projectId" \
'.ProjectId?|=$projectId ' \
"$(dirname "$0")/inputs_1_update.template.json" >"inputs/inputs_1_update.json"
cd "$(dirname "$0")" || exit
WORDTOREMOVE="template."
for inputFile in inputs_*; do
outputFile=${inputFile//$WORDTOREMOVE/}
jq --arg ProjectId "$projectId" --arg Profile "${MONGODB_ATLAS_PROFILE}" \
'.ProjectId?|=$ProjectId | .Profile?|=$Profile' \
"$inputFile" >"../inputs/$outputFile"
done
cd ..
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ProjectId": "",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
"Actions": [
{
"Action": "FIND",
Expand All @@ -12,5 +12,5 @@
}
],
"RoleName": "testcreate",
"Profile": "default"
"Profile": "${MONGODB_ATLAS_PROFILE}"
}
13 changes: 11 additions & 2 deletions cfn-resources/custom-db-role/test/inputs_1_update.template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ProjectId": "",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
"Actions": [
{
"Action": "FIND",
Expand All @@ -9,8 +9,17 @@
"DB": "sample_airbnb"
}
]
},
{
"Action": "INSERT",
"Resources": [
{
"Collection": "listingsAndReviews",
"DB": "sample_airbnb"
}
]
}
],
"RoleName": "testcreate",
"Profile": "default"
"Profile": "${MONGODB_ATLAS_PROFILE}"
}
16 changes: 16 additions & 0 deletions cfn-resources/custom-db-role/test/inputs_2_create.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
"Actions": [
{
"Action": "FIND",
"Resources": [
{
"Collection": "",
"DB": ""
}
]
}
],
"RoleName": "testcreate-cfn-empty-db",
"Profile": "${MONGODB_ATLAS_PROFILE}"
}
16 changes: 16 additions & 0 deletions cfn-resources/custom-db-role/test/inputs_2_update.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
"Actions": [
{
"Action": "INSERT",
"Resources": [
{
"Collection": "",
"DB": ""
}
]
}
],
"RoleName": "testcreate-cfn-empty-db",
"Profile": "${MONGODB_ATLAS_PROFILE}"
}
Loading