-
Notifications
You must be signed in to change notification settings - Fork 153
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
Validate event context key #5339
Conversation
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
The patternOK (tried
Invalid key format (tried
Key is nothing
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5339 +/- ##
==========================================
- Coverage 25.31% 25.30% -0.02%
==========================================
Files 444 444
Lines 47592 47601 +9
==========================================
- Hits 12050 12044 -6
- Misses 34600 34615 +15
Partials 942 942 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented on regexp and nits.
IMHO, the error message like below is a bit confusing.
The validation error occurs at the key of the map, but the message says "value."
2024/11/14 16:46:29 failed to register event: rpc error: code = InvalidArgument desc = invalid request: invalid RegisterEventRequest.Contexts[]: value length must be at least 1 rune
pkg/model/event.go
Outdated
var ( | ||
hashFunc = sha256.New | ||
|
||
eventKeyFormatRegex = regexp.MustCompile(`^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nits] This variable seems unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 🙏 341ce20
@@ -229,7 +229,7 @@ message RegisterEventRequest { | |||
string name = 1 [(validate.rules).string.min_len = 1]; | |||
string data = 2 [(validate.rules).string.min_len = 1]; | |||
map<string,string> labels = 3 [(validate.rules).map.keys.string.min_len = 1, (validate.rules).map.values.string.min_len = 1]; | |||
map<string,string> contexts = 4; | |||
map<string,string> contexts = 4 [(validate.rules).map.keys.string.min_len = 1, (validate.rules).map.keys.string.pattern = "^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$", (validate.rules).map.values.string.min_len = 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regexp might be wrong.
The git implementations seem to allow double or more hyphens continuously like test--hoge
or start with a hyphen like -test
.
The pattern might be like ^[\-a-zA-Z0-9]+$
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Warashi
Yes, I know that.
I don't plan to do the same as validation for git.
It is because the trailer format is not so concrete.
So I wanted to express the format like a kebab case test-hoge
in PipeCD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I got your point.
Signed-off-by: Yoshiki Fujikane <[email protected]>
I see. Thank you for finding it. This is based on the code generated by |
How about implementing validations in pipectl code with go's regexp? |
@Warashi
I got it. Sounds nice! 📝 It seems that these errors occurred when using pipectl.
|
Signed-off-by: Yoshiki Fujikane <[email protected]>
like this
It also works OK pattern.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -79,3 +86,13 @@ func (r *register) run(ctx context.Context, input cli.Input) error { | |||
) | |||
return nil | |||
} | |||
|
|||
func (r *register) validateEventContexts() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function looks testable, please add tests for this later (another PR is ok, since this one is for rc release)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @ffjlabo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
Signed-off-by: pipecd-bot <[email protected]>
* Sort trailers to ensure the order (#5334) * Sort trailers to ensure the order Signed-off-by: Yoshiki Fujikane <[email protected]> * Fixed to work on go1.22 Signed-off-by: Yoshiki Fujikane <[email protected]> --------- Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Validate event context key (#5339) Signed-off-by: pipecd-bot <[email protected]> --------- Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> Co-authored-by: Yoshiki Fujikane <[email protected]>
What this PR does:
Added validation for event context key.
The event context is used as
--trailer
. The trailer key is currently allowed to use-
alphabet, number, ' ', '\t' but it is unclear the actual format.ref: https://github.com/git/git/blob/25b0f41288718625b18495de23cc066394c09a92/trailer.c#L630-L646
Also tried some formats below.
So I added the restriction for the event context key format like kebab case such as
Test-hoge
test-hoge
for now.Why we need it:
Which issue(s) this PR fixes:
Part of #5028
Does this PR introduce a user-facing change?: