Closed ffjlabo closed 1 day ago
OK (tried test-hoge
)
% ./pipectl_v0.49.3_darwin_arm64 event register --address=localhost:8080 --api-key=xxx --name=simple --data="gcr.io/pipecd/helloworld:v0.40.0" --contexts="test-hoge=fuga" --insecure=true
Successfully registered event {"id": "cc64b59d-82d1-4d3d-a669-b6051e9fe33b"}
Invalid key format (tried test.hoge
)
% ./pipectl_v0.49.3_darwin_arm64 event register --address=localhost:8080 --api-key=xxx --name=simple --data="gcr.io/pipecd/helloworld:v0.40.0" --contexts="test.hoge=fuga" --insecure=true
2024/11/14 16:56:22 failed to register event: rpc error: code = InvalidArgument desc = invalid request: invalid RegisterEventRequest.Contexts[test.hoge]: value does not match regex pattern "^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$"
Key is nothing
% ./pipectl_v0.49.3_darwin_arm64 event register --address=localhost:8080 --api-key=xxx --name=simple --data="gcr.io/pipecd/helloworld:v0.40.0" --contexts="=fuga" --insecure=true
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
Attention: Patch coverage is 9.09091%
with 10 lines
in your changes missing coverage. Please review.
Project coverage is 25.30%. Comparing base (
249315b
) to head (179eef2
). Report is 3 commits behind head on master.
Files with missing lines | Patch % | Lines |
---|---|---|
pkg/app/pipectl/cmd/event/register.go | 0.00% | 10 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@Warashi
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."
I see. Thank you for finding it. This is based on the code generated by protoc-gen-validate
.
In my understanding, many validations are based on it.
Is there any idea?
@ffjlabo
I see. Thank you for finding it. This is based on the code generated by protoc-gen-validate. In my understanding, many validations are based on it. Is there any idea?
How about implementing validations in pipectl code with go's regexp? In my understanding, many parts of error messages from protoc-gen-validate will not be seen by users, but this is seen by users usually. So it's better that we can control the messages.
@Warashi Thanks
In my understanding, many parts of error messages from protoc-gen-validate will not be seen by users, but this is seen by users usually. So it's better that we can control the messages.
I got it. Sounds nice! So we would accept the message on the server side and implement the validation in pipectl.
📝 It seems that these errors occurred when using pipectl. e.g.
./pipectl_v0.49.3_darwin_arm64 event register --address=localhost:8080 --api-key=xxx --name=simple --data="gcr.io/pipecd/helloworld:v0.40.0" --labels="=fuga" --insecure=true
2024/11/14 18:06:51 failed to register event: rpc error: code = InvalidArgument desc = invalid request: invalid RegisterEventRequest.Labels[]: value length must be at least 1 runes
@Warashi Fixed in 179eef2
like this
go run cmd/pipectl/main.go event register --address=localhost:8080 --api-key=xxx --name=simple --data="gcr.io/pipecd/helloworld:v0.40.0" --contexts="test_hoge=fuga" --insecure=true
2024/11/14 18:32:34 failed to validate event context: invalid format key 'test_hoge', should be ^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$
exit status 1
It also works OK pattern.
go run cmd/pipectl/main.go event register --address=localhost:8080 --api-key=xxx --name=simple --data="gcr.io/pipecd/helloworld:v0.40.0" --contexts="test-hoge=fuga" --insecure=true
Successfully registered event {"id": "c256dfc4-d301-4cad-89f7-fb5afa87f31b"}
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-L646Also 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 https://github.com/pipe-cd/pipecd/issues/5028
Does this PR introduce a user-facing change?: