Skip to content

Commit 4c57c12

Browse files
authored
Merge pull request #33 from lamhaison/develop
Refactor Name functions and add aws iam Functionality
2 parents 5e0df75 + f252d84 commit 4c57c12

File tree

14 files changed

+573
-127
lines changed

14 files changed

+573
-127
lines changed

common/common.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
aws_assume_role_option_set_output_table() {
1+
function aws_assume_role_option_set_output_table() {
22
export AWS_DEFAULT_OUTPUT="table"
33
}
44

5-
aws_assume_role_option_set_output_json() {
5+
function aws_assume_role_option_set_output_json() {
66
export AWS_DEFAULT_OUTPUT="json"
77
}
88

9-
aws_assume_role_option_set_output_yml() {
9+
function aws_assume_role_option_set_output_yml() {
1010
export AWS_DEFAULT_OUTPUT="yaml"
1111
}
1212

13-
aws_assume_role_enable_fast_mode() {
13+
function aws_assume_role_enable_fast_mode() {
1414
export aws_assume_role_print_account_info=false
1515
}
1616

17-
aws_assume_role_disable_fast_mode() {
17+
function aws_assume_role_disable_fast_mode() {
1818
export aws_assume_role_print_account_info=true
1919
}
2020

21-
aws_assume_role_disable_load_current_assume_role_for_new_tab() {
21+
function aws_assume_role_disable_load_current_assume_role_for_new_tab() {
2222
rm -rf ${aws_cli_current_assume_role_name} >/dev/null
2323
}
2424

25-
aws_assume_role_disable_show_detail_commandline() {
25+
function aws_assume_role_disable_show_detail_commandline() {
2626
export aws_show_commandline=false
2727
}
2828

29-
aws_run_commandline_with_retry() {
29+
function aws_run_commandline_with_retry() {
3030
local aws_commandline=$1
3131
local silent_mode=$2
3232
local retry_counter=0
@@ -57,7 +57,7 @@ aws_run_commandline_with_retry() {
5757

5858
}
5959

60-
aws_run_commandline() {
60+
function aws_run_commandline() {
6161
aws_run_commandline=$1
6262
aws_run_commandline="${aws_run_commandline:?'aws_run_commandline is unset or empty'}"
6363
aws_run_commandline_with_logging "${aws_run_commandline}"
@@ -72,7 +72,7 @@ function aws_commandline_logging() {
7272
fi
7373
}
7474

75-
aws_run_commandline_with_logging() {
75+
function aws_run_commandline_with_logging() {
7676
local aws_commandline=$1
7777
local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}.log
7878

common/logging.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#!/bin/bash
22

3-
aws_assume_role_get_log() {
3+
function aws_assume_role_get_log() {
44
local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}.log
55
echo "Read the log ${log_file_path}"
66
view +$ -c 'set number' ${log_file_path}
77
}
88

9-
aws_assume_role_get_log_uploaded() {
9+
function aws_assume_role_get_log_uploaded() {
1010
local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}-uploaded.log
1111
echo "Read the log ${log_file_path}"
1212
view +$ -c 'set number' ${log_file_path}
1313
}
1414

1515
# TODO LATER
16-
aws_assume_role_enable_log_uploaded() {
16+
function aws_assume_role_enable_log_uploaded() {
1717
export aws_show_log_uploaded=true
1818
local log_uploaded_file_path=${aws_cli_logs}/${ASSUME_ROLE}-uploaded.log
1919
touch ${log_uploaded_file_path}

common/peco.sh

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
peco_assume_role_name() {
1+
function peco_assume_role_name() {
22
cat ~/.aws/config | grep -e "^\[profile.*\]$" | peco
33
}
44

5-
peco_format_name_convention_pre_defined() {
5+
function peco_format_name_convention_pre_defined() {
66
local peco_input=$1
77
echo "${peco_input}" | tr "\t" "\n" | tr -s " " "\n" | tr -s '\n'
88
}
99

10-
peco_format_aws_output_text() {
10+
function peco_format_aws_output_text() {
1111
local peco_input=$1
1212
echo "${peco_input}" | tr "\t" "\n"
1313
}
1414

15-
peco_aws_acm_list() {
15+
function peco_aws_acm_list() {
1616
aws_acm_list | peco
1717
}
1818

19-
peco_name_convention_input() {
19+
function peco_name_convention_input() {
2020
local text_input=$1
2121
local format_text=$(peco_format_name_convention_pre_defined $text_input)
2222
echo $format_text
2323
}
2424

25-
peco_create_menu_with_array_input() {
25+
function peco_create_menu_with_array_input() {
2626
local text_input=$1
2727
local format_text=$(peco_format_name_convention_pre_defined $text_input)
2828
echo $format_text
2929
}
3030

31-
peco_aws_disable_input_cached() {
31+
function peco_aws_disable_input_cached() {
3232
export peco_input_expired_time=0
3333
}
3434

35-
peco_aws_input() {
35+
function peco_aws_input() {
3636
peco_commandline_input "${1} --output text" $2
3737
}
3838

39-
peco_commandline_input() {
39+
function peco_commandline_input() {
4040

4141
local commandline="${1}"
4242
local result_cached=$2
@@ -73,7 +73,7 @@ peco_commandline_input() {
7373

7474
}
7575

76-
peco_create_menu() {
76+
function peco_create_menu() {
7777
local input_function=$1
7878
local peco_options=$2
7979
local peco_command="peco ${peco_options}"
@@ -83,33 +83,33 @@ peco_create_menu() {
8383
}
8484

8585
# AWS Logs
86-
peco_aws_logs_list() {
86+
function peco_aws_logs_list() {
8787
peco_aws_input 'aws logs describe-log-groups --query "*[].logGroupName"' 'true'
8888
}
8989

9090
# AWS ECS
91-
peco_aws_ecs_list_clusters() {
91+
function peco_aws_ecs_list_clusters() {
9292
peco_aws_input 'aws ecs list-clusters --query "*[]"' 'true'
9393
}
9494

95-
peco_aws_ecs_list_services() {
95+
function peco_aws_ecs_list_services() {
9696
peco_aws_input 'aws ecs list-services --cluster $aws_ecs_cluster_arn --query "*[]"'
9797
}
9898

9999
# AWS ECR
100100

101-
peco_aws_ecr_list_repo_names() {
101+
function peco_aws_ecr_list_repo_names() {
102102
peco_aws_input 'aws ecr describe-repositories --query "*[].repositoryName"' 'true'
103103
}
104104

105-
peco_aws_ecr_list_images() {
105+
function peco_aws_ecr_list_images() {
106106
aws_ecr_repo_name=$1
107107
peco_aws_input "aws ecr list-images \
108108
--repository-name ${aws_ecr_repo_name:?'aws_ecr_repo_name is unset or empy'} \
109109
--query \"imageIds[].{imageTag:imageTag}\""
110110
}
111111

112-
peco_aws_alb_list_listners() {
112+
function peco_aws_alb_list_listners() {
113113
aws_alb_arn=$1
114114
peco_aws_input " \
115115
aws elbv2 describe-listeners \
@@ -118,85 +118,85 @@ peco_aws_alb_list_listners() {
118118
}
119119

120120
# AWS RDS
121-
peco_aws_list_db_parameter_groups() {
121+
function peco_aws_list_db_parameter_groups() {
122122
peco_aws_input 'aws rds describe-db-parameter-groups --query "*[].DBParameterGroupName"' 'true'
123123
}
124124

125-
peco_aws_rds_list_db_cluster_snapshots() {
125+
function peco_aws_rds_list_db_cluster_snapshots() {
126126
peco_aws_input 'aws rds describe-db-cluster-snapshots \
127127
--snapshot-type manual \
128128
--query "DBClusterSnapshots[].DBClusterSnapshotIdentifier"'
129129
}
130130

131-
peco_aws_rds_list_db_snapshots() {
131+
function peco_aws_rds_list_db_snapshots() {
132132
peco_aws_input 'aws rds describe-db-snapshots \
133133
--snapshot-type manual \
134134
--query "DBSnapshots[].DBSnapshotIdentifier"'
135135
}
136136

137-
peco_aws_list_db_cluster_parameter_groups() {
137+
function peco_aws_list_db_cluster_parameter_groups() {
138138
peco_aws_input 'aws rds describe-db-cluster-parameter-groups --query "*[].DBClusterParameterGroupName"' 'true'
139139
}
140140

141-
peco_aws_list_db_clusters() {
141+
function peco_aws_list_db_clusters() {
142142
peco_aws_input 'aws rds describe-db-clusters --query "*[].DBClusterIdentifier"' 'true'
143143
}
144144

145-
peco_aws_list_db_endpoint() {
145+
function peco_aws_list_db_endpoint() {
146146
peco_aws_input 'aws rds describe-db-clusters --query "*[].[Endpoint, ReaderEndpoint]"' 'true'
147147
}
148148

149-
peco_aws_list_db_instances() {
149+
function peco_aws_list_db_instances() {
150150
peco_aws_input 'aws rds describe-db-instances --query "*[].DBInstanceIdentifier"' 'true'
151151
}
152152

153153
# Lambda
154-
peco_aws_lambda_list() {
154+
function peco_aws_lambda_list() {
155155
peco_aws_input 'aws lambda list-functions --query "*[].FunctionName"' 'true'
156156
}
157157

158158
# S3
159-
peco_aws_s3_list() {
159+
function peco_aws_s3_list() {
160160
peco_aws_input 'aws s3api list-buckets --query "Buckets[].Name"' 'true'
161161
}
162162

163163
# Codebuild
164-
peco_aws_codebuild_list() {
164+
function peco_aws_codebuild_list() {
165165
peco_aws_input 'aws codebuild list-projects --query "*[]"' 'true'
166166
}
167167

168-
peco_aws_codepipeline_list() {
168+
function peco_aws_codepipeline_list() {
169169
peco_aws_input 'aws codepipeline list-pipelines --query "*[].name"' 'true'
170170
}
171171

172172
# Codedeploy
173-
peco_aws_codedeploy_list_deployment_ids() {
173+
function peco_aws_codedeploy_list_deployment_ids() {
174174
peco_aws_input 'aws deploy list-deployments --query "deployments[]"'
175175
}
176176

177177
# Cloudfront
178-
peco_aws_cloudfront_list() {
178+
function peco_aws_cloudfront_list() {
179179
commandline="aws cloudfront list-distributions \
180180
--query 'DistributionList.Items[*].{AId:Id,BComment:Comment}' --output text | tr -s '\t' '_'"
181181
peco_commandline_input ${commandline} 'true'
182182
}
183183

184184
# Autoscaling group
185-
peco_aws_autoscaling_list() {
185+
function peco_aws_autoscaling_list() {
186186
peco_aws_input 'aws autoscaling describe-auto-scaling-groups --query "*[].AutoScalingGroupName"' 'true'
187187
}
188188

189189
# IAM role list
190-
peco_aws_iam_list_roles() {
190+
function peco_aws_iam_list_roles() {
191191
peco_aws_input 'aws iam list-roles --query "*[].{RoleName:RoleName}"' 'true'
192192
}
193193

194-
peco_aws_iam_list_attached_policies() {
194+
function peco_aws_iam_list_attached_policies() {
195195
peco_aws_input 'aws iam list-policies --scope Local --only-attached --query "*[].Arn"' 'true'
196196
}
197197

198198
# EC2 Instance
199-
peco_aws_ec2_list() {
199+
function peco_aws_ec2_list() {
200200
local instance_state=${1:-'running'}
201201

202202
commandline="aws ec2 describe-instances \
@@ -206,58 +206,82 @@ peco_aws_ec2_list() {
206206
peco_commandline_input ${commandline} 'true'
207207
}
208208

209-
peco_aws_ec2_list_all() {
209+
function peco_aws_ec2_list_all() {
210210
commandline="aws ec2 describe-instances \
211211
--query 'Reservations[].Instances[].{Name: Tags[?Key==\`Name\`].Value | [0],InstanceId:InstanceId,PrivateIpAddress:PrivateIpAddress}' \
212212
--output text | tr -s '\t' '_'"
213213
peco_commandline_input ${commandline} 'true'
214214
}
215215

216-
peco_aws_ssm_list_parameters() {
216+
function peco_aws_ssm_list_parameters() {
217217
commandline=" \
218-
aws ssm get-parameters-by-path \
219-
--path "/" \
220-
--recursive \
221-
--query 'Parameters[*].Name' \
222-
| jq -r '.[]'
218+
aws ssm get-parameters-by-path \
219+
--path "/" \
220+
--recursive \
221+
--query 'Parameters[*].Name' \
222+
| jq -r '.[]'
223223
"
224224
peco_commandline_input ${commandline} 'true'
225225
}
226226

227-
peco_aws_dynamodb_list_tables() {
227+
function peco_aws_dynamodb_list_tables() {
228228
peco_aws_input "aws dynamodb list-tables --query 'TableNames[]'" 'true'
229229
}
230230

231-
peco_aws_sqs_list() {
231+
function peco_aws_sqs_list() {
232232
peco_aws_input 'aws sqs list-queues --query "*[]"' 'true'
233233
}
234234

235-
peco_aws_eks_list_clusters() {
235+
function peco_aws_eks_list_clusters() {
236236
peco_aws_input 'aws eks list-clusters --query "*[]"' 'true'
237237
}
238238

239-
peco_aws_cloudformation_list_stacks() {
239+
function peco_aws_cloudformation_list_stacks() {
240240
peco_aws_input 'aws cloudformation list-stacks --query "*[].StackName"' 'true'
241241
}
242242

243-
peco_aws_imagebuilder_list() {
243+
function peco_aws_imagebuilder_list() {
244244
peco_aws_input 'aws imagebuilder list-image-pipelines --query "imagePipelineList[*].arn"' 'true'
245245
}
246246

247-
peco_aws_imagebuilder_list_recipes() {
247+
function peco_aws_imagebuilder_list_recipes() {
248248
peco_aws_input 'aws imagebuilder list-image-recipes --query "*[].arn"' 'true'
249249
}
250250

251-
peco_aws_budgets_list() {
251+
function peco_aws_budgets_list() {
252252
aws_assume_role_get_aws_account_id
253253
peco_aws_input 'aws budgets describe-budgets --account-id=${AWS_ACCOUNT_ID} --query "*[].BudgetName"' 'true'
254254
}
255255

256-
peco_aws_secretmanager_list() {
256+
function peco_aws_secretmanager_list() {
257257
peco_aws_input 'aws secretsmanager list-secrets --query "*[].Name"' 'true'
258258

259259
}
260260

261-
peco_aws_sns_list() {
261+
function peco_aws_sns_list() {
262262
peco_aws_input 'aws sns list-topics --query "*[].TopicArn"' 'true'
263263
}
264+
265+
function peco_aws_iam_user_list() {
266+
peco_aws_input 'aws iam list-users --query "*[].{UserName:UserName}"' 'true'
267+
}
268+
269+
function peco_aws_iam_group_list() {
270+
peco_aws_input 'aws iam list-groups --query "*[].{GroupName:GroupName}"' 'true'
271+
}
272+
273+
function peco_aws_iam_policy_list() {
274+
peco_aws_input 'aws iam list-policies --query "*[].{PolicyName:PolicyName}"' 'true'
275+
}
276+
277+
function peco_aws_iam_role_list() {
278+
peco_aws_input 'aws iam list-roles --query "*[].{RoleName:RoleName}"' 'true'
279+
}
280+
281+
function peco_aws_iam_instance_profile_list() {
282+
peco_aws_input 'aws iam list-instance-profiles --query "*[].{InstanceProfileName:InstanceProfileName}"' 'true'
283+
}
284+
285+
function peco_aws_scheduler_list() {
286+
peco_aws_input 'aws scheduler list-schedules --query "Schedules[*].[Name]"' 'true'
287+
}

0 commit comments

Comments
 (0)