-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-wrapper
More file actions
executable file
·98 lines (91 loc) · 2.59 KB
/
example-wrapper
File metadata and controls
executable file
·98 lines (91 loc) · 2.59 KB
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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
VERSION="0.1.0-alpha.3"
resolve_latchkeyd_bin() {
if [[ -n "${LATCHKEYD_BIN:-}" ]]; then
printf '%s\n' "${LATCHKEYD_BIN}"
return 0
fi
if command -v latchkeyd >/dev/null 2>&1; then
command -v latchkeyd
return 0
fi
if [[ -x "${REPO_ROOT}/.build/debug/latchkeyd" ]]; then
printf '%s\n' "${REPO_ROOT}/.build/debug/latchkeyd"
return 0
fi
echo "latchkeyd binary not found. Set LATCHKEYD_BIN or build the project first." >&2
exit 1
}
json() {
local payload="$1"
printf '%s\n' "${payload}"
}
usage() {
cat <<'USAGE' >&2
Usage:
example-wrapper --health
example-wrapper --whoami
example-wrapper --version
example-wrapper --discover
example-wrapper demo [--manifest PATH] [-- ARG...]
example-wrapper brokered-demo [--manifest PATH] [-- ARG...]
USAGE
exit 2
}
[[ $# -ge 1 ]] || usage
action="$1"
shift
case "${action}" in
--health)
json '{"ok":true,"connector":"example-wrapper","operation":"health","message":"ready"}'
;;
--whoami)
json "{\"ok\":true,\"connector\":\"example-wrapper\",\"operation\":\"whoami\",\"identity\":{\"wrapperPath\":\"${SCRIPT_DIR}/example-wrapper\"}}"
;;
--version)
json "{\"ok\":true,\"connector\":\"example-wrapper\",\"operation\":\"version\",\"version\":\"${VERSION}\"}"
;;
--discover)
json '{"ok":true,"connector":"example-wrapper","commands":[{"name":"demo","description":"Run the harmless handoff-mode example CLI."},{"name":"brokered-demo","description":"Run the brokered-mode example CLI over a local broker session."}],"contract":["--health","--whoami","--version","--discover"]}'
;;
demo|brokered-demo)
manifest_args=()
passthrough=()
while [[ $# -gt 0 ]]; do
case "$1" in
--manifest)
manifest_args+=("$1" "${2:-}")
shift 2
;;
--)
shift
passthrough=("$@")
break
;;
*)
passthrough+=("$1")
shift
;;
esac
done
cmd=("$(resolve_latchkeyd_bin)" "exec")
if [[ ${#manifest_args[@]} -gt 0 ]]; then
cmd+=("${manifest_args[@]}")
fi
policy_name="example-demo"
if [[ "${action}" == "brokered-demo" ]]; then
policy_name="example-brokered"
fi
cmd+=("--policy" "${policy_name}" "--caller" "${SCRIPT_DIR}/example-wrapper" "--")
if [[ ${#passthrough[@]} -gt 0 ]]; then
cmd+=("${passthrough[@]}")
fi
PATH="${PATH}:${SCRIPT_DIR}" exec "${cmd[@]}"
;;
*)
usage
;;
esac