Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
459f780049 | ||
|
|
97083982ba |
No files matched your search
@@ -19,8 +19,6 @@ on:
|
||||
- Caddyfile
|
||||
- portal/**
|
||||
- gdo/**
|
||||
- rauthy-providers.sh
|
||||
- rauthy-theme.sh
|
||||
- nats/nats.conf
|
||||
- rauthy/config.toml
|
||||
- deploy-tomtervel
|
||||
@@ -36,7 +34,6 @@ jobs:
|
||||
# What the stack is.
|
||||
PORTAL_HOST: ${{ vars.PORTAL_HOST }}
|
||||
CHAT_HOST: ${{ vars.CHAT_HOST }}
|
||||
PAY_HOST: ${{ vars.PAY_HOST }}
|
||||
PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }}
|
||||
GDO_RELEASE: ${{ vars.GDO_RELEASE }}
|
||||
CNATS_TAG: ${{ vars.CNATS_TAG }}
|
||||
@@ -79,16 +76,12 @@ jobs:
|
||||
OIDC_ISSUER: ${{ vars.OIDC_ISSUER }}
|
||||
RAUTHY_API_KEY: ${{ secrets.RAUTHY_API_KEY }}
|
||||
RAUTHY_LANGUAGE: ${{ vars.RAUTHY_LANGUAGE }}
|
||||
# The money service (README.md, "Payments"): Vipps's keys for the
|
||||
# Medlemskap sales unit, read by kron alone. All five are needed
|
||||
# once COMPOSE_PROFILES has `pay`; VIPPS_WEBHOOK_SECRET may wait,
|
||||
# kron then settles by asking Vipps every minute instead.
|
||||
VIPPS_MSN: ${{ vars.VIPPS_MSN }}
|
||||
VIPPS_CLIENT_ID: ${{ secrets.VIPPS_CLIENT_ID }}
|
||||
VIPPS_CLIENT_SECRET: ${{ secrets.VIPPS_CLIENT_SECRET }}
|
||||
VIPPS_SUBSCRIPTION_KEY: ${{ secrets.VIPPS_SUBSCRIPTION_KEY }}
|
||||
VIPPS_WEBHOOK_SECRET: ${{ secrets.VIPPS_WEBHOOK_SECRET }}
|
||||
steps:
|
||||
# The repo's own scripts (rauthy-providers.sh) run from the
|
||||
# checkout; the stack itself is pulled on the host by
|
||||
# deploy-tomtervel, not from here.
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# A missing value stops here, by name, before anything on the host
|
||||
# is touched. Only names are printed: the log is public.
|
||||
- name: Write the env files
|
||||
@@ -104,14 +97,6 @@ jobs:
|
||||
[ -n "${!v}" ] || missing="$missing $v"
|
||||
done
|
||||
[ -z "$missing" ] || { echo "not set as an Actions variable or secret:$missing"; exit 1; }
|
||||
pay=
|
||||
case ",$COMPOSE_PROFILES," in *,pay,*) pay=1;; esac
|
||||
if [ -n "$pay" ]; then
|
||||
for v in PAY_HOST VIPPS_MSN VIPPS_CLIENT_ID VIPPS_CLIENT_SECRET VIPPS_SUBSCRIPTION_KEY; do
|
||||
[ -n "${!v}" ] || missing="$missing $v"
|
||||
done
|
||||
[ -z "$missing" ] || { echo "COMPOSE_PROFILES has pay, but not set:$missing"; exit 1; }
|
||||
fi
|
||||
|
||||
umask 077
|
||||
mkdir -p "$STAGE"
|
||||
@@ -124,7 +109,6 @@ jobs:
|
||||
CNATS_TAG=$CNATS_TAG
|
||||
KRON_RELEASE=$KRON_RELEASE
|
||||
COMPOSE_PROFILES=$COMPOSE_PROFILES
|
||||
PAY_HOST=$PAY_HOST
|
||||
RAUTHY_HOST=$RAUTHY_HOST
|
||||
OIDC_ISSUER=$OIDC_ISSUER
|
||||
EOF
|
||||
@@ -154,13 +138,6 @@ jobs:
|
||||
RAUTHY_API_KEY=$RAUTHY_API_KEY
|
||||
RAUTHY_LANGUAGE=$RAUTHY_LANGUAGE
|
||||
EOF
|
||||
# With the money service in the stack, portal may ask for
|
||||
# payments without `by_hand`; the address itself is never
|
||||
# called (the two talk over NATS), the lint only reads that it
|
||||
# is set. The content repo's lint sets it the same way.
|
||||
if [ -n "$pay" ]; then
|
||||
echo "PAY_URL=http://kron:3000" >> "$STAGE/portal.env"
|
||||
fi
|
||||
# NATS itself (nats.conf reads NATS_PASSWORD), gdo and the chat.
|
||||
cat > "$STAGE/nats.env" <<EOF
|
||||
NATS_PASSWORD=$NATS_PASSWORD
|
||||
@@ -170,15 +147,6 @@ jobs:
|
||||
OAUTH2_CLIENT_ID=$CHAT_OAUTH2_CLIENT_ID
|
||||
OAUTH2_CLIENT_SECRET=$CHAT_OAUTH2_CLIENT_SECRET
|
||||
EOF
|
||||
# kron: Vipps's keys for the Medlemskap sales unit. Written even
|
||||
# without the profile, so the file compose names is there.
|
||||
cat > "$STAGE/kron.env" <<EOF
|
||||
VIPPS_MSN=$VIPPS_MSN
|
||||
VIPPS_CLIENT_ID=$VIPPS_CLIENT_ID
|
||||
VIPPS_CLIENT_SECRET=$VIPPS_CLIENT_SECRET
|
||||
VIPPS_SUBSCRIPTION_KEY=$VIPPS_SUBSCRIPTION_KEY
|
||||
WEBHOOK_SECRET=$VIPPS_WEBHOOK_SECRET
|
||||
EOF
|
||||
# Rauthy's secrets. The first admin is the vel's first person.
|
||||
cat > "$STAGE/rauthy.env" <<EOF
|
||||
ENC_KEYS=$RAUTHY_ENC_KEY
|
||||
@@ -200,7 +168,7 @@ jobs:
|
||||
# "$$" is compose's literal "$". Without this, RAUTHY_API_KEY reached
|
||||
# portal as "portal" alone, Rauthy answered 401, and every invite
|
||||
# failed. .env is left alone: it is what compose.yml interpolates.
|
||||
sed -i 's/\$/$$/g' "$STAGE/portal.env" "$STAGE/nats.env" "$STAGE/chat.env" "$STAGE/rauthy.env" "$STAGE/kron.env"
|
||||
sed -i 's/\$/$$/g' "$STAGE/portal.env" "$STAGE/nats.env" "$STAGE/chat.env" "$STAGE/rauthy.env"
|
||||
|
||||
- name: Pull and bring the stack up
|
||||
run: sudo /usr/local/bin/deploy-tomtervel
|
||||
@@ -213,8 +181,3 @@ jobs:
|
||||
VIPPS_LOGIN_CLIENT_ID: ${{ vars.VIPPS_LOGIN_CLIENT_ID }}
|
||||
VIPPS_LOGIN_CLIENT_SECRET: ${{ secrets.VIPPS_LOGIN_CLIENT_SECRET }}
|
||||
run: ./rauthy-providers.sh
|
||||
|
||||
# The vel's colours on Rauthy's pages: rauthy-theme.sh. Needs the
|
||||
# API key to have Clients read and update; without, it says so.
|
||||
- name: Colours in Rauthy
|
||||
run: ./rauthy-theme.sh
|
||||
@@ -5,4 +5,3 @@ gitea-oauth.secret
|
||||
dns/cloudflare.env
|
||||
nats.env
|
||||
rauthy.env
|
||||
kron.env
|
||||
@@ -124,10 +124,6 @@ Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`,
|
||||
| `RAUTHY_BOOTSTRAP_API_KEY`, `RAUTHY_BOOTSTRAP_API_KEY_SECRET` | secret | repo | optional, Rauthy's first start only: a short-lived key (base64 of `{"name","exp","access"}`, secret 64+ alphanumerics) that makes the OIDC clients through the API; read into an empty database, ignored after |
|
||||
| `RAUTHY_API_KEY`, `RAUTHY_LANGUAGE` | secret, variable | repo | portal makes accounts in Rauthy (`<name>$<secret>`, made in Rauthy's admin), in `nb` |
|
||||
| `VIPPS_LOGIN_CLIENT_ID`, `VIPPS_LOGIN_CLIENT_SECRET` | variable, secret | repo | Vipps Login (the login sales unit's keys from portal.vippsmobilepay.no): the deploy keeps Vipps as a sign-in provider in Rauthy with them (`rauthy-providers.sh`) |
|
||||
| `PAY_HOST` | variable | repo | where the money service answers: `betaling.tomtervel.no` (DNS in `dns/`, a kasse Caddy block) |
|
||||
| `VIPPS_MSN` | variable | repo | the Medlemskap sales unit's merchant serial number, `1192072` |
|
||||
| `VIPPS_CLIENT_ID`, `VIPPS_CLIENT_SECRET`, `VIPPS_SUBSCRIPTION_KEY` | secret | repo | the Medlemskap sales unit's ePayment keys (For developers, API keys, production), read by kron alone |
|
||||
| `VIPPS_WEBHOOK_SECRET` | secret | repo | what Vipps signs its webhooks with, from `vipps-webhook.sh register`; unset, kron refuses webhooks and asks Vipps about each open payment every minute instead |
|
||||
|
||||
A variable is printed wherever a workflow echoes it, and this repo's run
|
||||
logs are public: a value that must not be read is a secret.
|
||||
@@ -135,54 +131,6 @@ logs are public: a value that must not be read is a secret.
|
||||
What is not a value stays on the host, made there once: Garage's node
|
||||
secret.
|
||||
|
||||
## Colours in Rauthy
|
||||
|
||||
`rauthy-theme.sh` puts the site's palette (custom.css in the content
|
||||
repo) on Rauthy's sign-in, account and admin pages, for Rauthy's own
|
||||
client and the portal's, on every deploy. It needs the portal API key to
|
||||
have Clients read and update; until it does, the step says so and
|
||||
changes nothing, and the theme can be set by hand in the admin
|
||||
(Clients, the client, Branding).
|
||||
|
||||
## Payments
|
||||
|
||||
The money service is [kron](https://project.uhhm.no/uhhm/kron), in the
|
||||
stack under the `pay` profile (`COMPOSE_PROFILES=chat,pay`). Portal
|
||||
decides when money is owed: a household entering `open` or `fornyes` in
|
||||
the content's aggregates owes the fee, and portal publishes one request
|
||||
on this stack's NATS. kron answers at once with a link of its own,
|
||||
`https://betaling.tomtervel.no/pay/<reference>`, which portal shows on
|
||||
the person's own page and mails; opening it makes a Vipps payment for
|
||||
the Medlemskap sales unit and sends the person into Vipps, and a fresh
|
||||
one each time the last ran out (Vipps's own expire after ten minutes).
|
||||
Once they have paid, kron captures the reserved amount and says `paid`
|
||||
on the bus; portal moves the household to `betalt`, grants `medlemmer`,
|
||||
and mails them. Vipps's keys live in `kron.env` and nowhere else; portal
|
||||
never calls Vipps. `PAY_URL` in `portal.env` is what lets the content
|
||||
leave `by_hand: true` out of a `payment:`; portal never calls that
|
||||
address either.
|
||||
|
||||
Going live, in order:
|
||||
|
||||
1. Set `PAY_HOST`, `VIPPS_MSN` and the three key secrets (table above).
|
||||
The keys are in `pass` as `tomtervel/vipps/medlemskap`.
|
||||
2. Merge the DNS record (`dns/dnsconfig.js`, `betaling`) and run the DNS
|
||||
workflow; add the `betaling.tomtervel.no` block from
|
||||
`host-caddy/tomtervel.no` to kasse's Caddy.
|
||||
3. Set `COMPOSE_PROFILES=chat,pay` and `KRON_RELEASE` (a uhhm/kron
|
||||
version, `0.1.0`: the image is project.uhhm.no/uhhm/kron), then Run
|
||||
workflow. `https://betaling.tomtervel.no/healthz`
|
||||
answers `ok`.
|
||||
4. Register the webhook: `./vipps-webhook.sh register` on a machine with
|
||||
`pass` (it puts the secret in pass), then `gt secret set
|
||||
VIPPS_WEBHOOK_SECRET` as it says, and Run workflow once more. Until
|
||||
then kron settles by polling, a minute behind.
|
||||
5. Drop `by_hand: true` from the content's `payment:` states (the
|
||||
content repo's lint reads `PAY_URL` the same way).
|
||||
|
||||
Nothing here touches the Vippsnummer (500396): people may keep paying
|
||||
there, and the treasurer marks those by hand as before.
|
||||
|
||||
## Rauthy
|
||||
|
||||
[Rauthy](https://github.com/sebadob/rauthy) at `RAUTHY_HOST`
|
||||
|
||||
-28
@@ -144,34 +144,6 @@ services:
|
||||
nats:
|
||||
condition: service_healthy
|
||||
|
||||
# The money service (uhhm/kron): portal asks for a payment on this
|
||||
# NATS as a household owes its fee, kron gives it a link to pay by,
|
||||
# talks to Vipps's ePayment API for the Medlemskap sales unit, and
|
||||
# says `paid` back on the same bus. Vipps's keys are in kron.env and
|
||||
# nowhere else; portal never calls Vipps. Host-published for kasse's
|
||||
# host Caddy (betaling.tomtervel.no -> here): the pay links, the page
|
||||
# people come back to from Vipps, and Vipps's webhooks. A profile, since
|
||||
# it needs kron.env: COMPOSE_PROFILES gains `pay` once the keys are set.
|
||||
kron:
|
||||
profiles: ["pay"]
|
||||
image: project.uhhm.no/uhhm/kron:${KRON_RELEASE:-no-tag-set}
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- nats.env
|
||||
- kron.env
|
||||
environment:
|
||||
# Must be the portal's own: a request names its site.
|
||||
SITE_NAME: tomtervel
|
||||
PROVIDER: vipps
|
||||
VIPPS_ENV: prod
|
||||
PUBLIC_URL: https://${PAY_HOST:-no-host-set}
|
||||
LISTEN_ADDR: 0.0.0.0:3000
|
||||
ports:
|
||||
- "127.0.0.1:3080:3000"
|
||||
depends_on:
|
||||
nats:
|
||||
condition: service_healthy
|
||||
|
||||
# The Gitea Actions runner is a host service on kasse (pacman gitea-runner),
|
||||
# registered against prosjekt.klingenbergbygg.no. It reaches this NATS via the
|
||||
# published 127.0.0.1:4222 port above, so no in-compose runner — and no
|
||||
|
||||
@@ -31,8 +31,6 @@ D("tomtervel.no", REG_NONE, DnsProvider(DSP_CLOUDFLARE),
|
||||
A("@", KASSE, CF_PROXY_OFF),
|
||||
CNAME("www", "tomtervel.no.", CF_PROXY_OFF),
|
||||
A("konto", KASSE, CF_PROXY_OFF),
|
||||
// The money service (kron): pay links and Vipps's webhooks.
|
||||
A("betaling", KASSE, CF_PROXY_OFF),
|
||||
A("samtaler", KASSE, CF_PROXY_OFF),
|
||||
// The old names, kept so links from before still land: Caddy sends
|
||||
// id on to konto (the login) and chat on to samtaler.
|
||||
|
||||
@@ -33,14 +33,6 @@ konto.tomtervel.no {
|
||||
reverse_proxy 127.0.0.1:8090
|
||||
}
|
||||
|
||||
# The money service (kron, README.md "Payments"): the pay links portal
|
||||
# gives out, the page people come back to from Vipps, and Vipps's
|
||||
# webhooks. Kept out of search engines; nothing here is a page to find.
|
||||
betaling.tomtervel.no {
|
||||
header X-Robots-Tag "noindex, nofollow"
|
||||
reverse_proxy 127.0.0.1:3080
|
||||
}
|
||||
|
||||
# The content repo's previews (tomtervel/questions, .gitea/preview/): one
|
||||
# portal per branch on <branch>.forhandsvisning.tomtervel.no, for five days
|
||||
# after its last push, and the list of them on the bare name. Every name
|
||||
|
||||
+1
-8
@@ -10,13 +10,6 @@
|
||||
# Vipps's side: the sales unit's Vipps Login must have the redirect URI
|
||||
# https://<RAUTHY_HOST>/auth/v1/providers/callback registered, or every
|
||||
# sign-in is refused there.
|
||||
#
|
||||
# auto_link: a Vipps sign-in whose (Vipps-verified) email is an account
|
||||
# here already is linked to that account, so the board's password and
|
||||
# passkey accounts and Vipps lead to the same person and the same groups.
|
||||
# Without it Rauthy refuses the sign-in and asks them to link it from
|
||||
# their account page first, which nobody finds. auto_onboarding: a new
|
||||
# address becomes an account on the spot.
|
||||
set -euo pipefail
|
||||
for v in RAUTHY_HOST RAUTHY_API_KEY VIPPS_LOGIN_CLIENT_ID VIPPS_LOGIN_CLIENT_SECRET; do
|
||||
[ -n "${!v:-}" ] || { echo "rauthy-providers: $v is not set; nothing changed"; exit 0; }
|
||||
@@ -33,7 +26,7 @@ vipps=$(jq -n --arg id "$VIPPS_LOGIN_CLIENT_ID" --arg secret "$VIPPS_LOGIN_CLIEN
|
||||
client_id: $id, client_secret: $secret, client_secret_basic: true, client_secret_post: false,
|
||||
scope: "openid name email phoneNumber", use_pkce: true, danger_allow_insecure: false, root_pem: null,
|
||||
admin_claim_path: null, admin_claim_value: null, mfa_claim_path: null, mfa_claim_value: null,
|
||||
auto_onboarding: true, auto_link: true }')
|
||||
auto_onboarding: true, auto_link: false }')
|
||||
# Listing is a POST in Rauthy's API.
|
||||
existing=$(curl -sf -X POST -H "$auth" -H 'content-type: application/json' -d '{}' "$base/providers" | jq -r '.[] | select(.name == "Vipps") | .id' | head -n1)
|
||||
if [ -n "$existing" ]; then
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tomter Vel's colours on Rauthy's pages (sign-in, account, the admin),
|
||||
# as the deploy keeps them: Rauthy has no file for a theme, only its API,
|
||||
# so this script is the file. The palette is the site's (custom.css in
|
||||
# tomtervel/questions): accent #1785c2, paper #fffceb, ink #111111, line
|
||||
# #e6dfbf, error #ff4136, as HSL. Rauthy themes per OIDC client; the
|
||||
# sign-in page shows the client's theme and the account pages Rauthy's
|
||||
# own (`rauthy`), so both get the same. Needs RAUTHY_HOST and
|
||||
# RAUTHY_API_KEY with Clients read and update; without those rights it
|
||||
# says so and changes nothing.
|
||||
set -euo pipefail
|
||||
for v in RAUTHY_HOST RAUTHY_API_KEY; do
|
||||
[ -n "${!v:-}" ] || { echo "rauthy-theme: $v is not set; nothing changed"; exit 0; }
|
||||
done
|
||||
base="https://$RAUTHY_HOST/auth/v1"
|
||||
auth="Authorization: API-Key $RAUTHY_API_KEY"
|
||||
# Light: paper and ink. Dark: the same blue on a night sky.
|
||||
theme=$(jq -n '{
|
||||
light: { text: [46, 15, 27], text_high: [0, 0, 7], bg: [51, 100, 96], bg_high: [49, 44, 90],
|
||||
action: [201, 79, 43], accent: [201, 79, 33], error: [3, 100, 61],
|
||||
btn_text: "white", theme_sun: "hsla(var(--action) / .7)", theme_moon: "hsla(var(--accent) / .85)" },
|
||||
dark: { text: [49, 30, 78], text_high: [51, 100, 96], bg: [201, 35, 9], bg_high: [201, 25, 16],
|
||||
action: [201, 79, 52], accent: [201, 70, 70], error: [3, 100, 61],
|
||||
btn_text: "hsl(var(--bg))", theme_sun: "hsla(var(--action) / .7)", theme_moon: "hsla(var(--accent) / .85)" },
|
||||
border_radius: "6px" }')
|
||||
for client in rauthy ${OAUTH2_CLIENT_ID:-portal} ${CHAT_OAUTH2_CLIENT_ID:-}; do
|
||||
body=$(jq --arg c "$client" '. + {client_id: $c}' <<<"$theme")
|
||||
code=$(curl -s -o /tmp/rauthy-theme.out -w '%{http_code}' -X PUT -H "$auth" -H 'Content-Type: application/json' -d "$body" "$base/theme/$client")
|
||||
case "$code" in
|
||||
200|201|204) echo "rauthy-theme: $client themed" ;;
|
||||
403) echo "rauthy-theme: the API key may not update clients (403); give it Clients read+update, or set the theme in the admin. Nothing changed."; exit 0 ;;
|
||||
*) echo "rauthy-theme: $client: http $code: $(head -c 300 /tmp/rauthy-theme.out)"; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
@@ -1,53 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Vipps's webhooks for the money service (kron): registers kron's
|
||||
# endpoint with the Webhooks API for the Medlemskap sales unit, or lists
|
||||
# what is registered. Run by a person with the keys in `pass`, not by the
|
||||
# deploy: the registration answers with the webhook's secret exactly once,
|
||||
# and that secret has to become the repo secret VIPPS_WEBHOOK_SECRET (and
|
||||
# kron's WEBHOOK_SECRET) without ever being printed in a public log.
|
||||
#
|
||||
# ./vipps-webhook.sh list # what Vipps has for the unit
|
||||
# ./vipps-webhook.sh register # kron's /webhook, secret into pass
|
||||
# ./vipps-webhook.sh delete <webhook id>
|
||||
#
|
||||
# VIPPS_ENV=test uses apitest.vipps.no and the test unit's keys
|
||||
# (tomtervel/vipps/medlemskap-test in pass); the default is production
|
||||
# (tomtervel/vipps/medlemskap). PAY_HOST is the host kron answers on
|
||||
# (betaling.tomtervel.no).
|
||||
set -euo pipefail
|
||||
env=${VIPPS_ENV:-prod}
|
||||
case "$env" in
|
||||
test) api=https://apitest.vipps.no; entry=tomtervel/vipps/medlemskap-test ;;
|
||||
prod) api=https://api.vipps.no; entry=tomtervel/vipps/medlemskap ;;
|
||||
*) echo "VIPPS_ENV is $env; it is test or prod" >&2; exit 2 ;;
|
||||
esac
|
||||
host=${PAY_HOST:-betaling.tomtervel.no}
|
||||
field() { pass show "$entry" | sed -n "s/^$1: //p" | head -n1; }
|
||||
msn=$(field msn); cid=$(field client_id); csec=$(field client_secret); sub=$(field subscription_key_primary)
|
||||
[ -n "$msn" ] && [ -n "$cid" ] && [ -n "$csec" ] && [ -n "$sub" ] || { echo "pass entry $entry lacks msn, client_id, client_secret or subscription_key_primary" >&2; exit 1; }
|
||||
token=$(curl -sf -X POST "$api/accesstoken/get" -H "client_id: $cid" -H "client_secret: $csec" \
|
||||
-H "Ocp-Apim-Subscription-Key: $sub" -H "Merchant-Serial-Number: $msn" -H 'Content-Length: 0' | jq -r .access_token)
|
||||
[ -n "$token" ] && [ "$token" != null ] || { echo "no access token from $api" >&2; exit 1; }
|
||||
auth=(-H "Authorization: Bearer $token" -H "Ocp-Apim-Subscription-Key: $sub" -H "Merchant-Serial-Number: $msn" -H 'Content-Type: application/json')
|
||||
|
||||
case "${1:-list}" in
|
||||
list)
|
||||
curl -sf "$api/webhooks/v1/webhooks" "${auth[@]}" | jq .
|
||||
;;
|
||||
register)
|
||||
url="https://$host/webhook"
|
||||
events='["epayments.payment.created.v1","epayments.payment.authorized.v1","epayments.payment.captured.v1","epayments.payment.aborted.v1","epayments.payment.expired.v1","epayments.payment.cancelled.v1","epayments.payment.terminated.v1","epayments.payment.refunded.v1"]'
|
||||
answer=$(curl -sf -X POST "$api/webhooks/v1/webhooks" "${auth[@]}" -d "$(jq -n --arg url "$url" --argjson events "$events" '{url: $url, events: $events}')")
|
||||
id=$(jq -r .id <<<"$answer"); secret=$(jq -r .secret <<<"$answer")
|
||||
[ -n "$secret" ] && [ "$secret" != null ] || { echo "Vipps answered without a secret: $(jq -c 'del(.secret)' <<<"$answer")" >&2; exit 1; }
|
||||
# The secret goes into pass and nowhere on screen.
|
||||
printf 'id: %s\nurl: %s\nsecret: %s\n' "$id" "$url" "$secret" | pass insert -m -f "$entry-webhook" >/dev/null
|
||||
echo "registered webhook $id for $url; its secret is in pass as $entry-webhook"
|
||||
echo "now: pass show $entry-webhook | sed -n 's/^secret: //p' | gt secret set VIPPS_WEBHOOK_SECRET"
|
||||
;;
|
||||
delete)
|
||||
[ -n "${2:-}" ] || { echo "which webhook? ./vipps-webhook.sh delete <id>" >&2; exit 2; }
|
||||
curl -sf -X DELETE "$api/webhooks/v1/webhooks/$2" "${auth[@]}" && echo "deleted $2"
|
||||
;;
|
||||
*) echo "usage: $0 list | register | delete <id>" >&2; exit 2 ;;
|
||||
esac
|
||||
Reference in new issue
Block a user