aboutsummaryrefslogtreecommitdiff
path: root/brep/handler/ci
diff options
context:
space:
mode:
Diffstat (limited to 'brep/handler/ci')
-rw-r--r--brep/handler/ci/ci-load.in64
1 files changed, 62 insertions, 2 deletions
diff --git a/brep/handler/ci/ci-load.in b/brep/handler/ci/ci-load.in
index d568341..6029b7b 100644
--- a/brep/handler/ci/ci-load.in
+++ b/brep/handler/ci/ci-load.in
@@ -10,6 +10,11 @@
# brep tenant id to this value and include the resulting URL in the response
# message.
#
+# --cancel-url <url>
+# CI task canceling URL base for the response. If specified, the handler will
+# append the brep tenant id to this value and include the resulting URL in
+# the response message.
+#
# <loader-path>
# Loader program (normally brep-load(1)).
#
@@ -36,6 +41,7 @@ shopt -s nullglob # Expand no-match globs to nothing rather than themselves.
# The handler's own options.
#
result_url=
+cancel_url=
while [[ "$#" -gt 0 ]]; do
case $1 in
--result-url)
@@ -43,6 +49,11 @@ while [[ "$#" -gt 0 ]]; do
result_url="${1%/}"
shift
;;
+ --cancel-url)
+ shift
+ cancel_url="${1%/}"
+ shift
+ ;;
*)
break
;;
@@ -108,6 +119,14 @@ declare -A packages
#
spec=
+# Third party service information which, if specified, needs to be associated
+# with the being created tenant.
+#
+service_id=
+service_type=
+service_data=
+service_load=
+
while IFS=: read -ru "$manifest_parser_ofd" -d '' n v; do
case "$n" in
repository) repository="$v" ;;
@@ -122,6 +141,18 @@ while IFS=: read -ru "$manifest_parser_ofd" -d '' n v; do
fi
spec="$spec$v"
;;
+
+ service-id) service_id="$v" ;;
+ service-type) service_type="$v" ;;
+ service-data) service_data="$v" ;;
+
+ service-action)
+ if [[ "$v" == "load" ]]; then
+ service_load=true
+ elif [[ "$v" != "start" ]]; then
+ error "unrecognized service action '$v'"
+ fi
+ ;;
esac
done
@@ -141,6 +172,12 @@ if [[ -n "$simulate" && "$simulate" != "success" ]]; then
exit_with_manifest 400 "unrecognized simulation outcome '$simulate'"
fi
+# Use the generated reference if the tenant service id is not specified.
+#
+if [[ -n "$service_type" && -z "$service_id" ]]; then
+ service_id="$reference"
+fi
+
message_suffix=
if [[ -n "$result_url" ]]; then
message_suffix=": $result_url/@$reference" # Append the tenant id.
@@ -277,7 +314,7 @@ run mv "$cache_dir/packages.manifest" "$cache_dir/packages.manifest.orig"
#
manifest_serializer_start "$cache_dir/packages.manifest"
-for ((i=0; i <= "${#packages_manifest_names[@]}"; ++i)); do
+for ((i=0; i != "${#packages_manifest_names[@]}"; ++i)); do
manifest_serialize "${packages_manifest_names[$i]}" \
"${packages_manifest_values[$i]}"
done
@@ -306,6 +343,22 @@ if [[ -n "$interactive" ]]; then
loader_options+=(--interactive "$interactive")
fi
+# Pass the tenant service information, if specified, to the loader.
+#
+if [[ -n "$service_id" ]]; then
+ loader_options+=(--service-id "$service_id" --service-type "$service_type")
+
+ if [[ -n "$service_data" ]]; then
+ loader_options+=(--service-data "$service_data")
+ fi
+
+ # Load the pre-created tenant rather than create a new one.
+ #
+ if [[ "$service_load" ]]; then
+ loader_options+=(--existing-tenant)
+ fi
+fi
+
run "$loader" "${loader_options[@]}" "$loadtab"
# Remove the no longer needed CI request data directory.
@@ -313,4 +366,11 @@ run "$loader" "${loader_options[@]}" "$loadtab"
run rm -r "$data_dir"
trace "CI request for '$spec' is queued$message_suffix"
-exit_with_manifest 200 "CI request is queued$message_suffix"
+
+msg="CI request is queued$message_suffix"
+
+if [[ -n "$cancel_url" ]]; then
+ msg="$msg"$'\n'"To cancel CI request: $cancel_url=$reference&reason="
+fi
+
+exit_with_manifest 200 "$msg"