Piotr Dobrowolski | 2c5391b | 2019-04-09 23:30:38 +0200 | [diff] [blame] | 1 | #!/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 | # ./rook-s3cmd-config USERNAME STORENAME CLUSTERNAME > config |
| 9 | # s3cmd -c config --region "STORENAME:default-placement" mb s3://test/ |
| 10 | |
| 11 | set -e |
| 12 | |
| 13 | username="${1:-registry}" |
| 14 | storename="${2:-waw-hdd-redundant-1-object}" |
| 15 | clustername="${3:-ceph-waw1}" |
| 16 | |
| 17 | secret="$(kubectl get secrets rook-ceph-object-user-$storename-$username -n $clustername -o json)" |
| 18 | accesskey="$(echo "$secret" | jq -r '.data.AccessKey' | base64 -d)" |
| 19 | secretkey="$(echo "$secret" | jq -r '.data.SecretKey' | base64 -d)" |
| 20 | |
| 21 | if [[ ! -z "$K8S_INTERNAL" ]]; then |
| 22 | domain="rook-ceph-rgw-$storename.$clustername.svc.cluster.local" |
| 23 | else |
| 24 | domain="object.$clustername.hswaw.net" |
| 25 | fi |
| 26 | |
| 27 | cat <<EOF |
| 28 | [default] |
| 29 | access_key = $accesskey |
| 30 | secret_key = $secretkey |
| 31 | host_base = $domain |
| 32 | host_bucket = $domain |
| 33 | EOF |
| 34 | |
| 35 | if [[ ! -z "$K8S_INTERNAL" ]]; then |
| 36 | echo "use_https = False" |
| 37 | fi |