Skip to content

Commit bbfb9c6

Browse files
authored
PHPC-2395: Fetch Atlas connectivity URIs from AWS Secrets Manager (#1579)
* Conditionally source setup-secrets.sh from run-tests.sh * Use subprocess.exec * Use bash -c option to invoke command with its own args
1 parent 774ee78 commit bbfb9c6

File tree

7 files changed

+50
-57
lines changed

7 files changed

+50
-57
lines changed

.evergreen/config/functions.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ functions:
210210
params:
211211
include_expansions_in_env:
212212
- API_VERSION
213-
- ATLAS_CONNECTIVITY_URIS
214213
- CRYPT_SHARED_LIB_PATH
215214
- MONGODB_URI
216215
- APPEND_URI

.evergreen/config/test-tasks.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ tasks:
22
- name: "test-atlas-connectivity"
33
tags: ["atlas", "nodb"]
44
commands:
5+
# This creates secrets-export.sh, which is later sourced by run-tests.sh
6+
- command: subprocess.exec
7+
params:
8+
working_dir: "src"
9+
binary: bash
10+
args:
11+
- -c
12+
- ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect
513
- func: "run tests"
614
vars:
715
TESTS: "tests/atlas.phpt"

.evergreen/run-tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ else
3939
echo "crypt_shared library will be loaded from path: $CRYPT_SHARED_LIB_PATH"
4040
fi
4141

42+
# Conditionally source setup-secrets.sh created by drivers-evergreen-tools
43+
if [ -f "${PROJECT_DIRECTORY}/secrets-export.sh" ]; then
44+
source ${PROJECT_DIRECTORY}/secrets-export.sh
45+
fi
46+
4247
echo "Running tests with URI: $MONGODB_URI"
4348

4449
# Run the tests, and store the results in a junit result file

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ mongodb-*tgz
6767

6868
# Coverage files
6969
coverage*
70+
71+
# drivers-evergreen-tools secrets handling
72+
secrets-export.sh

tests/atlas.phpt

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,40 @@
22
Atlas Connectivity Tests
33
--SKIPIF--
44
<?php require __DIR__ . "/utils/basic-skipif.inc"; ?>
5-
<?php skip_if_no_atlas_connectivity_urls(); ?>
65
<?php if (getenv('TESTS') !== 'tests/atlas.phpt') { die('skip Atlas tests not wanted'); } ?>
76
--FILE--
87
<?php
98
require_once __DIR__ . "/utils/basic.inc";
109

10+
$envs = [
11+
'ATLAS_SERVERLESS',
12+
'ATLAS_SRV_SERVERLESS',
13+
'ATLAS_FREE',
14+
'ATLAS_SRV_FREE',
15+
'ATLAS_REPL',
16+
'ATLAS_SRV_REPL',
17+
'ATLAS_SHRD',
18+
'ATLAS_SRV_SHRD',
19+
'ATLAS_TLS11',
20+
'ATLAS_SRV_TLS11',
21+
'ATLAS_TLS12',
22+
'ATLAS_SRV_TLS12',
23+
];
24+
1125
$command = new \MongoDB\Driver\Command(['ping' => 1]);
1226
$query = new \MongoDB\Driver\Query([]);
1327

14-
foreach (getAtlasConnectivityUrls() as $url) {
15-
if (strpos($url, '#') === 0) {
16-
echo trim(substr($url, 1)), "\n";
28+
foreach ($envs as $env) {
29+
echo $env, ': ';
30+
$uri = getenv($env);
31+
32+
if (! is_string($uri)) {
33+
echo "FAIL: env var is undefined\n";
1734
continue;
1835
}
1936

2037
try {
21-
$m = new \MongoDB\Driver\Manager($url);
38+
$m = new \MongoDB\Driver\Manager($uri);
2239
$m->executeCommand('admin', $command);
2340
iterator_to_array($m->executeQuery('test.test', $query));
2441
echo "PASS\n";
@@ -30,25 +47,16 @@ foreach (getAtlasConnectivityUrls() as $url) {
3047
===DONE===
3148
<?php exit(0); ?>
3249
--EXPECTF--
33-
Atlas Serverless
34-
PASS
35-
PASS
36-
Atlas replica set (4.0)
37-
PASS
38-
PASS
39-
Atlas sharded cluster (4.0)
40-
PASS
41-
PASS
42-
Atlas free tier replica set
43-
PASS
44-
PASS
45-
Atlas with only TLSv1.1 enabled (4.0)
46-
PASS
47-
PASS
48-
Atlas with only TLSv1.2 enabled (4.0)
49-
PASS
50-
PASS
51-
Atlas with only TLSv1.2 enabled (4.0) and bad credentials
52-
FAIL: %s
53-
FAIL: %s
50+
ATLAS_SERVERLESS: PASS
51+
ATLAS_SRV_SERVERLESS: PASS
52+
ATLAS_FREE: PASS
53+
ATLAS_SRV_FREE: PASS
54+
ATLAS_REPL: PASS
55+
ATLAS_SRV_REPL: PASS
56+
ATLAS_SHRD: PASS
57+
ATLAS_SRV_SHRD: PASS
58+
ATLAS_TLS11: PASS
59+
ATLAS_SRV_TLS11: PASS
60+
ATLAS_TLS12: PASS
61+
ATLAS_SRV_TLS12: PASS
5462
===DONE===

tests/utils/skipif.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,3 @@ function skip_if_no_crypt_shared()
494494
exit('skip crypt_shared is not available');
495495
}
496496
}
497-
498-
function skip_if_no_atlas_connectivity_urls()
499-
{
500-
if (getAtlasConnectivityUrls() === []) {
501-
exit('skip No Atlas URIs found');
502-
}
503-
}

tests/utils/tools.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -847,26 +847,3 @@ function failGetMore(Manager $manager)
847847

848848
throw new Exception("Trying to configure a getMore fail point for a server version ($version) that doesn't support it");
849849
}
850-
851-
function getAtlasConnectivityUrls(): array
852-
{
853-
$atlasUriString = getenv('ATLAS_CONNECTIVITY_URIS') ?: '';
854-
if (!$atlasUriString) {
855-
return [];
856-
}
857-
858-
$rawUrls = explode("\n", $atlasUriString);
859-
860-
$urls = [];
861-
foreach ($rawUrls as $url) {
862-
$url = trim($url);
863-
864-
if ($url == '') {
865-
continue;
866-
}
867-
868-
$urls[] = $url;
869-
}
870-
871-
return $urls;
872-
}

0 commit comments

Comments
 (0)