43 строки
881 B
Bash
Executable File
43 строки
881 B
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eou pipefail
|
|
|
|
keyfile_path=${1?"Must specify keyfile path"}
|
|
|
|
connection=${2:-"google_cloud_airflow_gke"}
|
|
|
|
# Wait for full display until after checks
|
|
set -x
|
|
|
|
function format_gcp() {
|
|
KEYFILE="$1" python3 - <<END
|
|
import os
|
|
import json
|
|
|
|
with open(os.environ["KEYFILE"]) as f:
|
|
data = json.load(f)
|
|
|
|
extra = {
|
|
"extra__google_cloud_platform__project": data["project_id"],
|
|
"extra__google_cloud_platform__keyfile_dict": json.dumps(data)
|
|
}
|
|
|
|
print(json.dumps(extra))
|
|
END
|
|
}
|
|
|
|
function update_gcp() {
|
|
local conn_id=$1
|
|
local keyfile=$2
|
|
|
|
container_id=$(docker ps --filter name=web -q)
|
|
|
|
docker exec $container_id airflow connections delete $conn_id
|
|
|
|
docker exec $container_id airflow connections add $conn_id \
|
|
--conn-type google_cloud_platform \
|
|
--conn-extra "$(format_gcp $keyfile)"
|
|
}
|
|
|
|
update_gcp $connection $keyfile_path
|