Skip to content

Commit e341c0a

Browse files
committed
Add functions:
- cert-resource-record-valid: Check DNS domain validation record - iam-access-key-rotate: rotate key - ssm-automation-step-executions: list them
1 parent e2f24e7 commit e341c0a

File tree

7 files changed

+141
-56
lines changed

7 files changed

+141
-56
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# TODO
22

3+
- Only `add_to_path_if_missing()`
34
- (aws-)backup-functions
45

aliases

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ alias buckets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma buckets'
7777
alias cert-chain='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-chain'
7878
alias cert-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-delete'
7979
alias cert-ificate='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-ificate'
80+
alias cert-resource-record-valid='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-resource-record-valid'
8081
alias cert-users='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-users'
8182
alias cert-verify='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-verify'
8283
alias certs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma certs'
@@ -110,6 +111,7 @@ alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-
110111
alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s'
111112
alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records'
112113
alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones'
114+
alias iam-access-key-rotate='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-access-key-rotate'
113115
alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal'
114116
alias iam-roles='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-roles'
115117
alias iam-users='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-users'
@@ -200,7 +202,9 @@ alias ssm-association-execution-targets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma
200202
alias ssm-association-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-association-executions'
201203
alias ssm-associations='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-associations'
202204
alias ssm-automation-execution='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-execution'
205+
alias ssm-automation-execution-failures='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-execution-failures'
203206
alias ssm-automation-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-executions'
207+
alias ssm-automation-step-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-step-executions'
204208
alias ssm-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-instances'
205209
alias ssm-parameter-value='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-parameter-value'
206210
alias ssm-parameters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-parameters'

bash_completion.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ complete -F _bma_buckets_completion buckets
179179
complete -F _bma_certs_completion cert-chain
180180
complete -F _bma_certs_completion cert-delete
181181
complete -F _bma_certs_completion cert-ificate
182+
complete -F _bma_certs_completion cert-resource-record-valid
182183
complete -F _bma_certs_completion cert-users
183184
complete -F _bma_certs_completion cert-verify
184185
complete -F _bma_certs_completion certs

docs/command-reference.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,16 @@ Return Cert Chain for ACM Cert(s)
12851285
USAGE: cert-chain cert-arn [cert-arn]
12861286

12871287

1288+
### cert-resource-record-valid
1289+
1290+
cert-resource-record-valid - Check if a specified DNS resource record matches the expected value and includes input validation.
1291+
1292+
Usage: cert-resource-record-valid <name> <type> <value>
1293+
Perform the DNS query
1294+
Print the output of the DNS query
1295+
Check if the expected value is in the output
1296+
1297+
12881298
### cert-verify
12891299

12901300
Verify ACM cert(s)
@@ -1498,6 +1508,10 @@ List IAM Users
14981508
ecsInstanceRole AROAJFQ3WMZXESGIKW5YD 2017-03-09T05:31:39Z
14991509

15001510

1511+
### iam-access-key-rotate
1512+
1513+
1514+
15011515
## image-commands
15021516

15031517

@@ -1963,6 +1977,20 @@ USAGE: ssm-automation-executions [filter]
19631977
ghijqrst-uvwx-2345-yzab-abcd5678efgh UpdateAndSecureNodes i-3d4e5f6g7h8i90123 Failed 2023-07-20T09:00:40.000000+00:00 None
19641978

19651979

1980+
### ssm-automation-execution-failures
1981+
1982+
1983+
1984+
### ssm-automation-step-executions
1985+
1986+
Show step-by-step details for an SSM Automation Execution
1987+
1988+
USAGE: automation-execution-steps execution_id [execution_id]
1989+
1990+
$ ssm-automation-executions | ssm-automation-steps-executions
1991+
[Outputs detailed step information for each provided execution ID]
1992+
1993+
19661994
### ssm-automation-execution
19671995

19681996
Show details for an SSM Automation Execution

