stdlib: cue fmt
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
669a47a159
commit
1fb4f4e314
@ -37,36 +37,36 @@ import (
|
||||
"-eo",
|
||||
"pipefail",
|
||||
#"""
|
||||
if [ -s "$VHOST" ]; then
|
||||
# We passed a vhost as input, try to recycle priority from previously allocated vhost
|
||||
priority=$(aws elbv2 describe-rules \
|
||||
--listener-arn "$LISTENER_ARN" | \
|
||||
jq -r --arg vhost "$VHOST" '.Rules[] | select(.Conditions[].HostHeaderConfig.Values[] == $VHOST) | .Priority')
|
||||
|
||||
if [ -n "${priority}" ]; then
|
||||
echo -n "${priority}" > /priority
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -s "$VHOST" ]; then
|
||||
# We passed a vhost as input, try to recycle priority from previously allocated vhost
|
||||
priority=$(aws elbv2 describe-rules \
|
||||
--listener-arn "$LISTENER_ARN" | \
|
||||
jq -r --arg vhost "$VHOST" '.Rules[] | select(.Conditions[].HostHeaderConfig.Values[] == $VHOST) | .Priority')
|
||||
|
||||
if [ -n "${priority}" ]; then
|
||||
echo -n "${priority}" > /priority
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Grab a priority random from 1-50k and check if available, retry 10 times if none available
|
||||
priority=0
|
||||
for i in {1..10}
|
||||
do
|
||||
p=$(shuf -i 1-50000 -n 1)
|
||||
# Find the next priority available that we can allocate
|
||||
aws elbv2 describe-rules \
|
||||
--listener-arn "$LISTENER_ARN" \
|
||||
| jq -e "select(.Rules[].Priority == \"${p}\") | true" && continue
|
||||
priority="${p}"
|
||||
break
|
||||
done
|
||||
if [ "${priority}" -lt 1 ]; then
|
||||
echo "Error: cannot determine a Rule priority"
|
||||
exit 1
|
||||
fi
|
||||
echo -n "${priority}" > /priority
|
||||
"""#,
|
||||
# Grab a priority random from 1-50k and check if available, retry 10 times if none available
|
||||
priority=0
|
||||
for i in {1..10}
|
||||
do
|
||||
p=$(shuf -i 1-50000 -n 1)
|
||||
# Find the next priority available that we can allocate
|
||||
aws elbv2 describe-rules \
|
||||
--listener-arn "$LISTENER_ARN" \
|
||||
| jq -e "select(.Rules[].Priority == \"${p}\") | true" && continue
|
||||
priority="${p}"
|
||||
break
|
||||
done
|
||||
if [ "${priority}" -lt 1 ]; then
|
||||
echo "Error: cannot determine a Rule priority"
|
||||
exit 1
|
||||
fi
|
||||
echo -n "${priority}" > /priority
|
||||
"""#,
|
||||
]
|
||||
env: {
|
||||
LISTENER_ARN: listenerArn
|
||||
|
@ -41,27 +41,27 @@ import (
|
||||
"-eo",
|
||||
"pipefail",
|
||||
#"""
|
||||
echo "dbType: $DB_TYPE"
|
||||
|
||||
sql="CREATE DATABASE \`"$NAME" \`"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="CREATE DATABASE \""$NAME"\""
|
||||
fi
|
||||
|
||||
echo "$NAME" >> /db_created
|
||||
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata \
|
||||
|& tee /tmp/out
|
||||
exit_code=${PIPESTATUS[0]}
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
grep -q "database exists\|already exists" /tmp/out || exit $exit_code
|
||||
fi
|
||||
"""#,
|
||||
echo "dbType: $DB_TYPE"
|
||||
|
||||
sql="CREATE DATABASE \`"$NAME" \`"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="CREATE DATABASE \""$NAME"\""
|
||||
fi
|
||||
|
||||
echo "$NAME" >> /db_created
|
||||
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata \
|
||||
|& tee /tmp/out
|
||||
exit_code=${PIPESTATUS[0]}
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
grep -q "database exists\|already exists" /tmp/out || exit $exit_code
|
||||
fi
|
||||
"""#,
|
||||
]
|
||||
env: {
|
||||
NAME: name
|
||||
@ -119,53 +119,53 @@ import (
|
||||
"-eo",
|
||||
"pipefail",
|
||||
#"""
|
||||
echo "dbType: $DB_TYPE"
|
||||
|
||||
sql="CREATE USER '"$USERNAME"'@'%' IDENTIFIED BY '"$PASSWORD"'"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="CREATE USER \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'"
|
||||
fi
|
||||
|
||||
echo "$USERNAME" >> /username
|
||||
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata \
|
||||
|& tee tmp/out
|
||||
exit_code=${PIPESTATUS[0]}
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
grep -q "Operation CREATE USER failed for\|ERROR" tmp/out || exit $exit_code
|
||||
fi
|
||||
|
||||
sql="SET PASSWORD FOR '"$USERNAME"'@'%' = PASSWORD('"$PASSWORD"')"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="ALTER ROLE \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'"
|
||||
fi
|
||||
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata
|
||||
|
||||
sql="GRANT ALL ON \`"$GRAND_DATABASE"\`.* to '"$USERNAME"'@'%'"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO \""$USERNAME"\"; GRANT ALL PRIVILEGES ON DATABASE \""$GRAND_DATABASE"\" to \""$USERNAME"\"; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO \""$USERNAME"\"; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO \""$USERNAME"\"; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON SEQUENCES TO \""$USERNAME"\"; GRANT USAGE ON SCHEMA public TO \""$USERNAME"\";"
|
||||
fi
|
||||
|
||||
if [ -s "$GRAND_DATABASE ]; then
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata
|
||||
fi
|
||||
"""#,
|
||||
echo "dbType: $DB_TYPE"
|
||||
|
||||
sql="CREATE USER '"$USERNAME"'@'%' IDENTIFIED BY '"$PASSWORD"'"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="CREATE USER \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'"
|
||||
fi
|
||||
|
||||
echo "$USERNAME" >> /username
|
||||
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata \
|
||||
|& tee tmp/out
|
||||
exit_code=${PIPESTATUS[0]}
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
grep -q "Operation CREATE USER failed for\|ERROR" tmp/out || exit $exit_code
|
||||
fi
|
||||
|
||||
sql="SET PASSWORD FOR '"$USERNAME"'@'%' = PASSWORD('"$PASSWORD"')"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="ALTER ROLE \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'"
|
||||
fi
|
||||
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata
|
||||
|
||||
sql="GRANT ALL ON \`"$GRAND_DATABASE"\`.* to '"$USERNAME"'@'%'"
|
||||
if [ "$DB_TYPE" = postgres ]; then
|
||||
sql="GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO \""$USERNAME"\"; GRANT ALL PRIVILEGES ON DATABASE \""$GRAND_DATABASE"\" to \""$USERNAME"\"; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO \""$USERNAME"\"; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO \""$USERNAME"\"; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON SEQUENCES TO \""$USERNAME"\"; GRANT USAGE ON SCHEMA public TO \""$USERNAME"\";"
|
||||
fi
|
||||
|
||||
if [ -s "$GRAND_DATABASE ]; then
|
||||
aws rds-data execute-statement \
|
||||
--resource-arn "$DB_ARN" \
|
||||
--secret-arn "$SECRET_ARN" \
|
||||
--sql "$sql" \
|
||||
--database "$DB_TYPE" \
|
||||
--no-include-result-metadata
|
||||
fi
|
||||
"""#,
|
||||
]
|
||||
env: {
|
||||
USERNAME: username
|
||||
@ -222,11 +222,11 @@ import (
|
||||
"-eo",
|
||||
"pipefail",
|
||||
#"""
|
||||
data=$(aws rds describe-db-clusters --filters "Name=db-cluster-id,Values=$DB_URN" )
|
||||
echo "$data" | jq -r '.DBClusters[].Endpoint' > /tmp/out
|
||||
echo "$data" | jq -r '.DBClusters[].Port' >> /tmp/out
|
||||
cat /tmp/out | jq -sR 'split("\n") | {hostname: .[0], port: (.[1] | tonumber)}' > /out
|
||||
"""#,
|
||||
data=$(aws rds describe-db-clusters --filters "Name=db-cluster-id,Values=$DB_URN" )
|
||||
echo "$data" | jq -r '.DBClusters[].Endpoint' > /tmp/out
|
||||
echo "$data" | jq -r '.DBClusters[].Port' >> /tmp/out
|
||||
cat /tmp/out | jq -sR 'split("\n") | {hostname: .[0], port: (.[1] | tonumber)}' > /out
|
||||
"""#,
|
||||
]
|
||||
env: DB_ARN: dbArn
|
||||
},
|
||||
|
Reference in New Issue
Block a user