SetConfig sets a configuration.
(ctx context.Context, userID string, cfg userconfig.Config)
| 162 | |
| 163 | // SetConfig sets a configuration. |
| 164 | func (d DB) SetConfig(ctx context.Context, userID string, cfg userconfig.Config) error { |
| 165 | if !cfg.RulesConfig.FormatVersion.IsValid() { |
| 166 | return fmt.Errorf("invalid rule format version %v", cfg.RulesConfig.FormatVersion) |
| 167 | } |
| 168 | cfgBytes, err := json.Marshal(cfg) |
| 169 | if err != nil { |
| 170 | return err |
| 171 | } |
| 172 | |
| 173 | _, err = d.Insert("configs"). |
| 174 | Columns("owner_id", "owner_type", "subsystem", "config"). |
| 175 | Values(userID, entityType, subsystem, cfgBytes). |
| 176 | Exec() |
| 177 | return err |
| 178 | } |
| 179 | |
| 180 | // GetAllConfigs gets all of the userconfig. |
| 181 | func (d DB) GetAllConfigs(ctx context.Context) (map[string]userconfig.View, error) { |