All checks were successful
Deploy to K8s / deploy (push) Successful in 11s
- io/attendance: CSV-over-public-URL client + Fake for adult/junior tabs - io/drive: Drive v3 modifiedTime client + Fake - io/sheets: Sheets v4 client (GetValues/AppendValues/BatchUpdateValues/ WriteHeader/SortByDateColumn) + Fake with call-capture - io/cache: Drive-modifiedTime-gated FileCache; two TTL knobs; atomic writes; generic Get[T]; Python-compatible JSON format; Flush() - io/fio: Client interface backed by Fio REST API (apiClient) and HTML scraper (transparentClient); Fake; testdata fixtures - membership/sources: NewSources wires attendance CSV + Sheets + cache into LoadAdults/LoadJuniors/LoadTransactions/LoadExceptions; Czech month parsing + merged-month maps - banksync: SyncToSheets (SHA-256 dedup, optional sort) and InferPayments ([?] review prefix, dry-run) — tested with fakes - cmd/fuj: sync and infer subcommands wired; fees and reconcile use real NewSources; go.mod gains google.golang.org/api + x/net - gofumpt extra-rules applied across all packages; lint clean Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
94 lines
3.0 KiB
Go
94 lines
3.0 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// Google Sheets IDs — change in code if sheets change (not from env).
|
|
const (
|
|
AttendanceSheetID = "1E2e_gT_K5AwSRCDLDTa2UetZTkHmBOcz0kFbBUNUNBA"
|
|
PaymentsSheetID = "1Om0YPoDVCH5cV8BrNz5LG5eR5MMU05ypQC7UMN1xn_Y"
|
|
|
|
// Both attendance tabs live in the same Google Spreadsheet (AttendanceSheetID).
|
|
// The original adult and junior attendance data lives in separate source spreadsheets,
|
|
// but is collected into this one sheet via IMPORTRANGE — one tab per group.
|
|
// Tabs are identified by the gid= query param in the CSV export URL.
|
|
AttendanceAdultSheetGID = "0" // gid=0 — adult practices tab (IMPORTRANGE'd)
|
|
JuniorSheetGID = "1213318614" // gid=1213318614 — junior practices tab (IMPORTRANGE'd)
|
|
)
|
|
|
|
// CacheSheetMap mirrors scripts/config.py CACHE_SHEET_MAP.
|
|
// Maps a cache key to the Google Sheet ID whose Drive modifiedTime gates it.
|
|
// Both attendance keys map to the same spreadsheet — different tabs, one Drive file.
|
|
var CacheSheetMap = map[string]string{
|
|
"attendance_regular": AttendanceSheetID,
|
|
"attendance_juniors": AttendanceSheetID,
|
|
"exceptions_dict": PaymentsSheetID,
|
|
"payments_transactions": PaymentsSheetID,
|
|
}
|
|
|
|
// Config holds all runtime configuration loaded from environment variables.
|
|
// Mirrors scripts/config.py.
|
|
type Config struct {
|
|
CredentialsPath string
|
|
BankAccount string
|
|
CacheDir string
|
|
CacheTTL time.Duration
|
|
CacheAPICheckTTL time.Duration
|
|
DriveTimeout time.Duration
|
|
LogLevel string
|
|
FioAPIToken string
|
|
ServerAddr string
|
|
}
|
|
|
|
// Load reads configuration from the environment, applying defaults that
|
|
// match the Python side.
|
|
func Load() Config {
|
|
return Config{
|
|
CredentialsPath: env("CREDENTIALS_PATH", ".secret/fuj-management-bot-credentials.json"),
|
|
BankAccount: env("BANK_ACCOUNT", "CZ8520100000002800359168"),
|
|
CacheDir: env("CACHE_DIR", "tmp"),
|
|
CacheTTL: envDuration("CACHE_TTL_SECONDS", 300),
|
|
CacheAPICheckTTL: envDuration("CACHE_API_CHECK_TTL_SECONDS", 300),
|
|
DriveTimeout: envDuration("DRIVE_TIMEOUT_SECONDS", 10),
|
|
LogLevel: env("LOG_LEVEL", "INFO"),
|
|
FioAPIToken: env("FIO_API_TOKEN", ""),
|
|
ServerAddr: env("SERVER_ADDR", ":8080"),
|
|
}
|
|
}
|
|
|
|
// IBANAccountNum extracts the bare account number from a Czech IBAN.
|
|
// "CZ8520100000002800359168" → "2800359168"
|
|
// Structure: CZ(2 check)(4 bank code)(16 zero-padded account).
|
|
func IBANAccountNum(iban string) string {
|
|
s := strings.ReplaceAll(iban, " ", "")
|
|
if len(s) < 8 {
|
|
return iban
|
|
}
|
|
raw := s[8:] // 16-digit zero-padded account portion
|
|
n := strings.TrimLeft(raw, "0")
|
|
if n == "" {
|
|
return "0"
|
|
}
|
|
return n
|
|
}
|
|
|
|
func env(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func envDuration(key string, defaultSeconds int) time.Duration {
|
|
if v := os.Getenv(key); v != "" {
|
|
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
|
return time.Duration(n) * time.Second
|
|
}
|
|
}
|
|
return time.Duration(defaultSeconds) * time.Second
|
|
}
|