From 6c45c7746612e7248908b424f2dac0fe5475aa75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mej=C3=ADas=20Rodr=C3=ADguez?= Date: Fri, 23 Aug 2019 02:18:18 -0400 Subject: [PATCH] Add function in Portainer client to proxy a request to Docker API --- client/client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/client.go b/client/client.go index 9d16569..66264de 100644 --- a/client/client.go +++ b/client/client.go @@ -66,6 +66,9 @@ type PortainerClient interface { // Run a function after receiving a response from Portainer AfterResponse(hook func(resp *http.Response) (err error)) + + // Proxy proxies a request to /endpoint/{id}/docker and returns its result + Proxy(endpointId portainer.EndpointID, req *http.Request) (resp *http.Response, err error) } type portainerClientImp struct { @@ -305,6 +308,11 @@ func (n *portainerClientImp) GetStatus() (status portainer.Status, err error) { return } +func (n *portainerClientImp) Proxy(endpointId portainer.EndpointID, req *http.Request) (resp *http.Response, err error) { + resp, err = n.do(fmt.Sprintf("endpoints/%v/docker%s", endpointId, req.RequestURI), req.Method, req.Body, "", req.Header) + return +} + // Create a new client func NewClient(httpClient *http.Client, config Config) PortainerClient { return &portainerClientImp{