Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2022 provide the option to log a warning instead of failing modifying API calls in WoT based validation #2025

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5.12 # chart version is effectively set by release-job
version: 3.5.13 # chart version is effectively set by release-job
appVersion: 3.5.12
keywords:
- iot-chart
Expand Down
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
Loading