Skip to content

Commit 1c69b9c

Browse files
Merge branch 'master' into CLOUDP-369801-federated-settings-identity-provider
2 parents 75b844d + b075c56 commit 1c69b9c

95 files changed

Lines changed: 5272 additions & 426 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/contract-testing.yaml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
search-deployment: ${{ steps.filter.outputs.search-deployment }}
3232
stream-connection: ${{ steps.filter.outputs.stream-connection }}
3333
stream-instance: ${{ steps.filter.outputs.stream-instance }}
34+
stream-processor: ${{ steps.filter.outputs.stream-processor }}
3435
stream-workspace: ${{ steps.filter.outputs.stream-workspace }}
3536
steps:
3637
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
@@ -79,6 +80,8 @@ jobs:
7980
- 'cfn-resources/stream-connection/**'
8081
stream-instance:
8182
- 'cfn-resources/stream-instance/**'
83+
stream-processor:
84+
- 'cfn-resources/stream-processor/**'
8285
stream-workspace:
8386
- 'cfn-resources/stream-workspace/**'
8487
access-list-api-key:
@@ -901,6 +904,46 @@ jobs:
901904
pushd cfn-resources/stream-instance
902905
make create-test-resources
903906
cat inputs/inputs_1_create.json
907+
make run-contract-testing
908+
make delete-test-resources
909+
stream-processor:
910+
needs: change-detection
911+
if: ${{ needs.change-detection.outputs.stream-processor == 'true' }}
912+
runs-on: ubuntu-latest
913+
steps:
914+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
915+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
916+
with:
917+
go-version-file: 'cfn-resources/go.mod'
918+
- name: setup Atlas CLI
919+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
920+
- uses: aws-actions/setup-sam@c2a20b1822cc4a6bc594ff7f1dbb658758e383c3
921+
with:
922+
use-installer: true
923+
- uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
924+
with:
925+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
926+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
927+
aws-region: eu-west-1
928+
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
929+
with:
930+
python-version: '3.9'
931+
cache: 'pip' # caching pip dependencies
932+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
933+
- name: Run the Contract test
934+
shell: bash
935+
env:
936+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
937+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
938+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
939+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
940+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
941+
run: |
942+
cd cfn-resources/stream-processor
943+
make create-test-resources
944+
945+
cat inputs/*
946+
904947
make run-contract-testing
905948
make delete-test-resources
906949
stream-workspace:
@@ -943,4 +986,4 @@ jobs:
943986
cat inputs/inputs_1_update.json
944987
945988
make run-contract-testing
946-
make delete-test-resources
989+
make delete-test-resources

cfn-resources/federated-query-limit/cmd/resource/resource.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"fmt"
2020
"net/http"
2121

22+
"go.mongodb.org/atlas-sdk/v20250312012/admin"
23+
2224
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2325
"github.com/aws/aws-sdk-go-v2/aws"
2426
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
@@ -29,7 +31,6 @@ import (
2931
progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
3032
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
3133
"github.com/spf13/cast"
32-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
3334
)
3435

3536
var CreateOrUpdateRequiredFields = []string{constants.ProjectID, constants.TenantName, constants.LimitName, constants.Value}
@@ -132,7 +133,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
132133
// Check already exists or not
133134
_, response, err := getFederatedQueryLimit(atlas, currentModel)
134135

135-
if err != nil && response.StatusCode == http.StatusNotFound {
136+
if err != nil && util.StatusNotFound(response) {
136137
return handler.ProgressEvent{
137138
OperationStatus: handler.Failed,
138139
Message: DoesntExists,
@@ -157,7 +158,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
157158
if peErr != nil {
158159
return *peErr, nil
159160
}
160-
_, response, err := client.Atlas20231115014.DataFederationApi.DeleteOneDataFederationInstanceQueryLimit(
161+
response, err := client.AtlasSDK.DataFederationApi.DeleteDataFederationLimit(
161162
context.Background(),
162163
*currentModel.ProjectId,
163164
*currentModel.TenantName,
@@ -191,7 +192,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
191192
if peErr != nil {
192193
return *peErr, nil
193194
}
194-
listQueryLimitsAPIResult, response, err := client.Atlas20231115014.DataFederationApi.ReturnFederatedDatabaseQueryLimits(
195+
listQueryLimitsAPIResult, response, err := client.AtlasSDK.DataFederationApi.ListDataFederationLimits(
195196
context.Background(),
196197
*currentModel.ProjectId,
197198
*currentModel.TenantName,
@@ -220,7 +221,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
220221
func handleError(response *http.Response, method string, err error) (handler.ProgressEvent, error) {
221222
errMsg := fmt.Sprintf("%s error:%s", method, err.Error())
222223
_, _ = logger.Warn(errMsg)
223-
if response.StatusCode == http.StatusConflict {
224+
if util.StatusConflict(response) {
224225
return handler.ProgressEvent{
225226
OperationStatus: handler.Failed,
226227
Message: errMsg,
@@ -229,8 +230,8 @@ func handleError(response *http.Response, method string, err error) (handler.Pro
229230
return progress_events.GetFailedEventByResponse(errMsg, response), nil
230231
}
231232

232-
func getFederatedQueryLimit(client *util.MongoDBClient, currentModel *Model) (*admin20231115014.DataFederationTenantQueryLimit, *http.Response, error) {
233-
getQueryLimitAPIRequest := client.Atlas20231115014.DataFederationApi.ReturnFederatedDatabaseQueryLimit(
233+
func getFederatedQueryLimit(client *util.MongoDBClient, currentModel *Model) (*admin.DataFederationTenantQueryLimit, *http.Response, error) {
234+
getQueryLimitAPIRequest := client.AtlasSDK.DataFederationApi.GetDataFederationLimit(
234235
context.Background(),
235236
*currentModel.ProjectId,
236237
*currentModel.TenantName,
@@ -242,7 +243,7 @@ func getFederatedQueryLimit(client *util.MongoDBClient, currentModel *Model) (*a
242243

243244
func createOrUpdateQueryLimit(currentModel *Model, client *util.MongoDBClient, method string) (handler.ProgressEvent, error) {
244245
queryLimitInput := currentModel.setQueryLimit()
245-
queryLimit, response, err := client.Atlas20231115014.DataFederationApi.CreateOneDataFederationQueryLimit(
246+
queryLimit, response, err := client.AtlasSDK.DataFederationApi.SetDataFederationLimit(
246247
context.Background(),
247248
*currentModel.ProjectId,
248249
*currentModel.TenantName,
@@ -262,22 +263,24 @@ func createOrUpdateQueryLimit(currentModel *Model, client *util.MongoDBClient, m
262263
ResourceModel: currentModel}, nil
263264
}
264265

265-
func (model *Model) setQueryLimit() *admin20231115014.DataFederationTenantQueryLimit {
266-
queryLimit := &admin20231115014.DataFederationTenantQueryLimit{
266+
func (model *Model) setQueryLimit() *admin.DataFederationTenantQueryLimit {
267+
queryLimit := &admin.DataFederationTenantQueryLimit{
267268
OverrunPolicy: model.OverrunPolicy,
268269
}
269270
if model.Value != nil {
270271
queryLimit.Value = cast.ToInt64(*model.Value)
271272
}
272273
return queryLimit
273274
}
274-
func (model *Model) getQueryLimit(atlasQueryLimit *admin20231115014.DataFederationTenantQueryLimit) *Model {
275+
func (model *Model) getQueryLimit(atlasQueryLimit *admin.DataFederationTenantQueryLimit) *Model {
275276
if atlasQueryLimit == nil {
276277
return nil
277278
}
278279

279280
model.TenantName = atlasQueryLimit.TenantName
280-
model.OverrunPolicy = atlasQueryLimit.OverrunPolicy
281+
if atlasQueryLimit.OverrunPolicy != nil {
282+
model.OverrunPolicy = atlasQueryLimit.OverrunPolicy
283+
}
281284
model.LimitName = &atlasQueryLimit.Name
282285
if atlasQueryLimit.CurrentUsage != nil {
283286
currentUsage := cast.ToString(atlasQueryLimit.CurrentUsage)

cfn-resources/federated-query-limit/docs/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ _Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/l
7777

7878
#### OverrunPolicy
7979

80-
Only used for Data Federation limits. Action to take when the usage limit is exceeded. If limit span is set to QUERY, this is ignored because MongoDB Cloud stops the query when it exceeds the usage limit. "enum" : [ "BLOCK", "BLOCK_AND_KILL" ]
80+
Action to take when the usage limit is exceeded. If limit span is set to QUERY, this is ignored because MongoDB Cloud stops the query when it exceeds the usage limit.
8181

8282
_Required_: No
8383

@@ -117,10 +117,6 @@ For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::G
117117

118118
Amount that indicates the current usage of the limit.
119119

120-
#### DefaultLimit
121-
122-
Default value of the limit.
123-
124120
#### LastModifiedDate
125121

126122
Only used for Data Federation limits. Timestamp that indicates when this usage limit was last modified. This field uses the ISO 8601 timestamp format in UTC.

cfn-resources/federated-query-limit/mongodb-atlas-federatedquerylimit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"OverrunPolicy": {
4545
"type": "string",
46-
"description": "Only used for Data Federation limits. Action to take when the usage limit is exceeded. If limit span is set to QUERY, this is ignored because MongoDB Cloud stops the query when it exceeds the usage limit. \"enum\" : [ \"BLOCK\", \"BLOCK_AND_KILL\" ]"
46+
"description": "Action to take when the usage limit is exceeded. If limit span is set to QUERY, this is ignored because MongoDB Cloud stops the query when it exceeds the usage limit."
4747
},
4848
"Value": {
4949
"type": "string",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# MongoDB::Atlas::FederatedQueryLimit
2+
3+
## Prerequisites
4+
### Resources needed to run the manual QA
5+
All resources are created as part of `cfn-testing-helper.sh`:
6+
7+
- Atlas Project
8+
- Federated Database Instance (Tenant)
9+
10+
## Manual QA
11+
Please follow the steps in [TESTING.md](../../../TESTING.md).
12+
13+
14+
### Success criteria when testing the resource
15+
1. Ensure general [CFN resource success criteria](../../../TESTING.md#success-criteria-when-testing-the-resource) for this resource is met.
16+
17+
## Important Links
18+
- [API Documentation](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-data-federation)
19+
20+
## Unit Testing Locally
21+
22+
The local tests are integrated with the AWS `sam local` and `cfn invoke` tooling features:
23+
24+
```
25+
sam local start-lambda --skip-pull-image
26+
```
27+
then in another shell:
28+
```bash
29+
repo_root=$(git rev-parse --show-toplevel)
30+
source <(${repo_root}/quickstart-mongodb-atlas/scripts/export-mongocli-config.py)
31+
cd ${repo_root}/cfn-resources/federated-query-limit
32+
./test/cfn-test-create-inputs.sh YourProjectName YourTenantName > test.request.json
33+
echo "Sample request:"
34+
cat test.request.json
35+
cfn invoke resource CREATE test.request.json
36+
cfn invoke resource DELETE test.request.json
37+
cd -
38+
```
39+
40+
Both CREATE & DELETE tests must pass.

cfn-resources/federated-query-limit/test/cfn-test-create-inputs.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ jq --arg projectId "${projectId}" \
5656
--arg profile "$profile" \
5757
'.Profile?|=$profile |.ProjectId?|=$projectId | .TenantName?|=$tenantName' \
5858
"$(dirname "$0")/inputs_1_update.template.json" >"inputs/inputs_1_update.json"
59+
60+
jq --arg projectId "${projectId}" \
61+
--arg tenantName "${tenantName}" \
62+
--arg profile "$profile" \
63+
'.Profile?|=$profile |.ProjectId?|=$projectId | .TenantName?|=$tenantName' \
64+
"$(dirname "$0")/inputs_2_create.template.json" >"inputs/inputs_2_create.json"
65+
66+
jq --arg projectId "${projectId}" \
67+
--arg tenantName "${tenantName}" \
68+
--arg profile "$profile" \
69+
'.Profile?|=$profile |.ProjectId?|=$projectId | .TenantName?|=$tenantName' \
70+
"$(dirname "$0")/inputs_2_update.template.json" >"inputs/inputs_2_update.json"

cfn-resources/federated-query-limit/test/inputs_1_create.template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"ProjectId": "",
33
"TenantName":"",
44
"LimitName": "bytesProcessed.query",
5+
"OverrunPolicy": "BLOCK",
56
"Value": "2000000000",
67
"Profile": "default"
78
}

cfn-resources/federated-query-limit/test/inputs_1_update.template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"ProjectId": "",
33
"TenantName":"",
44
"LimitName": "bytesProcessed.query",
5+
"OverrunPolicy": "BLOCK_AND_KILL",
56
"Value": "3000000000",
67
"Profile": "default"
78
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ProjectId": "",
3+
"TenantName":"",
4+
"LimitName": "bytesProcessed.query",
5+
"Value": "2000000000",
6+
"Profile": "default"
7+
}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ProjectId": "",
3+
"TenantName":"",
4+
"LimitName": "bytesProcessed.query",
5+
"Value": "3000000000",
6+
"Profile": "default"
7+
}
8+

0 commit comments

Comments
 (0)