1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/server/store/datastore/server_config.go
antomy-gc 6516a28cdd
Secrets encryption in database (#1475)
closes #101

Added secrets encryption in database

- Google TINK or simple AES as encryption mechanisms
- Keys rotation support on TINK
- Existing SecretService is wrapped by encryption layer
- Encryption can be enabled and disabled at any time

Co-authored-by: Kuzmin Ilya <ilia.kuzmin@indrive.com>
Co-authored-by: 6543 <6543@obermui.de>
2023-01-12 20:59:07 +01:00

47 lines
808 B
Go

package datastore
import "github.com/woodpecker-ci/woodpecker/server/model"
func (s storage) ServerConfigGet(key string) (string, error) {
config := &model.ServerConfig{
Key: key,
}
err := wrapGet(s.engine.Get(config))
if err != nil {
return "", err
}
return config.Value, nil
}
func (s storage) ServerConfigSet(key, value string) error {
config := &model.ServerConfig{
Key: key,
}
count, err := s.engine.Count(config)
if err != nil {
return err
}
config.Value = value
if count == 0 {
_, err := s.engine.Insert(config)
return err
}
_, err = s.engine.Where("key = ?", config.Key).AllCols().Update(config)
return err
}
func (s storage) ServerConfigDelete(key string) error {
config := &model.ServerConfig{
Key: key,
}
_, err := s.engine.Delete(config)
return err
}