getOverridesFromBucket reads overrides for a specific tenant from the runtime config file
(ctx context.Context, userID string)
| 144 | |
| 145 | // getOverridesFromBucket reads overrides for a specific tenant from the runtime config file |
| 146 | func (a *API) getOverridesFromBucket(ctx context.Context, userID string) (map[string]any, error) { |
| 147 | reader, err := a.bucketClient.Get(ctx, a.runtimeConfigPath) |
| 148 | defer func() { |
| 149 | if reader != nil { |
| 150 | reader.Close() |
| 151 | } |
| 152 | }() |
| 153 | if err != nil { |
| 154 | return nil, fmt.Errorf("failed to get runtime config: %w", err) |
| 155 | } |
| 156 | |
| 157 | var config runtimeconfig.RuntimeConfigValues |
| 158 | if err := yaml.NewDecoder(reader).Decode(&config); err != nil { |
| 159 | return nil, fmt.Errorf("%s: %w", ErrRuntimeConfig, err) |
| 160 | } |
| 161 | |
| 162 | if config.TenantLimits != nil { |
| 163 | if tenantLimits, exists := config.TenantLimits[userID]; exists { |
| 164 | // Use YAML marshaling to convert validation.Limits to map[string]interface{} |
| 165 | // This follows the same pattern as the existing runtime config handler |
| 166 | yamlData, err := yaml.Marshal(tenantLimits) |
| 167 | if err != nil { |
| 168 | return nil, fmt.Errorf("failed to marshal limits: %w", err) |
| 169 | } |
| 170 | |
| 171 | var result map[string]any |
| 172 | if err := yaml.Unmarshal(yamlData, &result); err != nil { |
| 173 | return nil, fmt.Errorf("failed to unmarshal limits: %w", err) |
| 174 | } |
| 175 | |
| 176 | return result, nil |
| 177 | } |
| 178 | // User does not exist in config - return error |
| 179 | return nil, errors.New(ErrUserNotFound) |
| 180 | } |
| 181 | |
| 182 | // No tenant limits configured - return empty map (no overrides) |
| 183 | return map[string]any{}, nil |
| 184 | } |
| 185 | |
| 186 | // mergeLimits merges new overrides into existing limits |
| 187 | func mergeLimits(existing map[string]any, overrides map[string]any) map[string]any { |