Skip to content

Commit a5fc3fc

Browse files
committed
use tls stuff in uri
1 parent 0a13ee9 commit a5fc3fc

10 files changed

+14
-25
lines changed
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
1-
# Restore sample_mflix database with TLS (auto-detect modern vs legacy flags)
1+
# Restore sample_mflix database. Provide any TLS parameters directly within MDB_CONNECTION_STRING.
22
kubectl exec -n "${MDB_NS}" --context "${K8S_CTX}" \
33
mongodb-tools-pod -- env MDB_CONNECTION_STRING="${MDB_CONNECTION_STRING}" /bin/bash -eu -c "$(cat <<'EOF'
44
set -o pipefail
55
echo "Downloading sample database archive..."
66
curl -fSL https://atlas-education.s3.amazonaws.com/sample_mflix.archive -o /tmp/sample_mflix.archive
77
8-
echo "Detecting mongorestore TLS flag support..."
9-
if mongorestore --help 2>&1 | grep -q -- '--tlsCAFile'; then
10-
TLS_FLAG="--tls"
11-
CA_FLAG="--tlsCAFile"
12-
else
13-
TLS_FLAG="--ssl"
14-
CA_FLAG="--sslCAFile"
15-
fi
16-
17-
echo "Using $TLS_FLAG with $CA_FLAG"
18-
19-
echo "Restoring sample database with TLS"
8+
echo "Restoring sample database"
209
mongorestore \
2110
--archive=/tmp/sample_mflix.archive \
2211
--verbose=1 \
2312
--drop \
2413
--nsInclude 'sample_mflix.*' \
25-
"$TLS_FLAG" \
26-
"$CA_FLAG" /tls/ca.crt \
2714
--uri="${MDB_CONNECTION_STRING}"
2815
EOF
2916
)"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \
2-
mongosh --quiet --tls --tlsCAFile /tls/ca.crt "${MDB_CONNECTION_STRING}" \
2+
mongosh --quiet "${MDB_CONNECTION_STRING}" \
33
--eval "use sample_mflix" \
44
--eval 'db.movies.createSearchIndex("default", { mappings: { dynamic: true } });'

docs/search/03-search-query-usage/code_snippets/03_0435_create_vector_search_index.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \
2-
mongosh --quiet --tls --tlsCAFile /tls/ca.crt "${MDB_CONNECTION_STRING}" \
2+
mongosh --quiet "${MDB_CONNECTION_STRING}" \
33
--eval "use sample_mflix" \
44
--eval 'db.embedded_movies.createSearchIndex("vector_index", "vectorSearch",
55
{ "fields": [ {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \
2-
mongosh --quiet --tls --tlsCAFile /tls/ca.crt "${MDB_CONNECTION_STRING}" \
2+
mongosh --quiet "${MDB_CONNECTION_STRING}" \
33
--eval "use sample_mflix" \
44
--eval 'db.runCommand({"listSearchIndexes": "movies"});'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \
2-
mongosh --quiet --tls --tlsCAFile /tls/ca.crt "${MDB_CONNECTION_STRING}" \
2+
mongosh --quiet "${MDB_CONNECTION_STRING}" \
33
--eval "use sample_mflix" \
44
--eval 'db.runCommand({"listSearchIndexes": "embedded_movies"});'

docs/search/03-search-query-usage/code_snippets/03_0450_execute_search_query.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ EOF
4141
kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" \
4242
mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
4343
echo '${mdb_script}' > /tmp/mdb_script.js
44-
mongosh --quiet --tls --tlsCAFile /tls/ca.crt "${MDB_CONNECTION_STRING}" < /tmp/mdb_script.js
44+
mongosh --quiet "${MDB_CONNECTION_STRING}" < /tmp/mdb_script.js
4545
EOF
4646
)"

docs/search/03-search-query-usage/code_snippets/03_0455_execute_vector_search_query.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ EOF
2525

2626
kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF
2727
echo '${mdb_script}' > /tmp/mdb_script.js
28-
mongosh --quiet --tls --tlsCAFile /tls/ca.crt "${MDB_CONNECTION_STRING}" < /tmp/mdb_script.js
28+
mongosh --quiet "${MDB_CONNECTION_STRING}" < /tmp/mdb_script.js
2929
EOF
3030
)"

docs/search/03-search-query-usage/env_variables.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
# user only for the connection string in MDB_CONNECTION_STRING env var below
1616
#export MDB_RESOURCE_NAME="mdbc-rs"
1717

18-
# TLS-related secret names used by the snippets in this module
18+
# TLS-related resources used by the snippets in this module
1919
#export MDB_TLS_CA_SECRET_NAME="${MDB_RESOURCE_NAME}-ca"
20+
#export MDB_TLS_CA_CONFIGMAP="${MDB_RESOURCE_NAME}-ca-configmap"
2021
#export MDB_TLS_SERVER_CERT_SECRET_NAME="${MDB_RESOURCE_NAME}-tls"
2122
#export MDB_SEARCH_TLS_SECRET_NAME="${MDB_RESOURCE_NAME}-search-tls"
2223

2324
# default connection string if MongoDB database is deployed using the operator
2425
#export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}"
26+
# To enable TLS for the shared snippets, append driver options directly to the connection string, for example:
27+
#export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}&tls=true&tlsCAFile=%2Ftls%2Fca.crt"
2528

scripts/code_snippets/tests/test_kind_search_community_snippets.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ echo "Sourcing env variables for ${CODE_SNIPPETS_FLAVOR} flavor"
3131
test -f "${test_dir}/env_variables_${CODE_SNIPPETS_FLAVOR}.sh" && source "${test_dir}/env_variables_${CODE_SNIPPETS_FLAVOR}.sh"
3232

3333
export MDB_RESOURCE_NAME="mdbc-rs"
34-
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}"
34+
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}&tls=true&tlsCAFile=/tls/ca.crt"
3535

3636
${test_dir}/test.sh
37-

scripts/code_snippets/tests/test_kind_search_enterprise_snippets.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ echo "Sourcing env variables for ${CODE_SNIPPETS_FLAVOR} flavor"
3030
# shellcheck disable=SC1090
3131
test -f "${test_dir}/env_variables_${CODE_SNIPPETS_FLAVOR}.sh" && source "${test_dir}/env_variables_${CODE_SNIPPETS_FLAVOR}.sh"
3232

33-
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}"
33+
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}&tls=true&tlsCAFile=/tls/ca.crt"
3434

3535
${test_dir}/test.sh

0 commit comments

Comments
 (0)