9
9
# Extract the `variables:` section of a cryptic `pipeline.yml` plugin section
10
10
function extract_encrypted_variables() {
11
11
# Iterate over the steps in the yaml file
12
- (shyaml get-values-0 steps < " ${1} " || true) |
12
+ (shyaml -q get-values-0 steps < " ${1} " || true) |
13
13
while IFS=' ' read -r -d ' ' STEP; do
14
14
# For each step, get its list of plugins
15
- (shyaml get-values-0 plugins <<< " ${STEP}" 2> /dev/null || true) |
15
+ (shyaml -q get-values-0 plugins <<< " ${STEP}" || true) |
16
16
while IFS=' ' read -r -d ' ' PLUGINS; do
17
17
# Get the plugin names
18
- (shyaml keys-0 <<< " ${PLUGINS}" || true) |
18
+ (shyaml -q keys-0 <<< " ${PLUGINS}" || true) |
19
19
while IFS=' ' read -r -d ' ' PLUGIN_NAME; do
20
20
# Skip plugins that are not named `cryptic`
21
21
if [[ " ${PLUGIN_NAME} " != staticfloat/cryptic* ]]; then
22
22
continue
23
23
fi
24
24
# For each plugin, if its `cryptic`, extract the variables
25
- (shyaml get-values-0 " ${PLUGIN_NAME} .variables" <<< " ${PLUGINS}" 2> /dev/null || true) |
25
+ (shyaml -q get-values-0 " ${PLUGIN_NAME} .variables" <<< " ${PLUGINS}" || true) |
26
26
while IFS=' ' read -r -d ' ' VAR; do
27
27
printf " %s\n" " ${VAR} "
28
28
done
@@ -34,20 +34,20 @@ function extract_encrypted_variables() {
34
34
# Extract all variables that match "CRYPTIC_ADHOC_SECRET_*"
35
35
function extract_adhoc_encrypted_variables() {
36
36
# Iterate over any global env mappings
37
- (shyaml keys-0 env < " ${1} " 2> /dev/null || true) |
37
+ (shyaml -q keys-0 env < " ${1} " || true) |
38
38
while IFS=' ' read -r -d ' ' VARNAME; do
39
39
if [[ " ${VARNAME} " == CRYPTIC_ADHOC_SECRET_* ]]; then
40
- printf " %s\n" " ${VARNAME: 21} =$( shyaml get-value env.${VARNAME} < " ${1} " ) "
40
+ printf " %s\n" " ${VARNAME: 21} =$( shyaml -q get-value env.${VARNAME} < " ${1} " ) "
41
41
fi
42
42
done
43
43
44
44
# Iterate over the steps in the yaml file
45
- (shyaml get-values-0 steps < " ${1} " || true) |
45
+ (shyaml -q get-values-0 steps < " ${1} " || true) |
46
46
while IFS=' ' read -r -d ' ' STEP; do
47
- (shyaml keys-0 env <<< " ${STEP}" 2> /dev/null || true) |
47
+ (shyaml -q keys-0 env <<< " ${STEP}" || true) |
48
48
while IFS=' ' read -r -d ' ' VARNAME; do
49
49
if [[ " ${VARNAME} " == CRYPTIC_ADHOC_SECRET_* ]]; then
50
- printf " %s\n" " ${VARNAME: 21} =$( shyaml get-value env.${VARNAME} <<< " ${STEP}" ) "
50
+ printf " %s\n" " ${VARNAME: 21} =$( shyaml -q get-value env.${VARNAME} <<< " ${STEP}" ) "
51
51
fi
52
52
done
53
53
done
@@ -56,20 +56,20 @@ function extract_adhoc_encrypted_variables() {
56
56
# Extract the `files:` section of a cryptic `pipeline.yml` plugin section
57
57
function extract_encrypted_files() {
58
58
# Iterate over the steps in the yaml file
59
- (shyaml get-values-0 steps < " ${1} " || true) |
59
+ (shyaml -q get-values-0 steps < " ${1} " || true) |
60
60
while IFS=' ' read -r -d ' ' STEP; do
61
61
# For each step, get its list of plugins
62
- (shyaml get-values-0 plugins <<< " ${STEP}" 2> /dev/null || true) |
62
+ (shyaml -q get-values-0 plugins <<< " ${STEP}" || true) |
63
63
while IFS=' ' read -r -d ' ' PLUGINS; do
64
64
# Get the plugin names
65
- (shyaml keys-0 <<< " ${PLUGINS}" || true) |
65
+ (shyaml -q keys-0 <<< " ${PLUGINS}" || true) |
66
66
while IFS=' ' read -r -d ' ' PLUGIN_NAME; do
67
67
# Skip plugins that are not named `cryptic`
68
68
if [[ " ${PLUGIN_NAME} " != staticfloat/cryptic* ]]; then
69
69
continue
70
70
fi
71
71
# For each plugin, if its `cryptic`, extract the files
72
- (shyaml get-values-0 " ${PLUGIN_NAME} .files" <<< " ${PLUGINS}" 2> /dev/null || true) |
72
+ (shyaml -q get-values-0 " ${PLUGIN_NAME} .files" <<< " ${PLUGINS}" || true) |
73
73
while IFS=' ' read -r -d ' ' FILE; do
74
74
FILE=" $( echo ${FILE} | tr -d ' "' ) "
75
75
printf " %s\n" " ${FILE} "
@@ -88,56 +88,75 @@ function extract_pipeline_treehashes() {
88
88
vecho " Extracting treehashes from '${YAML_PATH} '"
89
89
90
90
# Iterate over the steps in the yaml file
91
- (shyaml get-values-0 steps < " ${1} " || true) |
91
+ (shyaml -q get-values-0 steps < " ${1} " || true) |
92
92
while IFS=' ' read -r -d ' ' STEP; do
93
- # For each step, get its list of plugins
94
- ( shyaml get-values-0 plugins <<< " ${STEP}" 2> /dev/null || true) |
95
- while IFS= ' ' read -r -d ' ' PLUGINS ; do
96
- # Get the plugin names
97
- (shyaml keys-0 <<< " ${PLUGINS} " || true) |
98
- while IFS= ' ' read -r -d ' ' PLUGIN_NAME ; do
99
- # Skip plugins that are not named `cryptic`
100
- if [[ " ${PLUGIN_NAME} " != staticfloat/cryptic * ]] ; then
101
- continue
102
- fi
93
+ # If this step is a `group` step, let's iterate over each of its steps
94
+ if shyaml -q get-value ' group ' > /dev/null <<< " ${STEP}" ; then
95
+ (shyaml -q get-values-0 steps <<< " ${STEP} " || true) |
96
+ while IFS= ' ' read -r -d ' ' INNER_STEP ; do
97
+ extract_plugin_treehashes " ${INNER_STEP} "
98
+ done
99
+ else
100
+ extract_plugin_treehashes " ${STEP} "
101
+ fi
102
+ done
103
103
104
- # For each plugin, if its `cryptic`, walk over the pipelines
105
- (shyaml get-values-0 " ${PLUGIN_NAME} .signed_pipelines" <<< " ${PLUGINS}" 2> /dev/null || true) |
106
- while IFS=' ' read -r -d ' ' PIPELINE; do
107
- # For each signed pipeline, get its pipeline path and its inputs
108
- PIPELINE_PATH=" $( shyaml get-value " pipeline" <<< " ${PIPELINE}" 2> /dev/null || true) "
109
-
110
- # Start by calculating the treehash of the yaml file
111
- INPUT_TREEHASHES=( " $( calc_treehash <<< " ${PIPELINE_PATH}" ) " )
112
-
113
- # Next, calculate the treehash of the rest of the glob patterns
114
- for PATTERN in $( shyaml get-values " inputs" <<< " ${PIPELINE}" 2> /dev/null || true) ; do
115
- INPUT_TREEHASHES+=( " $( collect_glob_pattern " ${PATTERN} " | calc_treehash) " )
116
- done
117
-
118
- # Calculate full treehash
119
- FULL_TREEHASH=" $( printf " %s" " ${INPUT_TREEHASHES[@]} " | calc_shasum) "
120
-
121
- # If `signature_file` is defined, use it!
122
- local BASE64_ENCRYPTED_TREEHASH=" "
123
- local TREEHASH_FILE_SOURCE=" "
124
- if shyaml get-value " signature_file" <<< " ${PIPELINE}" 2> /dev/null > /dev/null; then
125
- TREEHASH_FILE_SOURCE=" $( shyaml get-value " signature_file" <<< " ${PIPELINE}" 2> /dev/null) "
126
- if [[ -f " ${TREEHASH_FILE_SOURCE} " ]]; then
127
- BASE64_ENCRYPTED_TREEHASH=" $( base64enc < " ${TREEHASH_FILE_SOURCE} " ) "
128
- fi
129
- else
130
- # Try to extract the signature from the yaml directly too
131
- BASE64_ENCRYPTED_TREEHASH=" $( shyaml get-value " signature" <<< " ${PIPELINE}" 2> /dev/null || true) "
132
- fi
104
+ # Don't stay in `${REPO_ROOT}`
105
+ popd > /dev/null
106
+ }
107
+
108
+ function extract_plugin_treehashes() {
109
+ # Get the list of plugins
110
+ (shyaml -q get-values-0 plugins <<< " ${1}" || true) |
111
+ while IFS=' ' read -r -d ' ' PLUGINS; do
112
+ # Get the plugin names
113
+ (shyaml -q keys-0 <<< " ${PLUGINS}" || true) |
114
+ while IFS=' ' read -r -d ' ' PLUGIN_NAME; do
115
+ # Skip plugins that are not named `cryptic`
116
+ if [[ " ${PLUGIN_NAME} " != staticfloat/cryptic* ]]; then
117
+ continue
118
+ fi
119
+
120
+ # For each plugin, if its `cryptic`, walk over the pipelines
121
+ (shyaml -q get-values-0 " ${PLUGIN_NAME} .signed_pipelines" <<< " ${PLUGINS}" || true) |
122
+ while IFS=' ' read -r -d ' ' PIPELINE; do
123
+ # For each signed pipeline, get its pipeline path and its inputs
124
+ PIPELINE_PATH=" $( shyaml -q get-value " pipeline" <<< " ${PIPELINE}" || true) "
133
125
134
- # Print out treehash and pipeline path
135
- printf " %s&%s&%s&%s\n" " ${PIPELINE_PATH} " " ${FULL_TREEHASH} " " ${BASE64_ENCRYPTED_TREEHASH} " " ${TREEHASH_FILE_SOURCE} "
126
+ vecho " -> Found pipeline launch:"
127
+ vecho " -> ${PIPELINE_PATH} "
128
+
129
+ # Start by calculating the treehash of the yaml file
130
+ INPUT_TREEHASHES=( " $( calc_treehash <<< " ${PIPELINE_PATH}" ) " )
131
+
132
+ # Next, calculate the treehash of the rest of the glob patterns
133
+ readarray -d ' ' PATTERNS -t < <( shyaml -q get-values-0 " inputs" <<< " ${PIPELINE}" )
134
+ for PATTERN in " ${PATTERNS[@]} " ; do
135
+ HASH=" $( collect_glob_pattern " ${PATTERN} " | calc_treehash) "
136
+ vecho " + ${HASH} <- ${PATTERN} "
137
+ INPUT_TREEHASHES+=( " ${HASH} " )
136
138
done
139
+
140
+ # Calculate full treehash
141
+ FULL_TREEHASH=" $( printf " %s" " ${INPUT_TREEHASHES[@]} " | calc_shasum) "
142
+ vecho " ∟ ${FULL_TREEHASH} "
143
+
144
+ # If `signature_file` is defined, use it!
145
+ local BASE64_ENCRYPTED_TREEHASH=" "
146
+ local TREEHASH_FILE_SOURCE=" "
147
+ if shyaml get-value " signature_file" <<< " ${PIPELINE}" > /dev/null; then
148
+ TREEHASH_FILE_SOURCE=" $( shyaml -q get-value " signature_file" <<< " ${PIPELINE}" ) "
149
+ if [[ -f " ${TREEHASH_FILE_SOURCE} " ]]; then
150
+ BASE64_ENCRYPTED_TREEHASH=" $( base64enc < " ${TREEHASH_FILE_SOURCE} " ) "
151
+ fi
152
+ else
153
+ # Try to extract the signature from the yaml directly too
154
+ BASE64_ENCRYPTED_TREEHASH=" $( shyaml -q get-value " signature" <<< " ${PIPELINE}" || true) "
155
+ fi
156
+
157
+ # Print out treehash and pipeline path
158
+ printf " %s&%s&%s&%s\n" " ${PIPELINE_PATH} " " ${FULL_TREEHASH} " " ${BASE64_ENCRYPTED_TREEHASH} " " ${TREEHASH_FILE_SOURCE} "
137
159
done
138
160
done
139
161
done
140
-
141
- # Don't stay in `${REPO_ROOT}`
142
- popd > /dev/null
143
162
}
0 commit comments