mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Extract port-mapping validation to a function
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e1809510ca
commit
c0697c27aa
1 changed files with 18 additions and 12 deletions
|
@ -295,19 +295,9 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta
|
|||
}
|
||||
}
|
||||
|
||||
for port := range hostConfig.PortBindings {
|
||||
_, portStr := nat.SplitProtoPort(string(port))
|
||||
if _, err := nat.ParsePort(portStr); err != nil {
|
||||
return nil, errors.Errorf("invalid port specification: %q", portStr)
|
||||
}
|
||||
for _, pb := range hostConfig.PortBindings[port] {
|
||||
_, err := nat.NewPort(nat.SplitProtoPort(pb.HostPort))
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("invalid port specification: %q", pb.HostPort)
|
||||
}
|
||||
}
|
||||
if err := validatePortBindings(hostConfig.PortBindings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := validateRestartPolicy(hostConfig.RestartPolicy); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -343,6 +333,22 @@ func validateHealthCheck(healthConfig *containertypes.HealthConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func validatePortBindings(ports nat.PortMap) error {
|
||||
for port := range ports {
|
||||
_, portStr := nat.SplitProtoPort(string(port))
|
||||
if _, err := nat.ParsePort(portStr); err != nil {
|
||||
return errors.Errorf("invalid port specification: %q", portStr)
|
||||
}
|
||||
for _, pb := range ports[port] {
|
||||
_, err := nat.NewPort(nat.SplitProtoPort(pb.HostPort))
|
||||
if err != nil {
|
||||
return errors.Errorf("invalid port specification: %q", pb.HostPort)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRestartPolicy(policy containertypes.RestartPolicy) error {
|
||||
switch policy.Name {
|
||||
case "always", "unless-stopped", "no":
|
||||
|
|
Loading…
Add table
Reference in a new issue