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

feature: add rules for type validation #2394

Merged

Conversation

zhuangqh
Copy link
Contributor

@zhuangqh zhuangqh commented Oct 31, 2018

Signed-off-by: zhuangqh [email protected]

Ⅰ. Describe what this PR did

Add rules to validate post request body.

Parameter type pattern
StopTimeout *int64 >= 0
Parameter type pattern
ExecCreateConfig.Cmd []string len > 0
Parameter type pattern
HostPort string ^([1-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$ (0-65535)

Ⅱ. Does this pull request fix one issue?

fixes #443

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

added, but not complete. I would like to invite volunteers to complete test.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Oct 31, 2018

Codecov Report

Merging #2394 into master will increase coverage by 0.24%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2394      +/-   ##
==========================================
+ Coverage   68.35%   68.59%   +0.24%     
==========================================
  Files         272      272              
  Lines       18206    18210       +4     
==========================================
+ Hits        12445    12492      +47     
+ Misses       4332     4302      -30     
+ Partials     1429     1416      -13
Flag Coverage Δ
#criv1alpha1test 31.39% <0%> (+0.11%) ⬆️
#criv1alpha2test 35.65% <0%> (+0.21%) ⬆️
#integrationtest 40.01% <33.33%> (+0.13%) ⬆️
#nodee2etest 32.95% <0%> (+0.22%) ⬆️
#unittest 26.44% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
apis/opts/labels.go 100% <ø> (+12.5%) ⬆️
apis/server/system_bridge.go 47.77% <0%> (-2.23%) ⬇️
apis/server/container_bridge.go 87.42% <100%> (+0.07%) ⬆️
daemon/mgr/container_validation.go 42.5% <0%> (-2.5%) ⬇️
pkg/streams/utils.go 89.28% <0%> (-2.39%) ⬇️
cri/v1alpha2/cri_wrapper.go 63.6% <0%> (ø) ⬆️
cri/v1alpha2/cri_utils.go 91.21% <0%> (+0.29%) ⬆️
cri/v1alpha1/cri.go 60.59% <0%> (+0.33%) ⬆️
daemon/mgr/container.go 59% <0%> (+0.64%) ⬆️
... and 9 more

@allencloud
Copy link
Collaborator

feels so good to see it! 😍

@zhuangqh zhuangqh force-pushed the feature-type-validation branch from 3312a22 to 6136667 Compare October 31, 2018 08:38
apis/swagger.yml Outdated Show resolved Hide resolved
@zhuangqh zhuangqh force-pushed the feature-type-validation branch from 6136667 to 504e13b Compare October 31, 2018 09:45
@zhuangqh
Copy link
Contributor Author

@rudyfly please double check these rules.

@zhuangqh zhuangqh force-pushed the feature-type-validation branch from 504e13b to b192d7a Compare October 31, 2018 13:15
@fuweid
Copy link
Contributor

fuweid commented Nov 1, 2018

I think that there is no limit of Labels. Do we have any requirement for this kind of validation?

@zhuangqh zhuangqh force-pushed the feature-type-validation branch 3 times, most recently from 56e8d07 to afd8571 Compare November 1, 2018 08:33
@@ -325,6 +325,10 @@ func (s *Server) updateContainer(ctx context.Context, rw http.ResponseWriter, re
if err := json.NewDecoder(reader).Decode(config); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}
// validate request body
if err := config.Validate(strfmt.NewFormats()); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this validation should be before plugin point. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Any feedback on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion, the validation should be immediately before ContainerMgr.Update to promise
valid types like a sentinel, that's enough. @allencloud

Copy link
Collaborator

Choose a reason for hiding this comment

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

I got your point. Agree with you. @zhuangqh

apis/swagger.yml Outdated
@@ -3172,11 +3173,13 @@ definitions:
description: "The new volume's name. If not specified, Pouch generates a name."
type: "string"
x-nullable: false
pattern: ^[a-zA-Z0-9][a-zA-Z0-9_\-.]{0,63}$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we need @rudyfly to take a review of this to validate if the restriction rules is reasonable for volume management

apis/swagger.yml Outdated
@@ -3909,8 +3913,9 @@ definitions:
type: "string"
example: "127.0.0.1"
HostPort:
description: "Host port number that the container's port is mapped to."
description: "Host port number that the container's port is mapped to. range [0,65535]"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the port 0 is valid? I am it should be (0,65535].
WDYT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

has updated

@@ -3909,8 +3913,9 @@ definitions:
type: "string"
example: "127.0.0.1"
HostPort:
description: "Host port number that the container's port is mapped to."
description: "Host port number that the container's port is mapped to. range [0,65535]"
type: "string"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although it is strange to use string type to describe port, it is compatible with Moby.
Just comment to record this.

@zhuangqh zhuangqh force-pushed the feature-type-validation branch from b037706 to 3a66d8d Compare November 5, 2018 09:38
@pouchrobot pouchrobot added size/L and removed size/XL labels Nov 5, 2018
@zhuangqh
Copy link
Contributor Author

zhuangqh commented Nov 5, 2018

@allencloud after discussing with @rudyfly . I have removed all of the rules related to volume or label.

@allencloud
Copy link
Collaborator

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Nov 5, 2018
@allencloud allencloud merged commit 2b5fad7 into AliyunContainerService:master Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] Post Request Body Validation rules
5 participants