-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mongo-local-init.sh
39 lines (36 loc) · 1.49 KB
/
mongo-local-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
set -e;
# the mongo image only creates a root user in the admin database and not in the initdb_database
# so this script will grant a root role in the initdb_database aswell
# a default non-root role
# MONGO_NON_ROOT_ROLE="${MONGO_NON_ROOT_ROLE:-readWrite}"
if [ -n "${MONGO_INITDB_ROOT_USERNAME:-}" ] && [ -n "${MONGO_INITDB_ROOT_PASSWORD:-}" ]; then
"${mongo[@]}" "$MONGO_INITDB_DATABASE" <<-EOJS
db.createUser({
user: $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"),
pwd: $(_js_escape "$MONGO_INITDB_ROOT_PASSWORD"),
roles: [
{ role: $(_js_escape "root"), db: $(_js_escape "admin") },
{ role: "dbOwner", db: $(_js_escape "$MONGO_INITDB_DATABASE") }
]
})
EOJS
# db.createUser({
# user: $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"),
# pwd: $(_js_escape "$MONGO_INITDB_ROOT_PASSWORD"),
# roles: [ { role: "dbOwner", db: $(_js_escape "$MONGO_INITDB_DATABASE") }, ]
# })
# db.grantRolesToUser(
# $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"),
# [
# { role: "root", db: $(_js_escape "$MONGO_INITDB_DATABASE") }
# ]
# )
# db.createUser({
# user: $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"),
# pwd: $(_js_escape "$MONGO_INITDB_ROOT_PASSWORD"),
# roles: [ { role: $(_js_escape "root"), db: $(_js_escape "admin") }, ]
# })
# else
# # print warning or kill temporary mongo and exit non-zero
fi