Skip to content

Commit

Permalink
fix: ignore immutable objects (#143)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksander Zaruczewski <aleks@aiven.io>
  • Loading branch information
byashimov and Serpentiel authored Apr 29, 2024
1 parent 8407921 commit 64a3b87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
26 changes: 23 additions & 3 deletions internal/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ func UserConfigSchema(v aiven.UserConfigSchema) (*types.UserConfigSchema, error)
return nil, errUnexpected
}

var cv *types.UserConfigSchema

for k, v := range ap {
var cv *types.UserConfigSchema
if isImmutableObject(v) {
continue
}

cv, err = UserConfigSchema(v)
if err != nil {
Expand Down Expand Up @@ -77,9 +81,9 @@ func UserConfigSchema(v aiven.UserConfigSchema) (*types.UserConfigSchema, error)
return nil, errUnexpected
}

for i, v := range ao {
var cv *types.UserConfigSchema
var cv *types.UserConfigSchema

for i, v := range ao {
cv, err = UserConfigSchema(v)
if err != nil {
return nil, err
Expand Down Expand Up @@ -152,3 +156,19 @@ func normalizeTypes(t any) []string {

return typeList
}

// isImmutableObject Ignores immutable objects.
// Returns true if the object has no properties and does not allow additional properties.
// Ignores `patternProperties`.
func isImmutableObject(u aiven.UserConfigSchema) bool {
// An object with empty properties
t, ok := u.Type.(string)
if !(ok && t == "object" && len(u.Properties) == 0) {
return false
}

// Either no additional properties allowed or it is nil
allowed, ok := u.AdditionalProperties.(bool)

return ok != allowed || u.AdditionalProperties == nil
}
16 changes: 0 additions & 16 deletions pkg/dist/service_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5780,10 +5780,6 @@ thanos:
description: Retention time for data in days for each resolution (5m, 1h, raw)
type: integer
max_length: 20
env:
title: Environmental variables
type: object
default: {}
ip_filter:
title: IP filter
description: Allow incoming connections from CIDR address block, e.g. '10.20.0.0/16'
Expand Down Expand Up @@ -5883,14 +5879,6 @@ thanos:
description: Whether to align the query range boundaries with the step. If enabled, the query range boundaries will be aligned to the step, providing more accurate results for queries with high-resolution data.
type: boolean
default: true
receiver-ingesting:
title: CommonReceiveUserConfig
description: Generic model
type: object
receiver-routing:
title: ThanosReceiveRoutingUserConfig
description: Generic model
type: object
service_log:
title: Service logging
description: Store logs for the service so that they are available in the HTTP API and console.
Expand All @@ -5903,7 +5891,3 @@ thanos:
description: Use static public IP addresses
type: boolean
example: true
store:
title: ThanosStoreUserConfig
description: Generic model
type: object

0 comments on commit 64a3b87

Please sign in to comment.