forked from 0k/0k-charms
Browse Source
new: [etherpad] add ``list`` and ``drop`` actions to list pads and drop a given pad
odoo_fix_webhook_url
new: [etherpad] add ``list`` and ``drop`` actions to list pads and drop a given pad
odoo_fix_webhook_url
Valentin Lab
1 year ago
4 changed files with 251 additions and 0 deletions
@ -0,0 +1,63 @@ |
|||
#!/bin/bash |
|||
## compose: no-hooks |
|||
|
|||
if [ -z "$SERVICE_DATASTORE" ]; then |
|||
echo "This script is meant to be run through 'compose' to work properly." >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
|
|||
version=0.1 |
|||
usage="$exname [-h|--help] PAD_ID" |
|||
help=" |
|||
USAGE: |
|||
|
|||
$usage |
|||
|
|||
DESCRIPTION: |
|||
|
|||
Delete pad identified by PAD_ID |
|||
|
|||
EXAMPLES: |
|||
|
|||
$exname list |
|||
|
|||
" |
|||
|
|||
|
|||
while [ "$1" ]; do |
|||
case "$1" in |
|||
"--help"|"-h") |
|||
print_help >&2 |
|||
exit 0 |
|||
;; |
|||
--*|-*) |
|||
err "Unexpected optional argument '$1'" |
|||
print_usage >&2 |
|||
exit 1 |
|||
;; |
|||
*) |
|||
[ -z "$PAD_ID" ] && { PAD_ID="$1" ; shift ; continue ; } |
|||
err "Unexpected positional argument '$1'" |
|||
print_usage >&2 |
|||
exit 1 |
|||
;; |
|||
esac |
|||
shift |
|||
done |
|||
|
|||
|
|||
. "$CHARM_PATH"/lib/common |
|||
|
|||
set -e |
|||
|
|||
if [ -z "$PAD_ID" ]; then |
|||
err "Missing first positional argument PAD_ID to specify which pad to drop." |
|||
print_usage |
|||
exit 1 |
|||
fi |
|||
|
|||
etherpad:api:init || exit 1 |
|||
|
|||
etherpad:api deletePad --data-urlencode "padID=${PAD_ID}" >/dev/null || exit 1 |
|||
|
@ -0,0 +1,64 @@ |
|||
#!/bin/bash |
|||
## compose: no-hooks |
|||
|
|||
if [ -z "$SERVICE_DATASTORE" ]; then |
|||
echo "This script is meant to be run through 'compose' to work properly." >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
|
|||
version=0.1 |
|||
usage="$exname [-h|--help]" |
|||
help=" |
|||
USAGE: |
|||
|
|||
$usage |
|||
|
|||
DESCRIPTION: |
|||
|
|||
Lists all pads. |
|||
|
|||
EXAMPLES: |
|||
|
|||
$exname list |
|||
|
|||
" |
|||
|
|||
|
|||
while [ "$1" ]; do |
|||
case "$1" in |
|||
"--help"|"-h") |
|||
print_help >&2 |
|||
exit 0 |
|||
;; |
|||
--*|-*) |
|||
err "Unexpected optional argument '$1'" |
|||
print_usage >&2 |
|||
exit 1 |
|||
;; |
|||
*) |
|||
err "Unexpected positional argument '$1'" |
|||
print_usage >&2 |
|||
exit 1 |
|||
;; |
|||
esac |
|||
shift |
|||
done |
|||
|
|||
|
|||
. "$CHARM_PATH"/lib/common |
|||
|
|||
set -e |
|||
|
|||
etherpad:api:init || exit 1 |
|||
|
|||
out=$(etherpad:api listAllPads) || exit 1 |
|||
|
|||
if ! pads=$(e "$out" | jq -r ".padIDs[]"); then |
|||
err "Unexpected format from call to listAllPads API endpoint for ${DARKYELLOW}${SERVICE_NAME}${NORMAL}." |
|||
# echo "$out" | prefix " | " >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
e "$pads" |
|||
echo |
@ -0,0 +1,111 @@ |
|||
# -*- mode: shell-script -*- |
|||
|
|||
|
|||
CONFIG_DIR="$SERVICE_CONFIGSTORE"/etc/etherpad |
|||
ORIG_CONFIG_FILE="$CONFIG_DIR/settings.json.orig" |
|||
|
|||
etherpad:ensure-orig-json-exists() { |
|||
if ! [ -e "$ORIG_CONFIG_FILE" ]; then |
|||
mkdir -p "${ORIG_CONFIG_FILE%/*}" || return 1 |
|||
## Remove comments from container file and copy it in |
|||
## configstore |
|||
if out=$(docker run --rm --entrypoint bash "$DOCKER_BASE_IMAGE" \ |
|||
-c "npm install mjson && node_modules/.bin/mjson.js < settings.json"); then |
|||
## XXXvlab: output from mjson.js is still minified in my local install |
|||
## lets keep this code if necessary later. |
|||
# if ! echo "$out" | jq . > "$ORIG_CONFIG_FILE"; then |
|||
# err "Jq failed with output from container." |
|||
# rm -fv "$ORIG_CONFIG_FILE" |
|||
# return 1 |
|||
# fi |
|||
echo "$out" > "$ORIG_CONFIG_FILE" |
|||
else |
|||
err "Could not out-source clean 'setting.json' from container." |
|||
return 1 |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
|
|||
etherpad:api:init() { |
|||
container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 9001 4) || { |
|||
echo " Please ensure that ${DARKYELLOW}${SERVICE_NAME}${NORMAL} is running before using '$exname'." >&2 |
|||
return 1 |
|||
} |
|||
|
|||
container_ip=${container_network_ip##*:} |
|||
container_network=${container_network_ip%%:*} |
|||
|
|||
export ETHERPAD_DOCKER_OPTS=(--network "$container_network") |
|||
|
|||
if ! API_KEY=$(cat "$SERVICE_DATASTORE/var/lib/etherpad/APIKEY.txt"); then |
|||
err "Can't find API KEY for ${DARKYELLOW}${SERVICE_NAME}${NORMAL}." |
|||
return 1 |
|||
fi |
|||
|
|||
export DEFAULT_CURL_IMAGE=${DEFAULT_CURL_IMAGE:-docker.0k.io/curl} |
|||
export ETHERPAD_HOST="http://${container_ip}:9001" |
|||
|
|||
if ! out=$(etherpad:curl api/openapi.json); then |
|||
err "Couldn't get API description from ${DARKYELLOW}${SERVICE_NAME}${NORMAL}." |
|||
return 1 |
|||
fi |
|||
|
|||
if ! api_version=$(e "$out" | jq -r '.info.version'); then |
|||
err "Couldn't get version information from ${DARKYELLOW}${SERVICE_NAME}${NORMAL} API's description." |
|||
# echo "$out" | prefix " | " >&2 |
|||
return 1 |
|||
fi |
|||
|
|||
export ETHERPAD_API_BASE_PATH="api/${api_version}" |
|||
} |
|||
|
|||
etherpad:curl() { |
|||
local path="$1" cmd |
|||
shift |
|||
cmd=( |
|||
docker run --rm "${ETHERPAD_DOCKER_OPTS[@]}" |
|||
"$DEFAULT_CURL_IMAGE" |
|||
-sS |
|||
"$@" |
|||
"${ETHERPAD_HOST}/$path" |
|||
) |
|||
|
|||
# debug "Launching: ${cmd[@]}" |
|||
"${cmd[@]}" |
|||
} |
|||
|
|||
etherpad:api() { |
|||
local method="$1" code out |
|||
shift |
|||
|
|||
if [ -z "$ETHERPAD_API_BASE_PATH" ]; then |
|||
etherpad:api:init |
|||
fi |
|||
|
|||
if ! out=$( |
|||
etherpad:curl "${ETHERPAD_API_BASE_PATH}/$method" -X POST -d "apikey=${API_KEY}" "$@" |
|||
); then |
|||
err "Couldn't query API ${WHITE}$method${NORMAL} from ${DARKYELLOW}${SERVICE_NAME}${NORMAL}." |
|||
return 1 |
|||
fi |
|||
if ! code=$(e "$out" | jq -r ".code"); then |
|||
err "Unexpected response format from call to ${WHITE}$method${NORMAL} " \ |
|||
"API endpoint for ${DARKYELLOW}${SERVICE_NAME}${NORMAL}." |
|||
# echo "$out" | prefix " | " >&2 |
|||
exit 1 |
|||
fi |
|||
if [[ "$code" != "0" ]]; then |
|||
if ! message=$(e "$out" | jq -r ".message"); then |
|||
err "Unexpected response format from call to ${WHITE}$method${NORMAL} " \ |
|||
"API endpoint for ${DARKYELLOW}${SERVICE_NAME}${NORMAL}." |
|||
# echo "$out" | prefix " | " >&2 |
|||
exit 1 |
|||
fi |
|||
err "${WHITE}$method${NORMAL}: $message" |
|||
# echo "$out" | prefix " | " >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
e "$out" | jq '.data' |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue