aboutsummaryrefslogtreecommitdiff
path: root/brep
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-08-23 17:36:06 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-08-28 11:50:26 +0300
commit7e0e141273032c7afc1a9129512aa42c672fcf5d (patch)
tree970aa6fbe006df14c245363c3ce47d863ca3e4e1 /brep
parent6e7616b5ea02b61e15e4a8dcbbcf2978822730ce (diff)
Always serialize reference submit result manifest value if available and restructure handlers dir
Diffstat (limited to 'brep')
-rw-r--r--brep/handler/.gitignore1
-rw-r--r--brep/handler/buildfile10
-rw-r--r--brep/handler/handler.bash.in (renamed from brep/submit/submit.bash.in)64
-rw-r--r--brep/handler/submit/.gitignore (renamed from brep/submit/.gitignore)0
-rw-r--r--brep/handler/submit/buildfile13
-rw-r--r--brep/handler/submit/submit-dir.in (renamed from brep/submit/submit-dir.in)7
-rw-r--r--brep/handler/submit/submit-git.bash.in (renamed from brep/submit/submit-git.bash.in)9
-rw-r--r--brep/handler/submit/submit-git.in (renamed from brep/submit/submit-git.in)9
-rw-r--r--brep/handler/submit/submit.bash.in60
-rw-r--r--brep/submit/buildfile14
10 files changed, 107 insertions, 80 deletions
diff --git a/brep/handler/.gitignore b/brep/handler/.gitignore
new file mode 100644
index 0000000..e3cf716
--- /dev/null
+++ b/brep/handler/.gitignore
@@ -0,0 +1 @@
+handler.bash
diff --git a/brep/handler/buildfile b/brep/handler/buildfile
new file mode 100644
index 0000000..5223b5c
--- /dev/null
+++ b/brep/handler/buildfile
@@ -0,0 +1,10 @@
+# file : brep/handler/buildfile
+# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+import mods = libbutl.bash%bash{manifest-parser}
+import mods += libbutl.bash%bash{manifest-serializer}
+
+./: bash{handler} submit/
+
+bash{handler}: in{handler} $mods
diff --git a/brep/submit/submit.bash.in b/brep/handler/handler.bash.in
index babf081..89e7e21 100644
--- a/brep/submit/submit.bash.in
+++ b/brep/handler/handler.bash.in
@@ -1,13 +1,13 @@
-# file : brep/submit/submit.bash.in
+# file : brep/handler/handler.bash.in
# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-# Utility functions useful for implementing submission handlers.
+# Utility functions useful for implementing request handlers.
-if [ "$brep_submit" ]; then
+if [ "$brep_handler" ]; then
return 0
else
- brep_submit=true
+ brep_handler=true
fi
@import libbutl/manifest-parser@
@@ -33,7 +33,11 @@ fi
info_self="$(basename $0)"
if [ "$#" -gt 0 ]; then
- info_ref="$(basename "${!#/}")" # Last argument is the submission directory.
+ # Last argument is the request data directory which leaf component normally
+ # identifies the posted entity. A handler may overwrite this value if that's
+ # not the case.
+ #
+ info_ref="$(basename "${!#/}")"
fi
function info () # <severity> <text>
@@ -145,53 +149,3 @@ function manifest_serialize () # <name> <value>
# trace "$1: $2"
printf "%s:%s\0" "$1" "$2" >&"$manifest_serializer_ifd"
}
-
-# Serialize the submission result manifest to stdout and exit the (sub-)shell
-# with the zero status.
-#
-function exit_with_manifest () # <status> <message> [<reference>]
-{
- trace_func "$@"
-
- local sts="$1"
- local msg="$2"
- local ref="$3"
-
- manifest_serializer_start
-
- manifest_serialize "" "1" # Start of manifest.
- manifest_serialize "status" "$sts"
- manifest_serialize "message" "$msg"
-
- if [ -n "$ref" ]; then
- if [ "$sts" != "200" ]; then
- error "reference for code $sts"
- fi
-
- manifest_serialize "reference" "$ref"
- elif [ "$sts" == "200" ]; then
- error "no reference for code $sts"
- fi
-
- manifest_serializer_finish
- run exit 0
-}
-
-# Verify archive is a valid package and extract its manifest into
-# <manifest> file.
-#
-function extract_package_manifest () # <archive> <manifest>
-{
- local arc="$1"
- local man="$2"
-
- if ! run_silent bpkg pkg-verify --manifest "$arc" >"$man"; then
- # Perform the sanity check to make sure that bpkg is runnable.
- #
- if ! run bpkg --version >/dev/null; then
- error "unable to run bpkg"
- fi
-
- exit_with_manifest 400 "archive is not a valid package (run bpkg pkg-verify for details)"
- fi
-}
diff --git a/brep/submit/.gitignore b/brep/handler/submit/.gitignore
index ef91424..ef91424 100644
--- a/brep/submit/.gitignore
+++ b/brep/handler/submit/.gitignore
diff --git a/brep/handler/submit/buildfile b/brep/handler/submit/buildfile
new file mode 100644
index 0000000..b110a1d
--- /dev/null
+++ b/brep/handler/submit/buildfile
@@ -0,0 +1,13 @@
+# file : brep/handler/submit/buildfile
+# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+./: exe{brep-submit-dir} exe{brep-submit-git}
+
+exe{brep-submit-dir}: in{submit-dir} bash{submit} ../bash{handler}
+
+exe{brep-submit-git}: in{submit-git} \
+ bash{submit-git} bash{submit} ../bash{handler}
+
+bash{submit}: in{submit} ../bash{handler}
+bash{submit-git}: in{submit-git} bash{submit} ../bash{handler}
diff --git a/brep/submit/submit-dir.in b/brep/handler/submit/submit-dir.in
index 4bcbe5f..bda0bf8 100644
--- a/brep/submit/submit-dir.in
+++ b/brep/handler/submit/submit-dir.in
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-# file : brep/submit/submit-dir.in
+# file : brep/handler/submit/submit-dir.in
# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
@@ -18,7 +18,8 @@ verbose= #true
trap "{ exit 1; }" ERR
set -o errtrace # Trap ERR in functions.
-@import brep/submit/submit@
+@import brep/handler/handler@
+@import brep/handler/submit/submit@
if [ "$#" != 1 ]; then
error "$usage"
@@ -104,4 +105,4 @@ else
trace "$name/$version submission is queued"
fi
-exit_with_manifest 200 "$name/$version submission is queued" "$reference"
+exit_with_manifest 200 "$name/$version submission is queued"
diff --git a/brep/submit/submit-git.bash.in b/brep/handler/submit/submit-git.bash.in
index 06d9b7c..2fd26b0 100644
--- a/brep/submit/submit-git.bash.in
+++ b/brep/handler/submit/submit-git.bash.in
@@ -1,16 +1,17 @@
-# file : brep/submit/submit-git.bash.in
+# file : brep/handler/submit/submit-git.bash.in
# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
# Utility functions for the submit-git handler.
-if [ "$brep_submit_git" ]; then
+if [ "$brep_handler_submit_git" ]; then
return 0
else
- brep_submit_git=true
+ brep_handler_submit_git=true
fi
-@import brep/submit/submit@
+@import brep/handler/handler@
+@import brep/handler/submit/submit@
# If the section is mapped to a directory in the repository configuration then
# return this directory path and empty string otherwise.
diff --git a/brep/submit/submit-git.in b/brep/handler/submit/submit-git.in
index 0c90309..47f9a1a 100644
--- a/brep/submit/submit-git.in
+++ b/brep/handler/submit/submit-git.in
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-# file : brep/submit/submit-git.in
+# file : brep/handler/submit/submit-git.in
# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
@@ -182,8 +182,9 @@ ref_lock_timeout=30
trap "{ exit 1; }" ERR
set -o errtrace # Trap ERR in functions.
-@import brep/submit/submit@
-@import brep/submit/submit-git@
+@import brep/handler/handler@
+@import brep/handler/submit/submit@
+@import brep/handler/submit/submit-git@
# Parse the command line options.
#
@@ -656,4 +657,4 @@ else
trace "$name/$version submission is queued"
fi
-exit_with_manifest 200 "$name/$version submission is queued" "$reference"
+exit_with_manifest 200 "$name/$version submission is queued"
diff --git a/brep/handler/submit/submit.bash.in b/brep/handler/submit/submit.bash.in
new file mode 100644
index 0000000..38a4e06
--- /dev/null
+++ b/brep/handler/submit/submit.bash.in
@@ -0,0 +1,60 @@
+# file : brep/handler/submit/submit.bash.in
+# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Utility functions useful for implementing package submission handlers.
+
+if [ "$brep_handler_submit" ]; then
+ return 0
+else
+ brep_handler_submit=true
+fi
+
+@import brep/handler/handler@
+
+# Serialize the package submission result manifest to stdout and exit the
+# (sub-)shell with the zero status.
+#
+reference= # Should be assigned later by the handler, when becomes available.
+
+function exit_with_manifest () # <status> <message>
+{
+ trace_func "$@"
+
+ local sts="$1"
+ local msg="$2"
+
+ manifest_serializer_start
+
+ manifest_serialize "" "1" # Start of manifest.
+ manifest_serialize "status" "$sts"
+ manifest_serialize "message" "$msg"
+
+ if [ -n "$reference" ]; then
+ manifest_serialize "reference" "$reference"
+ elif [ "$sts" == "200" ]; then
+ error "no reference for code $sts"
+ fi
+
+ manifest_serializer_finish
+ run exit 0
+}
+
+# Verify archive is a valid package and extract its manifest into
+# <manifest> file.
+#
+function extract_package_manifest () # <archive> <manifest>
+{
+ local arc="$1"
+ local man="$2"
+
+ if ! run_silent bpkg pkg-verify --manifest "$arc" >"$man"; then
+ # Perform the sanity check to make sure that bpkg is runnable.
+ #
+ if ! run bpkg --version >/dev/null; then
+ error "unable to run bpkg"
+ fi
+
+ exit_with_manifest 400 "archive is not a valid package (run bpkg pkg-verify for details)"
+ fi
+}
diff --git a/brep/submit/buildfile b/brep/submit/buildfile
deleted file mode 100644
index 50f9615..0000000
--- a/brep/submit/buildfile
+++ /dev/null
@@ -1,14 +0,0 @@
-# file : brep/submit/buildfile
-# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
-# license : MIT; see accompanying LICENSE file
-
-import mods = libbutl.bash%bash{manifest-parser}
-import mods += libbutl.bash%bash{manifest-serializer}
-
-./: exe{brep-submit-dir} exe{brep-submit-git}
-
-exe{brep-submit-dir}: in{submit-dir} bash{submit}
-exe{brep-submit-git}: in{submit-git} bash{submit-git} bash{submit}
-
-bash{submit}: in{submit} $mods
-bash{submit-git}: in{submit-git} bash{submit}