2023-05-20 20:15:57 +02:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
2023-05-12 22:43:36 +02:00
|
|
|
"os"
|
2023-08-05 14:25:34 +02:00
|
|
|
"time"
|
2023-05-12 22:43:36 +02:00
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
"git.dotya.ml/mirre-mt/pcmt/config"
|
|
|
|
"git.dotya.ml/mirre-mt/pcmt/slogging"
|
2023-05-09 17:35:00 +02:00
|
|
|
"golang.org/x/exp/slog"
|
2023-05-03 02:18:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Settings struct {
|
2023-05-21 12:44:18 +02:00
|
|
|
host string
|
|
|
|
port int
|
|
|
|
appPath string
|
|
|
|
httpDomain string
|
|
|
|
httpSecure bool
|
|
|
|
httpGzipEnabled bool
|
|
|
|
httpGzipLevel int
|
|
|
|
httpRateLimitEnabled bool
|
|
|
|
httpRateLimit int
|
2023-09-08 17:48:51 +02:00
|
|
|
httpCSP string
|
2023-05-21 12:44:18 +02:00
|
|
|
isLive bool
|
|
|
|
isDevel bool
|
2023-05-21 18:50:41 +02:00
|
|
|
initCreateAdmin bool
|
|
|
|
initAdminPassword string
|
2023-05-21 12:44:18 +02:00
|
|
|
loggerJSON bool
|
|
|
|
sessionCookieName string
|
|
|
|
sessionCookieAuthSecret string
|
|
|
|
sessionCookieEncrSecret string
|
2023-08-04 18:13:23 +02:00
|
|
|
sessionAuthIsHex bool
|
|
|
|
sessionEncrIsHex bool
|
2023-08-04 18:28:56 +02:00
|
|
|
sessionMaxAge int
|
2023-05-21 12:44:18 +02:00
|
|
|
assetsPath string
|
|
|
|
templatesPath string
|
|
|
|
version string
|
|
|
|
dbConnstring string
|
|
|
|
dbType string
|
|
|
|
dbIsSetUp bool
|
2023-08-16 15:07:10 +02:00
|
|
|
RegistrationAllowed bool
|
2023-09-04 15:00:41 +02:00
|
|
|
hibpAPIKey string
|
|
|
|
dehashedAPIKey string
|
2023-05-03 02:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-09-04 15:00:41 +02:00
|
|
|
var log slogging.Slogger
|
|
|
|
|
2023-05-12 22:43:36 +02:00
|
|
|
// cleantgt is a list of ENV vars pertaining to pcmt.
|
|
|
|
var cleantgt = []string{
|
|
|
|
"PCMT_LIVE",
|
|
|
|
"PCMT_DEVEL",
|
|
|
|
"PCMT_CONNSTRING",
|
|
|
|
"PCMT_DBTYPE",
|
2023-05-21 12:44:18 +02:00
|
|
|
"PCMT_SESSION_AUTH_SECRET",
|
|
|
|
"PCMT_SESSION_ENCR_SECRET",
|
2023-05-21 18:50:41 +02:00
|
|
|
"PCMT_INIT_ADMIN_PASSWORD",
|
2023-08-22 19:57:48 +02:00
|
|
|
"PCMT_HIBP_API_KEY",
|
2023-09-04 15:00:41 +02:00
|
|
|
"PCMT_DEHASHED_API_KEY",
|
2023-05-12 22:43:36 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
// New returns a new instance of the settings struct.
|
|
|
|
func New() *Settings {
|
|
|
|
return &Settings{}
|
|
|
|
}
|
|
|
|
|
2023-08-05 14:25:34 +02:00
|
|
|
// DefaultServerWriteTimeout returns the server default write timeout.
|
|
|
|
func (s *Settings) DefaultServerWriteTimeout() time.Duration {
|
|
|
|
return defaultServerWriteTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultServerReadHeaderTimeout returns the server default read header timeout.
|
|
|
|
func (s *Settings) DefaultServerReadHeaderTimeout() time.Duration {
|
|
|
|
return defaultServerReadHeaderTimeout
|
|
|
|
}
|
|
|
|
|
2023-09-04 14:01:42 +02:00
|
|
|
// DefaultLoggerSkipAssets returns whether the logger skips reporting asset visits.
|
|
|
|
func (s *Settings) DefaultLoggerSkipAssets() bool {
|
|
|
|
return defaultLoggerSkipAssets
|
|
|
|
}
|
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
// Consolidate reconciles whatever values are set in config and via flags and
|
|
|
|
// sets it to one place that should be regarded as a single source of truth -
|
|
|
|
// the settings struct. Order of preference for values is (from higher to
|
|
|
|
// lower) as follows: flag -> Env var -> configuration file.
|
|
|
|
func (s *Settings) Consolidate(conf *config.Config, host *string, port *int, devel *bool, version string) {
|
2023-09-04 15:00:41 +02:00
|
|
|
log = *slogging.Logger() // have a local copy.
|
|
|
|
log.Logger = log.With(
|
2023-05-09 17:35:00 +02:00
|
|
|
slog.Group("pcmt extra", slog.String("module", "app/settings")),
|
|
|
|
)
|
2023-05-03 02:18:29 +02:00
|
|
|
|
|
|
|
log.Debug("starting to consolidate settings")
|
2023-05-09 17:35:00 +02:00
|
|
|
log.Debug("parsing config values")
|
2023-05-03 02:18:29 +02:00
|
|
|
|
2023-05-23 16:37:33 +02:00
|
|
|
if p := conf.Port; p > 0 && p < 65536 {
|
2023-08-20 23:01:27 +02:00
|
|
|
s.SetPort(conf.Port)
|
|
|
|
} else {
|
2023-08-04 18:31:45 +02:00
|
|
|
log.Warnf("port '%d', outside of bounds, setting a default of %d/tcp", p, defaultPort)
|
|
|
|
s.SetPort(defaultPort)
|
2023-05-23 16:37:33 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
s.SetHost(conf.Host)
|
2023-05-21 12:44:18 +02:00
|
|
|
s.SetAppPath(conf.AppPath)
|
2023-05-03 02:18:29 +02:00
|
|
|
s.SetIsLive(conf.LiveMode)
|
|
|
|
s.SetIsDevel(conf.DevelMode)
|
2023-05-21 12:44:18 +02:00
|
|
|
s.SetLoggerIsJSON(conf.Logger.JSON)
|
2023-09-08 17:22:20 +02:00
|
|
|
|
|
|
|
if conf.HTTP.Secure {
|
|
|
|
// https://www.sjoerdlangkemper.nl/2017/02/09/cookie-prefixes/
|
|
|
|
// https://scotthelme.co.uk/tough-cookies/
|
|
|
|
// https://check-your-website.server-daten.de/prefix-cookies.html
|
|
|
|
s.SetSessionCookieName("__Host-" + conf.Session.CookieName)
|
|
|
|
} else {
|
|
|
|
s.SetSessionCookieName(conf.Session.CookieName)
|
|
|
|
}
|
|
|
|
|
2023-09-04 21:02:06 +02:00
|
|
|
s.SetSessionMaxAge(conf.Session.MaxAge)
|
2023-05-21 12:44:18 +02:00
|
|
|
s.SetSessionCookieAuthSecret(conf.Session.CookieAuthSecret)
|
|
|
|
s.SetSessionCookieEncrSecret(conf.Session.CookieEncrSecret)
|
|
|
|
|
|
|
|
authHex, encrHex := conf.SessionSecretsAreHex()
|
|
|
|
|
|
|
|
if authHex {
|
2023-08-04 18:13:23 +02:00
|
|
|
s.sessionAuthIsHex = true
|
2023-05-21 12:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if encrHex {
|
2023-08-04 18:13:23 +02:00
|
|
|
s.sessionEncrIsHex = true
|
2023-05-21 12:44:18 +02:00
|
|
|
}
|
|
|
|
|
2023-09-08 17:48:51 +02:00
|
|
|
if conf.Init.CreateAdmin {
|
|
|
|
s.SetInitCreateAdmin(true)
|
|
|
|
s.SetInitAdminPassword(conf.Init.AdminPassword)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.Registration.Allowed {
|
|
|
|
s.RegistrationAllowed = true
|
|
|
|
}
|
|
|
|
|
2023-05-21 12:44:18 +02:00
|
|
|
if conf.HTTP.Gzip > 0 {
|
|
|
|
s.SetHTTPGzipEnabled(true)
|
|
|
|
s.SetHTTPGzipLevel(conf.HTTP.Gzip)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.HTTP.RateLimit > 0 {
|
|
|
|
s.SetHTTPRateLimitEnabled(true)
|
|
|
|
s.SetHTTPRateLimit(conf.HTTP.RateLimit)
|
|
|
|
}
|
2023-05-03 02:18:29 +02:00
|
|
|
|
2023-09-08 17:48:51 +02:00
|
|
|
s.SetHTTPCSP(conf.HTTP.ContentSecurityPolicy)
|
2023-09-08 17:22:20 +02:00
|
|
|
s.SetHTTPDomain(conf.HTTP.Domain)
|
|
|
|
s.SetHTTPSecure(conf.HTTP.Secure)
|
2023-09-04 15:00:41 +02:00
|
|
|
s.setAPIKeys()
|
2023-09-08 17:22:20 +02:00
|
|
|
s.sortOutFlags(conf, host, port, devel)
|
2023-05-03 02:18:29 +02:00
|
|
|
s.SetVersion(version)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Host returns the host.
|
|
|
|
func (s *Settings) Host() string {
|
|
|
|
return s.host
|
|
|
|
}
|
|
|
|
|
|
|
|
// Port returns the port.
|
|
|
|
func (s *Settings) Port() int {
|
|
|
|
return s.port
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppName returns the appName.
|
|
|
|
func (s *Settings) AppName() string {
|
2023-09-10 12:58:38 +02:00
|
|
|
return defaultAppName
|
2023-05-21 12:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AppPath returns the appPath.
|
|
|
|
func (s *Settings) AppPath() string {
|
|
|
|
return s.appPath
|
2023-05-03 02:18:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsLive returns the value of isLive of the receiver.
|
|
|
|
func (s *Settings) IsLive() bool {
|
|
|
|
return s.isLive
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDevel returns the value of isDevel of the receiver.
|
|
|
|
func (s *Settings) IsDevel() bool {
|
|
|
|
return s.isDevel
|
|
|
|
}
|
|
|
|
|
2023-05-21 18:50:41 +02:00
|
|
|
// InitCreateAdmin returns the value of initCreateAdmin of the receiver.
|
|
|
|
func (s *Settings) InitCreateAdmin() bool {
|
|
|
|
return s.initCreateAdmin
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitAdminPassword returns the value of initAdminPassword of the receiver.
|
|
|
|
func (s *Settings) InitAdminPassword() string {
|
|
|
|
return s.initAdminPassword
|
|
|
|
}
|
|
|
|
|
2023-05-21 12:44:18 +02:00
|
|
|
// LoggerIsJSON returns whether the logger should use the JSON handler.
|
|
|
|
func (s *Settings) LoggerIsJSON() bool {
|
|
|
|
return s.loggerJSON
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:35:57 +02:00
|
|
|
// SessionCookieName returns the name of the session cookie.
|
2023-05-03 02:18:29 +02:00
|
|
|
func (s *Settings) SessionCookieName() string {
|
|
|
|
return s.sessionCookieName
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:35:57 +02:00
|
|
|
// SessionCookieAuthSecret returns the session cookie authentication secret.
|
2023-05-21 12:44:18 +02:00
|
|
|
func (s *Settings) SessionCookieAuthSecret() string {
|
|
|
|
return s.sessionCookieAuthSecret
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:35:57 +02:00
|
|
|
// SessionCookieEncrSecret returns the session cookie encryption secret.
|
2023-05-21 12:44:18 +02:00
|
|
|
func (s *Settings) SessionCookieEncrSecret() string {
|
|
|
|
return s.sessionCookieEncrSecret
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:13:23 +02:00
|
|
|
// SessionAuthIsHex returns whether the session cookie authentication secret is hex.
|
|
|
|
func (s *Settings) SessionAuthIsHex() bool {
|
|
|
|
return s.sessionAuthIsHex
|
|
|
|
}
|
|
|
|
|
|
|
|
// SessionEncrIsHex returns whether the session cookie encryption secret is hex.
|
|
|
|
func (s *Settings) SessionEncrIsHex() bool {
|
|
|
|
return s.sessionEncrIsHex
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:28:56 +02:00
|
|
|
// SessionMaxAge returns the session cookie MaxAge value.
|
|
|
|
func (s *Settings) SessionMaxAge() int {
|
|
|
|
return s.sessionMaxAge
|
|
|
|
}
|
|
|
|
|
2023-05-21 12:44:18 +02:00
|
|
|
// HTTPDomain returns the httpDomain.
|
|
|
|
func (s *Settings) HTTPDomain() string {
|
|
|
|
return s.httpDomain
|
|
|
|
}
|
|
|
|
|
|
|
|
// HTTPSecure returns the httpSecure.
|
|
|
|
func (s *Settings) HTTPSecure() bool {
|
|
|
|
return s.httpSecure
|
|
|
|
}
|
|
|
|
|
|
|
|
// HTTPGzipEnabled returns the httpGzipEnabled variable.
|
|
|
|
func (s *Settings) HTTPGzipEnabled() bool {
|
|
|
|
return s.httpGzipEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// HTTPGzipLevel returns the httpGzipLevel.
|
|
|
|
func (s *Settings) HTTPGzipLevel() int {
|
|
|
|
return s.httpGzipLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
// HTTPRateLimitEnabled returns the httpRateLimitEnabled variable.
|
|
|
|
func (s *Settings) HTTPRateLimitEnabled() bool {
|
|
|
|
return s.httpRateLimitEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// HTTPRateLimit returns the httpRateLimit.
|
|
|
|
func (s *Settings) HTTPRateLimit() int {
|
|
|
|
return s.httpRateLimit
|
2023-05-03 02:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-09-08 17:48:51 +02:00
|
|
|
// HTTPCSP returns the httpCSP.
|
|
|
|
func (s *Settings) HTTPCSP() string {
|
|
|
|
return s.httpCSP
|
|
|
|
}
|
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
// AssetsPath returns the assetsPath.
|
|
|
|
func (s *Settings) AssetsPath() string {
|
|
|
|
return s.assetsPath
|
|
|
|
}
|
|
|
|
|
|
|
|
// TemplatesPath returns the templatesPath.
|
|
|
|
func (s *Settings) TemplatesPath() string {
|
|
|
|
return s.templatesPath
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version returns the version.
|
|
|
|
func (s *Settings) Version() string {
|
|
|
|
return s.version
|
|
|
|
}
|
|
|
|
|
2023-05-05 22:58:13 +02:00
|
|
|
// DbIsSetUp returns the dbIsSetUp.
|
|
|
|
func (s *Settings) DbIsSetUp() bool {
|
|
|
|
return s.dbIsSetUp
|
|
|
|
}
|
|
|
|
|
2023-09-04 15:00:41 +02:00
|
|
|
// APIKeyHIBP returns the hibpAPIKey.
|
|
|
|
func (s *Settings) APIKeyHIBP() string {
|
|
|
|
return s.hibpAPIKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// APIKeyDehashed returns the dehashedAPIKey.
|
|
|
|
func (s *Settings) APIKeyDehashed() string {
|
|
|
|
return s.dehashedAPIKey
|
|
|
|
}
|
|
|
|
|
2023-05-05 23:10:56 +02:00
|
|
|
// DbConnstring returns the dbConnString.
|
|
|
|
func (s *Settings) DbConnstring() string {
|
|
|
|
return s.dbConnstring
|
|
|
|
}
|
|
|
|
|
|
|
|
// DbType returns the dbType.
|
|
|
|
func (s *Settings) DbType() string {
|
|
|
|
return s.dbType
|
|
|
|
}
|
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
// SetHost sets the host.
|
|
|
|
func (s *Settings) SetHost(host string) {
|
|
|
|
s.host = host
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPort sets the port.
|
|
|
|
func (s *Settings) SetPort(port int) {
|
|
|
|
s.port = port
|
|
|
|
}
|
|
|
|
|
2023-05-21 12:44:18 +02:00
|
|
|
// SetAppPath sets the appPath.
|
|
|
|
func (s *Settings) SetAppPath(appPath string) {
|
|
|
|
s.appPath = appPath
|
2023-05-03 02:18:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetIsLive sets the value of isLive of the receiver.
|
|
|
|
func (s *Settings) SetIsLive(live bool) {
|
|
|
|
s.isLive = live
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIsDevel sets the value of isDevel of the receiver.
|
|
|
|
func (s *Settings) SetIsDevel(devel bool) {
|
|
|
|
s.isDevel = devel
|
|
|
|
}
|
|
|
|
|
2023-05-21 18:50:41 +02:00
|
|
|
// SetInitCreateAdmin sets the value of initCreateAdmin of the receiver.
|
|
|
|
func (s *Settings) SetInitCreateAdmin(create bool) {
|
|
|
|
s.initCreateAdmin = create
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetInitAdminPassword sets the value of initAdminPassword of the receiver.
|
|
|
|
func (s *Settings) SetInitAdminPassword(password string) {
|
|
|
|
s.initAdminPassword = password
|
|
|
|
}
|
|
|
|
|
2023-05-21 12:44:18 +02:00
|
|
|
// SetLoggerIsJSON sets the setting value of loggerIsJSON.
|
|
|
|
func (s *Settings) SetLoggerIsJSON(isJSON bool) {
|
|
|
|
s.loggerJSON = isJSON
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:35:57 +02:00
|
|
|
// SetSessionCookieName sets session cookie name.
|
2023-05-03 02:18:29 +02:00
|
|
|
func (s *Settings) SetSessionCookieName(sessionCookieName string) {
|
|
|
|
s.sessionCookieName = sessionCookieName
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:35:57 +02:00
|
|
|
// SetSessionCookieAuthSecret sets the session cookie authentication secret.
|
2023-05-21 12:44:18 +02:00
|
|
|
func (s *Settings) SetSessionCookieAuthSecret(sessionCookieAuthSecret string) {
|
|
|
|
s.sessionCookieAuthSecret = sessionCookieAuthSecret
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:35:57 +02:00
|
|
|
// SetSessionCookieEncrSecret sets the session cookie encryption secret.
|
2023-05-21 12:44:18 +02:00
|
|
|
func (s *Settings) SetSessionCookieEncrSecret(sessionCookieEncrSecret string) {
|
|
|
|
s.sessionCookieEncrSecret = sessionCookieEncrSecret
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:28:56 +02:00
|
|
|
// SetSessionMaxAge sets sessionMaxAge.
|
|
|
|
func (s *Settings) SetSessionMaxAge(sessionMaxAge int) {
|
|
|
|
if sessionMaxAge < 1 {
|
2023-09-04 21:02:06 +02:00
|
|
|
log.Debug("setting cookie max age to the default")
|
|
|
|
|
2023-08-04 18:31:45 +02:00
|
|
|
s.sessionMaxAge = defaultSessionMaxAge
|
2023-08-04 18:28:56 +02:00
|
|
|
} else {
|
2023-09-04 21:02:06 +02:00
|
|
|
log.Debug("setting cookie max age to a config-provided value", "maxAge", sessionMaxAge)
|
|
|
|
|
2023-08-04 18:28:56 +02:00
|
|
|
s.sessionMaxAge = sessionMaxAge
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-21 12:44:18 +02:00
|
|
|
// SetHTTPDomain sets the httpDomain.
|
|
|
|
func (s *Settings) SetHTTPDomain(domain string) {
|
2023-08-04 17:19:06 +02:00
|
|
|
switch domain {
|
|
|
|
case "":
|
2023-08-04 18:31:45 +02:00
|
|
|
s.httpDomain = defaultHTTPDomain
|
2023-08-04 17:19:06 +02:00
|
|
|
default:
|
|
|
|
s.httpDomain = domain
|
|
|
|
}
|
2023-05-21 12:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetHTTPSecure sets the httpSecure.
|
|
|
|
func (s *Settings) SetHTTPSecure(secure bool) {
|
|
|
|
s.httpSecure = secure
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHTTPGzipEnabled sets the httpGzipEnabled variable.
|
|
|
|
func (s *Settings) SetHTTPGzipEnabled(enabled bool) {
|
|
|
|
s.httpGzipEnabled = enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHTTPGzipLevel sets the httpGzipLevel.
|
|
|
|
func (s *Settings) SetHTTPGzipLevel(level int) {
|
|
|
|
s.httpGzipLevel = level
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHTTPRateLimitEnabled sets the httpRateLimitEnabled variable.
|
|
|
|
func (s *Settings) SetHTTPRateLimitEnabled(enabled bool) {
|
|
|
|
s.httpRateLimitEnabled = enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHTTPRateLimit sets the httpRateLimit.
|
|
|
|
func (s *Settings) SetHTTPRateLimit(rateLimit int) {
|
|
|
|
s.httpRateLimit = rateLimit
|
2023-05-03 02:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-09-08 17:48:51 +02:00
|
|
|
// SetHTTPCSP sets the content security policy.
|
|
|
|
func (s *Settings) SetHTTPCSP(csp string) {
|
|
|
|
switch csp {
|
|
|
|
case "":
|
|
|
|
if s.isDevel {
|
|
|
|
s.httpCSP = defaultCSPDevel
|
|
|
|
} else {
|
|
|
|
s.httpCSP = defaultCSP
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
s.httpCSP = csp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-03 02:18:29 +02:00
|
|
|
// SetAssetsPath sets the assetsPath.
|
|
|
|
func (s *Settings) SetAssetsPath(assetsPath string) {
|
|
|
|
s.assetsPath = assetsPath
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTemplatesPath sets the templatesPath.
|
|
|
|
func (s *Settings) SetTemplatesPath(templatesPath string) {
|
|
|
|
s.templatesPath = templatesPath
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVersion sets the version.
|
|
|
|
func (s *Settings) SetVersion(version string) {
|
|
|
|
s.version = version
|
|
|
|
}
|
2023-05-05 22:58:13 +02:00
|
|
|
|
2023-05-05 23:10:56 +02:00
|
|
|
// SetDbConnstring sets the dbConnString.
|
|
|
|
func (s *Settings) SetDbConnstring(connstring string) {
|
|
|
|
s.dbConnstring = connstring
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDbType sets the dbType.
|
|
|
|
func (s *Settings) SetDbType(dbType string) {
|
|
|
|
s.dbType = dbType
|
|
|
|
}
|
|
|
|
|
2023-05-05 22:58:13 +02:00
|
|
|
// SetDbIsSetUp sets the dbIsSetUp.
|
|
|
|
func (s *Settings) SetDbIsSetUp(is bool) {
|
|
|
|
s.dbIsSetUp = is
|
|
|
|
}
|
2023-05-12 22:43:36 +02:00
|
|
|
|
2023-09-04 15:00:41 +02:00
|
|
|
// SetAPIKeyHIBP sets the hibpAPIKey.
|
|
|
|
func (s *Settings) SetAPIKeyHIBP(k string) {
|
|
|
|
s.hibpAPIKey = k
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAPIKeyDehashed sets the dehashedAPIKey.
|
|
|
|
func (s *Settings) SetAPIKeyDehashed(k string) {
|
|
|
|
s.dehashedAPIKey = k
|
|
|
|
}
|
|
|
|
|
2023-05-12 22:43:36 +02:00
|
|
|
// EraseENVs attempts to clear environment vars pertaining to pcmt.
|
|
|
|
func (s *Settings) EraseENVs() error {
|
|
|
|
for _, v := range cleantgt {
|
|
|
|
err := os.Unsetenv(v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|