sql="CREATE USER '"$USERNAME"'@'%' IDENTIFIED BY '"$PASSWORD"'"
if["$DB_TYPE"=postgres];then
sql="CREATE USER \""$USERNAME"\" WITH PASSWORD '"$PASSWORD"'"
fi
echo"$USERNAME">>/username
awsrds-dataexecute-statement \
--resource-arn"$DB_ARN" \
--secret-arn"$SECRET_ARN" \
--sql"$sql" \
--database"$DB_TYPE" \
--no-include-result-metadata \
|&teetmp/out
exit_code=${PIPESTATUS[0]}
if[$exit_code-ne0];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
awsrds-dataexecute-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"\";"