stdlib: fixed typo in pkg (cc @tomChv)

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-06-04 16:32:46 +02:00
parent 92ceae9ce6
commit 6ae9a0b16d
2 changed files with 108 additions and 107 deletions

View File

@ -1,6 +1,7 @@
package elb package elb
import ( import (
"dagger.io/dagger/op"
"dagger.io/aws" "dagger.io/aws"
) )
@ -36,36 +37,36 @@ import (
"-eo", "-eo",
"pipefail", "pipefail",
#""" #"""
if [ -s "$VHOST" ]; then if [ -s "$VHOST" ]; then
# We passed a vhost as input, try to recycle priority from previously allocated vhost # We passed a vhost as input, try to recycle priority from previously allocated vhost
priority=$(aws elbv2 describe-rules \ priority=$(aws elbv2 describe-rules \
--listener-arn "$LISTENER_ARN" | \ --listener-arn "$LISTENER_ARN" | \
jq -r --arg vhost "$VHOST" '.Rules[] | select(.Conditions[].HostHeaderConfig.Values[] == $VHOST) | .Priority') 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 [ -n "${priority}" ]; then # Grab a priority random from 1-50k and check if available, retry 10 times if none available
echo -n "${priority}" > /priority priority=0
exit 0 for i in {1..10}
fi do
fi p=$(shuf -i 1-50000 -n 1)
# Find the next priority available that we can allocate
# Grab a priority random from 1-50k and check if available, retry 10 times if none available aws elbv2 describe-rules \
priority=0 --listener-arn "$LISTENER_ARN" \
for i in {1..10} | jq -e "select(.Rules[].Priority == \"${p}\") | true" && continue
do priority="${p}"
p=$(shuf -i 1-50000 -n 1) break
# Find the next priority available that we can allocate done
aws elbv2 describe-rules \ if [ "${priority}" -lt 1 ]; then
--listener-arn "$LISTENER_ARN" \ echo "Error: cannot determine a Rule priority"
| jq -e "select(.Rules[].Priority == \"${p}\") | true" && continue exit 1
priority="${p}" fi
break echo -n "${priority}" > /priority
done """#,
if [ "${priority}" -lt 1 ]; then
echo "Error: cannot determine a Rule priority"
exit 1
fi
echo -n "${priority}" > /priority
"""#,
] ]
env: { env: {
LISTENER_ARN: listenerArn LISTENER_ARN: listenerArn

View File

@ -1,8 +1,8 @@
package rds package rds
import ( import (
"dagger.io/dagger/op"
"encoding/json" "encoding/json"
"dagger.io/dagger"
"dagger.io/aws" "dagger.io/aws"
) )
@ -41,27 +41,27 @@ import (
"-eo", "-eo",
"pipefail", "pipefail",
#""" #"""
echo "dbType: $DB_TYPE" echo "dbType: $DB_TYPE"
sql="CREATE DATABASE \`"$NAME" \`" sql="CREATE DATABASE \`"$NAME" \`"
if [ "$DB_TYPE" = postgres ]; then if [ "$DB_TYPE" = postgres ]; then
sql="CREATE DATABASE \""$NAME"\"" sql="CREATE DATABASE \""$NAME"\""
fi fi
echo "$NAME" >> /db_created echo "$NAME" >> /db_created
aws rds-data execute-statement \ aws rds-data execute-statement \
--resource-arn "$DB_ARN" \ --resource-arn "$DB_ARN" \
--secret-arn "$SECRET_ARN" \ --secret-arn "$SECRET_ARN" \
--sql "$sql" \ --sql "$sql" \
--database "$DB_TYPE" \ --database "$DB_TYPE" \
--no-include-result-metadata \ --no-include-result-metadata \
|& tee /tmp/out |& tee /tmp/out
exit_code=${PIPESTATUS[0]} exit_code=${PIPESTATUS[0]}
if [ $exit_code -ne 0 ]; then if [ $exit_code -ne 0 ]; then
grep -q "database exists\|already exists" /tmp/out || exit $exit_code grep -q "database exists\|already exists" /tmp/out || exit $exit_code
fi fi
"""#, """#,
] ]
env: { env: {
NAME: name NAME: name
@ -84,10 +84,10 @@ import (
config: aws.#Config config: aws.#Config
// Username // Username
username: dagger.#Secret @dagger(input) username: string @dagger(input)
// Password // Password
password: dagger.#Secret @dagger(input) password: string @dagger(input)
// ARN of the database instance // ARN of the database instance
dbArn: string @dagger(input) dbArn: string @dagger(input)
@ -119,60 +119,60 @@ import (
"-eo", "-eo",
"pipefail", "pipefail",
#""" #"""
echo "dbType: $DB_TYPE" echo "dbType: $DB_TYPE"
sql="CREATE USER '"$USERNAME"'@'%' IDENTIFIED BY '"$PASSWORD"'" sql="CREATE USER '"$USERNAME"'@'%' IDENTIFIED BY '"$PASSWORD"'"
if [ "$DB_TYPE" = postgres ]; then if [ "$DB_TYPE" = postgres ]; then
sql="CREATE USER \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'" sql="CREATE USER \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'"
fi fi
echo "$USERNAME" >> /username echo "$USERNAME" >> /username
aws rds-data execute-statement \ aws rds-data execute-statement \
--resource-arn "$DB_ARN" \ --resource-arn "$DB_ARN" \
--secret-arn "$SECRET_ARN" \ --secret-arn "$SECRET_ARN" \
--sql "$sql" \ --sql "$sql" \
--database "$DB_TYPE" \ --database "$DB_TYPE" \
--no-include-result-metadata \ --no-include-result-metadata \
|& tee tmp/out |& tee tmp/out
exit_code=${PIPESTATUS[0]} exit_code=${PIPESTATUS[0]}
if [ $exit_code -ne 0 ]; then if [ $exit_code -ne 0 ]; then
grep -q "Operation CREATE USER failed for\|ERROR" tmp/out || exit $exit_code grep -q "Operation CREATE USER failed for\|ERROR" tmp/out || exit $exit_code
fi fi
sql="SET PASSWORD FOR '"$USERNAME"'@'%' = PASSWORD('"$PASSWORD"')" sql="SET PASSWORD FOR '"$USERNAME"'@'%' = PASSWORD('"$PASSWORD"')"
if [ "$DB_TYPE" = postgres ]; then if [ "$DB_TYPE" = postgres ]; then
sql="ALTER ROLE \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'" sql="ALTER ROLE \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'"
fi fi
aws rds-data execute-statement \ aws rds-data execute-statement \
--resource-arn "$DB_ARN" \ --resource-arn "$DB_ARN" \
--secret-arn "$SECRET_ARN" \ --secret-arn "$SECRET_ARN" \
--sql "$sql" \ --sql "$sql" \
--database "$DB_TYPE" \ --database "$DB_TYPE" \
--no-include-result-metadata --no-include-result-metadata
sql="GRANT ALL ON \`"$GRAND_DATABASE"\`.* to '"$USERNAME"'@'%'" sql="GRANT ALL ON \`"$GRAND_DATABASE"\`.* to '"$USERNAME"'@'%'"
if [ "$DB_TYPE" = postgres ]; then 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"\";" 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 fi
if [ -s "$GRAND_DATABASE ]; then if [ -s "$GRAND_DATABASE ]; then
aws rds-data execute-statement \ aws rds-data execute-statement \
--resource-arn "$DB_ARN" \ --resource-arn "$DB_ARN" \
--secret-arn "$SECRET_ARN" \ --secret-arn "$SECRET_ARN" \
--sql "$sql" \ --sql "$sql" \
--database "$DB_TYPE" \ --database "$DB_TYPE" \
--no-include-result-metadata --no-include-result-metadata
fi fi
"""#, """#,
] ]
env: { env: {
USERNAME: unsername USERNAME: username
PASSWORD: password PASSWORD: password
DB_ARN: dbArn DB_ARN: dbArn
SECRET_ARN: secretArn SECRET_ARN: secretArn
GRAND_DATABASE: grandDatabase GRAND_DATABASE: grantDatabase
DB_TYPE: dbType DB_TYPE: dbType
} }
}, },
@ -222,11 +222,11 @@ import (
"-eo", "-eo",
"pipefail", "pipefail",
#""" #"""
data=$(aws rds describe-db-clusters --filters "Name=db-cluster-id,Values=$DB_URN" ) 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[].Endpoint' > /tmp/out
echo "$data" | jq -r '.DBClusters[].Port' >> /tmp/out echo "$data" | jq -r '.DBClusters[].Port' >> /tmp/out
cat /tmp/out | jq -sR 'split("\n") | {hostname: .[0], port: (.[1] | tonumber)}' > /out cat /tmp/out | jq -sR 'split("\n") | {hostname: .[0], port: (.[1] | tonumber)}' > /out
"""#, """#,
] ]
env: DB_ARN: dbArn env: DB_ARN: dbArn
}, },