blob: 703b597ab4dd359aaba5424e033ee4d136c02691 [file] [log] [blame]
Sergiusz Bazanski0037eda2020-06-13 22:43:06 +02001#!/bin/bash
2
3# Generates s3cmd config from rook.io CephObjectStoreUser secrets fetched from
4# Kubernetes apiserver. Accepts extra K8S_INTERNAL=1 environment variable flag
5# that generates config that connects to internal rgw service.
6#
7# Usage:
8# bazel run //cluster/tools:rook-s3cmd-config > config
9# s3cmd -c config --region "STORENAME:default-placement" mb s3://test/
10
11set -euo pipefail
12
13# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
14if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
15 if [[ -f "$0.runfiles_manifest" ]]; then
16 export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
17 elif [[ -f "$0.runfiles/MANIFEST" ]]; then
18 export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
19 elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
20 export RUNFILES_DIR="$0.runfiles"
21 fi
22fi
23if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
24 source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
25elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
26 source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
27else
28 echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
29 exit 1
30fi
31# endpaste
32
33kubectl=$(rlocation "hscloud/cluster/tools/kubectl")
34if [ -z "$kubectl" ]; then
35 echo "Could not find kubectl in runfiles" >&2
36 exit 1
37fi
38
39jq=$(rlocation "com_github_stedolan_jq/jq")
40if [ -z "$jq" ]; then
41 echo "Could not find jq in runfiles" >&2
42 exit 1
43fi
44
45username="${1}"
46storename="${2:-waw-hdd-redundant-3-object}"
47clustername="${3:-ceph-waw3}"
48
49if [ -z "$username" ]; then
50 echo "Usage: $0 <username>" >&2
51 exit 1
52fi
53
54
55secret="$($kubectl get secrets rook-ceph-object-user-$storename-$username -n $clustername -o json)"
56accesskey="$(echo "$secret" | $jq -r '.data.AccessKey' | base64 -d)"
57secretkey="$(echo "$secret" | $jq -r '.data.SecretKey' | base64 -d)"
58
59if [[ ! -z "${K8S_INTERNAL:-}" ]]; then
60 domain="rook-ceph-rgw-$storename.$clustername.svc.cluster.local"
61else
62 domain="object.$clustername.hswaw.net"
63fi
64
65cat <<EOF
66[default]
67access_key = $accesskey
68secret_key = $secretkey
69host_base = $domain
70host_bucket = $domain
71EOF
72
73if [[ ! -z "${K8S_INTERNAL:-}" ]]; then
74 echo "use_https = False"
75fi