Mercurial > prosody-modules
comparison mod_rest/example/rest.sh @ 5666:e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 01 Oct 2023 16:39:48 +0200 |
| parents | acd2f397ce6b |
| children | a9c75430cb26 |
comparison
equal
deleted
inserted
replaced
| 5665:bbde136a4c29 | 5666:e5ad3f1f48bd |
|---|---|
| 11 | 11 |
| 12 # Settings | 12 # Settings |
| 13 HOST="" | 13 HOST="" |
| 14 DOMAIN="" | 14 DOMAIN="" |
| 15 | 15 |
| 16 SESSION="session-read-only" | |
| 17 | |
| 16 if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" ]; then | 18 if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" ]; then |
| 17 # Config file can contain the above settings | 19 # Config file can contain the above settings |
| 18 source "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" | 20 source "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" |
| 19 | 21 |
| 20 if [ -z "${SCOPE:-}" ]; then | 22 if [ -z "${SCOPE:-}" ]; then |
| 21 SCOPE="openid xmpp" | 23 SCOPE="openid xmpp" |
| 22 fi | 24 fi |
| 23 fi | 25 fi |
| 24 | 26 |
| 25 if [[ $# == 0 ]]; then | 27 if [[ $# == 0 ]]; then |
| 26 echo "${0##*/} [-h HOST] [/path] kind=(message|presence|iq) ...." | 28 echo "${0##*/} [-h HOST] [-rw] [/path] kind=(message|presence|iq) ...." |
| 27 # Last arguments are handed to HTTPie, so refer to its docs for further details | 29 # Last arguments are handed to HTTPie, so refer to its docs for further details |
| 28 exit 0 | 30 exit 0 |
| 29 fi | 31 fi |
| 30 | 32 |
| 31 if [[ "$1" == "-h" ]]; then | 33 if [[ "$1" == "-h" ]]; then |
| 32 HOST="$2" | 34 HOST="$2" |
| 33 shift 2 | 35 shift 2 |
| 34 elif [ -z "${HOST:-}" ]; then | 36 elif [ -z "${HOST:-}" ]; then |
| 35 HOST="$(hostname)" | 37 HOST="$(hostname)" |
| 38 fi | |
| 39 | |
| 40 if [[ "$1" == "-rw" ]]; then | |
| 41 # To e.g. save Accept headers to the session | |
| 42 SESSION="session" | |
| 43 shift 1 | |
| 36 fi | 44 fi |
| 37 | 45 |
| 38 if [[ "$HOST" != *.* ]]; then | 46 if [[ "$HOST" != *.* ]]; then |
| 39 # Assumes subdomain of your DOMAIN | 47 # Assumes subdomain of your DOMAIN |
| 40 if [ -z "${DOMAIN:-}" ]; then | 48 if [ -z "${DOMAIN:-}" ]; then |
| 53 if [[ "$1" == /* ]]; then | 61 if [[ "$1" == /* ]]; then |
| 54 GET_PATH="$1" | 62 GET_PATH="$1" |
| 55 shift 1 | 63 shift 1 |
| 56 fi | 64 fi |
| 57 | 65 |
| 58 https --check-status -p b --session rest -A oauth2 -a "$HOST" --oauth2-scope "$SCOPE" "$HOST/rest$GET_PATH" "$@" | 66 https --check-status -p b --"$SESSION" rest -A oauth2 -a "$HOST" --oauth2-scope "$SCOPE" "$HOST/rest$GET_PATH" "$@" |
