Skip to content

Commit

Permalink
Merge pull request #6491 from vrothberg/fix-6490
Browse files Browse the repository at this point in the history
/images/.../json: fix port parsing
  • Loading branch information
openshift-merge-robot authored Jun 4, 2020
2 parents 650ed43 + 6229d9d commit ceef4f6
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions pkg/api/handlers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,25 @@ func ImageDataToImageInspect(ctx context.Context, l *libpodImage.Image) (*ImageI
func portsToPortSet(input map[string]struct{}) (nat.PortSet, error) {
ports := make(nat.PortSet)
for k := range input {
npTCP, err := nat.NewPort("tcp", k)
if err != nil {
return nil, errors.Wrapf(err, "unable to create tcp port from %s", k)
}
npUDP, err := nat.NewPort("udp", k)
if err != nil {
return nil, errors.Wrapf(err, "unable to create udp port from %s", k)
proto, port := nat.SplitProtoPort(k)
switch proto {
// See the OCI image spec for details:
// https://github.com/opencontainers/image-spec/blob/e562b04403929d582d449ae5386ff79dd7961a11/config.md#properties
case "tcp", "":
p, err := nat.NewPort("tcp", port)
if err != nil {
return nil, errors.Wrapf(err, "unable to create tcp port from %s", k)
}
ports[p] = struct{}{}
case "udp":
p, err := nat.NewPort("udp", port)
if err != nil {
return nil, errors.Wrapf(err, "unable to create tcp port from %s", k)
}
ports[p] = struct{}{}
default:
return nil, errors.Errorf("invalid port proto %q in %q", proto, k)
}
ports[npTCP] = struct{}{}
ports[npUDP] = struct{}{}
}
return ports, nil
}

0 comments on commit ceef4f6

Please sign in to comment.