on master help sign in
Fixes PortBindings serialization bug
commit21aabae2ddc4408804f10fae11805a4bcb516542 authorDeni Bertovic <deni@denibertovic.com> dateThu 11 Aug 2016, 19:46 (10 years ago) parent45d7f43
1 file changed+11−2
src/Docker/Client/Types.hs+11−2
src/Docker/Client/Types.hs+11−2
@@ -796,7 +796,11 @@ instance ToJSON NetworkMode where
796796 toJSON Host = JSON.String "host"
797797 toJSON NetworkDisabled = JSON.String "none"
798798
799−data PortType = TCP | UDP deriving (Eq, Show, Generic, Read, Ord)
799+data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
800+
801+instance Show PortType where
802+ show TCP = "tcp"
803+ show UDP = "udp"
800804
801805instance ToJSON PortType where
802806 toJSON TCP = "tcp"
@@ -821,6 +825,8 @@ instance FromJSON PortType where
821825-- host system s that the service running in the container can be accessed from
822826-- the outside world. We either map a port onto all interfaces (default) or onto a specific
823827-- interface like `127.0.0.1`.
828+-- __NOTE__: We should disallow duplicate port bindings as the ToJSON
829+-- instnace will only send the last one.
824830newtype PortBindings = PortBindings [PortBinding]
825831 deriving (Eq, Show)
826832
@@ -856,7 +862,10 @@ instance FromJSON PortBindings where
856862
857863instance ToJSON PortBindings where
858864 toJSON (PortBindings []) = JSON.Object HM.empty
859− toJSON (PortBindings (p:ps)) = toJSON (p:ps)
865+ toJSON (PortBindings (p:ps)) = JSON.Object $ foldl f HM.empty (p:ps)
866+ where mKey p = portAndType2Text (containerPort p) (portType p)
867+ mVal p = toJSON $ hostPorts p
868+ f acc p = HM.insert (mKey p) (mVal p) acc
860869
861870data HostPort = HostPort {
862871 hostIp :: Text