interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / tools / doi / fixture-curl.sh

47 lines · 2179 bytes Raw Blame History
1#!/bin/sh
2# Offline curl stand-in: accepts the same argv as doi.sh gives curl, reads auth only
3# from stdin, copies fixed fixture answers, and records requests without the bearer.
4set +x
5set -eu
6F=$1; shift
7printf '%s\n' '--- argv ---' "$@" >> "$F/argv.log"
8method= url= output= payload= upload= config=
9while [ "$#" -gt 0 ]; do
10 case "$1" in
11 --request) method=$2; shift 2;;
12 --url) url=$2; shift 2;;
13 --output) output=$2; shift 2;;
14 --data-binary) payload=$2; shift 2;;
15 --upload-file) upload=$2; shift 2;;
16 --config) config=$2; shift 2;;
17 --proto|--max-redirs|--proxy|--write-out|--header) shift 2;;
18 -q|--globoff|--silent|--show-error) shift;;
19 *) echo 'fixture-curl: unexpected option' >&2; exit 2;;
20 esac
21done
22[ "$config" = - ] || exit 2
23IFS= read -r auth || exit 2
24# Comparison stays in the shell, not argv, output or a file.
25[ "$auth" = "header = \"Authorization: Bearer ${ZENODO_TOKEN:?}\"" ] || exit 2
26unset auth
27printf '%s %s auth=ok\n' "$method" "$url" >> "$F/requests.log"
28case "$method $url" in
29 'POST https://sandbox.zenodo.org/api/deposit/depositions'|'POST https://zenodo.org/api/deposit/depositions')
30 kind=create; code=201
31 case "$payload" in @*) cp -- "${payload#@}" "$F/request-create.json";; *) exit 2;; esac;;
32 'PUT https://sandbox.zenodo.org/api/files/'*|'PUT https://zenodo.org/api/files/'*)
33 kind=upload; code=200
34 [ -f "$upload" ] || exit 2
35 cp -- "$upload" "$F/uploaded-${upload##*/}"
36 # A per-file acknowledgement allows PDF and source uploads in one fixture.
37 if [ -f "$F/upload-${upload##*/}.json" ]; then kind=upload-${upload##*/}; fi;;
38 'POST https://sandbox.zenodo.org/api/deposit/depositions/'*'/actions/publish'|'POST https://zenodo.org/api/deposit/depositions/'*'/actions/publish')
39 kind=publish; code=202
40 [ "$payload" = '{}' ] || exit 2;;
41 *) echo 'fixture-curl: unexpected request URL or method' >&2; exit 2;;
42esac
43# Test-only timing actions are confined to this offline transport, never the product engine.
44if [ -f "$F/$kind.hook" ]; then sh "$F/$kind.hook"; fi
45cp -- "$F/$kind.json" "$output"
46if [ -f "$F/$kind.code" ]; then code=$(cat "$F/$kind.code"); fi
47printf '%s' "$code"