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

Enhancement: generalise the validation in wrapper library #598

Open
agni-lanka opened this issue Oct 10, 2023 · 4 comments
Open

Enhancement: generalise the validation in wrapper library #598

agni-lanka opened this issue Oct 10, 2023 · 4 comments

Comments

@agni-lanka
Copy link

Adding a validation wrapper Library separated from manifests. By adding this in our library we are avoiding each validation to be added by each consumer.

cloudevents/spec#2 aspects:

  1. validation - IN-SCOPE
  2. governance - OUT-OF-SCOPE

sdk-java issue reference#: #592
slack Thread : https://cloud-native.slack.com/archives/C9DB5ABAA/p1696404658583879?thread_ts=1695874684.630259&cid=C9DB5ABAA

@agni-lanka
Copy link
Author

Summary / Theme / High level :
...Validation Manifest:
A JSON file (ValidationManifest.json) is the in-situ placeholder to define validation rules for CloudEvent properties.
1/allowed values; 2/range of values; 3/regex etc.

...Core CloudEvents Library:
A ValidationService class that takes the validation manifest and performs property validation based on the rules defined within.

...Wrapper Library:
Offers a CustomCloudEventValidator class that implements the CloudEventValidator interface.
This class uses the ValidationService from the core library to perform customizable property validation.

...Application Code:
Consumers of the CloudEvent w/ or w/o validation, can instantiate and use the CustomCloudEventValidator from the wrapper library to validate CloudEvent properties based on the rules defined in the validation manifest.


new:
ValidationRule.java
ValidationService.java
CloudEventValidator.java
CloudEventsTest.java
configuration\ValidationManifest.json


Consumption:
package io.cloudevents;
import io.cloudevents.CloudEvent;
import io.cloudevents.CustomCloudEventValidator;
import java.io.IOException;
public class CloudEventsTest {
public static void main(String[] args) throws IOException {
String manifestFilePath = "configuration\ValidationManifest.json";
CustomCloudEventValidator customValidator = new CustomCloudEventValidator(manifestFilePath);
// magic here
// Set CloudEvent properties
CloudEvent event = new CloudEvent();
event.setProperty1("balalah Value");
customValidator.validate(event);
}
}

@duglin
Copy link
Contributor

duglin commented Oct 10, 2023

@agni-lanka is this a "spec" (or CE-wide) issue or a java specific issue?

@duglin duglin transferred this issue from cloudevents/spec Oct 12, 2023
@agni-lanka
Copy link
Author

agni-lanka commented Oct 16, 2023

@duglin - subjectively for sdk-java.

however, needs a cloudevent "spec" level for schematic/rule for extensible validations

@duglin
Copy link
Contributor

duglin commented Oct 16, 2023

@agni-lanka can you elaborate, perhaps with a small example, of what kind of spec changes (or new spec) you'd be looking for? I find it's easier for people to understand concepts when there are concrete examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants