Compare commits
23
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1106dc1b8 | ||
|
|
78e7aaba6d | ||
|
|
1c9004b30d | ||
|
|
43421f0923 | ||
|
|
6d5e936f18 | ||
|
|
48f286650b | ||
|
|
99852cdce6 | ||
|
|
3d7da36401 | ||
|
|
bd37ae5786 | ||
|
|
6cbd6ada9b | ||
|
|
459f780049 | ||
|
|
0c60e8f181 | ||
|
|
7e241a90d0 | ||
|
|
a0af480890 | ||
|
|
47342b0867 | ||
|
|
97083982ba | ||
|
|
c88d396ad7 | ||
|
|
33e102dc25 | ||
|
|
64fc9a1911 | ||
|
|
b2ee900602 | ||
|
|
b128801ee2 | ||
|
|
fdac5084d1 | ||
|
|
4cf56ac588 |
No files matched your search
@@ -19,6 +19,8 @@ on:
|
|||||||
- Caddyfile
|
- Caddyfile
|
||||||
- portal/**
|
- portal/**
|
||||||
- gdo/**
|
- gdo/**
|
||||||
|
- rauthy-providers.sh
|
||||||
|
- rauthy-theme.sh
|
||||||
- nats/nats.conf
|
- nats/nats.conf
|
||||||
- rauthy/config.toml
|
- rauthy/config.toml
|
||||||
- deploy-tomtervel
|
- deploy-tomtervel
|
||||||
@@ -34,6 +36,7 @@ jobs:
|
|||||||
# What the stack is.
|
# What the stack is.
|
||||||
PORTAL_HOST: ${{ vars.PORTAL_HOST }}
|
PORTAL_HOST: ${{ vars.PORTAL_HOST }}
|
||||||
CHAT_HOST: ${{ vars.CHAT_HOST }}
|
CHAT_HOST: ${{ vars.CHAT_HOST }}
|
||||||
|
PAY_HOST: ${{ vars.PAY_HOST }}
|
||||||
PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }}
|
PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }}
|
||||||
GDO_RELEASE: ${{ vars.GDO_RELEASE }}
|
GDO_RELEASE: ${{ vars.GDO_RELEASE }}
|
||||||
CNATS_TAG: ${{ vars.CNATS_TAG }}
|
CNATS_TAG: ${{ vars.CNATS_TAG }}
|
||||||
@@ -76,7 +79,23 @@ jobs:
|
|||||||
OIDC_ISSUER: ${{ vars.OIDC_ISSUER }}
|
OIDC_ISSUER: ${{ vars.OIDC_ISSUER }}
|
||||||
RAUTHY_API_KEY: ${{ secrets.RAUTHY_API_KEY }}
|
RAUTHY_API_KEY: ${{ secrets.RAUTHY_API_KEY }}
|
||||||
RAUTHY_LANGUAGE: ${{ vars.RAUTHY_LANGUAGE }}
|
RAUTHY_LANGUAGE: ${{ vars.RAUTHY_LANGUAGE }}
|
||||||
|
# The money service (README.md, "Payments"): Vipps's keys for the
|
||||||
|
# Medlemskap sales unit, read by kron alone. Unset, kron starts
|
||||||
|
# without them and asks for them on the treasurer's desk
|
||||||
|
# ("Tjenester som venter"), sealed to its own identity; set, they
|
||||||
|
# are kron's from the env. 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:
|
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
|
# A missing value stops here, by name, before anything on the host
|
||||||
# is touched. Only names are printed: the log is public.
|
# is touched. Only names are printed: the log is public.
|
||||||
- name: Write the env files
|
- name: Write the env files
|
||||||
@@ -92,6 +111,14 @@ jobs:
|
|||||||
[ -n "${!v}" ] || missing="$missing $v"
|
[ -n "${!v}" ] || missing="$missing $v"
|
||||||
done
|
done
|
||||||
[ -z "$missing" ] || { echo "not set as an Actions variable or secret:$missing"; exit 1; }
|
[ -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
|
umask 077
|
||||||
mkdir -p "$STAGE"
|
mkdir -p "$STAGE"
|
||||||
@@ -104,6 +131,7 @@ jobs:
|
|||||||
CNATS_TAG=$CNATS_TAG
|
CNATS_TAG=$CNATS_TAG
|
||||||
KRON_RELEASE=$KRON_RELEASE
|
KRON_RELEASE=$KRON_RELEASE
|
||||||
COMPOSE_PROFILES=$COMPOSE_PROFILES
|
COMPOSE_PROFILES=$COMPOSE_PROFILES
|
||||||
|
PAY_HOST=$PAY_HOST
|
||||||
RAUTHY_HOST=$RAUTHY_HOST
|
RAUTHY_HOST=$RAUTHY_HOST
|
||||||
OIDC_ISSUER=$OIDC_ISSUER
|
OIDC_ISSUER=$OIDC_ISSUER
|
||||||
EOF
|
EOF
|
||||||
@@ -133,6 +161,13 @@ jobs:
|
|||||||
RAUTHY_API_KEY=$RAUTHY_API_KEY
|
RAUTHY_API_KEY=$RAUTHY_API_KEY
|
||||||
RAUTHY_LANGUAGE=$RAUTHY_LANGUAGE
|
RAUTHY_LANGUAGE=$RAUTHY_LANGUAGE
|
||||||
EOF
|
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.
|
# NATS itself (nats.conf reads NATS_PASSWORD), gdo and the chat.
|
||||||
cat > "$STAGE/nats.env" <<EOF
|
cat > "$STAGE/nats.env" <<EOF
|
||||||
NATS_PASSWORD=$NATS_PASSWORD
|
NATS_PASSWORD=$NATS_PASSWORD
|
||||||
@@ -142,6 +177,16 @@ jobs:
|
|||||||
OAUTH2_CLIENT_ID=$CHAT_OAUTH2_CLIENT_ID
|
OAUTH2_CLIENT_ID=$CHAT_OAUTH2_CLIENT_ID
|
||||||
OAUTH2_CLIENT_SECRET=$CHAT_OAUTH2_CLIENT_SECRET
|
OAUTH2_CLIENT_SECRET=$CHAT_OAUTH2_CLIENT_SECRET
|
||||||
EOF
|
EOF
|
||||||
|
# kron: Vipps's keys for the Medlemskap sales unit, when the
|
||||||
|
# deploy holds them; none set, and kron asks for them through
|
||||||
|
# portal (kron refuses some set and some not). Written even
|
||||||
|
# without the profile, so the file compose names is there.
|
||||||
|
{
|
||||||
|
echo "WEBHOOK_SECRET=$VIPPS_WEBHOOK_SECRET"
|
||||||
|
for name in VIPPS_MSN VIPPS_CLIENT_ID VIPPS_CLIENT_SECRET VIPPS_SUBSCRIPTION_KEY; do
|
||||||
|
if [ -n "${!name}" ]; then echo "$name=${!name}"; fi
|
||||||
|
done
|
||||||
|
} > "$STAGE/kron.env"
|
||||||
# Rauthy's secrets. The first admin is the vel's first person.
|
# Rauthy's secrets. The first admin is the vel's first person.
|
||||||
cat > "$STAGE/rauthy.env" <<EOF
|
cat > "$STAGE/rauthy.env" <<EOF
|
||||||
ENC_KEYS=$RAUTHY_ENC_KEY
|
ENC_KEYS=$RAUTHY_ENC_KEY
|
||||||
@@ -156,6 +201,28 @@ jobs:
|
|||||||
printf 'BOOTSTRAP_API_KEY=%s\nBOOTSTRAP_API_KEY_SECRET=%s\n' \
|
printf 'BOOTSTRAP_API_KEY=%s\nBOOTSTRAP_API_KEY_SECRET=%s\n' \
|
||||||
"$RAUTHY_BOOTSTRAP_API_KEY" "$RAUTHY_BOOTSTRAP_API_KEY_SECRET" >> "$STAGE/rauthy.env"
|
"$RAUTHY_BOOTSTRAP_API_KEY" "$RAUTHY_BOOTSTRAP_API_KEY_SECRET" >> "$STAGE/rauthy.env"
|
||||||
fi
|
fi
|
||||||
|
# Compose reads an env_file the way it reads compose.yml: "$name" in
|
||||||
|
# a value is a variable to fill in, and one that is not set comes
|
||||||
|
# out empty. Every value above is the secret itself, so a "$" left
|
||||||
|
# in one is literal (Rauthy's API keys are "<name>$<secret>"), and
|
||||||
|
# "$$" 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"
|
||||||
|
|
||||||
- name: Pull and bring the stack up
|
- name: Pull and bring the stack up
|
||||||
run: sudo /usr/local/bin/deploy-tomtervel
|
run: sudo /usr/local/bin/deploy-tomtervel
|
||||||
|
|
||||||
|
# The sign-in providers Rauthy offers (Vipps Login), kept by the
|
||||||
|
# deploy through Rauthy's API: rauthy-providers.sh. Unset values
|
||||||
|
# change nothing.
|
||||||
|
- name: Sign-in providers in Rauthy
|
||||||
|
env:
|
||||||
|
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,3 +5,4 @@ gitea-oauth.secret
|
|||||||
dns/cloudflare.env
|
dns/cloudflare.env
|
||||||
nats.env
|
nats.env
|
||||||
rauthy.env
|
rauthy.env
|
||||||
|
kron.env
|
||||||
@@ -62,10 +62,13 @@ account mail, in Norwegian. Portal and the chat sign in there
|
|||||||
`responsible` gets an account at start and a place in
|
`responsible` gets an account at start and a place in
|
||||||
`RESPONSIBLE_GROUP` (`redaktor`).
|
`RESPONSIBLE_GROUP` (`redaktor`).
|
||||||
|
|
||||||
The groups are portal's (`PEOPLE_BACKEND=memberships`): who is in
|
The groups are kept in Rauthy (`PEOPLE_BACKEND=rauthy`): an invite
|
||||||
`styret` is on the board's desk, "Medlemmer og invitasjoner", where a
|
puts the person in the group there, and an invite is a case in
|
||||||
person is taken out or invited again. Portal decides what a group may
|
`portal_invites` until they come. Who is in `styret` is on the board's
|
||||||
do, on the site and in the chat's rooms alike.
|
desk, "Medlemmer og invitasjoner", where a person is taken out or invited
|
||||||
|
again. Portal decides what a group may do, on the site and in the chat's
|
||||||
|
rooms alike. Records in `portal_memberships` are left from before
|
||||||
|
(Kanidm); nothing new is written there.
|
||||||
|
|
||||||
## Content changes
|
## Content changes
|
||||||
|
|
||||||
@@ -103,7 +106,7 @@ Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`,
|
|||||||
| `COMPOSE_PROFILES` | variable | repo | `chat` |
|
| `COMPOSE_PROFILES` | variable | repo | `chat` |
|
||||||
| `CONTENT_REPO`, `CONTENT_BRANCH` | variable | repo | the content this site serves |
|
| `CONTENT_REPO`, `CONTENT_BRANCH` | variable | repo | the content this site serves |
|
||||||
| `SITE_NAME` | variable | repo | `tomtervel`; never changed (a new name is a new, empty site) |
|
| `SITE_NAME` | variable | repo | `tomtervel`; never changed (a new name is a new, empty site) |
|
||||||
| `PEOPLE_BACKEND`, `RESPONSIBLE_GROUP` | variable | repo | `memberships`, `redaktor` |
|
| `PEOPLE_BACKEND`, `RESPONSIBLE_GROUP` | variable | repo | `rauthy`, `redaktor` |
|
||||||
| `OAUTH2_CLIENT_ID`, `CHAT_OAUTH2_CLIENT_ID` | variable | repo | the Rauthy clients of the site and the chat: `portal`, `chat` |
|
| `OAUTH2_CLIENT_ID`, `CHAT_OAUTH2_CLIENT_ID` | variable | repo | the Rauthy clients of the site and the chat: `portal`, `chat` |
|
||||||
| `NATS_ADOPT_LEGACY` | variable | repo | `sole` |
|
| `NATS_ADOPT_LEGACY` | variable | repo | `sole` |
|
||||||
| `GARAGE_S3_ENDPOINT`, `GARAGE_UPLOADS_BUCKET` | variable | repo | uploads |
|
| `GARAGE_S3_ENDPOINT`, `GARAGE_UPLOADS_BUCKET` | variable | repo | uploads |
|
||||||
@@ -120,6 +123,11 @@ Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`,
|
|||||||
| `OIDC_ISSUER` | variable | repo | where the site and the chat sign in: `https://konto.tomtervel.no/auth/v1/` |
|
| `OIDC_ISSUER` | variable | repo | where the site and the chat sign in: `https://konto.tomtervel.no/auth/v1/` |
|
||||||
| `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_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` |
|
| `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 | optional: the Medlemskap sales unit's ePayment keys (For developers, API keys, production), read by kron alone. Unset (with `VIPPS_MSN` unset too), kron asks for them on the treasurer's desk instead |
|
||||||
|
| `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
|
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.
|
logs are public: a value that must not be read is a secret.
|
||||||
@@ -127,6 +135,67 @@ 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
|
What is not a value stays on the host, made there once: Garage's node
|
||||||
secret.
|
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`, or, from kron 0.2, are
|
||||||
|
given once on the treasurer's desk: started without them, kron asks on
|
||||||
|
the bus and portal shows the ask under "Tjenester som venter" to the
|
||||||
|
`kasserer` group (a passkey sign-in); the secret fields are sealed to
|
||||||
|
kron's own identity (`kron_data` volume, `KRON_IDENTITY_FILE`) before
|
||||||
|
anything else sees them, kron tries them against Vipps and keeps them
|
||||||
|
sealed in its own bucket. Portal never holds a value and never calls
|
||||||
|
Vipps. The identity volume is never copied or backed up with the data:
|
||||||
|
a lost host means giving the keys again, which is a form. `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`. The keys: either `VIPPS_MSN` and the three key
|
||||||
|
secrets (table above; in `pass` as `tomtervel/vipps/medlemskap`), or
|
||||||
|
none of them, and the treasurer gives them on their desk once kron
|
||||||
|
is up (step 3). The host
|
||||||
|
script must know `kron.env` (this repo's `deploy-tomtervel`, optional
|
||||||
|
files): on kasse, `sudo install -m 0755 -o root -g root
|
||||||
|
/srv/tomtervel/infrastructure/deploy-tomtervel /usr/local/bin/deploy-tomtervel`
|
||||||
|
after the pull, since the installed copy does not update itself.
|
||||||
|
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
|
||||||
|
|
||||||
[Rauthy](https://github.com/sebadob/rauthy) at `RAUTHY_HOST`
|
[Rauthy](https://github.com/sebadob/rauthy) at `RAUTHY_HOST`
|
||||||
@@ -152,12 +221,18 @@ On a new host:
|
|||||||
Signed in, it sets up a passkey.
|
Signed in, it sets up a passkey.
|
||||||
3. In Rauthy's admin (`https://konto.tomtervel.no/auth/v1/admin`), or
|
3. In Rauthy's admin (`https://konto.tomtervel.no/auth/v1/admin`), or
|
||||||
with the bootstrap key: the client `portal` (`authorization_code`,
|
with the bootstrap key: the client `portal` (`authorization_code`,
|
||||||
`S256`, scopes `openid profile email`, redirect
|
`S256`, scopes `openid profile email groups`, redirect
|
||||||
`https://tomtervel.no/auth/callback`) and `chat` (also
|
`https://tomtervel.no/auth/callback`; without `groups` Rauthy leaves
|
||||||
|
the groups out of the sign-in, and portal sees everyone in none: no
|
||||||
|
board, no committee) and `chat` (also
|
||||||
`refresh_token`, redirect `https://samtaler.tomtervel.no/auth/callback`),
|
`refresh_token`, redirect `https://samtaler.tomtervel.no/auth/callback`),
|
||||||
their secrets into `OAUTH2_CLIENT_SECRET` and
|
their secrets into `OAUTH2_CLIENT_SECRET` and
|
||||||
`CHAT_OAUTH2_CLIENT_SECRET`, and an API key `portal` with read,
|
`CHAT_OAUTH2_CLIENT_SECRET`, and an API key `portal` with read,
|
||||||
create and update on users and groups into `RAUTHY_API_KEY`.
|
create and update on users, groups, roles and auth providers into `RAUTHY_API_KEY`
|
||||||
|
(a committee's leaders get a role that goes with managing it). A key
|
||||||
|
Rauthy no longer knows, or one past its expiry, answers 401 to
|
||||||
|
everything, and every invite fails ("the account could not be made
|
||||||
|
just now"; `rauthy: reading the groups: http 401` in the log).
|
||||||
|
|
||||||
Rauthy's mail leaves through kasse's postfix like gdo's, and Rauthy
|
Rauthy's mail leaves through kasse's postfix like gdo's, and Rauthy
|
||||||
stops if it cannot reach it.
|
stops if it cannot reach it.
|
||||||
|
|||||||
+37
@@ -144,6 +144,42 @@ services:
|
|||||||
nats:
|
nats:
|
||||||
condition: service_healthy
|
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
|
||||||
|
# kron's own identity, made on first start: what the Vipps keys
|
||||||
|
# given through portal (the treasurer's "Tjenester som venter")
|
||||||
|
# are sealed to. On its own volume, never copied anywhere. With
|
||||||
|
# no VIPPS_* in kron.env, kron waits to be given them.
|
||||||
|
KRON_IDENTITY_FILE: /var/lib/kron/identity
|
||||||
|
KRON_LANG: nb
|
||||||
|
volumes:
|
||||||
|
- kron_data:/var/lib/kron
|
||||||
|
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),
|
# The Gitea Actions runner is a host service on kasse (pacman gitea-runner),
|
||||||
# registered against prosjekt.klingenbergbygg.no. It reaches this NATS via the
|
# 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
|
# published 127.0.0.1:4222 port above, so no in-compose runner — and no
|
||||||
@@ -190,6 +226,7 @@ services:
|
|||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
garage_data:
|
garage_data:
|
||||||
|
kron_data:
|
||||||
caddy_data:
|
caddy_data:
|
||||||
caddy_config:
|
caddy_config:
|
||||||
nats_data:
|
nats_data:
|
||||||
|
|||||||
+3
-2
@@ -18,8 +18,9 @@ set -euo pipefail
|
|||||||
root=/srv/tomtervel/infrastructure
|
root=/srv/tomtervel/infrastructure
|
||||||
stage=/var/lib/gitea-runner/tomtervel-env
|
stage=/var/lib/gitea-runner/tomtervel-env
|
||||||
files=(.env portal.env nats.env chat.env)
|
files=(.env portal.env nats.env chat.env)
|
||||||
# Written only when the site runs what needs it (Rauthy).
|
# Written only when the site runs what needs it (Rauthy, the money
|
||||||
optional=(rauthy.env)
|
# service under the pay profile).
|
||||||
|
optional=(rauthy.env kron.env)
|
||||||
|
|
||||||
[ -d "$root/.git" ] || { echo "no checkout at $root - bootstrap it first" >&2; exit 1; }
|
[ -d "$root/.git" ] || { echo "no checkout at $root - bootstrap it first" >&2; exit 1; }
|
||||||
for f in "${files[@]}"; do
|
for f in "${files[@]}"; do
|
||||||
|
|||||||
+9
-1
@@ -31,6 +31,8 @@ D("tomtervel.no", REG_NONE, DnsProvider(DSP_CLOUDFLARE),
|
|||||||
A("@", KASSE, CF_PROXY_OFF),
|
A("@", KASSE, CF_PROXY_OFF),
|
||||||
CNAME("www", "tomtervel.no.", CF_PROXY_OFF),
|
CNAME("www", "tomtervel.no.", CF_PROXY_OFF),
|
||||||
A("konto", KASSE, 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),
|
A("samtaler", KASSE, CF_PROXY_OFF),
|
||||||
// The old names, kept so links from before still land: Caddy sends
|
// The old names, kept so links from before still land: Caddy sends
|
||||||
// id on to konto (the login) and chat on to samtaler.
|
// id on to konto (the login) and chat on to samtaler.
|
||||||
@@ -61,7 +63,13 @@ D("tomtervel.no", REG_NONE, DnsProvider(DSP_CLOUDFLARE),
|
|||||||
|
|
||||||
// Reports only, to start. Tighten to p=quarantine once the reports
|
// Reports only, to start. Tighten to p=quarantine once the reports
|
||||||
// show both Zoho and kasse passing.
|
// show both Zoho and kasse passing.
|
||||||
TXT("_dmarc", "v=DMARC1; p=none; rua=mailto:post@tomtervel.no"),
|
//
|
||||||
|
// The reports (a daily XML file from each large mailbox provider) go
|
||||||
|
// to dmarc@, not the board's post@. dmarc@ is an address at Zoho, made
|
||||||
|
// in Zoho Mail's admin before this is pushed: otherwise they bounce.
|
||||||
|
// Another domain in rua= needs its own consent record there
|
||||||
|
// (tomtervel.no._report._dmarc.<that domain>).
|
||||||
|
TXT("_dmarc", "v=DMARC1; p=none; rua=mailto:dmarc@tomtervel.no"),
|
||||||
|
|
||||||
// Zoho's DKIM key, as it stands today: on the zone's apex, where no
|
// Zoho's DKIM key, as it stands today: on the zone's apex, where no
|
||||||
// receiver looks for it, so mail from Zoho is unsigned in effect. Zoho
|
// receiver looks for it, so mail from Zoho is unsigned in effect. Zoho
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ RUN pacman-key --init \
|
|||||||
'SigLevel = Required DatabaseOptional' \
|
'SigLevel = Required DatabaseOptional' \
|
||||||
'Server = https://project.uhhm.no/api/packages/bl/arch/$repo/$arch' \
|
'Server = https://project.uhhm.no/api/packages/bl/arch/$repo/$arch' \
|
||||||
>> /etc/pacman.conf \
|
>> /etc/pacman.conf \
|
||||||
&& pacman -Sy --noconfirm --needed ca-certificates gdo \
|
&& pacman -Syu --noconfirm --needed ca-certificates gdo \
|
||||||
&& pacman -Scc --noconfirm \
|
&& pacman -Scc --noconfirm \
|
||||||
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
|
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ konto.tomtervel.no {
|
|||||||
reverse_proxy 127.0.0.1:8090
|
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
|
# The content repo's previews (tomtervel/questions, .gitea/preview/): one
|
||||||
# portal per branch on <branch>.forhandsvisning.tomtervel.no, for five days
|
# 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
|
# after its last push, and the list of them on the bare name. Every name
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
# The move to portal 1.0
|
||||||
|
|
||||||
|
Portal 0.19 keeps the vel's records on NATS. Portal 1.0 keeps them in one
|
||||||
|
file of its own, and starts empty. This folder is what carries the records
|
||||||
|
across, on kasse, and the order the whole switch goes in.
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| `move.sh rehearse` | the whole middle of the move beside the running site, into a volume it removes again |
|
||||||
|
| `move.sh move` | the same for real: stops the 0.19 site first, and fills `tomtervel_portal_data`, the volume the 1.0 stack starts on |
|
||||||
|
| `compare.py` | holds a 1.0 store to the export: every record, its state, its fields, its files, and the sign-ups in the order they came |
|
||||||
|
| `sink.py` | takes what the site would have sent while the sign-ups are taken again, and lets it go |
|
||||||
|
|
||||||
|
Everything is run as root on kasse. The export holds names and addresses:
|
||||||
|
it stays in `/srv/tomtervel/move-1.0` (root only) and nothing here prints
|
||||||
|
a name, an address or a text, only counts and the names of fields.
|
||||||
|
|
||||||
|
## What `move.sh` does
|
||||||
|
|
||||||
|
1. **Export** with portal 0.19.3 (`portal export`), reading NATS only.
|
||||||
|
2. **Rewrite** for the 1.0 content with `flytting/fra-0.19.py` from
|
||||||
|
tomtervel/questions: the committees become `gruppe` on each record.
|
||||||
|
3. **Import** with portal 1.0 into the volume, after a dry run.
|
||||||
|
4. **A 1.0 site on the store** that only kasse can reach (127.0.0.1:3997),
|
||||||
|
with the stack's garage for the files and no sign-in.
|
||||||
|
5. **The sign-ups** again, through their form
|
||||||
|
(`flytting/pameldinger.py`), in the order they came. A sign-up cannot
|
||||||
|
be imported: in 1.0 a seat is taken through the event's own count.
|
||||||
|
6. **Compare**, with every picture and document fetched as a visitor
|
||||||
|
would. Anything that differs is counted and the run ends non-zero.
|
||||||
|
7. **Stop** the site again.
|
||||||
|
|
||||||
|
### No mail leaves
|
||||||
|
|
||||||
|
Taking a sign-up again makes the mail the form makes ("Dere har plass"),
|
||||||
|
and what the site says in the chat's rooms. With no mail service beside
|
||||||
|
it, the site does not drop them: they wait in the store, and go out the
|
||||||
|
moment gdo dials it. A store filled on a preview and then started on in
|
||||||
|
production would mail every sign-up on its first start.
|
||||||
|
|
||||||
|
So while the site of step 4 runs, its `mail`, `rooms` and `answers`
|
||||||
|
outboxes are posted to `sink.py` (`DHD_HOOKS`), which acknowledges each
|
||||||
|
row and delivers nothing. The run says how many mails it took, and fails
|
||||||
|
if that is not one per sign-up. `payments` is left alone: nothing the
|
||||||
|
move does asks for money.
|
||||||
|
|
||||||
|
The cost: nobody gets a new link to withdraw by, and the links in the
|
||||||
|
mail 0.19 sent stop working at the move. Someone who cannot come tells
|
||||||
|
the board, who takes them off on the event's page.
|
||||||
|
|
||||||
|
## The switch, in order
|
||||||
|
|
||||||
|
Rehearsed on 2026-11-24 against the live site: 91 records and 15 sign-ups
|
||||||
|
(25 guests) across, all 53 files fetched, 15 mails taken by the sink,
|
||||||
|
nothing differing. Steps 1 to 3 are done or can be done any time; 4 on
|
||||||
|
are the switch itself, with the site down from 4 to 6.
|
||||||
|
|
||||||
|
1. **Programs that speak to a 1.0 site.** 1.0 has no NATS; the programs
|
||||||
|
beside the site dial it over `dhd/1`. As of 2026-11-24 none of what
|
||||||
|
the stack runs can:
|
||||||
|
- **gdo** (mail): v0.3.1 is NATS only. The `one-oh` branch dials a
|
||||||
|
site, built against portal v1.0.0-rc.10.
|
||||||
|
- **kron** (Vipps): 0.2.0 is NATS only. `one-oh` likewise.
|
||||||
|
- **cnats** (the chat) is NATS only. Its successor kino 0.1.1 dials a
|
||||||
|
site, but is published as an Arch package, not an image, and takes
|
||||||
|
no history over.
|
||||||
|
|
||||||
|
Until gdo has a release, a 1.0 site here sends no mail at all: no
|
||||||
|
invites, no confirmations. That is what the switch waits for.
|
||||||
|
2. **The stack for 1.0** (`compose.yml`, `deploy.yml`, a pull request of
|
||||||
|
its own once step 1 has releases to try it with): a volume for the
|
||||||
|
store, `PORTAL_STORE`, `DHD_KEYS` naming each program's key,
|
||||||
|
`DHD_TOKENS` with the hash of `LOAD_TOKEN` named `load`, the programs
|
||||||
|
in portal's network namespace (they dial loopback), sealed backups
|
||||||
|
(`PORTAL_BACKUP_TO`), and NATS out.
|
||||||
|
3. **`LOAD_TOKEN`** as a secret of the tomtervel org: the content repo's
|
||||||
|
reload posts it to `/dhd/1/load`.
|
||||||
|
4. **`move.sh rehearse`** once more on the day, then **`move.sh move`**.
|
||||||
|
The 0.19 site is down from here.
|
||||||
|
5. **The 1.0 stack up**: `PORTAL_RELEASE=v1.0.2` (the org's variable),
|
||||||
|
questions#48 merged so `main` is the 1.0 content, then the deploy.
|
||||||
|
The reload that merge sets off fails while the site is down; the site
|
||||||
|
reads `main` as it starts.
|
||||||
|
6. **Look**: `/hva-skjer` says 25 of 100 seats, a document opens, a
|
||||||
|
sign-in lands on `/styret` with its lists, and a test invite arrives.
|
||||||
|
7. **Rauthy's groups**: from `komiteer_<id>_medlem` and `_leder` to the
|
||||||
|
group named as its page (questions' README has the names).
|
||||||
|
|
||||||
|
### Going back
|
||||||
|
|
||||||
|
- **Before step 5**: `podman start tomtervel-portal-1`, and remove
|
||||||
|
`tomtervel_portal_data`. Nothing else was touched.
|
||||||
|
- **After**: `PORTAL_RELEASE` and the stack back to what they were, and
|
||||||
|
the content's `main` reverted. NATS still holds everything 0.19 had as
|
||||||
|
long as `tomtervel_nats_data` is kept, so keep it for some weeks. What
|
||||||
|
people did on 1.0 in between does not go back with it.
|
||||||
|
|
||||||
|
### What does not come across
|
||||||
|
|
||||||
|
- **Sign-ins.** Everyone signs in again. Their accounts and groups are in
|
||||||
|
Rauthy and are not touched.
|
||||||
|
- **Invites nobody has answered yet** stay valid in Rauthy, but the
|
||||||
|
site's list of them starts empty.
|
||||||
|
- **Each record's history.** A record arrives with one event saying it
|
||||||
|
was imported, and its date.
|
||||||
|
- **The chat's history,** and **payments under way in kron** (none may be
|
||||||
|
open when the switch is made: a fee paid in between would not be seen).
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
# Compares a 1.0 store (read over /dhd/1/read) with the 0.19 export.
|
||||||
|
# Prints counts and field NAMES only: never a name, an address or a text.
|
||||||
|
#
|
||||||
|
# compare.py <site> <token file> <records-1.0.yaml> <places.yaml> [--files] [bucket ...]
|
||||||
|
#
|
||||||
|
# The token must be named `read` in the site's DHD_TOKENS. With buckets
|
||||||
|
# named, only those are held to the store; --files also fetches every
|
||||||
|
# file a record names, as a visitor would.
|
||||||
|
import json, sys, re, hashlib, urllib.request, urllib.error, yaml, collections
|
||||||
|
args = [a for a in sys.argv[1:] if not a.startswith('--')]
|
||||||
|
files = '--files' in sys.argv
|
||||||
|
site, tokfile, records, places = args[:4]
|
||||||
|
buckets = args[4:]
|
||||||
|
tok=open(tokfile).read().strip()
|
||||||
|
def read(bucket):
|
||||||
|
r=urllib.request.Request(site+'/dhd/1/read',data=json.dumps({'bucket':bucket}).encode(),
|
||||||
|
headers={'Authorization':'Bearer '+tok,'Content-Type':'application/json'})
|
||||||
|
return json.load(urllib.request.urlopen(r))
|
||||||
|
def h(s): return hashlib.sha256(str(s).encode()).hexdigest()[:8]
|
||||||
|
def norm(s): return re.sub(r'\s+',' ',re.sub(r'<[^>]+>',' ',str(s))).strip()
|
||||||
|
bad=0
|
||||||
|
y=yaml.safe_load(open(records))
|
||||||
|
for b,recs in y.items():
|
||||||
|
if buckets and b not in buckets: continue
|
||||||
|
if not isinstance(recs,list): print(f'{b}: not a list in the export, skipped'); continue
|
||||||
|
st=read(b); c=collections.Counter(); diff=collections.Counter(); kinds=collections.Counter()
|
||||||
|
ids={str(r['id']) for r in recs}
|
||||||
|
for r in recs:
|
||||||
|
s=st.get(str(r['id']))
|
||||||
|
if s is None: c['missing in store']+=1; continue
|
||||||
|
c['found']+=1
|
||||||
|
if r.get('state') and r['state']!=s['state']: c['state differs']+=1
|
||||||
|
at=r.get('at')
|
||||||
|
if at is not None:
|
||||||
|
got=(s.get('at') or {}).get('text','')
|
||||||
|
if not str(got).startswith(str(at)[:10]): c['at differs']+=1
|
||||||
|
f=r.get('fields') or {}; g=s.get('responses') or {}
|
||||||
|
for k,v in f.items():
|
||||||
|
if k not in g: diff[k+': not in store']+=1
|
||||||
|
elif str(g[k])==str(v): pass
|
||||||
|
elif norm(g[k])==norm(v): diff[k+': differs in markup or spacing only']+=1
|
||||||
|
else: diff[k+': DIFFERS']+=1
|
||||||
|
for k in g:
|
||||||
|
if k not in f and g[k] not in ('',None): diff[k+': in store only']+=1
|
||||||
|
for k in ('vedlegg','bilde'):
|
||||||
|
v=g.get(k)
|
||||||
|
if not v: continue
|
||||||
|
if not files: kinds[k+' named']+=1; continue
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(f'{site}/attachment/{b}/{r["id"]}/{k}', timeout=30) as a:
|
||||||
|
kinds[f'{k} fetched' if len(a.read())>0 else f'{k} EMPTY']+=1
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
# a list that needs a sign-in keeps its files to those signed in
|
||||||
|
kinds[f'{k} needs a sign-in' if e.code in (401,403) else f'{k} FAILED {e.code}']+=1
|
||||||
|
extra=[k for k in st if k not in ids]
|
||||||
|
states=collections.Counter(s['state'] for s in st.values())
|
||||||
|
print(f'{b}: export {len(recs)}, store {len(st)}, {dict(c)}, extra in store {len(extra)}')
|
||||||
|
print(f' states in store {dict(states)}')
|
||||||
|
if diff: print(f' fields {dict(diff)}')
|
||||||
|
if kinds: print(f' files {dict(kinds)}')
|
||||||
|
bad+=c['missing in store']+c['state differs']+c['at differs']+len(extra)+sum(n for k,n in diff.items() if 'DIFFERS' in k or 'not in store' in k)
|
||||||
|
bad+=sum(n for k,n in kinds.items() if 'FAILED' in k or 'EMPTY' in k)
|
||||||
|
# the sign-ups
|
||||||
|
p=yaml.safe_load(open(places)); st=read('pameldinger'); led=read('portal_places')
|
||||||
|
for b,recs in p.items():
|
||||||
|
live=sorted([r for r in recs if r.get('state') in ('tatt','venter')], key=lambda r:str(r['at']))
|
||||||
|
print(f'{b}: export {len(recs)} ({dict(collections.Counter(r.get("state") for r in recs))}), store {len(st)} ({dict(collections.Counter(s["state"] for s in st.values()))})')
|
||||||
|
sig=lambda f:(str(f.get('arrangement')),h(str(f.get('email','')).lower()),h(f.get('navn')),str(f.get('antall') or 1))
|
||||||
|
want=collections.Counter(sig(r['fields']) for r in live); got=collections.Counter(sig(s['responses']) for s in st.values())
|
||||||
|
print(f' same people, events and numbers: {want==got} (only in export {sum((want-got).values())}, only in store {sum((got-want).values())})')
|
||||||
|
bad+=sum((want-got).values())+sum((got-want).values())
|
||||||
|
seats=lambda rs,key:sum(int(key(r).get('antall') or 1) for r in rs)
|
||||||
|
print(f' guests: export {seats(live,lambda r:r["fields"])}, store {seats(st.values(),lambda s:s["responses"])}')
|
||||||
|
# the state each has: a seat stays a seat, a place in line a place in line
|
||||||
|
wst=collections.Counter((sig(r['fields']),r['state']) for r in live)
|
||||||
|
gst=collections.Counter((sig(s['responses']),s['state']) for s in st.values())
|
||||||
|
print(f' same state each: {wst==gst}'); bad+= (wst!=gst)
|
||||||
|
# the order: the ledger's against the order they came in 0.19
|
||||||
|
for key,l in led.items():
|
||||||
|
for line in ('taken','waiting'):
|
||||||
|
ids=[e['id'] for e in l.get(line,[])]
|
||||||
|
order=[sig(st[i]['responses']) for i in ids if i in st]
|
||||||
|
wanted=[sig(r['fields']) for r in live if r['state']==('tatt' if line=='taken' else 'venter') and str(r['fields'].get('arrangement')) in key]
|
||||||
|
ok = order==wanted
|
||||||
|
print(f' ledger {h(key)} {line}: {len(ids)} entries, each a record: {len(order)==len(ids)}, in the order they came: {ok}')
|
||||||
|
bad+= (not ok) or len(order)!=len(ids)
|
||||||
|
dup=[k for k,n in got.items() if n>1]; print(f' taken twice: {len(dup)}'); bad+=len(dup)
|
||||||
|
print('OK' if not bad else f'{bad} THINGS TO LOOK AT'); sys.exit(1 if bad else 0)
|
||||||
Executable
+157
@@ -0,0 +1,157 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# The vel's records from portal 0.19 (NATS) into a 1.0 store, on kasse, as
|
||||||
|
# root. README.md beside this has the whole switch; this is its middle.
|
||||||
|
#
|
||||||
|
# move.sh rehearse beside the running site, into a throwaway volume
|
||||||
|
# move.sh move stops the 0.19 site first, and fills the volume the
|
||||||
|
# 1.0 stack starts on (tomtervel_portal_data)
|
||||||
|
#
|
||||||
|
# Either way it: exports with portal 0.19.3, rewrites for the 1.0 content
|
||||||
|
# (flytting/fra-0.19.py in the content repo), imports with 1.0, starts a
|
||||||
|
# 1.0 site on the store that only this host can reach, takes the sign-ups
|
||||||
|
# again through their form (flytting/pameldinger.py), holds the store to
|
||||||
|
# the export (compare.py) and stops the site again.
|
||||||
|
#
|
||||||
|
# No mail leaves: while that site runs, what it would send (the mail to
|
||||||
|
# each sign-up, what it says in the chat's rooms) is posted to sink.py,
|
||||||
|
# which counts it and lets it go. A store started on without that step
|
||||||
|
# mails every sign-up as soon as gdo dials it.
|
||||||
|
#
|
||||||
|
# Nothing is printed that names anyone: counts, and the names of fields.
|
||||||
|
set -euo pipefail
|
||||||
|
umask 077
|
||||||
|
|
||||||
|
mode=${1:-}
|
||||||
|
case "$mode" in rehearse|move) ;; *) sed -n '2,20p' "$0" >&2; exit 2 ;; esac
|
||||||
|
|
||||||
|
here=$(dirname "$(readlink -f "$0")")
|
||||||
|
infra=/srv/tomtervel/infrastructure
|
||||||
|
base=/srv/tomtervel/move-1.0
|
||||||
|
release=${PORTAL_RELEASE:-v1.0.2}
|
||||||
|
image=localhost/tomtervel-portal:$release
|
||||||
|
branch=${CONTENT_BRANCH_1_0:-innhold-1-0} # the content the 1.0 site will run
|
||||||
|
repo=https://prosjekt.klingenbergbygg.no/tomtervel/questions
|
||||||
|
old=tomtervel-portal-1 # the 0.19 site
|
||||||
|
stage=tomtervel-move-stage
|
||||||
|
port=3997; sink_port=3996
|
||||||
|
export_sha=e417cbfddb7d3710a36c7b3b0b6a86ff1ed6d08dcffc66417760f9b20fbdfe4f # portal-x86_64-linux v0.19.3
|
||||||
|
|
||||||
|
if [ "$mode" = move ]; then volume=tomtervel_portal_data; else volume=tomtervel-move-rehearsal; fi
|
||||||
|
work=$base/$mode-$(date +%Y%m%d-%H%M%S)
|
||||||
|
|
||||||
|
podman image exists "$image" || { echo "no image $image: build it first (README.md)" >&2; exit 1; }
|
||||||
|
if [ "$mode" = move ] && podman volume exists "$volume"; then
|
||||||
|
echo "the volume $volume is already there: a move was made, or begun. Look before removing it." >&2; exit 1
|
||||||
|
fi
|
||||||
|
podman rm -f "$stage" >/dev/null 2>&1 || true
|
||||||
|
for p in $port $sink_port; do
|
||||||
|
if (exec 3<>"/dev/tcp/127.0.0.1/$p") 2>/dev/null; then echo "something already answers on 127.0.0.1:$p" >&2; exit 1; fi
|
||||||
|
done
|
||||||
|
[ "$mode" = rehearse ] && podman volume rm -f "$volume" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
install -d -m 0700 "$base" "$work"
|
||||||
|
cd "$work"
|
||||||
|
sink=
|
||||||
|
cleanup() {
|
||||||
|
[ -n "$sink" ] && kill "$sink" 2>/dev/null || true
|
||||||
|
podman rm -f "$stage" >/dev/null 2>&1 || true
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
step() { printf '\n== %s\n' "$*"; }
|
||||||
|
|
||||||
|
if [ "$mode" = move ]; then
|
||||||
|
step "stopping the 0.19 site, so nothing is answered after the export"
|
||||||
|
podman stop -t 30 "$old" >/dev/null
|
||||||
|
echo "to go back before the 1.0 stack is up: podman start $old"
|
||||||
|
fi
|
||||||
|
|
||||||
|
step "export from 0.19"
|
||||||
|
if [ ! -x "$base/portal" ]; then
|
||||||
|
curl -sfL -o "$base/portal.part" https://project.uhhm.no/uhhm/portal/releases/download/v0.19.3/portal-x86_64-linux
|
||||||
|
echo "$export_sha $base/portal.part" | sha256sum -c --quiet
|
||||||
|
chmod 0700 "$base/portal.part"; mv "$base/portal.part" "$base/portal"
|
||||||
|
fi
|
||||||
|
# The content the 0.19 site runs, to read its buckets by.
|
||||||
|
old_branch=$(grep -m1 '^CONTENT_BRANCH=' "$infra/portal.env" | cut -d= -f2-)
|
||||||
|
old_at=${CONTENT_AT_0_19:-$old_branch}
|
||||||
|
git clone --quiet "$repo" content-0.19
|
||||||
|
git -C content-0.19 checkout --quiet "$old_at"
|
||||||
|
echo "0.19 content: $(git -C content-0.19 rev-parse --short HEAD)"
|
||||||
|
url=$(grep -m1 '^NATS_URL=' "$infra/portal.env" | cut -d= -f2-)
|
||||||
|
url=${url/@nats:4222/@127.0.0.1:4223}
|
||||||
|
case "$url" in *@127.0.0.1:4223*) ;; *) echo "NATS_URL is not the expected shape" >&2; exit 1 ;; esac
|
||||||
|
pay=$(grep -m1 '^PAY_URL=' "$infra/portal.env" | cut -d= -f2- || true)
|
||||||
|
( cd content-0.19 && PAY_URL="$pay" NATS_URL="$url" SITE_NAME=tomtervel "$base/portal" export --path questions --out ../export ) \
|
||||||
|
| grep -vE '@|[0-9]{8}' || true
|
||||||
|
ls export
|
||||||
|
|
||||||
|
step "rewrite for the 1.0 content ($branch)"
|
||||||
|
git clone --quiet --depth 1 -b "$branch" "$repo" content
|
||||||
|
echo "1.0 content: $(git -C content rev-parse --short HEAD)"
|
||||||
|
python3 content/flytting/fra-0.19.py export/records.yaml records-1.0.yaml
|
||||||
|
chmod -R a+rX content; chmod 711 "$base" "$work"; chmod 644 records-1.0.yaml
|
||||||
|
|
||||||
|
step "import into $volume"
|
||||||
|
podman volume create "$volume" >/dev/null
|
||||||
|
run() { podman run --rm --user 0 -v "$volume:/data" -v "$work:/w:ro" -e PORTAL_STORE=/data/site.redb -e PAY_URL="$pay" "$image" "$@"; }
|
||||||
|
run /app/portal import --path /w/content/questions /w/records-1.0.yaml --dry-run | tail -3
|
||||||
|
run /app/portal import --path /w/content/questions /w/records-1.0.yaml | tail -1
|
||||||
|
chmod 600 records-1.0.yaml; chmod 700 "$base"
|
||||||
|
|
||||||
|
step "a 1.0 site on the store, for this host only, its outboxes posted to the sink"
|
||||||
|
token=$(head -c 32 /dev/urandom | base64 | tr -dc A-Za-z0-9); printf %s "$token" > token
|
||||||
|
hash=$(printf %s "$token" | sha256sum | cut -d' ' -f1)
|
||||||
|
python3 "$here/sink.py" "$sink_port" > sink.out 2>&1 & sink=$!
|
||||||
|
# The files are in the stack's garage, which answers on the compose
|
||||||
|
# network only; the host reaches its address there. Compose doubles each
|
||||||
|
# "$" in an env file, podman does not.
|
||||||
|
grep -E '^GARAGE_' "$infra/portal.env" | sed 's/\$\$/$/g' > stage.env
|
||||||
|
garage=$(podman inspect tomtervel-garage-1 --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}')
|
||||||
|
podman run -d --name "$stage" --user 0 --network host --add-host "garage:$garage" --env-file stage.env \
|
||||||
|
-v "$volume:/data" -v "$work/content:/w:ro" \
|
||||||
|
-e CONTENT_DIR=/w -e PORTAL_STORE=/data/site.redb -e SITE_NAME=tomtervel -e PUBLIC_URL="https://$(grep -m1 '^PORTAL_HOST=' "$infra/.env" | cut -d= -f2-)" \
|
||||||
|
-e LEPTOS_SITE_ADDR=127.0.0.1:$port -e LEPTOS_SITE_ROOT=site -e LEPTOS_HASH_FILES=true -e PAY_URL="$pay" \
|
||||||
|
-e DHD_TOKENS="$hash=submit:pameldinger,read" -e DHD_HOOK_SECRET="$token" \
|
||||||
|
-e DHD_HOOKS="mail=http://127.0.0.1:$sink_port/;rooms=http://127.0.0.1:$sink_port/;answers=http://127.0.0.1:$sink_port/" \
|
||||||
|
"$image" >/dev/null
|
||||||
|
code=000
|
||||||
|
for _ in $(seq 1 45); do
|
||||||
|
code=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$port/" || true)
|
||||||
|
[ "$code" = 200 ] && break; sleep 1
|
||||||
|
done
|
||||||
|
[ "$code" = 200 ] || { echo "the site did not come up ($code)" >&2; podman logs "$stage" 2>&1 | tail -20 >&2; exit 1; }
|
||||||
|
|
||||||
|
step "the sign-ups, through their form, in the order they came"
|
||||||
|
SUBMIT_TOKEN=$token python3 content/flytting/pameldinger.py export/places.yaml "http://127.0.0.1:$port" --send \
|
||||||
|
| sed -E 's/ på [0-9a-f]+,/,/' | tee replay.out | tail -3
|
||||||
|
sent=$(grep -c '^sendt' replay.out || true)
|
||||||
|
|
||||||
|
step "the store against the export"
|
||||||
|
ok=0
|
||||||
|
python3 "$here/compare.py" "http://127.0.0.1:$port" token records-1.0.yaml export/places.yaml --files || ok=1
|
||||||
|
|
||||||
|
step "what the site would have sent, taken by the sink"
|
||||||
|
# A hook looks every 10 seconds; wait until the mail is all there and nothing more comes.
|
||||||
|
for _ in $(seq 1 12); do sleep 10; kill -USR1 "$sink"; sleep 1; [ "$(tail -1 sink.out | cut -d' ' -f2)" = "$sent" ] && break; done
|
||||||
|
sleep 15
|
||||||
|
podman stop -t 30 "$stage" >/dev/null
|
||||||
|
kill "$sink"; wait "$sink" 2>/dev/null || true; sink=
|
||||||
|
grep -v '^count ' sink.out
|
||||||
|
mails=$(grep -m1 '^mail: ' sink.out | sed -E 's/^mail: ([0-9]+) rows.*/\1/' || true)
|
||||||
|
if [ "${mails:-0}" != "$sent" ]; then echo "MAIL: $sent sign-ups sent, ${mails:-0} mails taken by the sink"; ok=1; fi
|
||||||
|
podman logs "$stage" 2>&1 | sed 's/\x1b\[[0-9;]*m//g' | grep -E ' (WARN|ERROR) ' | grep -v '@' > site-warnings.out || true
|
||||||
|
echo "warnings and errors in the site's log: $(wc -l < site-warnings.out)"
|
||||||
|
cut -d' ' -f2- site-warnings.out | cut -c1-200 | sort | uniq -c | head -15
|
||||||
|
run chown -R portal /data
|
||||||
|
podman rm -f "$stage" >/dev/null
|
||||||
|
|
||||||
|
step "done"
|
||||||
|
if [ "$mode" = rehearse ]; then
|
||||||
|
podman volume rm "$volume" >/dev/null
|
||||||
|
echo "rehearsal volume removed; the export and the logs are in $work (root only)"
|
||||||
|
else
|
||||||
|
echo "the 1.0 store is in $volume; the export is in $work (root only)"
|
||||||
|
if [ "$ok" = 0 ]; then echo "next: the 1.0 stack on it (README.md, step 5)"; else echo "not as it should be: podman start $old brings the 0.19 site back; remove $volume before trying again"; fi
|
||||||
|
fi
|
||||||
|
exit "$ok"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Takes what a 1.0 site posts from its outboxes (DHD_HOOKS) and lets each row go:
|
||||||
|
# sink.py <port> on 127.0.0.1; SIGUSR1 prints `count <mail rows so far>`, SIGTERM the sums.
|
||||||
|
# Nothing is delivered and nothing kept: it counts rows per outbox, and for
|
||||||
|
# mail how many addresses and which subjects. Never an address or a body.
|
||||||
|
import sys, json, hashlib, collections, http.server, signal
|
||||||
|
port=int(sys.argv[1]); rows=collections.Counter(); who=collections.defaultdict(set); subj=collections.Counter(); keys=collections.defaultdict(set)
|
||||||
|
class H(http.server.BaseHTTPRequestHandler):
|
||||||
|
def do_POST(s):
|
||||||
|
b=s.rfile.read(int(s.headers.get('Content-Length',0))); o=s.headers.get('Dhd-Outbox','?'); rows[o]+=1
|
||||||
|
try:
|
||||||
|
d=json.loads(b); keys[o].update(d.keys())
|
||||||
|
if o=='mail':
|
||||||
|
to=d.get('to'); to=to if isinstance(to,list) else [to]
|
||||||
|
for t in to: who[o].add(hashlib.sha256(str(t).encode()).hexdigest())
|
||||||
|
subj[str(d.get('subject'))[:60]]+=1
|
||||||
|
except Exception: pass
|
||||||
|
s.send_response(204); s.end_headers()
|
||||||
|
def log_message(s,*a): pass
|
||||||
|
def done(*a):
|
||||||
|
print(f'mail: {rows["mail"]} rows to {len(who["mail"])} different addresses; subjects {dict(subj)}')
|
||||||
|
for o,n in rows.items():
|
||||||
|
if o!='mail': print(f'{o}: {n} rows; fields {sorted(keys[o])}')
|
||||||
|
sys.stdout.flush(); sys.exit(0)
|
||||||
|
def count(*a): print('count',rows['mail']); sys.stdout.flush()
|
||||||
|
signal.signal(signal.SIGUSR1,count)
|
||||||
|
signal.signal(signal.SIGTERM,done); signal.signal(signal.SIGINT,done)
|
||||||
|
http.server.HTTPServer(('127.0.0.1',port),H).serve_forever()
|
||||||
+4
-1
@@ -12,7 +12,10 @@
|
|||||||
# reason.
|
# reason.
|
||||||
FROM archlinux:base
|
FROM archlinux:base
|
||||||
ARG PORTAL_RELEASE
|
ARG PORTAL_RELEASE
|
||||||
RUN pacman -Sy --noconfirm --needed ca-certificates curl \
|
# -Syu, never -Sy: a partial upgrade pulls a library newer than what the
|
||||||
|
# base image's own pacman was built against (openssl 4, November 2026) and
|
||||||
|
# refuses to install.
|
||||||
|
RUN pacman -Syu --noconfirm --needed ca-certificates curl \
|
||||||
&& pacman -Scc --noconfirm \
|
&& pacman -Scc --noconfirm \
|
||||||
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
|
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# The sign-in providers Rauthy offers beside its own accounts, as the
|
||||||
|
# deploy keeps them: today Vipps Login. Rauthy has no file for this, only
|
||||||
|
# its API, so this script is the file: run on every deploy, it makes the
|
||||||
|
# provider the first time and updates it after, by name, so a change here
|
||||||
|
# is a change in Rauthy. Needs RAUTHY_HOST, RAUTHY_API_KEY (AuthProviders
|
||||||
|
# read/create/update), VIPPS_LOGIN_CLIENT_ID and VIPPS_LOGIN_CLIENT_SECRET;
|
||||||
|
# with any of them unset it changes nothing and says so.
|
||||||
|
#
|
||||||
|
# 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; }
|
||||||
|
done
|
||||||
|
base="https://$RAUTHY_HOST/auth/v1"
|
||||||
|
auth="Authorization: API-Key $RAUTHY_API_KEY"
|
||||||
|
vipps=$(jq -n --arg id "$VIPPS_LOGIN_CLIENT_ID" --arg secret "$VIPPS_LOGIN_CLIENT_SECRET" '{
|
||||||
|
name: "Vipps", typ: "custom", enabled: true,
|
||||||
|
issuer: "https://api.vipps.no/access-management-1.0/access/",
|
||||||
|
authorization_endpoint: "https://api.vipps.no/access-management-1.0/access/oauth2/auth",
|
||||||
|
token_endpoint: "https://api.vipps.no/access-management-1.0/access/oauth2/token",
|
||||||
|
userinfo_endpoint: "https://api.vipps.no/vipps-userinfo-api/userinfo",
|
||||||
|
jwks_endpoint: "https://api.vipps.no/access-management-1.0/access/.well-known/jwks.json",
|
||||||
|
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 }')
|
||||||
|
# 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
|
||||||
|
curl -sf -X PUT -H "$auth" -H 'content-type: application/json' -d "$vipps" "$base/providers/$existing" >/dev/null
|
||||||
|
echo "rauthy-providers: Vipps updated ($existing)"
|
||||||
|
else
|
||||||
|
id=$(curl -sf -X POST -H "$auth" -H 'content-type: application/json' -d "$vipps" "$base/providers/create" | jq -r .id)
|
||||||
|
echo "rauthy-providers: Vipps made ($id)"
|
||||||
|
fi
|
||||||
Executable
+34
@@ -0,0 +1,34 @@
|
|||||||
|
#!/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
|
||||||
Executable
+53
@@ -0,0 +1,53 @@
|
|||||||
|
#!/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