Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions common/peco.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ peco_assume_role_name() {
cat ~/.aws/config | grep -e "^\[profile.*\]$" | peco
}

peco_format_name_convention_pre_defined() {
peco_input=$1
echo "${peco_input}" | tr "\t" "\n" | tr -s " " "\n" | tr -s '\n'
}

peco_format_aws_output_text() {
peco_input=$1
echo "${peco_input}" | tr "\t" "\n"
Expand All @@ -14,6 +19,12 @@ peco_aws_acm_list() {
aws_acm_list | peco
}

peco_name_convention_input() {
text_input=$1
format_text=$(peco_format_name_convention_pre_defined $text_input)
echo $format_text
}

peco_aws_input() {
aws_cli_commandline="${1} --output text"
result_cached=$2
Expand Down Expand Up @@ -93,3 +104,7 @@ peco_aws_s3_list() {
peco_aws_codebuild_list() {
peco_aws_input 'aws codebuild list-projects --query "*[]"' 'true'
}

peco_aws_codepipeline_list() {
peco_aws_input 'aws codepipeline list-pipelines --query "*[].name"' 'true'
}
14 changes: 12 additions & 2 deletions services/assume_role.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ aws_assume_role_unzip_tmp_credential() {

aws_assume_role_remove_tmp_credential() {
assume_role_name_input=$1
tmp_credentials_file_zip=${tmp_credentials}/${assume_role_name_input}.zip
tmp_credentials_file_zip=${tmp_credentials}/${assume_role_name_input:?"aws_assume_role_remove_tmp_credential is unset or empty"}.zip
if [ -f "${tmp_credentials_file_zip}" ]; then
rm -r ${tmp_credentials_file_zip}
fi
Expand All @@ -44,7 +44,17 @@ aws_assume_role_get_credentail() {
echo "Running assume-role ${ASSUME_ROLE}"
echo "Remove the credential ${tmp_credentials_file}"
rm -rf ${tmp_credentials_file}
assume-role -duration ${aws_assume_role_duration} ${ASSUME_ROLE} >${tmp_credentials_file}

assume_role_result=""
while [[ "${assume_role_result}" == "" ]]; do
assume_role_result=$(assume-role -duration ${aws_assume_role_duration} ${ASSUME_ROLE})

if [[ "${assume_role_result}" == "" ]]; then
echo "Assume role couldn't be succesful.Please try again or Ctrl + C to exit"
fi
done

echo $assume_role_result >${tmp_credentials_file}
empty_file=$(find ${tmp_credentials} -name ${ASSUME_ROLE} -empty)
if [ -z "${empty_file}" ]; then
zip_tmp_credential
Expand Down
23 changes: 15 additions & 8 deletions services/codepipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ aws_codepipeline_list() {
}

aws_codepipeline_get_latest_execution_with_hint() {

echo "List pipelines"
aws codepipeline list-pipelines --query "*[].name"

echo "Your pipeline >"
read codepipeline_name
aws_codepipeline_get_latest_execution $codepipeline_name
aws_codepipeline_get_latest_execution $(echo "$(peco_aws_codepipeline_list)" | peco)
}

aws_codepipeline_get_latest_execution() {

codepipeline_name=$1
aws codepipeline list-action-executions --pipeline-name $codepipeline_name --filter pipelineExecutionId=$(aws codepipeline list-pipeline-executions --pipeline-name $codepipeline_name --query "*[0].pipelineExecutionId" --output text) --output table
aws_codepipeline_execution_id_latest=$(
aws codepipeline list-pipeline-executions \
--pipeline-name ${codepipeline_name:?'codepipeline_name is unset or empty'} \
--query 'pipelineExecutionSummaries[0].pipelineExecutionId' \
--output text | head -1
)
aws_run_commandline \
"
aws codepipeline list-action-executions \
--pipeline-name ${codepipeline_name:?'codepipeline_name is unset or empty'} \
--filter pipelineExecutionId=${aws_codepipeline_execution_id_latest:?'aws_codepipeline_execution_id_latest is unset or empty'} \
--output table
"

}
6 changes: 6 additions & 0 deletions services/iam.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# TODO LATER
aws_iam_add_policy_to_role() {

}
30 changes: 30 additions & 0 deletions services/name-convention.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
aws_name_convention_get_prefix_name() {
echo "${ASSUME_ROLE}"
}

aws_name_convention_get_short_env_name() {
echo "dev stg prd"
}

aws_name_convention_get_long_env_name() {
echo "development staging production"
}

aws_name_convention_get_s3_bucket_name() {
aws_s3_bucket_name=$1
echo "The bucket name should will be like that \
[ ${ASSUME_ROLE}-${aws_s3_bucket_name:?"aws_s3_bucket_name is unset or empty"} ]" | tr -s ''
}

aws_name_convention_get_s3_bucket_name_with_hint() {

aws_name_convention_resource_types="static \
vod terraform cf-logs \
alb-logs webapp-react admin-react"

echo "List resource type ${aws_name_convention_resource_types}"

aws_name_convention_get_s3_bucket_name \
$(echo "$(peco_name_convention_input $aws_name_convention_resource_types)" | peco)

}
16 changes: 15 additions & 1 deletion services/rds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,25 @@ aws_rds_create_instance_snapshot_with_hint() {

# AWS events
aws_rds_list_events() {
aws rds describe-events
aws_run_commandline 'aws rds describe-events'

}

# AWS rds reboot

aws_rds_failover_db_cluster() {
aws_rds_db_cluster_name=$1
aws_run_commandline \
"
aws rds failover-db-cluster \
--db-cluster-identifier ${aws_rds_db_cluster_name:?'aws_rds_db_cluster_name is unset or empty'}
"
}

aws_rds_failover_db_cluster_with_hint() {
aws_rds_db_cluster_name $(echo "$(peco_aws_list_db_clusters)" | peco)
}

aws_rds_reboot_db_instance() {
aws_rds_db_instance_identifier=$1
echo Reboot the aws rds db instance ${aws_rds_db_instance_identifier:?"aws_rds_db_instance_identifier is unset or empty"}
Expand Down
59 changes: 59 additions & 0 deletions services/s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ aws_s3_list() {
aws_run_commandline 'aws s3api list-buckets --query "Buckets[].Name"'
}

aws_s3_get_bucket() {
aws_s3_bucket_name=$1
aws_run_commandline \
"
aws s3 ls s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
"

}

aws_s3_get_bucket_recursived() {
aws_s3_bucket_name=$1
aws_run_commandline \
"
aws s3 ls s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'} --recursive
"
}

aws_s3_get_bucket_with_hint() {
aws_s3_get_bucket $(echo "$(peco_aws_s3_list)" | peco)
}

aws_s3_get_bucket_recursived_with_hint() {
aws_s3_get_bucket_recursived $(echo "$(peco_aws_s3_list)" | peco)
}

aws_s3_get_object_metadata() {
bucket_name=$1
object_key=$2
Expand All @@ -19,6 +44,15 @@ aws_s3_get_object_metadata() {

}

aws_s3_get_bucket_arn() {
aws_s3_bucket_name=$1
echo "arn:aws:s3:::${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}"
}

aws_s3_get_bucket_arn_with_hint() {
aws_s3_get_s3_bucket_arn $(echo "$(peco_aws_s3_list)" | peco)
}

# aws_s3_get_object_metadata_with_hint() {
# bucket_name=$(echo "$(peco_aws_s3_list)" | peco)
# object_key=$2
Expand All @@ -29,3 +63,28 @@ aws_s3_get_object_metadata() {
# aws_run_commandline "${commandline}"

# }

aws_s3_create() {
aws_s3_bucket_name=$1
aws s3api create-bucket \
--bucket ${aws_s3_bucket_name:?"aws_s3_bucket_name is unset or empty"} \
--create-bucket-configuration LocationConstraint=${AWS_REGION}
}

aws_s3_delete() {
aws_s3_bucket_name=$1
echo "We didn't run the commandline, we just suggest the commandline"
echo "If you want ot process it please run the commandline \
[
aws_s3_get_bucket_recursived ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
aws s3 rm s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}/ --recursive
aws_s3_get_bucket_recursived ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
aws s3api delete-bucket --bucket ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
aws_s3_ls
]
"
}

aws_s3_rm_with_hint() {
aws_s3_delete $(echo "$(peco_aws_s3_list)" | peco)
}