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

Add proto validation for ProfileService #4905

Merged
merged 5 commits into from
Nov 8, 2024
Merged

Add proto validation for ProfileService #4905

merged 5 commits into from
Nov 8, 2024

Conversation

rdimitrov
Copy link
Member

Summary

Ref https://github.com/stacklok/minder-stories/issues/94

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@rdimitrov rdimitrov requested a review from a team as a code owner November 7, 2024 15:08
@rdimitrov rdimitrov self-assigned this Nov 7, 2024
@coveralls
Copy link

coveralls commented Nov 7, 2024

Coverage Status

coverage: 54.754% (-0.004%) from 54.758%
when pulling 7dd13bb on validate-profiles
into 8b01055 on main.

@rdimitrov rdimitrov force-pushed the validate-profiles branch 2 times, most recently from 7c4398d to bddddb6 Compare November 7, 2024 23:05
string version = 11;
string version = 11 [
(buf.validate.field).string = {
pattern: "^v\\d+(\\.\\d+)?(\\.\\d+)?(?:-[\\w\\.-]+)?$",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this for the profiles given we might add some notion of versioning in the hopefully not so distant future?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want only ^v\d$ (or empty) for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 👍

string label_filter = 2;
string label_filter = 2 [
(buf.validate.field).string = {
pattern: "^(\\*|[a-zA-Z][a-zA-Z0-9_]*)$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was unable to find a usage of this server-side (though maybe that comment was on another PR?), so I'm not sure if it's in use at the moment. I'd enforce lower-case on this for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed it 👍

Comment on lines +2285 to +2286
pattern: "^([a-zA-Z0-9]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9])?:)?[a-zA-Z0-9]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9])?$"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you want to keep or remove the preceeding comment. Maybe keep until we can generate these in the OpenAPI doc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it for now 👍

@@ -2290,33 +2332,78 @@ message Profile {
// id is optional and use for updates to match upserts as well as read operations. It is ignored for creates.
string id = 1;
// entity is the entity to select.
string entity = 2;
string entity = 2 [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have called this entity_type, huh?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's one of the few examples I was talking about yesterday 😃

string selector = 4;
string selector = 4 [
(buf.validate.field).string = {
pattern: "^[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*(?:\\[\\d+\\])?$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. This is a CEL expression, correct?

It feels like this might be a special case where we say "this will be parsed as a CEL expression", because I'm nervous about encoding the allowed CEL characters in a regex. (In particular, I suspect they allow for greater-than and less-than expressions...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍 So we can leave it without validation for now I suppose?

string description = 6;
string description = 6 [
(buf.validate.field).string = {
pattern: "[A-Za-z][-/.!?,:;[:word:] ]*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not [[:punct:][:word:] ]*? Are there specific characters we're trying to exclude from the punctuation set?

(Also, why a leading letter?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, punct seems to include < > which we don't want right?
As for the leading letter, I thought it feels better to establish some form of common formatting for when this value is visualised.

optional string remediate = 8;
optional string remediate = 8 [
(buf.validate.field).string = {
pattern: "^(on|off|dry_run)$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use in here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 👍

string version = 11;
string version = 11 [
(buf.validate.field).string = {
pattern: "^v\\d+(\\.\\d+)?(\\.\\d+)?(?:-[\\w\\.-]+)?$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want only ^v\d$ (or empty) for now.

@rdimitrov rdimitrov force-pushed the validate-profiles branch 2 times, most recently from 42e238f to 0f98428 Compare November 8, 2024 14:13
@@ -1847,7 +1865,7 @@ message ListEvaluationResultsRequest {
(buf.validate.field).repeated = {
items: {
string: {
pattern: "[-[:word:]]*",
pattern: "^[-[:word:]]*$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this include "/"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, actually this should be ^[A-Za-z][-/[:word:]]*$, you're right 👍

Comment on lines +2391 to +2393
(buf.validate.field).string = {
pattern: "^v\\d$",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never empty, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I checked all of the profiles I could find and it's set everywhere 👍

@@ -2915,7 +2999,7 @@ message ListEvaluationHistoryRequest {
(buf.validate.field).repeated = {
items: {
string: {
pattern: "[,[:word:]]*",
pattern: "^[,[:word:]]*$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we allow "," in a repeated field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of -

// of values. Such elements are either "complex", i.e. they represent
// a comma-separated list of sub-elements, or "simple", they do not
// contain comma characters. If element contains one or more comma
// characters, it is further split into sub-elements before calling
// `f` in them.

@@ -2927,7 +3011,7 @@ message ListEvaluationHistoryRequest {
(buf.validate.field).repeated = {
items: {
string: {
pattern: "[,-./[:word:]]*",
pattern: "^[,-./[:word:]]*$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, why allow , here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of -

// of values. Such elements are either "complex", i.e. they represent
// a comma-separated list of sub-elements, or "simple", they do not
// contain comma characters. If element contains one or more comma
// characters, it is further split into sub-elements before calling
// `f` in them.

@@ -2951,7 +3035,7 @@ message ListEvaluationHistoryRequest {
(buf.validate.field).repeated = {
items: {
string: {
pattern: "[,[:word:]]*",
pattern: "^[,[:word:]]*$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, , seems like an error converting to a repeated field

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of -

// of values. Such elements are either "complex", i.e. they represent
// a comma-separated list of sub-elements, or "simple", they do not
// contain comma characters. If element contains one or more comma
// characters, it is further split into sub-elements before calling
// `f` in them.

@@ -2963,7 +3047,7 @@ message ListEvaluationHistoryRequest {
(buf.validate.field).repeated = {
items: {
string: {
pattern: "[,[:word:]]*",
pattern: "^[,[:word:]]*$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of -

// of values. Such elements are either "complex", i.e. they represent
// a comma-separated list of sub-elements, or "simple", they do not
// contain comma characters. If element contains one or more comma
// characters, it is further split into sub-elements before calling
// `f` in them.

@@ -2975,7 +3059,7 @@ message ListEvaluationHistoryRequest {
(buf.validate.field).repeated = {
items: {
string: {
pattern: "[,[:word:]]*",
pattern: "^[,[:word:]]*$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(last one)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of -

// of values. Such elements are either "complex", i.e. they represent
// a comma-separated list of sub-elements, or "simple", they do not
// contain comma characters. If element contains one or more comma
// characters, it is further split into sub-elements before calling
// `f` in them.

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
@rdimitrov rdimitrov merged commit 4aa7e72 into main Nov 8, 2024
25 checks passed
@rdimitrov rdimitrov deleted the validate-profiles branch November 8, 2024 15:26
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

Successfully merging this pull request may close these issues.

3 participants