be6ad15efc
Security: apply AdminOnly middleware to mutating routes, require ENCRYPTION_KEY and ADMIN_PASSWORD (no insecure defaults), restrict CORS to same-origin, fix OIDC token delivery via cookie instead of URL query param, add rate limiting on login, add MaxBytesReader, validate volume paths against traversal, add security headers, validate user roles, add Secure flag to OIDC cookie. Performance: set SQLite MaxOpenConns(1) to prevent SQLITE_BUSY, add FK indexes on 8 columns, track notifier goroutines with WaitGroup for graceful shutdown, use GetRegistryByName instead of GetAllRegistries in deployer, pass basePath param to avoid redundant settings query, return empty slices from store to remove reflection. Quality: refactor TriggerDeploy to delegate to runDeploy (~100 lines removed), consolidate duplicated utilities (extractPort, boolToInt, now, isTerminalStatus) into shared exports, migrate all log.Printf to slog structured logging, use consistent webhook response envelope, remove dead code (parseEnvVars, duplicate auth types). UX: clean up NPM proxy on instance removal via API, add README with quickstart guide, add .env.example, require ADMIN_PASSWORD in docker-compose, document staging-net prerequisite.
38 lines
1.4 KiB
Go
38 lines
1.4 KiB
Go
package store
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// GetSettings returns the global settings (single-row pattern, always row id=1).
|
|
func (s *Store) GetSettings() (Settings, error) {
|
|
var st Settings
|
|
err := s.db.QueryRow(
|
|
`SELECT domain, server_ip, network, subdomain_pattern, notification_url,
|
|
npm_url, npm_email, npm_password, webhook_secret, polling_interval, base_volume_path, updated_at
|
|
FROM settings WHERE id = 1`,
|
|
).Scan(&st.Domain, &st.ServerIP, &st.Network, &st.SubdomainPattern, &st.NotificationURL,
|
|
&st.NpmURL, &st.NpmEmail, &st.NpmPassword, &st.WebhookSecret, &st.PollingInterval, &st.BaseVolumePath, &st.UpdatedAt)
|
|
if err != nil {
|
|
return Settings{}, fmt.Errorf("query settings: %w", err)
|
|
}
|
|
return st, nil
|
|
}
|
|
|
|
// UpdateSettings upserts the global settings row.
|
|
func (s *Store) UpdateSettings(st Settings) error {
|
|
st.UpdatedAt = Now()
|
|
_, err := s.db.Exec(
|
|
`UPDATE settings SET
|
|
domain=?, server_ip=?, network=?, subdomain_pattern=?, notification_url=?,
|
|
npm_url=?, npm_email=?, npm_password=?, webhook_secret=?, polling_interval=?, base_volume_path=?, updated_at=?
|
|
WHERE id = 1`,
|
|
st.Domain, st.ServerIP, st.Network, st.SubdomainPattern, st.NotificationURL,
|
|
st.NpmURL, st.NpmEmail, st.NpmPassword, st.WebhookSecret, st.PollingInterval, st.BaseVolumePath, st.UpdatedAt,
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("update settings: %w", err)
|
|
}
|
|
return nil
|
|
}
|