@@ -83,6 +83,9 @@ function display_help
8383 echo " ingestion procedure" >&2
8484 echo " -l | --list-variables - list variables that are available" >&2
8585 echo " for expansion" >&2
86+ echo " -k | --sign-key SCRIPT_KEY - specify location of the key to be" >&2
87+ echo " used to sign artefacts and metadata" >&2
88+ echo " files [optional; default: don't sign]" >&2
8689 echo " -m | --metadata-prefix PREFIX - a directory to which the metadata" >&2
8790 echo " file shall be uploaded; BASH variable" >&2
8891 echo " expansion will be applied; arg '-l'" >&2
@@ -93,6 +96,13 @@ function display_help
9396 echo " link the upload to a PR" >&2
9497 echo " -r | --repository FULL_NAME - a repository name ACCOUNT/REPONAME;" >&2
9598 echo " used to link the upload to a PR" >&2
99+ echo " -s | --sign-script SCRIPT_PATH - path to script that is used to sign" >&2
100+ echo " artefacts and metadata files. The" >&2
101+ echo " script is called with two arguments:" >&2
102+ echo " KEY file_to_sign. The KEY is the one" >&2
103+ echo " provided via option --sign-key. The" >&2
104+ echo " latter is determined by this script." >&2
105+ echo " [optional; default: don't sign]" >&2
96106}
97107
98108if [[ $# -lt 1 ]]; then
@@ -120,6 +130,8 @@ endpoint_url=
120130pr_comment_id=" none"
121131pull_request_number=" none"
122132github_repository=" EESSI/software-layer"
133+ sign_key=
134+ sign_script=
123135
124136# provided via options in the bot's config file app.cfg and/or command line argument
125137metadata_prefix=
@@ -155,6 +167,14 @@ while [[ $# -gt 0 ]]; do
155167 pr_comment_id=" $2 "
156168 shift 2
157169 ;;
170+ -k|--sign-key)
171+ sign_key=$2
172+ if [[ ! -r " ${sign_key} " ]]; then
173+ echo " Error: SSH key '${sign_key} ' to be used for signing doesn't exist or cannot be read" >&2
174+ exit 1
175+ fi
176+ shift 2
177+ ;;
158178 -m|--metadata-prefix)
159179 metadata_prefix=" $2 "
160180 shift 2
@@ -171,6 +191,14 @@ while [[ $# -gt 0 ]]; do
171191 github_repository=" $2 "
172192 shift 2
173193 ;;
194+ -s|--sign-script)
195+ sign_script=$2
196+ if [[ ! -x " ${sign_script} " ]]; then
197+ echo " Error: Script '${sign_script} ' to be used for signing doesn't exist or is not executable" >&2
198+ exit 1
199+ fi
200+ shift 2
201+ ;;
174202 -* |--* )
175203 echo " Error: Unknown option: $1 " >&2
176204 exit 1
@@ -185,6 +213,21 @@ done
185213# restore potentially parsed filename(s) into $*
186214set -- " ${POSITIONAL_ARGS[@]} "
187215
216+ # ensure that either none or both of $sign_key and $sign_script are defined
217+ if [[ -n " ${sign_key} " ]] && [[ -n " ${sign_script} " ]]; then
218+ sign=1
219+ elif [[ -n " ${sign_key} " ]]; then
220+ sign=0
221+ echo " Error: Signing requires a key (${sign_key} ) AND a script (${sign_script} ); likely the bot config is incomplete" >&2
222+ exit 1
223+ elif [[ -n " ${sign_script} " ]]; then
224+ sign=0
225+ echo " Error: Signing requires a key (${sign_key} ) AND a script (${sign_script} ); likely the bot config is incomplete" >&2
226+ exit 1
227+ else
228+ sign=0
229+ fi
230+
188231# infer bucket_base:
189232# if endpoint_url is not set (assume AWS S3 is used),
190233# bucket_base=https://${bucket_name}.s3.amazonaws.com/
@@ -217,6 +260,33 @@ for file in "$*"; do
217260 aws_path=$( envsubst <<< " ${artefact_prefix}" )
218261 fi
219262 aws_file=$( basename ${file} )
263+ # 1st sign artefact, and upload signature
264+ if [[ " ${sign} " = " 1" ]]; then
265+ # sign artefact
266+ ${sign_script} sign ${sign_key} ${file}
267+ # TODO check if signing worked (just check exit code == 0)
268+ sig_file=${file} .sig
269+ aws_sig_file=${aws_file} .sig
270+
271+ # uploading signature
272+ echo " store artefact signature at ${aws_path} /${aws_sig_file} "
273+ upload_to_staging_bucket \
274+ " ${sig_file} " \
275+ " ${bucket_name} " \
276+ " ${aws_path} /${aws_sig_file} " \
277+ " ${endpoint_url} "
278+ else
279+ echo " no signing method defined; not signing artefact"
280+ fi
281+
282+ echo Uploading to " ${url} "
283+ echo " store artefact at ${aws_path} /${aws_file} "
284+ upload_to_staging_bucket \
285+ " ${file} " \
286+ " ${bucket_name} " \
287+ " ${aws_path} /${aws_file} " \
288+ " ${endpoint_url} "
289+
220290 echo " Creating metadata file"
221291 url=" ${bucket_base} /${aws_path} /${aws_file} "
222292 echo " create_metadata_file file=${file} \
@@ -229,24 +299,35 @@ for file in "$*"; do
229299 " ${github_repository} " \
230300 " ${pull_request_number} " \
231301 " ${pr_comment_id} " )
302+ aws_metadata_file=${aws_file} .meta.txt
303+ # TODO check that creating the metadata file succeeded
232304 echo " metadata:"
233305 cat ${metadata_file}
234306
235- echo Uploading to " ${url} "
236- echo " store artefact at ${aws_path} /${aws_file} "
237- upload_to_staging_bucket \
238- " ${file} " \
239- " ${bucket_name} " \
240- " ${aws_path} /${aws_file} " \
241- " ${endpoint_url} "
242-
243307 if [ -z ${metadata_prefix} ]; then
244308 aws_path=${legacy_aws_path}
245309 else
246310 export pull_request_number
247311 export github_repository
248312 aws_path=$( envsubst <<< " ${metadata_prefix}" )
249313 fi
314+ # 2nd sign metadata file, and upload signature
315+ if [[ " ${sign} " = " 1" ]]; then
316+ # sign metadata file
317+ ${sign_script} sign ${sign_key} ${metadata_file}
318+ # TODO check if signing worked (just check exit code == 0)
319+ sig_metadata_file=${metadata_file} .sig
320+ aws_sig_metadata_file=${aws_metadata_file} .sig
321+
322+ echo " store metadata signature at ${aws_path} /${aws_sig_metadata_file} "
323+ upload_to_staging_bucket \
324+ " ${sig_metadata_file} " \
325+ " ${bucket_name} " \
326+ " ${aws_path} /${aws_sig_metadata_file} " \
327+ " ${endpoint_url} "
328+ else
329+ echo " no signing method defined; not signing metadata file"
330+ fi
250331 echo " store metadata file at ${aws_path} /${aws_file} .meta.txt"
251332 upload_to_staging_bucket \
252333 " ${metadata_file} " \
0 commit comments