deleteOverridesFromBucket removes overrides for a specific tenant from the runtime config file
(ctx context.Context, userID string)
| 260 | |
| 261 | // deleteOverridesFromBucket removes overrides for a specific tenant from the runtime config file |
| 262 | func (a *API) deleteOverridesFromBucket(ctx context.Context, userID string) error { |
| 263 | reader, err := a.bucketClient.Get(ctx, a.runtimeConfigPath) |
| 264 | defer func() { |
| 265 | if reader != nil { |
| 266 | reader.Close() |
| 267 | } |
| 268 | }() |
| 269 | if err != nil { |
| 270 | return fmt.Errorf("failed to get runtime config: %w", err) |
| 271 | } |
| 272 | |
| 273 | var config runtimeconfig.RuntimeConfigValues |
| 274 | if err := yaml.NewDecoder(reader).Decode(&config); err != nil { |
| 275 | return fmt.Errorf("%s: %w", ErrRuntimeConfig, err) |
| 276 | } |
| 277 | |
| 278 | if config.TenantLimits != nil { |
| 279 | delete(config.TenantLimits, userID) |
| 280 | } |
| 281 | |
| 282 | data, err := yaml.Marshal(config) |
| 283 | if err != nil { |
| 284 | return fmt.Errorf("%s: %w", ErrRuntimeConfig, err) |
| 285 | } |
| 286 | |
| 287 | return a.bucketClient.Upload(ctx, a.runtimeConfigPath, bytes.NewReader(data)) |
| 288 | } |