diff --git a/internal/config/config.go b/internal/config/config.go
index 41a5ae9..99cabe4 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -2,13 +2,12 @@
package config
import (
- "fmt"
"hash/fnv"
"math/rand"
"reflect"
"time"
- "github.com/tkw1536/pkglib/pools"
+ "github.com/tkw1536/pkglib/reflectx"
"github.com/tkw1536/pkglib/yamlx"
"gopkg.in/yaml.v3"
@@ -42,7 +41,7 @@ type Config struct {
PublicSSHPort uint16 `yaml:"ssh_port" default:"2222" validate:"port"`
// session secret holds the secret for login
- SessionSecret string `yaml:"session_secret" validate:"nonempty"`
+ SessionSecret string `yaml:"session_secret" validate:"nonempty" sensitive:"true"`
// interval to trigger distillery cron tasks in
CronInterval time.Duration `yaml:"cron_interval" default:"10m" validate:"duration"`
@@ -51,6 +50,34 @@ type Config struct {
ConfigPath string `yaml:"-"`
}
+func zeroSensitive(v reflect.Value) {
+ reflectx.IterateFields(v.Type(), func(field reflect.StructField, index int) (stop bool) {
+ // if we set the recurse tag, recurse into it
+ if _, ok := field.Tag.Lookup("recurse"); ok {
+ zeroSensitive(v.FieldByName(field.Name))
+ }
+
+ // if the field is sensitive, set the zero value!
+ if _, ok := field.Tag.Lookup("sensitive"); ok {
+ v.FieldByName(field.Name).Set(reflect.Zero(field.Type))
+ }
+ return false
+ })
+}
+
+func (config Config) MarshalSensitive() string {
+ // zero out all the sensitive fields
+ zeroSensitive(reflect.ValueOf(&config).Elem())
+
+ // marshal the result
+ result, err := Marshal(&config, nil)
+ if err != nil {
+ return ""
+ }
+
+ return string(result)
+}
+
//go:embed config.yml
var configBytes []byte
@@ -100,28 +127,3 @@ func (config *Config) CSRFSecret() []byte {
rand.Read(secret)
return secret
}
-
-// String serializes this configuration into a string
-func (config Config) String() string {
- builder := pools.GetBuilder()
- defer pools.ReleaseBuilder(builder)
-
- vConfig := reflect.ValueOf(config)
- tConfig := vConfig.Type()
-
- // iterate over the types
- numValues := tConfig.NumField()
- for i := 0; i < numValues; i++ {
- tField := tConfig.Field(i)
- vField := vConfig.FieldByName(tField.Name)
-
- env := tField.Tag.Get("env")
- if env == "" {
- continue
- }
-
- fmt.Fprintf(builder, "%s=%v\n", env, vField.Interface())
- }
-
- return builder.String()
-}
diff --git a/internal/config/database.go b/internal/config/database.go
index 6b4d9ba..6843162 100644
--- a/internal/config/database.go
+++ b/internal/config/database.go
@@ -4,7 +4,7 @@ type DatabaseConfig struct {
// Credentials for the admin user.
// Is automatically created if it does not exist.
AdminUsername string `yaml:"username" default:"admin" validate:"nonempty"`
- AdminPassword string `yaml:"password" validate:"nonempty"`
+ AdminPassword string `yaml:"password" validate:"nonempty" sensitive:"****"`
// Prefix for new users and data setss
UserPrefix string `yaml:"user_prefix" default:"wisski-distillery-" validate:"slug"`
diff --git a/internal/dis/component/server/admin/html/index.html b/internal/dis/component/server/admin/html/index.html
index e3cc4a4..68cd1e8 100644
--- a/internal/dis/component/server/admin/html/index.html
+++ b/internal/dis/component/server/admin/html/index.html
@@ -1,183 +1,3 @@
-
-
Distillery Configuration
-
-
-
-
-
-
-
- |
- Domains
- |
-
-
-
-
- |
- Primary
- |
-
- {{.Config.DefaultDomain}}
- |
-
-
- |
- Extra
- |
-
- {{ range .Config.SelfExtraDomains }}
- {{.}}
- {{ end }}
- |
-
-
- |
- Email (HTTPS)
- |
-
- {{.Config.CertbotEmail}}
- |
-
-
-
-
-
-
-
-
-
-
-
-
- |
- Database Settings
- |
-
-
-
-
- |
- MySQL User Prefix
- |
-
- {{.Config.MysqlUserPrefix}}
- |
-
-
- |
- MySQL Database Prefix
- |
-
- {{.Config.MysqlDatabasePrefix}}
- |
-
-
- |
- GraphDB User Prefix
- |
-
- {{.Config.GraphDBUserPrefix}}
- |
-
-
- |
- GraphDB Database Prefix
- |
-
- {{.Config.GraphDBRepoPrefix}}
- |
-
-
- |
- Bookkeeping Database
- |
-
- {{.Config.DistilleryDatabase}}
- |
-
-
-
-
-
-
-
-
-
-
-
-
- |
- Directory Settings
- |
-
-
-
-
-
-
- root
- |
-
- {{.Config.Paths.Root}}
- |
-
-
-
- config
- |
-
- {{.Config.ConfigPath}}
- |
-
-
-
-
-
-
-
-
-
-
-
-
- |
- Misc Settings
- |
-
-
-
-
-
- |
- Homepage
- |
-
- {{.Config.SelfRedirect}}
- |
-
-
- |
- Docker Network Name
- |
-
- {{.Config.Docker.Network}}
- |
-
-
- |
- Backup Age
- |
-
- {{.Config.MaxBackupAge}} Day(s)
- |
-
-
-
-
-
-
-
Backups
@@ -211,3 +31,13 @@
+
+
+
Distillery Configuration
+
+
+
+
+ {{ .Config.MarshalSensitive }}
+
+
\ No newline at end of file