Skip to content

Commit aa272b3

Browse files
authored
Merge pull request #2 from lamhaison/develop
Develop
2 parents 8d1bd4a + d53f26d commit aa272b3

File tree

7 files changed

+152
-11
lines changed

7 files changed

+152
-11
lines changed

common/peco.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ peco_assume_role_name() {
55
cat ~/.aws/config | grep -e "^\[profile.*\]$" | peco
66
}
77

8+
peco_format_name_convention_pre_defined() {
9+
peco_input=$1
10+
echo "${peco_input}" | tr "\t" "\n" | tr -s " " "\n" | tr -s '\n'
11+
}
12+
813
peco_format_aws_output_text() {
914
peco_input=$1
1015
echo "${peco_input}" | tr "\t" "\n"
@@ -14,6 +19,12 @@ peco_aws_acm_list() {
1419
aws_acm_list | peco
1520
}
1621

22+
peco_name_convention_input() {
23+
text_input=$1
24+
format_text=$(peco_format_name_convention_pre_defined $text_input)
25+
echo $format_text
26+
}
27+
1728
peco_aws_input() {
1829
aws_cli_commandline="${1} --output text"
1930
result_cached=$2
@@ -93,3 +104,7 @@ peco_aws_s3_list() {
93104
peco_aws_codebuild_list() {
94105
peco_aws_input 'aws codebuild list-projects --query "*[]"' 'true'
95106
}
107+
108+
peco_aws_codepipeline_list() {
109+
peco_aws_input 'aws codepipeline list-pipelines --query "*[].name"' 'true'
110+
}

services/assume_role.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ aws_assume_role_unzip_tmp_credential() {
2828

2929
aws_assume_role_remove_tmp_credential() {
3030
assume_role_name_input=$1
31-
tmp_credentials_file_zip=${tmp_credentials}/${assume_role_name_input}.zip
31+
tmp_credentials_file_zip=${tmp_credentials}/${assume_role_name_input:?"aws_assume_role_remove_tmp_credential is unset or empty"}.zip
3232
if [ -f "${tmp_credentials_file_zip}" ]; then
3333
rm -r ${tmp_credentials_file_zip}
3434
fi
@@ -44,7 +44,17 @@ aws_assume_role_get_credentail() {
4444
echo "Running assume-role ${ASSUME_ROLE}"
4545
echo "Remove the credential ${tmp_credentials_file}"
4646
rm -rf ${tmp_credentials_file}
47-
assume-role -duration ${aws_assume_role_duration} ${ASSUME_ROLE} >${tmp_credentials_file}
47+
48+
assume_role_result=""
49+
while [[ "${assume_role_result}" == "" ]]; do
50+
assume_role_result=$(assume-role -duration ${aws_assume_role_duration} ${ASSUME_ROLE})
51+
52+
if [[ "${assume_role_result}" == "" ]]; then
53+
echo "Assume role couldn't be succesful.Please try again or Ctrl + C to exit"
54+
fi
55+
done
56+
57+
echo $assume_role_result >${tmp_credentials_file}
4858
empty_file=$(find ${tmp_credentials} -name ${ASSUME_ROLE} -empty)
4959
if [ -z "${empty_file}" ]; then
5060
zip_tmp_credential

services/codepipeline.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ aws_codepipeline_list() {
55
}
66

77
aws_codepipeline_get_latest_execution_with_hint() {
8-
9-
echo "List pipelines"
10-
aws codepipeline list-pipelines --query "*[].name"
11-
12-
echo "Your pipeline >"
13-
read codepipeline_name
14-
aws_codepipeline_get_latest_execution $codepipeline_name
8+
aws_codepipeline_get_latest_execution $(echo "$(peco_aws_codepipeline_list)" | peco)
159
}
1610

1711
aws_codepipeline_get_latest_execution() {
1812

1913
codepipeline_name=$1
20-
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
14+
aws_codepipeline_execution_id_latest=$(
15+
aws codepipeline list-pipeline-executions \
16+
--pipeline-name ${codepipeline_name:?'codepipeline_name is unset or empty'} \
17+
--query 'pipelineExecutionSummaries[0].pipelineExecutionId' \
18+
--output text | head -1
19+
)
20+
aws_run_commandline \
21+
"
22+
aws codepipeline list-action-executions \
23+
--pipeline-name ${codepipeline_name:?'codepipeline_name is unset or empty'} \
24+
--filter pipelineExecutionId=${aws_codepipeline_execution_id_latest:?'aws_codepipeline_execution_id_latest is unset or empty'} \
25+
--output table
26+
"
27+
2128
}

services/iam.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# TODO LATER
4+
aws_iam_add_policy_to_role() {
5+
6+
}

services/name-convention.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
aws_name_convention_get_prefix_name() {
2+
echo "${ASSUME_ROLE}"
3+
}
4+
5+
aws_name_convention_get_short_env_name() {
6+
echo "dev stg prd"
7+
}
8+
9+
aws_name_convention_get_long_env_name() {
10+
echo "development staging production"
11+
}
12+
13+
aws_name_convention_get_s3_bucket_name() {
14+
aws_s3_bucket_name=$1
15+
echo "The bucket name should will be like that \
16+
[ ${ASSUME_ROLE}-${aws_s3_bucket_name:?"aws_s3_bucket_name is unset or empty"} ]" | tr -s ''
17+
}
18+
19+
aws_name_convention_get_s3_bucket_name_with_hint() {
20+
21+
aws_name_convention_resource_types="static \
22+
vod terraform cf-logs \
23+
alb-logs webapp-react admin-react"
24+
25+
echo "List resource type ${aws_name_convention_resource_types}"
26+
27+
aws_name_convention_get_s3_bucket_name \
28+
$(echo "$(peco_name_convention_input $aws_name_convention_resource_types)" | peco)
29+
30+
}

services/rds.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,25 @@ aws_rds_create_instance_snapshot_with_hint() {
156156

157157
# AWS events
158158
aws_rds_list_events() {
159-
aws rds describe-events
159+
aws_run_commandline 'aws rds describe-events'
160+
160161
}
161162

162163
# AWS rds reboot
163164

165+
aws_rds_failover_db_cluster() {
166+
aws_rds_db_cluster_name=$1
167+
aws_run_commandline \
168+
"
169+
aws rds failover-db-cluster \
170+
--db-cluster-identifier ${aws_rds_db_cluster_name:?'aws_rds_db_cluster_name is unset or empty'}
171+
"
172+
}
173+
174+
aws_rds_failover_db_cluster_with_hint() {
175+
aws_rds_db_cluster_name $(echo "$(peco_aws_list_db_clusters)" | peco)
176+
}
177+
164178
aws_rds_reboot_db_instance() {
165179
aws_rds_db_instance_identifier=$1
166180
echo Reboot the aws rds db instance ${aws_rds_db_instance_identifier:?"aws_rds_db_instance_identifier is unset or empty"}

services/s3.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ aws_s3_list() {
88
aws_run_commandline 'aws s3api list-buckets --query "Buckets[].Name"'
99
}
1010

11+
aws_s3_get_bucket() {
12+
aws_s3_bucket_name=$1
13+
aws_run_commandline \
14+
"
15+
aws s3 ls s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
16+
"
17+
18+
}
19+
20+
aws_s3_get_bucket_recursived() {
21+
aws_s3_bucket_name=$1
22+
aws_run_commandline \
23+
"
24+
aws s3 ls s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'} --recursive
25+
"
26+
}
27+
28+
aws_s3_get_bucket_with_hint() {
29+
aws_s3_get_bucket $(echo "$(peco_aws_s3_list)" | peco)
30+
}
31+
32+
aws_s3_get_bucket_recursived_with_hint() {
33+
aws_s3_get_bucket_recursived $(echo "$(peco_aws_s3_list)" | peco)
34+
}
35+
1136
aws_s3_get_object_metadata() {
1237
bucket_name=$1
1338
object_key=$2
@@ -19,6 +44,15 @@ aws_s3_get_object_metadata() {
1944

2045
}
2146

47+
aws_s3_get_bucket_arn() {
48+
aws_s3_bucket_name=$1
49+
echo "arn:aws:s3:::${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}"
50+
}
51+
52+
aws_s3_get_bucket_arn_with_hint() {
53+
aws_s3_get_s3_bucket_arn $(echo "$(peco_aws_s3_list)" | peco)
54+
}
55+
2256
# aws_s3_get_object_metadata_with_hint() {
2357
# bucket_name=$(echo "$(peco_aws_s3_list)" | peco)
2458
# object_key=$2
@@ -29,3 +63,28 @@ aws_s3_get_object_metadata() {
2963
# aws_run_commandline "${commandline}"
3064

3165
# }
66+
67+
aws_s3_create() {
68+
aws_s3_bucket_name=$1
69+
aws s3api create-bucket \
70+
--bucket ${aws_s3_bucket_name:?"aws_s3_bucket_name is unset or empty"} \
71+
--create-bucket-configuration LocationConstraint=${AWS_REGION}
72+
}
73+
74+
aws_s3_delete() {
75+
aws_s3_bucket_name=$1
76+
echo "We didn't run the commandline, we just suggest the commandline"
77+
echo "If you want ot process it please run the commandline \
78+
[
79+
aws_s3_get_bucket_recursived ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
80+
aws s3 rm s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}/ --recursive
81+
aws_s3_get_bucket_recursived ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
82+
aws s3api delete-bucket --bucket ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
83+
aws_s3_ls
84+
]
85+
"
86+
}
87+
88+
aws_s3_rm_with_hint() {
89+
aws_s3_delete $(echo "$(peco_aws_s3_list)" | peco)
90+
}

0 commit comments

Comments
 (0)