2022-06-01 18:06:27 +00:00
|
|
|
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{
|
2023-01-12 19:59:07 +00:00
|
|
|
Key: key,
|
2022-06-01 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
count, err := s.engine.Count(config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-01-12 19:59:07 +00:00
|
|
|
config.Value = value
|
|
|
|
|
2022-06-01 18:06:27 +00:00
|
|
|
if count == 0 {
|
|
|
|
_, err := s.engine.Insert(config)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = s.engine.Where("key = ?", config.Key).AllCols().Update(config)
|
|
|
|
return err
|
|
|
|
}
|
2023-01-12 19:59:07 +00:00
|
|
|
|
|
|
|
func (s storage) ServerConfigDelete(key string) error {
|
|
|
|
config := &model.ServerConfig{
|
|
|
|
Key: key,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := s.engine.Delete(config)
|
|
|
|
return err
|
|
|
|
}
|