Compare commits

...

3 commits

Author SHA1 Message Date
c1611114d0
Add encryption key to storage config
Some checks are pending
/ test (push) Waiting to run
2025-03-31 17:11:02 +02:00
4c8ebaeab8
Add name field to user auth entries 2025-03-31 16:42:57 +02:00
1e59c661c7
Update code style policy for Go code 2025-03-31 16:42:32 +02:00
4 changed files with 13 additions and 2 deletions

View file

@ -13,6 +13,8 @@
use `hlog.FromRequest` to get a logger instance prepared with a bunch of metadata use `hlog.FromRequest` to get a logger instance prepared with a bunch of metadata
- As Linstrom is both intended for active use as well as providing a learning resource, - As Linstrom is both intended for active use as well as providing a learning resource,
all functions and structs must be documented all functions and structs must be documented
- Errors returned from public functions must be wrapped with `git.mstar.dev/mstar/goutils/other.Error`
and given appropriate descriptive information
## JS/TS ## JS/TS

View file

@ -4,9 +4,9 @@ import (
"fmt" "fmt"
"os" "os"
"git.mstar.dev/mstar/goutils/other"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"git.mstar.dev/mstar/goutils/other"
) )
type ConfigSSL struct { type ConfigSSL struct {
@ -68,6 +68,9 @@ type ConfigStorage struct {
MaxInMemoryCacheTTL int `toml:"max_in_memory_cache_ttl"` MaxInMemoryCacheTTL int `toml:"max_in_memory_cache_ttl"`
// The time to live for items in redis, in seconds // The time to live for items in redis, in seconds
MaxRedisCacheTTL *int `toml:"max_redis_cache_ttl"` MaxRedisCacheTTL *int `toml:"max_redis_cache_ttl"`
// Key used for encrypting sensitive information in the db
// DO NOT CHANGE THIS AFTER SETUP
EncryptionKey string `toml:"encryption_key"`
} }
type ConfigS3 struct { type ConfigS3 struct {
@ -145,6 +148,7 @@ var defaultConfig Config = Config{
MaxInMemoryCacheSize: 1e6, // 1 Megabyte MaxInMemoryCacheSize: 1e6, // 1 Megabyte
MaxInMemoryCacheTTL: 5, MaxInMemoryCacheTTL: 5,
MaxRedisCacheTTL: nil, MaxRedisCacheTTL: nil,
EncryptionKey: "Encryption key for sensitive information. DO NOT CHANGE THIS AFTER SETUP",
}, },
Mail: ConfigMail{ Mail: ConfigMail{
Host: "localhost", Host: "localhost",

View file

@ -30,6 +30,7 @@ func newUserAuthMethod(db *gorm.DB, opts ...gen.DOOption) userAuthMethod {
_userAuthMethod.UserId = field.NewString(tableName, "user_id") _userAuthMethod.UserId = field.NewString(tableName, "user_id")
_userAuthMethod.AuthMethod = field.NewField(tableName, "auth_method") _userAuthMethod.AuthMethod = field.NewField(tableName, "auth_method")
_userAuthMethod.Token = field.NewBytes(tableName, "token") _userAuthMethod.Token = field.NewBytes(tableName, "token")
_userAuthMethod.Name = field.NewString(tableName, "name")
_userAuthMethod.User = userAuthMethodBelongsToUser{ _userAuthMethod.User = userAuthMethodBelongsToUser{
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
@ -184,6 +185,7 @@ type userAuthMethod struct {
UserId field.String UserId field.String
AuthMethod field.Field AuthMethod field.Field
Token field.Bytes Token field.Bytes
Name field.String
User userAuthMethodBelongsToUser User userAuthMethodBelongsToUser
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
@ -205,6 +207,7 @@ func (u *userAuthMethod) updateTableName(table string) *userAuthMethod {
u.UserId = field.NewString(table, "user_id") u.UserId = field.NewString(table, "user_id")
u.AuthMethod = field.NewField(table, "auth_method") u.AuthMethod = field.NewField(table, "auth_method")
u.Token = field.NewBytes(table, "token") u.Token = field.NewBytes(table, "token")
u.Name = field.NewString(table, "name")
u.fillFieldMap() u.fillFieldMap()
@ -221,11 +224,12 @@ func (u *userAuthMethod) GetFieldByName(fieldName string) (field.OrderExpr, bool
} }
func (u *userAuthMethod) fillFieldMap() { func (u *userAuthMethod) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 5) u.fieldMap = make(map[string]field.Expr, 6)
u.fieldMap["id"] = u.ID u.fieldMap["id"] = u.ID
u.fieldMap["user_id"] = u.UserId u.fieldMap["user_id"] = u.UserId
u.fieldMap["auth_method"] = u.AuthMethod u.fieldMap["auth_method"] = u.AuthMethod
u.fieldMap["token"] = u.Token u.fieldMap["token"] = u.Token
u.fieldMap["name"] = u.Name
} }

View file

@ -13,4 +13,5 @@ type UserAuthMethod struct {
UserId string UserId string
AuthMethod AuthenticationMethodType `gorm:"type:auth_method_type"` AuthMethod AuthenticationMethodType `gorm:"type:auth_method_type"`
Token []byte Token []byte
Name string
} }