functions

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ buckets
7777
cert-chain
7878
cert-delete
7979
cert-ificate
80+
cert-resource-record-valid
8081
cert-users
8182
cert-verify
8283
certs
@@ -110,6 +111,7 @@ elbv2-target-groups
110111
elbv2s
111112
hosted-zone-ns-records
112113
hosted-zones
114+
iam-access-key-rotate
113115
iam-role-principal
114116
iam-roles
115117
iam-users
@@ -201,7 +203,9 @@ ssm-association-execution-targets
201203
ssm-association-executions
202204
ssm-associations
203205
ssm-automation-execution
206+
ssm-automation-execution-failures
204207
ssm-automation-executions
208+
ssm-automation-step-executions
205209
ssm-instances
206210
ssm-parameter-value
207211
ssm-parameters

lib/extras/git/git-functions

Lines changed: 102 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,106 @@
88
# - git-tarball-create: Creates a tarball based on a gitinclude (special gitginore) file
99
# - git-repos: List all git repos (remote_url and git_dir)
1010

11+
git-tarball-create() {
12+
13+
# git-tarball-create - Creates a tarball based on a single gitinclude file
14+
#
15+
# Usage: git-tarball-create <gitinclude_file>
16+
#
17+
18+
local gitinclude_file="${1:-}"
19+
20+
# Verify gitinclude_file argument is provided
21+
if [[ -z $gitinclude_file ]]; then
22+
echo "Usage: tarball-create <gitinclude_file>" >&2
23+
return 1
24+
elif [[ ! -f $gitinclude_file ]]; then
25+
# Verify gitinclude_file file exists
26+
echo "Error: gitinclude file '$gitinclude_file' not found." >&2
27+
return 1
28+
fi
29+
30+
local last_commit_date="$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
31+
local git_repo_path="$(git rev-parse --show-toplevel)"
32+
local git_repo_name="${git_repo_path##*/}"
33+
local variant="$(basename "${gitinclude_file}")"
34+
local release="${git_repo_name}-${variant}-${last_commit_date}"
35+
local build_dir="${git_repo_path}/build"
36+
local tarball="${build_dir}/${release}.tar.gz"
37+
38+
(
39+
cd "${git_repo_path}" || exit
40+
# Ensure the build directory exists
41+
mkdir -p "$build_dir" || { echo "Failed to create build directory: $build_dir" >&2; return 1; }
42+
43+
# Use git to list files for inclusion in the tarball
44+
if ! git-ls-noticed "$gitinclude_file" \
45+
| tar \
46+
--transform "s,^,${release}/," \
47+
--transform 's,${release}/\([^/]*\) -> \(.*\),\1 -> \2,' \
48+
-czf "${tarball}" -T -
49+
then
50+
echo "Error: Failed to create tarball." >&2
51+
return 1
52+
fi
53+
)
54+
55+
echo "Tarball created: ${tarball}"
56+
}
57+
58+
git-archive() {
59+
60+
local last_commit_date="$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
61+
local git_repo_path="$(git rev-parse --show-toplevel)"
62+
local git_repo_name="${git_repo_path##*/}"
63+
local release="${git_repo_name}-${last_commit_date}"
64+
local build_dir="${git_repo_path}/build"
65+
local tarball="${build_dir}/${release}.tar.gz"
66+
local label="$(basename $(git rev-parse --show-toplevel))-$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
67+
68+
(
69+
cd "${git_repo_path}" || exit
70+
71+
# Ensure the build directory exists
72+
mkdir -p "$build_dir" || { echo "Failed to create build directory: $build_dir" >&2; return 1; }
73+
74+
git archive \
75+
--prefix="${release}/" \
76+
--format=tar.gz \
77+
-o "${build_dir}/${release}.tar.gz" \
78+
HEAD
79+
)
80+
}
81+
82+
git-remote-add-github() {
83+
git remote add github "github.com_mbailey:mbailey/$(git-repo-name).git"
84+
git branch -M master
85+
git push -u github master
86+
}
87+
88+
git-repo-name() {
89+
basename "$(git rev-parse --show-toplevel)"
90+
}
91+
1192
git-repos() {
1293

13-
local search_dir="${1:-.}" # Use provided directory or default to current directory if not provided
14-
15-
# Find all .git directories under the specified directory
16-
find "$search_dir" -type d -name .git 2>/dev/null | while read -r git_dir; do
17-
local repo_dir
18-
repo_dir=$(dirname "$git_dir") # Get the repository directory by removing the .git part
19-
local repo_url
20-
repo_url=$(git -C "$repo_dir" config --get remote.origin.url) # Get the repository's remote URL
21-
printf "%s\t%s\n" "$repo_url" "${repo_dir}" # Print the repository URL and directory path, separated by a tab
22-
done \
23-
| sort -k1,1 \
24-
| bma columnise
94+
local search_dirs="$(skim-stdin "$@")"
95+
[[ -z $search_dirs ]] && search_dirs='.'
96+
97+
# debug "$search_dirs"
98+
99+
# Find all .git directories under the specified directories
100+
for search_dir in $search_dirs; do
101+
find -L "$search_dir" -type d -name .git 2>/dev/null | while read -r git_dir; do
102+
local repo_dir
103+
repo_dir=$(dirname "$git_dir") # Get the repository directory by removing the .git part
104+
local repo_url
105+
repo_url=$(git -C "$repo_dir" config --get remote.origin.url) # Get the repository's remote URL
106+
printf "%s\t%s\n" "$repo_url" "${repo_dir}" # Print the repository URL and directory path, separated by a tab
107+
done \
108+
| sort -k1,1 \
109+
| bma columnise
110+
done
25111
}
26112

