Skip to content

Commit

Permalink
Merge pull request #2045 from beyonnex-io/bugfix/wot-dynamic-config
Browse files Browse the repository at this point in the history
fix WoT tm validation "dynamic" config Helm template
  • Loading branch information
thjaeckle authored Oct 16, 2024
2 parents 57235f6 + 60ec3bd commit 4656457
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
2 changes: 1 addition & 1 deletion deployment/helm/ditto/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description: |
A digital twin is a virtual, cloud based, representation of his real world counterpart
(real world “Things”, e.g. devices like sensors, smart heating, connected cars, smart grids, EV charging stations etc).
type: application
version: 3.6.0 # chart version is effectively set by release-job
version: 3.6.1 # chart version is effectively set by release-job
appVersion: 3.6.0
keywords:
- iot-chart
Expand Down
40 changes: 27 additions & 13 deletions deployment/helm/ditto/templates/things-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,35 +163,49 @@ spec:
{{- end }}
'-Dditto.things.wot.to-thing-description.json-template={{ .Values.things.config.wot.tdJsonTemplate | replace "\n" "" | replace "\\\"" "\"" }}'
{{- range $dynConfIdx, $dynamicWotTmValidationConfig := .Values.things.config.wot.tmValidation.dynamicConfig }}
{{- if or (gt (len $dynamicWotTmValidationConfig.validationContext.dittoHeadersPatterns) 0) (gt (len $dynamicWotTmValidationConfig.validationContext.thingDefinitionPatterns) 0) (gt (len $dynamicWotTmValidationConfig.validationContext.featureDefinitionPatterns) 0) }}
{{- range $dhpIdx, $dittoHeadersPatterns := $dynamicWotTmValidationConfig.validationContext.dittoHeadersPatterns }}
{{- range $dhpKey, $dhpVal := $dittoHeadersPatterns }}
{{- if $dynamicWotTmValidationConfig.validationContext.dittoHeadersPatterns }}
{{- if gt (len $dynamicWotTmValidationConfig.validationContext.dittoHeadersPatterns) 0 }}
{{- range $dhpIdx, $dittoHeadersPatterns := $dynamicWotTmValidationConfig.validationContext.dittoHeadersPatterns }}
{{- range $dhpKey, $dhpVal := $dittoHeadersPatterns }}
"{{ printf "%s%d%s%d%s%s=%v" "-Dditto.things.wot.tm-model-validation.dynamic-configuration." $dynConfIdx ".validation-context.ditto-headers-patterns." $dhpIdx "." $dhpKey $dhpVal }}"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- range $tdpIdx, $thingDefinitionPattern := $dynamicWotTmValidationConfig.validationContext.thingDefinitionPatterns }}
{{- if $dynamicWotTmValidationConfig.validationContext.thingDefinitionPatterns }}
{{- if gt (len $dynamicWotTmValidationConfig.validationContext.thingDefinitionPatterns) 0 }}
{{- range $tdpIdx, $thingDefinitionPattern := $dynamicWotTmValidationConfig.validationContext.thingDefinitionPatterns }}
"{{ printf "%s%d%s%d=%v" "-Dditto.things.wot.tm-model-validation.dynamic-configuration." $dynConfIdx ".validation-context.thing-definition-patterns." $tdpIdx $thingDefinitionPattern }}"
{{- end }}
{{- end }}
{{- end }}
{{- range $fdpIdx, $featureDefinitionPattern := $dynamicWotTmValidationConfig.validationContext.featureDefinitionPatterns }}
{{- if $dynamicWotTmValidationConfig.validationContext.featureDefinitionPatterns }}
{{- if gt (len $dynamicWotTmValidationConfig.validationContext.featureDefinitionPatterns) 0 }}
{{- range $fdpIdx, $featureDefinitionPattern := $dynamicWotTmValidationConfig.validationContext.featureDefinitionPatterns }}
"{{ printf "%s%d%s%d=%v" "-Dditto.things.wot.tm-model-validation.dynamic-configuration." $dynConfIdx ".validation-context.feature-definition-patterns." $fdpIdx $featureDefinitionPattern }}"
{{- end }}
{{- end }}
{{- end }}
{{- range $configOverridesKey, $configOverridesValue := $dynamicWotTmValidationConfig.configOverrides }}
{{- if or (eq (kindOf $configOverridesValue) "map") (eq (kindOf $configOverridesValue) "slice") }}
{{- range $nested1ConfigOverridesKey, $nested1ConfigOverridesValue := $configOverridesValue }}
{{- if or (eq (kindOf $nested1ConfigOverridesValue) "map") (eq (kindOf $nested1ConfigOverridesValue) "slice") }}
{{- range $nested2ConfigOverridesKey, $nested2ConfigOverridesValue := $nested1ConfigOverridesValue }}
{{- range $nested1ConfigOverridesKey, $nested1ConfigOverridesValue := $configOverridesValue }}
{{- if or (eq (kindOf $nested1ConfigOverridesValue) "map") (eq (kindOf $nested1ConfigOverridesValue) "slice") }}
{{- range $nested2ConfigOverridesKey, $nested2ConfigOverridesValue := $nested1ConfigOverridesValue }}
{{- if not (kindIs "invalid" $nested2ConfigOverridesValue) }}
"{{ printf "%s%d%s%s%s%s%s%s=%v" "-Dditto.things.wot.tm-model-validation.dynamic-configuration." $dynConfIdx ".config-overrides." $configOverridesKey "." $nested1ConfigOverridesKey "." $nested2ConfigOverridesKey $nested2ConfigOverridesValue }}"
{{- end }}
{{- else }}
{{- end }}
{{- end }}
{{- else }}
{{- if not (kindIs "invalid" $nested1ConfigOverridesValue) }}
"{{ printf "%s%d%s%s%s%s=%v" "-Dditto.things.wot.tm-model-validation.dynamic-configuration." $dynConfIdx ".config-overrides." $configOverridesKey "." $nested1ConfigOverridesKey $nested1ConfigOverridesValue }}"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- else }}
"{{ printf "%s%d%s%s=%v" "-Dditto.things.wot.tm-model-validation.dynamic-configuration." $dynConfIdx ".config-overrides." $configOverridesKey $configOverridesValue }}"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{ join " " .Values.things.systemProps }}
- name: MONGO_DB_SSL_ENABLED
value: "{{ printf "%t" .Values.dbconfig.things.ssl }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,33 @@ final class InternalDynamicTmValidationConfiguration {

