From 64a3b8783c45cc91c6bcce4d9fa333e47f986ddb Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Mon, 29 Apr 2024 15:08:33 +0200 Subject: [PATCH] fix: ignore immutable objects (#143) Co-authored-by: Aleksander Zaruczewski --- internal/convert/convert.go | 26 +++++++++++++++++++++++--- pkg/dist/service_types.yml | 16 ---------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/internal/convert/convert.go b/internal/convert/convert.go index 7ec6977..180c361 100644 --- a/internal/convert/convert.go +++ b/internal/convert/convert.go @@ -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 { @@ -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 @@ -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 +} diff --git a/pkg/dist/service_types.yml b/pkg/dist/service_types.yml index e379f49..7be74b5 100644 --- a/pkg/dist/service_types.yml +++ b/pkg/dist/service_types.yml @@ -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' @@ -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. @@ -5903,7 +5891,3 @@ thanos: description: Use static public IP addresses type: boolean example: true - store: - title: ThanosStoreUserConfig - description: Generic model - type: object