-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
184 lines (151 loc) · 7.18 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Configure System Access
description: 'Configure System Access'
####----------------------------------------------------------------------------
inputs:
action-functions:
description: 'Configure Access Functions'
required: false
default: 'action.functions'
private-keypair-file:
description: 'KeyPair Private Key'
required: false
default: 'devops.pem'
private-keypair-name:
description: 'KeyPair Private Name'
required: false
default: 'devops'
private-keypair-secret:
description: 'KeyPair Private Data'
required: true
default: ''
debuger-mode:
description: 'Enabling Shell Debugger'
required: false
default: false
verbose-mode:
description: 'Enabling Verbosity'
required: false
default: false
####----------------------------------------------------------------------------
outputs:
private-keypair-file:
description: "Exporting Private KeyPair File"
value: ${{ steps.export-keypair-items.outputs.private-keypair-file }}
private-keypair-name:
description: "Exporting Private KeyPair Name"
value: ${{ steps.export-keypair-items.outputs.private-keypair-name }}
private-keypair-secret:
description: "Exporting Private KeyPair Secret"
value: ${{ steps.provision-keypair-file.outputs.private-keypair-secret }}
####----------------------------------------------------------------------------
runs:
using: "composite"
steps:
- name: Configure System Access
id: configure-system-access
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
####--------------------------------------------------------------------
completion="Skipping ...! " ;
####--------------------------------------------------------------------
completion="Completed! " ;
####--------------------------------------------------------------------
private_keypair_secret="${{ inputs.private-keypair-secret }}" ;
if [[ "${#private_keypair_secret}" -eq 0 ]]; then
echo "Warning: Private KeyPair (Content) is empty! " ;
exit 1 ;
fi ;
echo "PRIVATE_KEYPAIR_SECRET=${private_keypair_secret}" >> ${GITHUB_ENV} ;
####--------------------------------------------------------------------
- name: Export Keypair Items
id: export-keypair-items
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
private_keypair_file="${{ github.workspace }}/.ssh/${{ inputs.private-keypair-file }}" ;
echo "PRIVATE_KEYPAIR_FILE=${private_keypair_file}" >> ${GITHUB_ENV} ;
####--------------------------------------------------------------------
private_keypair_name="${{ inputs.private-keypair-name }}" ;
echo "PRIVATE_KEYPAIR_NAME=${private_keypair_name}" >> ${GITHUB_ENV} ;
####--------------------------------------------------------------------
echo "private-keypair-file=${private_keypair_file}" >> ${GITHUB_OUTPUT} ;
echo "private-keypair-name=${private_keypair_name}" >> ${GITHUB_OUTPUT} ;
####--------------------------------------------------------------------
- name: Provision Keypair File
id: provision-keypair-file
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
mkdir -p "${{ github.workspace }}/.ssh" ;
[[ ! -e ${{ env.PRIVATE_KEYPAIR_FILE }} ]] && cat /dev/null > ${{ env.PRIVATE_KEYPAIR_FILE }} ;
echo -e "\nDecode/Extract Private SSH Key ..." ;
echo -en "${{ env.PRIVATE_KEYPAIR_SECRET }}" | base64 --decode > ${{ env.PRIVATE_KEYPAIR_FILE }} ;
chmod 0400 ${{ env.PRIVATE_KEYPAIR_FILE }} ;
keypair_length=$(
wc -c ${{ env.PRIVATE_KEYPAIR_FILE }} | awk '{print $1}'
) ;
echo -e "Key Pair Length: ${keypair_length}";
if [[ ${keypair_length} -gt 0 ]]; then
# echo "private-keypair-secret=$(
# cat ${{ env.PRIVATE_KEYPAIR_FILE }}
# )" >> ${GITHUB_OUTPUT} ;
ls -al ${{ env.PRIVATE_KEYPAIR_FILE }} ;
## cat ${{ env.PRIVATE_KEYPAIR_FILE }} ;
echo -e ;
else echo -e "\nWarning: Access Key-Pair is invalid [${keypair_length}]! " ;
exit -2 ;
fi ;
####--------------------------------------------------------------------
- name: Download Actions functions
id: download-action-functions
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
github_usercontent="https://raw.githubusercontent.com" ;
usercontent_repository="${github_usercontent}/emvaldes/configure-access/master" ;
####--------------------------------------------------------------------
echo -e "\nDownloading Action-Functions: ${{ inputs.action-functions }} ..." ;
wget --quiet --output-document=./${{ inputs.action-functions }} ${usercontent_repository}/${{ inputs.action-functions }} ;
action_functions="${{ github.workspace }}/action.functions" ;
ls -al "${action_functions}" ;
echo -e ;
echo "ACTION_FUNCTIONS=${action_functions}" >> ${GITHUB_ENV} ;
####--------------------------------------------------------------------
- name: Validate Keypair credentials
id: validate-keypair-credentials
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
echo -e "\nSourcing Action-Functions ..." ;
ls -al "${{ env.ACTION_FUNCTIONS }}" ;
source "${{ env.ACTION_FUNCTIONS }}" ;
####--------------------------------------------------------------------
validate_accesskey "${{ github.workspace }}" \
"${{ env.PRIVATE_KEYPAIR_FILE }}" ;
result=${?} ;
####--------------------------------------------------------------------
if [[ ${result} -eq 0 ]]; then
# echo -e "AWS Access Key-Pair file length: [${keypair_length}] ..." ;
## Unable to store multi-line values:
echo "PRIVATE_KEYPAIR_SECRET=$(
echo -en "${{ env.PRIVATE_KEYPAIR_SECRET }}" | base64 -w0
)" >> ${GITHUB_ENV} ;
fi ;
####--------------------------------------------------------------------
####--------------------------------------------------------------------
echo -e "\n${completion}\n" ;
####--------------------------------------------------------------------