Add function in Portainer client to proxy a request to Docker API

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-23 02:18:18 -04:00
parent 0be0262fcb
commit 6c45c77466

View File

@ -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{