InternalDynamicTmValidationConfiguration(final Config config) {
final Config validationContext = config.getConfig(CONFIG_KEY_VALIDATION_CONTEXT);
final List<Map<String, Pattern>> parsedDittoHeadersPatterns = validationContext
.getConfigList(CONFIG_KEY_DITTO_HEADERS_PATTERNS)
.stream()
.map(c -> c.entrySet()
.stream()
.map(e -> new AbstractMap.SimpleEntry<>(
e.getKey(),
Pattern.compile(e.getValue().unwrapped().toString())

final List<Map<String, Pattern>> parsedDittoHeadersPatterns =
validationContext.hasPath(CONFIG_KEY_DITTO_HEADERS_PATTERNS) ?
validationContext.getConfigList(CONFIG_KEY_DITTO_HEADERS_PATTERNS)
.stream()
.map(c -> c.entrySet()
.stream()
.map(e -> new AbstractMap.SimpleEntry<>(
e.getKey(),
Pattern.compile(e.getValue().unwrapped().toString())
)
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
)
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
)
.toList();
final List<Pattern> thingDefinitionPatterns = validationContext
.getStringList(CONFIG_KEY_THING_DEFINITION_PATTERNS)
.stream()
.map(Pattern::compile)
.toList();
final List<Pattern> featureDefinitionPatterns = validationContext
.getStringList(CONFIG_KEY_FEATURE_DEFINITION_PATTERNS)
.stream()
.map(Pattern::compile)
.toList();
.toList() : List.of();
final List<Pattern> thingDefinitionPatterns =
validationContext.hasPath(CONFIG_KEY_THING_DEFINITION_PATTERNS) ?
validationContext.getStringList(CONFIG_KEY_THING_DEFINITION_PATTERNS)
.stream()
.map(Pattern::compile)
.toList() : List.of();
final List<Pattern> featureDefinitionPatterns =
validationContext.hasPath(CONFIG_KEY_FEATURE_DEFINITION_PATTERNS) ?
validationContext.getStringList(CONFIG_KEY_FEATURE_DEFINITION_PATTERNS)
.stream()
.map(Pattern::compile)
.toList() : List.of();

dynamicValidationContextConfiguration = new DynamicValidationContextConfiguration(
parsedDittoHeadersPatterns,
Expand Down Expand Up @@ -102,7 +106,8 @@ Optional<Config> calculateDynamicTmValidationConfigOverrides(
// OR
.anyMatch(pattern -> pattern.matcher(validationContext.featureDefinition().toString())
.matches());
if (!dynamicValidationContextConfiguration.featureDefinitionPatterns().isEmpty() && !featureDefinitionMatches) {
if (!dynamicValidationContextConfiguration.featureDefinitionPatterns().isEmpty() &&
!featureDefinitionMatches) {
return Optional.empty();
}

Expand Down

0 comments on commit 4656457

Please sign in to comment.