mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
3136ffad1b
> ### Description Update `go.mod` to allow other packages to import [v2.0.0 versions](https://blog.golang.org/v2-go-modules). ### Changelog - [x] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label. ### Affected components - [x] CLI https://github.com/hasura/graphql-engine-mono/pull/1584 GitOrigin-RevId: a5d17ad20289d1cd7217763f56ef3ba6552d69c4
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package settings
|
|
|
|
import (
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/statestore"
|
|
)
|
|
|
|
type StateStoreCatalog struct {
|
|
client *statestore.CLICatalogState
|
|
}
|
|
|
|
func NewStateStoreCatalog(c *statestore.CLICatalogState) *StateStoreCatalog {
|
|
return &StateStoreCatalog{c}
|
|
}
|
|
|
|
func (s StateStoreCatalog) GetSetting(key string) (value string, err error) {
|
|
// get setting
|
|
state, err := s.client.Get()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return state.GetSetting(key), nil
|
|
}
|
|
|
|
func (s StateStoreCatalog) UpdateSetting(name string, value string) error {
|
|
// get setting
|
|
state, err := s.client.Get()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
state.SetSetting(name, value)
|
|
_, err = s.client.Set(*state)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s StateStoreCatalog) GetAllSettings() (map[string]string, error) {
|
|
// get setting
|
|
state, err := s.client.Get()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return state.GetSettings(), nil
|
|
}
|
|
|
|
func (s StateStoreCatalog) PrepareSettingsDriver() error {
|
|
return s.setDefaults()
|
|
}
|
|
|
|
func (s StateStoreCatalog) setDefaults() error {
|
|
// get setting
|
|
state, err := s.client.Get()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, setting := range Settings {
|
|
if v := state.GetSetting(setting.GetName()); len(v) == 0 {
|
|
state.SetSetting(setting.GetName(), setting.GetDefaultValue())
|
|
}
|
|
}
|
|
_, err = s.client.Set(*state)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|