Compare commits
9
Commits
da97fd4fb1
..
v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfae1cb572 | ||
|
|
752f3ba433 | ||
|
|
72a5e289f6 | ||
|
|
01401cb1cd | ||
|
|
d3cb76dc32 | ||
|
|
61b1eda37d | ||
|
|
e2e21e84f7 | ||
|
|
90080a8425 | ||
|
|
2093c39ed2 |
No files matched your search
@@ -0,0 +1,78 @@
|
||||
name: Publish Go package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'backend/v*'
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
name: Publish shared Go module
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout source
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: backend/go.mod
|
||||
cache: false
|
||||
|
||||
- name: Test Go module
|
||||
working-directory: backend
|
||||
run: go test ./...
|
||||
|
||||
- name: Install ZIP tools
|
||||
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y zip
|
||||
|
||||
- name: Package Go module
|
||||
env:
|
||||
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref_name }}
|
||||
run: |
|
||||
package_directory='gitea-go-package'
|
||||
rm -rf "$package_directory"
|
||||
mkdir -p "$package_directory"
|
||||
bash scripts/package-go-module.sh "$RELEASE_TAG" "$package_directory"
|
||||
find "$package_directory" -maxdepth 1 -type f -name '*.zip' -print -quit | grep -q .
|
||||
|
||||
- name: Publish to Gitea Package Registry
|
||||
env:
|
||||
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
|
||||
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
|
||||
GITEA_GO_REGISTRY: https://repos.gfranz.ch/api/packages/Gabriel20xx/go/upload
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then
|
||||
echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2
|
||||
exit 1
|
||||
fi
|
||||
package_file="$(find gitea-go-package -maxdepth 1 -type f -name '*.zip' -print -quit)"
|
||||
test -n "$package_file"
|
||||
response_file="$(mktemp)"
|
||||
http_status="$(curl --silent --show-error --fail-with-body \
|
||||
--user "$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN" \
|
||||
--output "$response_file" \
|
||||
--write-out '%{http_code}' \
|
||||
--upload-file "$package_file" \
|
||||
"$GITEA_GO_REGISTRY" || true)"
|
||||
case "$http_status" in
|
||||
201)
|
||||
echo 'Go package published.'
|
||||
;;
|
||||
409)
|
||||
echo 'Go package version already exists; leaving the immutable package unchanged.'
|
||||
;;
|
||||
*)
|
||||
cat "$response_file" >&2
|
||||
echo "Gitea Go package upload failed with HTTP status $http_status." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,66 @@
|
||||
name: Publish npm packages
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
name: Publish shared npm packages
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout source
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: npm
|
||||
|
||||
- name: Install and build packages
|
||||
run: |
|
||||
npm ci
|
||||
npm run build
|
||||
|
||||
- name: Configure Gitea npm registry
|
||||
env:
|
||||
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
|
||||
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then
|
||||
echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2
|
||||
exit 1
|
||||
fi
|
||||
npmrc_path="$RUNNER_TEMP/gitea-npmrc"
|
||||
umask 077
|
||||
{
|
||||
printf '@gabriel20xx:registry=https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/\n'
|
||||
printf '//repos.gfranz.ch/api/packages/Gabriel20xx/npm/:_authToken=%s\n' "$PACKAGE_REGISTRY_TOKEN"
|
||||
printf 'always-auth=true\n'
|
||||
} > "$npmrc_path"
|
||||
printf 'NPM_CONFIG_USERCONFIG=%s\n' "$npmrc_path" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Publish npm packages
|
||||
env:
|
||||
NPM_REGISTRY: https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for package in \
|
||||
@gabriel20xx/design-tokens \
|
||||
@gabriel20xx/web-ui \
|
||||
@gabriel20xx/node-backend; do
|
||||
version="$(npm pkg get version --workspace="$package" | tr -d '"[:space:]')"
|
||||
if npm view "$package@$version" version --registry="$NPM_REGISTRY" >/dev/null 2>&1; then
|
||||
echo "$package@$version is already published; skipping."
|
||||
else
|
||||
npm publish --workspace="$package" --registry="$NPM_REGISTRY"
|
||||
fi
|
||||
done
|
||||
@@ -0,0 +1,74 @@
|
||||
name: Publish Python package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
name: Publish shared Python package
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout source
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Build and publish package
|
||||
env:
|
||||
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
|
||||
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
|
||||
TWINE_REPOSITORY_URL: https://repos.gfranz.ch/api/packages/Gabriel20xx/pypi
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then
|
||||
echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2
|
||||
exit 1
|
||||
fi
|
||||
python -m pip install --disable-pip-version-check --no-cache-dir build twine
|
||||
package_directory="$RUNNER_TEMP/gitea-pypi-package"
|
||||
python -m build packages/python-backend --outdir "$package_directory"
|
||||
package_index_url="${TWINE_REPOSITORY_URL%/}/simple/gabriel20xx-shared-backend/"
|
||||
package_index_file="$(mktemp)"
|
||||
package_index_status="$(curl --silent --show-error --fail-with-body \
|
||||
--user "$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN" \
|
||||
--output "$package_index_file" \
|
||||
--write-out '%{http_code}' \
|
||||
"$package_index_url" || true)"
|
||||
package_files=("$package_directory"/*)
|
||||
files_to_upload=()
|
||||
case "$package_index_status" in
|
||||
200)
|
||||
for package_file in "${package_files[@]}"; do
|
||||
if ! grep -Fq "$(basename "$package_file")" "$package_index_file"; then
|
||||
files_to_upload+=("$package_file")
|
||||
fi
|
||||
done
|
||||
;;
|
||||
404)
|
||||
files_to_upload=("${package_files[@]}")
|
||||
;;
|
||||
*)
|
||||
cat "$package_index_file" >&2
|
||||
echo "Gitea PyPI package lookup failed with HTTP status $package_index_status." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if [ "${#files_to_upload[@]}" -eq 0 ]; then
|
||||
echo 'Python package version already exists with all build artifacts; leaving it unchanged.'
|
||||
exit 0
|
||||
fi
|
||||
TWINE_USERNAME="$PACKAGE_REGISTRY_USERNAME" \
|
||||
TWINE_PASSWORD="$PACKAGE_REGISTRY_TOKEN" \
|
||||
python -m twine upload --non-interactive \
|
||||
--repository-url "$TWINE_REPOSITORY_URL" \
|
||||
"${files_to_upload[@]}"
|
||||
@@ -6,7 +6,7 @@ The first packages are:
|
||||
|
||||
- `@gabriel20xx/design-tokens` — colors, typography, spacing, radii, shadows, and light/dark theme variables.
|
||||
- `@gabriel20xx/web-ui` — Svelte components for the application shell, header/navigation, authentication, dialogs, profile/settings/about windows, buttons, cards, badges, and page headers.
|
||||
- `repos.gfranz.ch/Gabriel20xx/SharedCode/backend` — Go helpers for environment configuration, `pgx` PostgreSQL pools, transactions, common auth persistence/passwords/tokens, and embedded Goose migrations.
|
||||
- `repos.gfranz.ch/Gabriel20xx/shared/backend` — Go helpers for environment configuration, `pgx` PostgreSQL pools, transactions, common auth persistence/passwords/tokens, and embedded Goose migrations.
|
||||
- `@gabriel20xx/node-backend` — Node.js `pg` pool/configuration, transactions, migrations, and auth/session persistence.
|
||||
- `gabriel20xx-shared-backend` — Python `asyncpg` pool/configuration and auth/session persistence.
|
||||
|
||||
@@ -25,7 +25,7 @@ npm run test:node-backend
|
||||
|
||||
`npm run build` creates the distributable package in `packages/web-ui/dist`. The generated `dist` directory is intentionally ignored by the package configuration and should not be committed.
|
||||
|
||||
Validate the Go backend package from `SharedCode/backend`:
|
||||
Validate the Go backend package from `shared/backend`:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
@@ -39,7 +39,7 @@ The repository is the canonical source and is installable directly from Gitea. T
|
||||
builds the Svelte package during installation and exposes the runtime packages as subpaths:
|
||||
|
||||
```bash
|
||||
npm install --save-exact git+https://repos.gfranz.ch/Gabriel20xx/SharedCode.git#<commit>
|
||||
npm install --save-exact git+https://repos.gfranz.ch/Gabriel20xx/shared#<commit>
|
||||
```
|
||||
|
||||
Use the shared UI from the root package:
|
||||
@@ -59,31 +59,29 @@ SharedCode version has been validated.
|
||||
|
||||
## Publish the individual packages
|
||||
|
||||
The package names use the `@gabriel20xx` npm scope. That scope must belong to the npm account used to publish. If a different scope is preferred, replace the scope consistently in both package manifests and imports before publishing.
|
||||
The package names use the `@gabriel20xx` npm scope. The `publish-npm.yml` and
|
||||
`publish-python.yml` Gitea workflows publish the packages when a `v*` tag is pushed or a
|
||||
matching Gitea release is published. Configure `PACKAGE_REGISTRY_USERNAME` and
|
||||
`PACKAGE_REGISTRY_TOKEN` as user Actions secrets before publishing.
|
||||
|
||||
Publish the tokens first because `web-ui` depends on them:
|
||||
|
||||
```bash
|
||||
npm login
|
||||
npm publish --workspace=@gabriel20xx/design-tokens --access public
|
||||
npm publish --workspace=@gabriel20xx/web-ui --access public
|
||||
npm publish --workspace=@gabriel20xx/node-backend --access public
|
||||
```
|
||||
|
||||
For a private registry, configure that registry and omit `--access public` if the registry does not use npm's public scoped-package rules.
|
||||
The npm workflow publishes `design-tokens` first because `web-ui` depends on it. It also
|
||||
skips an npm version that is already present, so retrying a partially completed release is safe.
|
||||
The Python workflow uses Twine's `--skip-existing` option for the same reason.
|
||||
|
||||
## Install individual packages from a registry
|
||||
|
||||
From a project's frontend directory, install the published UI package:
|
||||
From a project's frontend directory, install the published UI package from Gitea:
|
||||
|
||||
```bash
|
||||
npm install @gabriel20xx/web-ui@^0.1.0
|
||||
npm config set @gabriel20xx:registry https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/
|
||||
npm config set //repos.gfranz.ch/api/packages/Gabriel20xx/npm/:_authToken "$PACKAGE_REGISTRY_TOKEN"
|
||||
npm install @gabriel20xx/web-ui@0.1.0
|
||||
```
|
||||
|
||||
The design-token package is installed transitively. Install it directly only when an application needs to reference its theme file itself:
|
||||
|
||||
```bash
|
||||
npm install @gabriel20xx/design-tokens@^0.1.0
|
||||
npm install @gabriel20xx/design-tokens@0.1.0
|
||||
```
|
||||
|
||||
Import the shared stylesheet once from the application's global stylesheet, before project-specific overrides:
|
||||
@@ -96,10 +94,20 @@ The stylesheet imports the design tokens and uses an `sc-` prefix, so it does no
|
||||
|
||||
## Use the shared Go backend package
|
||||
|
||||
From a Go backend directory, add the module (the module is a subdirectory of the SharedCode repository):
|
||||
The Go module is published to the private Gitea Go Package Registry. Configure a
|
||||
read-only package token in the consuming workflow as `PACKAGE_REGISTRY_USERNAME`
|
||||
and `PACKAGE_REGISTRY_TOKEN`, then configure Go to use the registry before running
|
||||
`go get`, `go test`, or `go build`:
|
||||
|
||||
```bash
|
||||
go get repos.gfranz.ch/Gabriel20xx/SharedCode/backend@backend/v0.1.0
|
||||
export GOPROXY=https://repos.gfranz.ch/api/packages/Gabriel20xx/go,https://proxy.golang.org
|
||||
export GONOSUMDB=repos.gfranz.ch/Gabriel20xx/shared/*
|
||||
```
|
||||
|
||||
From a Go backend directory, add the released module (the module is a subdirectory of the shared repository):
|
||||
|
||||
```bash
|
||||
go get repos.gfranz.ch/Gabriel20xx/shared/backend@v0.1.0
|
||||
```
|
||||
|
||||
Then initialize the pool and shared auth store at startup:
|
||||
@@ -109,8 +117,8 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"repos.gfranz.ch/Gabriel20xx/SharedCode/backend/auth"
|
||||
"repos.gfranz.ch/Gabriel20xx/SharedCode/backend/postgres"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/postgres"
|
||||
)
|
||||
|
||||
cfg, err := postgres.FromEnv()
|
||||
@@ -133,20 +141,20 @@ Use `auth.SchemaOptions{SingleUser: false, APITokens: true}` for a multi-user se
|
||||
|
||||
For embedded SQL migrations, use `migrate.Up(ctx, databaseURL, embeddedMigrations, "migrations")`. The package does not contain application tables, so migrations remain versioned with the service that owns those tables.
|
||||
|
||||
The Go module lives under `backend`, so its release tag must use the submodule prefix (`backend/v0.1.0`). If the SharedCode code is moved into its own repository, update the module path and use ordinary `v0.1.0` tags instead.
|
||||
The Go module lives under `backend`, so its release tag must use the submodule prefix (`backend/v0.1.0`). The consuming `go.mod` uses the normal module version (`v0.1.0`). To publish a release, push a tag such as `backend/v0.1.0`; the Gitea workflow packages the module and uploads it to the private registry. The workflow also listens for Gitea's `release.published` event, so a release can be published from the Gitea Releases page to manually retry a failed upload for an existing tag. Never reuse a package version that was already uploaded successfully.
|
||||
|
||||
For Node services, install the shared package after publishing it:
|
||||
|
||||
```bash
|
||||
npm install @gabriel20xx/node-backend@^0.1.0
|
||||
npm install @gabriel20xx/node-backend@0.1.0
|
||||
```
|
||||
|
||||
For Python services, build and publish the wheel to the Python package index used by the projects, then install it normally:
|
||||
For Python services, configure the Gitea index and install the published wheel:
|
||||
|
||||
```bash
|
||||
python -m pip install build
|
||||
python -m build packages/python-backend
|
||||
python -m pip install gabriel20xx-shared-backend==0.1.0
|
||||
python -m pip install \
|
||||
--index-url "https://$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN@repos.gfranz.ch/api/packages/Gabriel20xx/pypi/simple" \
|
||||
gabriel20xx-shared-backend==0.1.0
|
||||
```
|
||||
|
||||
The Node and Python packages intentionally expose the same infrastructure concepts but use their native database drivers. This is the safe way to share behavior across the polyglot services; a Go package cannot be imported by the Python or Node applications.
|
||||
@@ -237,14 +245,14 @@ The shared reset controls request a short-lived code printed by the server-side
|
||||
Before publishing, build the packages and install them from the local workspace in a frontend project:
|
||||
|
||||
```bash
|
||||
# From Web/SharedCode
|
||||
# From Web/shared
|
||||
npm run build
|
||||
|
||||
# From a project frontend directory; do not commit this file dependency for CI
|
||||
npm install ../../../SharedCode/packages/design-tokens ../../../SharedCode/packages/web-ui
|
||||
npm install ../../../shared/packages/design-tokens ../../../shared/packages/web-ui
|
||||
```
|
||||
|
||||
For CI and normal development, use the published version instead of a `file:` dependency. A local file dependency only works when the checkout also contains the sibling `SharedCode` directory.
|
||||
For CI and normal development, use the published version instead of a `file:` dependency. A local file dependency only works when the checkout also contains the sibling `shared` directory.
|
||||
|
||||
## Updating the design system
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ services, not application-specific SQL or HTTP handlers.
|
||||
- `migrate` — embedded filesystem adapter for Goose migrations.
|
||||
|
||||
Run `go test ./...` and `go vet ./...` from this directory. The module path is
|
||||
`repos.gfranz.ch/Gabriel20xx/SharedCode/backend`; change it if the SharedCode folder is
|
||||
`repos.gfranz.ch/Gabriel20xx/shared/backend`; change it if the shared folder is
|
||||
hosted under a different repository path.
|
||||
|
||||
Application-specific table definitions and HTTP behavior stay in the service.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
module repos.gfranz.ch/Gabriel20xx/SharedCode/backend
|
||||
module repos.gfranz.ch/Gabriel20xx/shared/backend
|
||||
|
||||
go 1.25.7
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"repos.gfranz.ch/Gabriel20xx/SharedCode/backend/config"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/config"
|
||||
)
|
||||
|
||||
// Config controls a shared pgx connection pool. URL is normally read from
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://repos.gfranz.ch/Gabriel20xx/SharedCode.git"
|
||||
"url": "https://repos.gfranz.ch/Gabriel20xx/shared"
|
||||
},
|
||||
"type": "module",
|
||||
"files": [
|
||||
|
||||
@@ -13,5 +13,5 @@ published index or directly from the SharedCode repository with a subdirectory
|
||||
install during development:
|
||||
|
||||
```bash
|
||||
pip install "git+https://repos.gfranz.ch/Gabriel20xx/SharedCode.git@v0.1.0#subdirectory=packages/python-backend"
|
||||
pip install "git+https://repos.gfranz.ch/Gabriel20xx/shared@v0.1.0#subdirectory=packages/python-backend"
|
||||
```
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "gabriel20xx-shared-backend"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
description = "Shared PostgreSQL and authentication primitives for Python services."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"""Shared PostgreSQL and authentication primitives for Python services."""
|
||||
|
||||
from .auth import (
|
||||
RESET_CODE_TTL,
|
||||
ROLE_ADMIN,
|
||||
ROLE_SUPERADMIN,
|
||||
ROLE_USER,
|
||||
RESET_CODE_TTL,
|
||||
AuthStore,
|
||||
AuthUser,
|
||||
ResetManager,
|
||||
@@ -16,8 +16,8 @@ from .auth import (
|
||||
)
|
||||
from .config import DatabaseConfig, database_url_from_env
|
||||
from .postgres import Database
|
||||
from .totp import generate_totp_secret, totp_provisioning_uri, verify_totp
|
||||
from .tokens import hash_token, new_session_token
|
||||
from .totp import generate_totp_secret, totp_provisioning_uri, verify_totp
|
||||
|
||||
__all__ = [
|
||||
"AuthStore",
|
||||
|
||||
@@ -63,7 +63,10 @@ def can_manage_users(role: str | None) -> bool:
|
||||
|
||||
|
||||
def can_assign_role(actor_role: str | None, target_role: str | None) -> bool:
|
||||
return normalize_role(actor_role) == ROLE_SUPERADMIN and normalize_role(target_role) != ROLE_SUPERADMIN
|
||||
return (
|
||||
normalize_role(actor_role) == ROLE_SUPERADMIN
|
||||
and normalize_role(target_role) != ROLE_SUPERADMIN
|
||||
)
|
||||
|
||||
|
||||
class ResetManager:
|
||||
@@ -153,7 +156,8 @@ class AuthStore:
|
||||
"""
|
||||
INSERT INTO auth_users (username, email, password_hash, role, updated_at)
|
||||
VALUES ($1, $2, $3,
|
||||
CASE WHEN EXISTS (SELECT 1 FROM auth_users) THEN 'user' ELSE 'superadmin' END,
|
||||
CASE WHEN EXISTS (SELECT 1 FROM auth_users) THEN 'user'
|
||||
ELSE 'superadmin' END,
|
||||
now())
|
||||
RETURNING id, username, email, password_hash, role, created_at, updated_at
|
||||
""",
|
||||
@@ -256,17 +260,23 @@ class AuthStore:
|
||||
) -> None:
|
||||
fields: list[str] = []
|
||||
values: list[object] = []
|
||||
for column, value in (("username", username), ("email", email), ("password_hash", password_hash), ("role", normalize_role(role) if role is not None else None)):
|
||||
for column, value in (
|
||||
("username", username),
|
||||
("email", email),
|
||||
("password_hash", password_hash),
|
||||
("role", normalize_role(role) if role is not None else None),
|
||||
):
|
||||
if value is not None:
|
||||
fields.append(f"{column} = ${len(values) + 1}")
|
||||
values.append(value)
|
||||
if not fields:
|
||||
return
|
||||
values.append(user_id)
|
||||
await self.database.execute(
|
||||
f"UPDATE auth_users SET {', '.join(fields)}, updated_at = now() WHERE id = ${len(values)}",
|
||||
*values,
|
||||
query = (
|
||||
f"UPDATE auth_users SET {', '.join(fields)}, "
|
||||
f"updated_at = now() WHERE id = ${len(values)}"
|
||||
)
|
||||
await self.database.execute(query, *values)
|
||||
|
||||
async def delete_user(self, user_id: int) -> None:
|
||||
await self.database.execute("DELETE FROM auth_users WHERE id = $1", user_id)
|
||||
@@ -284,7 +294,8 @@ class AuthStore:
|
||||
|
||||
async def set_totp_secret(self, user_id: int, secret: str) -> None:
|
||||
await self.database.execute(
|
||||
"UPDATE auth_users SET totp_secret = $1, totp_enabled = false, updated_at = now() WHERE id = $2",
|
||||
"UPDATE auth_users SET totp_secret = $1, totp_enabled = false, "
|
||||
"updated_at = now() WHERE id = $2",
|
||||
secret,
|
||||
user_id,
|
||||
)
|
||||
@@ -298,7 +309,8 @@ class AuthStore:
|
||||
|
||||
async def disable_totp(self, user_id: int) -> None:
|
||||
await self.database.execute(
|
||||
"UPDATE auth_users SET totp_secret = '', totp_enabled = false, updated_at = now() WHERE id = $1",
|
||||
"UPDATE auth_users SET totp_secret = '', totp_enabled = false, "
|
||||
"updated_at = now() WHERE id = $1",
|
||||
user_id,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from shared_backend.auth import ResetManager, hash_password, verify_password
|
||||
from shared_backend.config import DatabaseConfig
|
||||
from shared_backend.totp import totp_provisioning_uri, verify_totp
|
||||
from shared_backend.tokens import hash_token, new_session_token
|
||||
from shared_backend.totp import totp_provisioning_uri, verify_totp
|
||||
|
||||
|
||||
class SharedBackendTests(unittest.TestCase):
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
readonly module_path='repos.gfranz.ch/Gabriel20xx/shared/backend'
|
||||
readonly module_directory='backend'
|
||||
|
||||
release_tag="${1:?usage: package-go-module.sh backend/vX.Y.Z [output-directory]}"
|
||||
output_directory="${2:-dist}"
|
||||
version="${release_tag#backend/}"
|
||||
|
||||
if [[ "$release_tag" != backend/v* ]] || [[ ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
|
||||
echo "Expected a release tag such as backend/v0.1.0; got: $release_tag" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
repository_root="$(git rev-parse --show-toplevel)"
|
||||
git rev-parse --verify --quiet "${release_tag}^{commit}" >/dev/null || {
|
||||
echo "Release tag does not resolve to a commit: $release_tag" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
stage_directory="$(mktemp -d)"
|
||||
trap 'rm -rf "$stage_directory"' EXIT
|
||||
|
||||
module_root="$stage_directory/${module_path}@${version}"
|
||||
mkdir -p "$module_root"
|
||||
|
||||
# Go module ZIP files must contain <module>@<version>/ at their root. The
|
||||
# module is stored in the backend/ subdirectory of the shared repository,
|
||||
# so strip that repository directory while extracting the tagged source.
|
||||
git archive --format=tar "$release_tag" "$module_directory" \
|
||||
| tar -x --strip-components=1 -C "$module_root"
|
||||
|
||||
test -f "$module_root/go.mod"
|
||||
grep -Fxq "module $module_path" "$module_root/go.mod"
|
||||
if [[ "$output_directory" = /* ]]; then
|
||||
output_path="$output_directory"
|
||||
else
|
||||
output_path="$repository_root/$output_directory"
|
||||
fi
|
||||
mkdir -p "$output_path"
|
||||
zip_file="$output_path/${module_path//\//_}@${version}.zip"
|
||||
rm -f "$zip_file"
|
||||
|
||||
(
|
||||
cd "$stage_directory"
|
||||
zip -qr "$zip_file" "${module_path}@${version}"
|
||||
)
|
||||
|
||||
unzip -tq "$zip_file" >/dev/null
|
||||
echo "Created $zip_file"
|
||||
Reference in new issue
Block a user