Skip to content

Commit 68d522f

Browse files
authored
CLOUDP-298233: Postman SA support (#428)
1 parent c4bec38 commit 68d522f

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

.github/workflows/release-postman.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ jobs:
4848
BASE_URL: ${{ inputs.atlas_prod_base_url }}
4949
working-directory: ./tools/postman
5050
run: |
51-
make transform_collection
52-
make transform_collection_test
51+
make transform_collection_js
5352
5453
- name: Upload Collection to Postman
5554
env:

tools/postman/collection-description.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,28 @@ This collection is an introduction to the [MongoDB Atlas Administration API](htt
77
To test out the MongoDB Atlas Admin API collection, start by [creating a free MongoDB Atlas cluster](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/).
88
Once you have a cluster, you can [fork this collection](https://learning.postman.com/docs/collaborating-in-postman/using-version-control/forking-elements/\#create-a-fork) into your own workspace in order to manage your MongoDB Atlas resources. Make sure to also fork the MongoDB Atlas Administration API Environment at the same time.
99

10-
Once you have your cluster up and running, follow [this guide](https://www.mongodb.com/docs/atlas/configure-api-access/) to find your public and private API keys. Set each of these values as secrets in the [Postman Vault](https://learning.postman.com/docs/sending-requests/postman-vault/postman-vault-secrets/):
10+
### Authentication Using Service Accounts (OAuth)
11+
12+
Once you have your cluster up and running, follow [this guide](https://www.mongodb.com/docs/atlas/configure-api-access/) to create new Service Account.
13+
Once created copy your public and private API keys.
14+
Set each of these values as secrets in the [Postman Vault](https://learning.postman.com/docs/sending-requests/postman-vault/postman-vault-secrets/):
15+
16+
- Service Account Client ID: \`mongodb-public-clientid\`
17+
- Service Account Client Secret: \`mongodb-private-clientsecret\`
18+
19+
#### Digest Authentication
20+
21+
Alternatively to Service Account you can use [API Keys](https://www.mongodb.com/docs/atlas/configure-api-access/) authentication.
22+
Set each of these values as secrets in the [Postman Vault](https://learning.postman.com/docs/sending-requests/postman-vault/postman-vault-secrets/):
1123

1224
- public API key as the value for a key named \`mongodb-public-api-key\`
1325
- private API key as the value for a key named \`mongodb-private-api-key\`
1426

27+
Additionally to setting those values you would need to manually configure[Digest Authentication in the Collection Authentication Settings](https://learning.postman.com/docs/sending-requests/authorization/digest-auth/)
28+
29+
30+
### Using API
31+
1532
You can now explore the various endpoints. For each endpoint, edit the query and path variables such as group ID and organization ID. For some requests, like POST requests, editing the body of the request is also required.
1633

1734
For more details, you can follow along with the [Configuring Atlas in Postman With the Atlas Administration API](https://www.mongodb.com/developer/products/atlas/admin-api-postman/) blog.

tools/postman/scripts/transform-for-api.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
## NOTE: Use JS script instead.
5+
## Script is kept only for backwards compatibilty
6+
47
#########################################################
58
# Prepare collection for Postman API
69
# Environment variables:
@@ -27,7 +30,6 @@ DESCRIPTION_FILE=${DESCRIPTION_FILE:-"../collection-description.md"}
2730

2831
TOGGLE_INCLUDE_BODY=${TOGGLE_INCLUDE_BODY:-true}
2932
TOGGLE_ADD_DOCS_LINKS=${TOGGLE_ADD_DOCS_LINKS:-true}
30-
TOKEN_URL_ENV=${TOKEN_URL_ENV:-""}
3133

3234
current_api_revision=$(<"$OPENAPI_FOLDER/$VERSION_FILE_NAME")
3335

tools/postman/scripts/transform-postman.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const VERSION_FILE_NAME = process.env.VERSION_FILE_NAME || 'version.txt';
2626
const DESCRIPTION_FILE = process.env.DESCRIPTION_FILE || './collection-description.md';
2727
const TOGGLE_INCLUDE_BODY = process.env.TOGGLE_INCLUDE_BODY !== 'false';
2828
const TOGGLE_ADD_DOCS_LINKS = process.env.TOGGLE_ADD_DOCS_LINKS === 'true';
29-
const TOKEN_URL_ENV = process.env.TOKEN_URL_ENV || '';
3029
const BASE_URL = process.env.BASE_URL || '';
3130

3231
// Dedicated transformation for postman collection.json file.
@@ -103,9 +102,21 @@ const transform = () => {
103102
});
104103
}
105104

106-
if (TOKEN_URL_ENV) {
107-
console.log(`Adding client credentials auth url variable ${TOKEN_URL_ENV}`);
108-
collection.collection.variable.push({ key: 'clientCredentialsTokenUrl', value: TOKEN_URL_ENV });
105+
if (collection.collection.auth && collection.collection.auth.oauth2) {
106+
collection.collection.auth.oauth2.push[
107+
({
108+
key: 'clientSecret',
109+
value: '{{vault:mongodb-private-clientsecret}}',
110+
type: 'string',
111+
},
112+
{
113+
key: 'clientId',
114+
value: '{{vault:mongodb-public-clientid}}',
115+
type: 'string',
116+
})
117+
];
118+
} else {
119+
throw 'Failed to add required authentication variables';
109120
}
110121

111122
saveJsonFile(path.join(TMP_FOLDER, COLLECTION_TRANSFORMED_FILE_NAME), collection);

0 commit comments

Comments
 (0)