Files
pipu-music/services/api/internal/platform/config/config.go
T
mrleo1nidandClaude Opus 5.5 ed4a492dba
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m15s
ci / api / api (push) Successful in 1m31s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 47s
ci / ts / ts (packages + web) (push) Successful in 39s
ci / docker / docker (образы собираются — их сервер собирает сам при обновлении) (push) Successful in 26s
feat(api): sign-in, refresh rotation and bootstrap admin (M1)
- users, refresh_tokens and audit_log schema (migration 00002)
- argon2id passwords with rehash on login, password policy, lockout
  with exponential back-off and a per-IP rate limit in Redis
- Ed25519 JWT access tokens with kid-based key rotation; rotating
  refresh tokens with reuse detection (cookie for web, body for Android)
- bootstrap admin on first start; must_change_credentials and
  must_change_password gate every other endpoint
- /auth/login, /auth/refresh, /auth/logout(-all), /me, /me/password,
  /me/bootstrap-credentials, /me/sessions; server-info reports
  bootstrap_required
- role policy from docs/auth-and-roles.md with table tests
- problem+json errors with field errors; ru/en translations of the codes
- install.sh and update.sh generate JWT_PRIVATE_KEY

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 06:12:25 +03:00

53 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package config читает конфигурацию сервиса из переменных окружения.
package config
import (
"fmt"
"time"
"github.com/caarlos0/env/v11"
)
// API — конфигурация публичного сервиса api.
type API struct {
HTTPAddr string `env:"HTTP_ADDR" envDefault:":8080"`
DatabaseURL string `env:"DATABASE_URL,required"`
RedisURL string `env:"REDIS_URL,required"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
MigrateOnStart bool `env:"MIGRATE_ON_START" envDefault:"true"`
ShutdownTimeout time.Duration `env:"SHUTDOWN_TIMEOUT" envDefault:"15s"`
SupportedLocales []string `env:"SUPPORTED_LOCALES" envDefault:"ru,en" envSeparator:","`
MinAndroidVersionCode int `env:"MIN_ANDROID_VERSION_CODE" envDefault:"0"`
// JWTPrivateKey — Ed25519 (base64: 32-байтовый seed или 64-байтовый ключ). Пусто — случайный ключ
// на время жизни процесса: после перезапуска всем придётся обновить access-токен (refresh остаётся).
JWTPrivateKey string `env:"JWT_PRIVATE_KEY"`
// JWTPreviousKeys — прежние ключи через запятую: токены, подписанные ими, ещё принимаются.
JWTPreviousKeys []string `env:"JWT_PREVIOUS_KEYS" envSeparator:","`
AccessTokenTTL time.Duration `env:"ACCESS_TOKEN_TTL" envDefault:"15m"`
// CookieSecure — флаг Secure у refresh-cookie. Отключать только для разработки по http не на localhost.
CookieSecure bool `env:"COOKIE_SECURE" envDefault:"true"`
BootstrapAdminUsername string `env:"BOOTSTRAP_ADMIN_USERNAME" envDefault:"admin"`
BootstrapAdminPassword string `env:"BOOTSTRAP_ADMIN_PASSWORD"`
}
// StorageAgent — конфигурация внутреннего сервиса storage-agent.
type StorageAgent struct {
HTTPAddr string `env:"HTTP_ADDR" envDefault:":8090"`
InternalToken string `env:"INTERNAL_TOKEN,required,notEmpty"`
LibraryRoot string `env:"LIBRARY_ROOT" envDefault:"/library"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
ShutdownTimeout time.Duration `env:"SHUTDOWN_TIMEOUT" envDefault:"15s"`
}
// Load заполняет структуру конфигурации T из окружения.
func Load[T any]() (T, error) {
var cfg T
if err := env.Parse(&cfg); err != nil {
return cfg, fmt.Errorf("config: %w", err)
}
return cfg, nil
}