on master help sign in
Adds delete endpoint
commit0943a5a8ef3e896d0215e0710c78ccb0bec5ec5f authorDeni Bertovic <deni@denibertovic.com> dateTue 23 Feb 2016, 13:01 (11 years ago) parentcb0e5d8
3 files changed+18−10
Network/Docker.hs+7−10 Network/Docker/Internal.hs+8 Network/Docker/Types.hs+3
Network/Docker.hs+7−10
@@ -90,8 +90,6 @@ _dockerEmptyPostQuery clientOpts@DockerClientOpts{ssl = NoSSL} endpoint = Free (
9090_dockerEmptyPostQuery clientOpts@DockerClientOpts{ssl = SSL sslOpts} endpoint = Free (PostSSL sslOpts (fullUrl clientOpts endpoint) (toJSON emptyPost))
9191
9292
93−_dockerEmptyDeleteQuery endpoint clientOpts = delete (fullUrl clientOpts endpoint)
94−
9593_dockerEmptyDeleteQuery endpoint clientOpts = delete (fullUrl clientOpts endpoint)
9694
9795getDockerVersion :: DockerClientOpts -> IO (Maybe DockerVersion)
@@ -124,13 +122,12 @@ pauseContainer clientOpts cid = (^. responseStatus) <$> runDocker (pauseContaine
124122unpauseContainer :: DockerClientOpts -> String -> IO (Status)
125123unpauseContainer clientOpts cid = (^. responseStatus) <$> runDocker (unpauseContainerM clientOpts (SUnpauseContainerEndpoint cid))
126124
125+deleteContainer :: DockerClientOpts -> DeleteOpts -> String -> IO (Status)
126+deleteContainer c d cid = deleteContainerWithOpts c d cid
127127
128−-- deleteContainer :: DockerClientOpts -> String -> IO (Status)
129−-- deleteContainer = deleteContainerWithOpts defaultDeleteOpts
130−
131−-- deleteContainerWithOpts :: DeleteOpts -> DockerClientOpts -> String -> IO (Status)
132−-- deleteContainerWithOpts (DeleteOpts removeVolumes force) clientOpts containerId = (^. responseStatus) <$> _dockerEmptyDeleteQuery req clientOpts
133−-- where req = printf "/containers/%s?v=%s;force=%s" containerId (show removeVolumes) (show force)
128+deleteContainerWithOpts :: DockerClientOpts -> DeleteOpts -> String -> IO (Status)
129+deleteContainerWithOpts clientOpts deleteOpts cid = (^. responseStatus) <$>
130+ runDocker (deleteContainerM clientOpts (SDeleteContainerEndpoint cid deleteOpts))
134131
135132-- getContainerLogsStream :: DockerClientOpts -> String -> IO ()
136133-- getContainerLogsStream clientOpts containerId = do
@@ -140,10 +137,10 @@ unpauseContainer clientOpts cid = (^. responseStatus) <$> runDocker (unpauseCont
140137-- where url = (printf "/containers/%s/logs?stdout=1&stderr=1&follow=1" containerId)
141138
142139-- getContainerLogs :: DockerClientOpts -> String -> Bool -> IO (L.ByteString)
143−-- getContainerLogs clientOpts cid follow = (^. responseBody) <$> runDocker (getContainerLogsM clientOpts (SContainerLogsEndpoint cid) follow)
140+-- getContainerLogs clientOpts cid follow = (^. responseBody) <$> run (getContainerLogsM clientOpts (SContainerLogsEndpoint cid) follow)
144141
145142
146− -- False -> (^. responseBody) <$> runDocker (getContainerLogsM clientOpts (SContainerLogsEndpoint cid "0"))
143+ -- False -> (^. responseBody) <$> run (getContainerLogsM clientOpts (SContainerLogsEndpoint cid "0"))
147144 -- True -> error "dinamo"
148145 -- req <- PH.parseUrl (SContainerLogsEndpoint cid "1")
149146 -- let req' = req {PH.method = "GET"}
Network/Docker/Internal.hs+8
@@ -23,6 +23,7 @@ emptyPost = "" :: String
2323runDocker :: HttpRequestM r -> IO (Response L.ByteString)
2424runDocker (Free (Get url)) = get url
2525runDocker (Free (Post url body)) = post url body
26+runDocker (Free (Delete url)) = delete url
2627
2728constructUrl :: URL -> ApiVersion -> String -> URL
2829constructUrl url apiVersion endpoint = printf "%s%s%s" url apiVersion endpoint
@@ -46,6 +47,7 @@ getEndpoint (SRestartContainerEndpoint cid) = printf "/containers/%s/restart" ci
4647getEndpoint (SPauseContainerEndpoint cid) = printf "/containers/%s/pause" cid
4748getEndpoint (SUnpauseContainerEndpoint cid) = printf "/containers/%s/unpause" cid
4849getEndpoint (SContainerLogsEndpoint cid) = printf "/containers/%s/logs?stdout=1&stderr=1" cid
50+getEndpoint (SDeleteContainerEndpoint cid (DeleteOpts removeVolumes force)) = printf "/containers/%s?v=%s;force=%s" cid (show removeVolumes) (show force)
4951
5052fullUrl :: DockerClientOpts -> SEndpoint a -> URL
5153fullUrl clientOpts endpoint = constructUrl (baseUrl clientOpts) (apiVersion clientOpts) (getEndpoint endpoint)
@@ -59,6 +61,9 @@ _dockerPostQuery clientOpts endpoint postObject = Free (Post (fullUrl clientOpts
5961_dockerEmptyPostQuery :: DockerClientOpts -> SEndpoint a -> HttpRequestM (SEndpoint a)
6062_dockerEmptyPostQuery clientOpts endpoint = Free (Post (fullUrl clientOpts endpoint) (toJSON emptyPost))
6163
64+_dockerDeleteQuery :: DockerClientOpts -> SEndpoint a -> HttpRequestM (SEndpoint a)
65+_dockerDeleteQuery clientOpts endpoint = Free $ Delete $ fullUrl clientOpts endpoint
66+
6267getDockerVersionM :: DockerClientOpts -> SEndpoint VersionEndpoint -> HttpRequestM (SEndpoint VersionEndpoint)
6368getDockerVersionM clientOpts e = _dockerGetQuery clientOpts e
6469
@@ -89,6 +94,9 @@ createContainerM clientOpts e c = _dockerPostQuery clientOpts e c
8994startContainerM :: DockerClientOpts -> SEndpoint StartContainerEndpoint -> StartContainerOpts -> HttpRequestM (SEndpoint StartContainerEndpoint)
9095startContainerM clientOpts e c = _dockerPostQuery clientOpts e c
9196
97+deleteContainerM :: DockerClientOpts -> SEndpoint DeleteContainerEndpoint -> HttpRequestM (SEndpoint DeleteContainerEndpoint)
98+deleteContainerM clientOpts e = _dockerDeleteQuery clientOpts e
99+
92100-- getContainerLogsM :: DockerClientOpts -> SEndpoint ContainerLogsEndpoint -> Bool -> HttpRequestM (SEndpoint ContainerLogsEndpoint)
93101-- getContainerLogsM clientOpts e f = case f of
94102-- False -> _dockerGetQuery clientOpts e
Network/Docker/Types.hs+3
@@ -52,6 +52,7 @@ data Endpoint =
5252 | PauseContainerEndpoint
5353 | UnpauseContainerEndpoint
5454 | ContainerLogsEndpoint
55+ | DeleteContainerEndpoint
5556
5657
5758data SEndpoint (a :: Endpoint) where
@@ -66,6 +67,7 @@ data SEndpoint (a :: Endpoint) where
6667 SPauseContainerEndpoint :: String -> SEndpoint PauseContainerEndpoint
6768 SUnpauseContainerEndpoint :: String -> SEndpoint UnpauseContainerEndpoint
6869 SContainerLogsEndpoint :: String -> SEndpoint ContainerLogsEndpoint
70+ SDeleteContainerEndpoint :: String -> DeleteOpts -> SEndpoint DeleteContainerEndpoint
6971
7072defaultClientOpts :: DockerClientOpts
7173defaultClientOpts = DockerClientOpts
@@ -77,6 +79,7 @@ defaultClientOpts = DockerClientOpts
7779data HttpRequestF a =
7880 Get URL
7981 | Post URL Value
82+ | Delete URL
8083 deriving ( Functor, Show )
8184
8285