Skip to content

Commit

Permalink
#2022 provide the option to log a warning instead of failing modifyin…
Browse files Browse the repository at this point in the history
…g API calls in WoT based validation
  • Loading branch information
thjaeckle committed Sep 20, 2024
1 parent fc610da commit 2d9f6d9
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 20 deletions.
2 changes: 2 additions & 0 deletions deployment/helm/ditto/templates/things-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ spec:
value: "{{ .Values.things.config.wot.tdBasePrefix }}"
- name: THINGS_WOT_TM_MODEL_VALIDATION_ENABLED
value: "{{ .Values.things.config.wot.tmValidation.enabled }}"
- name: THINGS_WOT_TM_MODEL_VALIDATION_LOG_WARNING_INSTEAD_OF_FAILING_API_CALLS
value: "{{ .Values.things.config.wot.tmValidation.enabled }}"
- name: THINGS_WOT_TM_MODEL_VALIDATION_THING_ENFORCE_TD_MODIFICATION
value: "{{ index .Values.things.config.wot.tmValidation.thing.enforce "thing-description-modification" }}"
- name: THINGS_WOT_TM_MODEL_VALIDATION_THING_ENFORCE_ATTRIBUTES
Expand Down
3 changes: 3 additions & 0 deletions deployment/helm/ditto/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,8 @@ things:
tmValidation:
# enabled whether the ThingModel validation of Things/Features should be enabled
enabled: true
# log-warning-instead-of-failing-api-calls whether to instead of to reject/fail API calls (when enabled=true), log a WARNING log instead
log-warning-instead-of-failing-api-calls: false
# thing provides configuration settings for WoT based validation of Things
thing:
# enforce holds all configuration relating to enforcing the model
Expand Down Expand Up @@ -1116,6 +1118,7 @@ things:
# configOverrides:
# # exactly the same config keys and structure applies as in the static config
# enabled: true
# log-warning-instead-of-failing-api-calls: true
# thing:
# enforce:
# thing-description-modification: false
Expand Down
5 changes: 5 additions & 0 deletions things/service/src/main/resources/things.conf
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ ditto {
enabled = true
enabled = ${?THINGS_WOT_TM_MODEL_VALIDATION_ENABLED}

# whether to instead of to reject/fail API calls (when enabled=true), log a WARNING log instead
log-warning-instead-of-failing-api-calls = false
log-warning-instead-of-failing-api-calls = ${?THINGS_WOT_TM_MODEL_VALIDATION_LOG_WARNING_INSTEAD_OF_FAILING_API_CALLS}

thing {
enforce {
# whether to enforce a thing whenever the "definition" of the thing is updated to a new/other WoT TM
Expand Down Expand Up @@ -382,6 +386,7 @@ ditto {
// // if the validation-context "matches" a processed API call, apply the following overrides:
// config-overrides {
// enabled = true
// log-warning-instead-of-failing-api-calls = true
// thing {
// enforce.attributes = false
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ final class DefaultTmValidationConfig implements TmValidationConfig {
private final List<InternalDynamicTmValidationConfiguration> dynamicTmValidationConfigurations;

private final boolean enabled;
private final boolean logWarningInsteadOfFailingApiCalls;
private final ThingValidationConfig thingValidationConfig;
private final FeatureValidationConfig featureValidationConfig;

Expand All @@ -59,6 +60,7 @@ private DefaultTmValidationConfig(final ScopedConfig scopedConfig,
.reduce(ConfigFactory.empty(), (a, b) -> b.withFallback(a))
.withFallback(scopedConfig.resolve());
enabled = effectiveConfig.getBoolean(ConfigValue.ENABLED.getConfigPath());
logWarningInsteadOfFailingApiCalls = effectiveConfig.getBoolean(ConfigValue.LOG_WARNING_INSTEAD_OF_FAILING_API_CALLS.getConfigPath());

thingValidationConfig = DefaultThingValidationConfig.of(effectiveConfig);
featureValidationConfig = DefaultFeatureValidationConfig.of(effectiveConfig);
Expand Down Expand Up @@ -87,6 +89,11 @@ public boolean isEnabled() {
return enabled;
}

@Override
public boolean logWarningInsteadOfFailingApiCalls() {
return logWarningInsteadOfFailingApiCalls;
}

@Override
public ThingValidationConfig getThingValidationConfig() {
return thingValidationConfig;
Expand Down Expand Up @@ -117,22 +124,24 @@ public boolean equals(final Object o) {
final DefaultTmValidationConfig that = (DefaultTmValidationConfig) o;
return Objects.equals(dynamicTmValidationConfigurations, that.dynamicTmValidationConfigurations) &&
enabled == that.enabled &&
logWarningInsteadOfFailingApiCalls == that.logWarningInsteadOfFailingApiCalls &&
Objects.equals(thingValidationConfig, that.thingValidationConfig) &&
Objects.equals(featureValidationConfig, that.featureValidationConfig) &&
Objects.equals(scopedConfig, that.scopedConfig);
}

@Override
public int hashCode() {
return Objects.hash(dynamicTmValidationConfigurations, enabled, thingValidationConfig, featureValidationConfig,
scopedConfig);
return Objects.hash(dynamicTmValidationConfigurations, enabled, logWarningInsteadOfFailingApiCalls,
thingValidationConfig, featureValidationConfig, scopedConfig);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"dynamicTmValidationConfiguration=" + dynamicTmValidationConfigurations +
", enabled=" + enabled +
", logWarningInsteadOfFailingApiCalls=" + logWarningInsteadOfFailingApiCalls +
", thingValidationConfig=" + thingValidationConfig +
", featureValidationConfig=" + featureValidationConfig +
", scopedConfig=" + scopedConfig +
Expand Down
Loading

0 comments on commit 2d9f6d9

Please sign in to comment.