-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcreate-magpie-users
executable file
·123 lines (108 loc) · 4.43 KB
/
create-magpie-users
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh
#
# Batch create or delete magpie users using config file at
# /tmp/create_magpie_users/config.yml (configurable using MAGPIE_CLI_CONF env
# var).
#
# Should run from checkout on same host running Birdhouse to have access to
# env.local file for Magpie credentials. Else these can be provided via
# environment variables.
#
# Sample /tmp/create_magpie_users/config.yml:
# Full sample at
# https://github.com/Ouranosinc/Magpie/blob/master/config/config.yml:
#
# users:
# - username: bogus01
# password: min_12_length
# email: [email protected]
# group: users
# - username: bogus02
# password: min_12_length
# email: [email protected]
# group: users
# - username: bogus03
# password: min_12_length
# email: [email protected]
# group: users
#
# If a username already exist, will not modify it (old password is kept), nice!
#
# Sample usage: create-magpie-users [-d]
# -d: delete users instead of create
#
# Sample output against Magpie server 1.7.3:
#
# $ scripts/create-magpie-users
# + docker run --rm -it --name create_magpie_users -v /tmp/create_magpie_users:/tmp/create_magpie_users:rw pavics/magpie:2.0.0 magpie_cli batch_update_users https://pavics.ouranos.ca/magpie admin 'sanitized' -f /tmp/create_magpie_users/config.yml -o /tmp/create_magpie_users/
# Constant could not be found: MAGPIE_GITHUB_CLIENT_ID (using default: None)
# Constant could not be found: MAGPIE_GITHUB_CLIENT_SECRET (using default: None)
# Constant could not be found: WSO2_HOSTNAME (using default: None)
# Constant could not be found: WSO2_CLIENT_ID (using default: None)
# Constant could not be found: WSO2_CLIENT_SECRET (using default: None)
# Constant could not be found: WSO2_CERTIFICATE_FILE (using default: None)
# Constant could not be found: WSO2_SSL_VERIFY (using default: True)
# 28-Sep-20 23:15:37 - INFO - Output results sent to [/tmp/create_magpie_users/magpie_create_users_log__20200928__231537.txt]
#
# $ cat /tmp/create_magpie_users/magpie_create_users_log__20200928__231537.txt
#
# USERNAME PASSWORD RESULT
# ____________________________________________________________
#
# bogus01 I1gthT3JgjAb 200 : Login successful.
# bogus02 McsksZTe7nwN 200 : Login successful.
# bogus03 8a3GKcaqRxFW 200 : Login successful.
#
# Output when user already exist:
#
# $ cat /tmp/create_magpie_users/magpie_create_users_log__20200929__190328.txt
#
# USERNAME PASSWORD RESULT
# ___________________________________________________________________________________________
#
# bogus01 P8sL5zwKcF8c 409 : User name matches an already existing user name.
# bogus02 s5XXrVPgfzsQ 409 : User name matches an already existing user name.
# bogus03 bvNWVWCQi8M6 409 : User name matches an already existing user name.
#
THIS_FILE="$(readlink -f "$0" || realpath "$0")"
THIS_DIR="$(dirname "${THIS_FILE}")"
COMPOSE_DIR="${COMPOSE_DIR:-$(dirname "${THIS_DIR}")}"
if [ -f "${COMPOSE_DIR}/read-configs.include.sh" ]; then
. "${COMPOSE_DIR}/read-configs.include.sh"
# Get MAGPIE_VERSION, BIRDHOUSE_FQDN, MAGPIE_ADMIN_PASSWORD, MAGPIE_ADMIN_USERNAME
read_configs
fi
##############################################################################
# Allow override using same name env var.
if [ -z "$MAGPIE_SERVER_URL" ]; then
MAGPIE_SERVER_URL="https://$BIRDHOUSE_FQDN/magpie"
fi
if [ -z "$MAGPIE_CLI_USER" ]; then
MAGPIE_CLI_USER="$MAGPIE_ADMIN_USERNAME"
fi
if [ -z "$MAGPIE_CLI_PASS" ]; then
MAGPIE_CLI_PASS="$MAGPIE_ADMIN_PASSWORD"
fi
if [ -z "$MAGPIE_CLI_OUTPUT_DIR" ]; then
MAGPIE_CLI_OUTPUT_DIR="/tmp/create_magpie_users"
fi
if [ -z "$MAGPIE_CLI_CONF" ]; then
MAGPIE_CLI_CONF="$MAGPIE_CLI_OUTPUT_DIR/config.yml"
fi
if [ -z "$MAGPIE_CLI_IMAGE" ]; then
# MAGPIE_VERSION must be provided by 'default.env', 'env.local' or directly
if [ -z "${MAGPIE_VERSION}" ]; then
log ERROR "Required MAGPIE_VERSION is undefined or empty."
exit 1
fi
MAGPIE_CLI_IMAGE="pavics/magpie:${MAGPIE_VERSION}"
fi
# End configurable config via env var.
##############################################################################
BASE_CMD="docker run --rm --name create_magpie_users \
-v $MAGPIE_CLI_CONF:$MAGPIE_CLI_CONF:ro \
-v $MAGPIE_CLI_OUTPUT_DIR:$MAGPIE_CLI_OUTPUT_DIR:rw \
$DOCKER_EXTRA_OPTS \
$MAGPIE_CLI_IMAGE magpie_cli batch_update_users $MAGPIE_SERVER_URL $MAGPIE_CLI_USER $MAGPIE_CLI_PASS"
set -x
$BASE_CMD -f $MAGPIE_CLI_CONF -o $MAGPIE_CLI_OUTPUT_DIR/ "$@"