|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +function restore_sentinel_acl() { |
| 4 | + export PATH="$PATH:$DP_DATASAFED_BIN_PATH" |
| 5 | + export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" |
| 6 | + |
| 7 | + if [ -z "$SENTINEL_POD_FQDN_LIST" ]; then |
| 8 | + echo "INFO: no sentinel found, skip restore sentinel ACL file" |
| 9 | + return |
| 10 | + fi |
| 11 | + |
| 12 | + sentinel_acl_file="sentinel.acl" |
| 13 | + if [ "$(datasafed list $sentinel_acl_file)" == "${sentinel_acl_file}" ]; then |
| 14 | + datasafed pull "${sentinel_acl_file}" /tmp/sentinel.acl |
| 15 | + fi |
| 16 | + |
| 17 | + for sentinel_fqdn in $(echo "$SENTINEL_POD_FQDN_LIST" | tr "," "\n"); do |
| 18 | + echo "INFO: restore sentinel ${sentinel_fqdn} ACL file" |
| 19 | + sentinel_cmd="redis-cli $REDIS_CLI_TLS_CMD -h $sentinel_fqdn -p ${SENTINEL_SERVICE_PORT}" |
| 20 | + if [ -n "$SENTINEL_PASSWORD" ]; then |
| 21 | + sentinel_cmd="$sentinel_cmd -a $SENTINEL_PASSWORD" |
| 22 | + fi |
| 23 | + if [ "$($sentinel_cmd ping)" != "PONG" ]; then |
| 24 | + echo "Waring: failed to connect sentinel ${sentinel_fqdn}, skip" |
| 25 | + continue |
| 26 | + fi |
| 27 | + while IFS= read -r user_rule; do |
| 28 | + [[ -z "$user_rule" ]] && continue |
| 29 | + |
| 30 | + if [[ "$user_rule" =~ ^user[[:space:]]+([^[:space:]]+) ]]; then |
| 31 | + username="${BASH_REMATCH[1]}" |
| 32 | + else |
| 33 | + # skip invalid user rule |
| 34 | + continue |
| 35 | + fi |
| 36 | + |
| 37 | + if [[ "$username" == "default" ]]; then |
| 38 | + continue |
| 39 | + fi |
| 40 | + rule_part="${user_rule#user $username }" |
| 41 | + echo "$username" $rule_part |
| 42 | + $sentinel_cmd ACL SETUSER "$username" $rule_part >&2 |
| 43 | + done < /tmp/sentinel.acl |
| 44 | + break |
| 45 | + done |
| 46 | +} |
| 47 | +# restore sentinel acl |
| 48 | +restore_sentinel_acl |
3 | 49 | if [ -z "$DP_RESTORE_KEY_PATTERNS" ]; then |
4 | 50 | echo "DP_RESTORE_KEY_PATTERNS is not set. Exiting..." |
5 | 51 | exit 0 |
|
0 commit comments