Skip to content

Commit

Permalink
parameterise profile in sspa script
Browse files Browse the repository at this point in the history
  • Loading branch information
sebykrueger committed Dec 27, 2015
1 parent a118df1 commit 97ea570
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions sspa
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function check_aws() {
echo "Can't find AWS CLI. Install 'awscli' using pip."
exit 1
fi
if ! aws configure list --profile admin > /dev/null; then
echo "Run \`aws configure --profile admin\` to create it"
if ! aws configure list --profile $profile > /dev/null; then
echo "Run \`aws configure --profile $profile\` to create it"
exit 1
fi
}
Expand All @@ -42,8 +42,8 @@ function create_s3_bucket() {
local bucket_path=conf/s3/${bucket_name}
# The s3 command doesn't output JSON :-/
if [[ ! -e ${bucket_path}/endpoint.txt ]]; then
aws --profile admin s3 mb $bucket_uri && mkdir -p ${bucket_path}
local region=$(aws --profile admin configure get region)
aws --profile $profile s3 mb $bucket_uri && mkdir -p ${bucket_path}
local region=$(aws --profile $profile configure get region)
local endpoint="http://${1}.s3-website-${region}.amazonaws.com"
echo "$endpoint" > ${bucket_path}/endpoint.txt
echo "Website endpoint is: $endpoint"
Expand All @@ -53,7 +53,7 @@ function create_s3_bucket() {
function webify_bucket() {
local bucket_name=$1
local bucket_uri="s3://${bucket_name}"
aws --profile admin s3 website \
aws --profile $profile s3 website \
--index-document index.html \
--error-document error.html \
$bucket_uri
Expand All @@ -65,7 +65,7 @@ function deploy_s3_bucket() {
bucket_name=$(basename $bucket_name)
fi
local bucket_uri="s3://${1}"
aws --profile admin s3 sync public/ $bucket_uri --acl public-read
aws --profile $profile s3 sync public/ $bucket_uri --acl public-read
}

function generate_assume_role_policy() {
Expand Down Expand Up @@ -130,7 +130,7 @@ function create_cognito_auth_role() {
local role_name="${pool_name}_cognito_authenticated"
echo "Creaing role: $role_name"
# Might be able to use the create_iam_role function for this
aws --profile admin iam create-role \
aws --profile $profile iam create-role \
--role-name "$role_name" \
--assume-role-policy-document "file://${identity_pool_dir}/assume_role_policy.json" \
> ${identity_pool_dir}/role_info.json
Expand All @@ -148,7 +148,7 @@ function create_identity_pool() {
local identity_pool_name=$(basename $identity_pool_dir)
if [[ ! -s ${identity_pool_dir}/pool_info.json ]]; then
echo "Creating identity pool: $identity_pool_name"
aws --profile admin cognito-identity create-identity-pool \
aws --profile $profile cognito-identity create-identity-pool \
--identity-pool-name $identity_pool_name \
--cli-input-json "file://${identity_pool_dir}/config.json" \
> ${identity_pool_dir}/pool_info.json
Expand All @@ -158,7 +158,7 @@ function create_identity_pool() {
local pool_id=$(support/jsed.py ${identity_pool_dir}/pool_info.json 'IdentityPoolId')
local role_arn=$(support/jsed.py ${identity_pool_dir}/role_info.json 'Role.Arn')
echo "Updating identity pool roles"
aws --profile admin cognito-identity set-identity-pool-roles \
aws --profile $profile cognito-identity set-identity-pool-roles \
--identity-pool-id ${pool_id} \
--roles authenticated=${role_arn}
}
Expand All @@ -168,15 +168,15 @@ function create_table() {
local table_name=$(basename $table_dir)
local role_name="${2}_cognito_authenticated"
if [[ ! -s ${table_dir}/table_info.json ]]; then
aws --profile admin dynamodb create-table \
aws --profile $profile dynamodb create-table \
--table-name $table_name \
--cli-input-json "file://${table_dir}/config.json" \
> ${table_dir}/table_info.json
fi

local table_arn=$(support/jsed.py ${table_dir}/table_info.json 'TableDescription.TableArn')
generate_table_policy ${table_arn} > ${table_dir}/role_policy.json
aws --profile admin iam put-role-policy \
aws --profile $profile iam put-role-policy \
--policy-document file://${table_dir}/role_policy.json \
--role-name ${role_name} \
--policy-name ${table_name}_table_access
Expand Down Expand Up @@ -223,7 +223,7 @@ function create_iam_role() {
local policy_document=$2
mkdir -p $role_dir
if [[ ! -e ${role_dir}/info.json ]]; then
aws --profile admin iam create-role \
aws --profile $profile iam create-role \
--role-name "$role_name" \
--assume-role-policy-document "${policy_document}" \
> ${role_dir}/info.json
Expand Down

0 comments on commit 97ea570

Please sign in to comment.