27113
git-ls-noticed() {
@@ -36,6 +122,10 @@ git-ls-noticed() {
36122
# `--ignored`: Lists all files that are ignored by git
37123
# `--cached`: Lists all files that are staged for commit. (Required to use `--ignored`.)
38124
# `--exclude-from`: Use specified file as the ignore file (and ignore all others)
125+
#
126+
# Test with:
127+
#
128+
# diff <(git-ls-noticed path/to/.gitinclude/target) <(tar-ls build/example-target-2024-04-17.tar.gz)
39129

40130
local gitinclude_file="${1:-}"
41131

@@ -65,49 +155,6 @@ git-ls-noticed() {
65155
)
66156
}
67157

68-
git-tarball-create() {
69-
70-
# git-tarball-create - Creates a tarball based on a single gitinclude file
71-
#
72-
# Usage: git-tarball-create <gitinclude_file>
73-
#
74-
75-
local gitinclude_file="${1:-}"
76-
77-
# Verify gitinclude_file argument is provided
78-
if [[ -z $gitinclude_file ]]; then
79-
echo "Usage: tarball-create <gitinclude_file>" >&2
80-
return 1
81-
elif [[ ! -f $gitinclude_file ]]; then
82-
# Verify gitinclude_file file exists
83-
echo "Error: gitinclude file '$gitinclude_file' not found." >&2
84-
return 1
85-
fi
86-
87-
local last_commit_date="$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
88-
local git_repo_path="$(git rev-parse --show-toplevel)"
89-
local git_repo_name="${git_repo_path##*/}"
90-
local variant="$(basename "${gitinclude_file}")"
91-
local release="${git_repo_name}-${variant}-${last_commit_date}"
92-
local build_dir="build"
93-
local tarball="${build_dir}/${release}.tar.gz"
94-
95-
(
96-
cd "${git_repo_path}" || exit
97-
# Ensure the build directory exists
98-
mkdir -p "$build_dir" || { echo "Failed to create build directory: $build_dir" >&2; return 1; }
99-
100-
# Use git to list files for inclusion in the tarball
101-
if ! git-ls-noticed "$gitinclude_file" \
102-
| tar --transform "s,^,${release}/," -czf "${tarball}" -T -
103-
then
104-
echo "Error: Failed to create tarball." >&2
105-
return 1
106-
fi
107-
)
108-
109-
echo "Tarball created: ${tarball}"
110-
}
111158

112159

113160
git-repo-dirs(){

scripts/build-docs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ lib/stack-functions
88
lib/instance-functions
99
"
1010

11-
filelist="${filelist}$(ls lib/* | grep -v 'aws-account\|region\|stack\|instance\|shared\|misc\|github\|pkcs12\|extras')"
11+
filelist="${filelist}$(ls lib/* | grep -v 'aws-account\|region\|stack\|instance\|shared\|misc\|git\|github\|pkcs12\|extras')"
1212

1313
cp docs/.command-reference-intro.md $COMMAND_REFERENCE_FILE
1414

0 commit comments

Comments
 (0)