From 63129e1c547c2c4f4904542bf8ed5f11735ab279 Mon Sep 17 00:00:00 2001 From: lamhaison Date: Tue, 4 Apr 2023 01:09:00 +0700 Subject: [PATCH 1/9] [Add] - install file for homebrew tool --- aws-cli-utils.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 aws-cli-utils.rb diff --git a/aws-cli-utils.rb b/aws-cli-utils.rb new file mode 100644 index 0000000..76323f6 --- /dev/null +++ b/aws-cli-utils.rb @@ -0,0 +1,39 @@ +# Documentation: https://docs.brew.sh/Formula-Cookbook +# https://rubydoc.brew.sh/Formula +# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! +class V180 < Formula + desc "aws-cli-utils" + homepage "https://github.com/lamhaison/aws-cli-utils" + url "https://github.com/lamhaison/aws-cli-utils/archive/refs/tags/v1.8.0.tar.gz" + sha256 "bef5b298d17dbfad86bdebeb08384dd848dae165beb2f9e0538c1f3508852963" + license "Apache-2.0" + + # depends_on "cmake" => :build + + depends_on "jq" + depends_on "peco" + + def install + # ENV.deparallelize # if your formula fails when building in parallel + # Remove unrecognized options if warned by configure + # https://rubydoc.brew.sh/Formula.html#std_configure_args-instance_method + # system "./configure", *std_configure_args, "--disable-silent-rules" + # system "cmake", "-S", ".", "-B", "build", *std_cmake_args + + prefix.install "README.md" + prefix.install "LICENSE" + end + + test do + # `test do` will create, run in and delete a temporary directory. + # + # This test will fail and we won't accept that! For Homebrew/homebrew-core + # this will need to be a test that verifies the functionality of the + # software. Run the test with `brew test v1.8.0`. Options passed + # to `brew install` such as `--HEAD` also need to be provided to `brew test`. + # + # The installed folder is not in the path, so use the entire path to any + # executables being tested: `system "#{bin}/program", "do", "something"`. + system "false" + end +end From 424b2e8d42153f669ffdbf9247de15a703a6a411 Mon Sep 17 00:00:00 2001 From: lamhaison Date: Tue, 4 Apr 2023 01:48:10 +0700 Subject: [PATCH 2/9] [Add] - makefile for installing --- makefile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..83af6fa --- /dev/null +++ b/makefile @@ -0,0 +1,2 @@ +install: + echo "Do nothing" \ No newline at end of file From 5799283232de02d9ed599ab8ee99eac1c9156c45 Mon Sep 17 00:00:00 2001 From: lamhaison Date: Tue, 4 Apr 2023 09:50:13 +0700 Subject: [PATCH 3/9] [Test] - install instruction brew --- makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 83af6fa..5eee03c 100644 --- a/makefile +++ b/makefile @@ -1,2 +1,3 @@ install: - echo "Do nothing" \ No newline at end of file + echo "Do nothing" + echo $(PWD) > /tmp/test.txt \ No newline at end of file From b57791d96d285403ee28494761ed6a90300fbe7c Mon Sep 17 00:00:00 2001 From: lamhaison Date: Tue, 4 Apr 2023 11:28:03 +0700 Subject: [PATCH 4/9] [Test] - install instruction brew --- README.md | 7 +++++++ main.sh | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78839e7..3bb584f 100755 --- a/README.md +++ b/README.md @@ -5,7 +5,14 @@ This is the project to collect helpful aws cli commandlines with complex options - Sometimes, you want to add more options on purpose and you want to have a place to collect and reuse it in the future. That is the reason I defined that structure to help me collect helpful commandlines and share on the github. - You have a lot of assume role profile, you can search it by peco and assume it one time by caching feature instead of filling in MFA every time. You can re-use assume-role in the other tab of Iterm. +# Setup by hombrew +``` +brew tap lamhaison/aws-cli-utils + +brew install --verbose --debug aws-cli-utils +``` +# Setup manullay ## Setup dependencies Notes: This document is for macos environment. diff --git a/main.sh b/main.sh index c481138..e3ddb1d 100755 --- a/main.sh +++ b/main.sh @@ -58,7 +58,10 @@ alias get-account-alias='aws iam list-account-aliases' alias get-account-id='echo AccountId $(aws sts get-caller-identity --query "Account" --output text)' # Import sub-commandlines. -for script in $(find ${AWS_CLI_SOURCE_SCRIPTS} -type f -name '*.sh' | grep -v main.sh | grep -v main.sh | grep -v test.sh | grep -v temp.sh); do +for script in $( + find ${AWS_CLI_SOURCE_SCRIPTS} -type f -name '*.sh' | + grep -v main.sh | grep -v main.sh | grep -v test.sh | grep -v temp.sh | grep -v aws-cli-utils.sh +); do source $script done From dd18f401fd7e8070156e89486111a6c7c0ab8d10 Mon Sep 17 00:00:00 2001 From: lamhaison Date: Tue, 4 Apr 2023 16:54:07 +0700 Subject: [PATCH 5/9] [Test] - install instruction brew --- README.md | 10 ++++++++-- main.sh | 27 ++++++++++++++++++++------- makefile | 5 +++-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3bb584f..a1b0369 100755 --- a/README.md +++ b/README.md @@ -5,11 +5,17 @@ This is the project to collect helpful aws cli commandlines with complex options - Sometimes, you want to add more options on purpose and you want to have a place to collect and reuse it in the future. That is the reason I defined that structure to help me collect helpful commandlines and share on the github. - You have a lot of assume role profile, you can search it by peco and assume it one time by caching feature instead of filling in MFA every time. You can re-use assume-role in the other tab of Iterm. -# Setup by hombrew +# Setup by brew on macos +## Install ``` brew tap lamhaison/aws-cli-utils - brew install --verbose --debug aws-cli-utils +``` +## Load when start an Iterm terminal +Add these lines to ~/.bashrc or ~/.zshrc or ~/.bash_profile +``` +source "$(which aws-cli-utils.sh)" "/opt/homebrew/Cellar/aws-cli-utils/$(brew info aws-cli-utils | head -1 | awk -F "stable " '{print $2}')" "${HOME}" "True" + ``` # Setup manullay diff --git a/main.sh b/main.sh index e3ddb1d..c806d3c 100755 --- a/main.sh +++ b/main.sh @@ -4,7 +4,8 @@ # @script main.sh # @description TODO : to load function for aws-cli-utils # $1: Where is looking for sh files and source the list -# $2: Do you want to set the bind key? +# $2: Where do you want to save logs? +# $3: Do you want to set the bind key? AWS_CLI_SOURCE_SCRIPTS=$1 @@ -19,14 +20,26 @@ else export AWS_CLI_SOURCE_SCRIPTS=${AWS_CLI_SOURCE_SCRIPTS} fi +AWS_CLI_DATA=$2 +if [[ -z "${AWS_CLI_DATA}" ]]; then + LOCAL_AWS_CLI_DATA=$(dirname -- "$0") + if [[ "${LOCAL_AWS_CLI_DATA}" = "." ]]; then + DEFAULT_AWS_CLI_DATA='/opt/lamhaison-tools/aws-cli-utils' + fi + + export AWS_CLI_DATA="${LOCAL_AWS_CLI_DATA:-${DEFAULT_AWS_CLI_DATA}}" +else + export AWS_CLI_DATA=${AWS_CLI_DATA} +fi + export assume_role_password_encrypted="$(cat ~/.password_assume_role_encrypted)" export tmp_credentials="/tmp/aws_temporary_credentials" -export aws_cli_results="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results" -export aws_cli_logs="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results/logs" -export aws_cli_images="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results/images" -export aws_cli_input_tmp="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results/inputs" -export aws_cli_input_folder="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_inputs" +export aws_cli_results="${AWS_CLI_DATA}/aws_cli_results" +export aws_cli_logs="${AWS_CLI_DATA}/aws_cli_results/logs" +export aws_cli_images="${AWS_CLI_DATA}/aws_cli_results/images" +export aws_cli_input_tmp="${AWS_CLI_DATA}/aws_cli_results/inputs" +export aws_cli_input_folder="${AWS_CLI_DATA}/aws_cli_inputs" export aws_cli_list_commands_folder="${aws_cli_input_folder}/aws_services_commands" export aws_tmp_input="/tmp/aws_tmp_input_23647494949484.txt" export aws_cli_document_root_url="https://awscli.amazonaws.com/v2/documentation/api/latest/reference" @@ -74,7 +87,7 @@ if [ "true" = "${aws_cli_load_current_assume_role}" ] && [ -s "${aws_cli_current aws_assume_role_load_current_assume_role_for_new_tab fi -LHS_BIND_KEY=${2:-'True'} +LHS_BIND_KEY=${3:-'True'} if [[ "${LHS_BIND_KEY}" = "True" ]]; then # Add hot-keys diff --git a/makefile b/makefile index 5eee03c..77abe9b 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,4 @@ install: - echo "Do nothing" - echo $(PWD) > /tmp/test.txt \ No newline at end of file + echo "Todo later" + + From 324108d7ca3caf6807e12f835ac4401c1ee6f849 Mon Sep 17 00:00:00 2001 From: lamhaison Date: Wed, 5 Apr 2023 13:43:23 +0700 Subject: [PATCH 6/9] [Docs] - updates documents for installing by brew --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1b0369..aff13fb 100755 --- a/README.md +++ b/README.md @@ -18,7 +18,15 @@ source "$(which aws-cli-utils.sh)" "/opt/homebrew/Cellar/aws-cli-utils/$(brew in ``` -# Setup manullay +## Re-install the latest version +``` +brew uninstall --verbose --debug aws-cli-utils +brew untap lamhaison/aws-cli-utils +brew tap lamhaison/aws-cli-utils +brew install --verbose --debug aws-cli-utils +``` + +# Setup manually ## Setup dependencies Notes: This document is for macos environment. From 9f69e57f61358aff4614aaacafd0e328ba7b0c33 Mon Sep 17 00:00:00 2001 From: lamhaison Date: Thu, 6 Apr 2023 05:28:22 +0700 Subject: [PATCH 7/9] [Refactor] - function names --- common/logging.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/logging.sh b/common/logging.sh index 0aad77b..f22dc81 100644 --- a/common/logging.sh +++ b/common/logging.sh @@ -1,12 +1,12 @@ #!/bin/bash -aws_assume_role_check_log() { +aws_assume_role_get_log() { local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}.log echo "Read the log ${log_file_path}" view +$ -c 'set number' ${log_file_path} } -aws_assume_role_check_log_uploaded() { +aws_assume_role_get_log_uploaded() { local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}-uploaded.log echo "Read the log ${log_file_path}" view +$ -c 'set number' ${log_file_path} From 49d99c3c5a7898aeaa18f0eeb3c88d1e520112f5 Mon Sep 17 00:00:00 2001 From: lamhaison Date: Thu, 6 Apr 2023 05:30:15 +0700 Subject: [PATCH 8/9] [Improvement] - add option to set get from from x time instead of 120m as the default --- services/logs.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/logs.sh b/services/logs.sh index a1630ba..86b7554 100644 --- a/services/logs.sh +++ b/services/logs.sh @@ -7,14 +7,16 @@ aws_logs_list() { aws_logs_tail() { aws_log_group_name=$1 + local aws_logs_sinces=${2:-$aws_log_tail_since} echo Get log of the group name ${aws_log_group_name:?"aws_log_group_name is unset or empty"} - echo "Running commandline [ aws logs tail --follow $aws_log_group_name --since ${aws_log_tail_since} ]" - aws logs tail --follow $aws_log_group_name --since ${aws_log_tail_since} + local aws_cmd="aws logs tail --follow $aws_log_group_name --since ${aws_logs_sinces}" + lhs_commandline_logging "${aws_cmd}" + eval ${aws_cmd} } aws_logs_tail_with_hint() { echo "Your log group name >" aws_log_group_name=$(peco_create_menu 'peco_aws_logs_list') - aws_logs_tail $aws_log_group_name + aws_logs_tail $aws_log_group_name $1 } From 752c1ed7ea0e59b73727a881891f6ba791544f4c Mon Sep 17 00:00:00 2001 From: lamhaison Date: Thu, 6 Apr 2023 05:30:32 +0700 Subject: [PATCH 9/9] [Docs] - updates documents for installing by brew --- README.md | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index aff13fb..a13e05f 100755 --- a/README.md +++ b/README.md @@ -5,27 +5,6 @@ This is the project to collect helpful aws cli commandlines with complex options - Sometimes, you want to add more options on purpose and you want to have a place to collect and reuse it in the future. That is the reason I defined that structure to help me collect helpful commandlines and share on the github. - You have a lot of assume role profile, you can search it by peco and assume it one time by caching feature instead of filling in MFA every time. You can re-use assume-role in the other tab of Iterm. -# Setup by brew on macos -## Install -``` -brew tap lamhaison/aws-cli-utils -brew install --verbose --debug aws-cli-utils -``` -## Load when start an Iterm terminal -Add these lines to ~/.bashrc or ~/.zshrc or ~/.bash_profile -``` -source "$(which aws-cli-utils.sh)" "/opt/homebrew/Cellar/aws-cli-utils/$(brew info aws-cli-utils | head -1 | awk -F "stable " '{print $2}')" "${HOME}" "True" - -``` - -## Re-install the latest version -``` -brew uninstall --verbose --debug aws-cli-utils -brew untap lamhaison/aws-cli-utils -brew tap lamhaison/aws-cli-utils -brew install --verbose --debug aws-cli-utils -``` - # Setup manually ## Setup dependencies Notes: This document is for macos environment. @@ -67,7 +46,9 @@ echo "random_string" > ~/.password_assume_role_encrypted ``` -## Settings when open terminal (I am using iterm) +## Setup the aws-cli-utils + +### Setup from source code ``` sudo mkdir -p /opt/lamhaison-tools chown $(whoami) /opt/lamhaison-tools @@ -94,6 +75,27 @@ echo "source /opt/lamhaison-tools/aws-cli-utils/main.sh" >> ~/.zshrc ``` +### Setup from homebrew +#### Install +``` +brew tap lamhaison/aws-cli-utils +brew install --verbose --debug aws-cli-utils +``` +## Load when start an Iterm terminal +Add these lines to ~/.bashrc or ~/.zshrc or ~/.bash_profile +``` +source "$(which aws-cli-utils.sh)" "/opt/homebrew/Cellar/aws-cli-utils/$(brew info aws-cli-utils | head -1 | awk -F "stable " '{print $2}')" "${HOME}" "True" + +``` + +### Re-install the latest version +``` +brew uninstall --verbose --debug aws-cli-utils +brew untap lamhaison/aws-cli-utils +brew tap lamhaison/aws-cli-utils +brew install --verbose --debug aws-cli-utils +``` + ## Setting AWS credentials ### The file ~/.aws/config ```