mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
fix(endpoints): add the ability to update TLS for an existing endpoint (#784)
This commit is contained in:
parent
44e48423ed
commit
abc929824c
7 changed files with 90 additions and 45 deletions
67
api/http/proxy.go
Normal file
67
api/http/proxy.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/orcaman/concurrent-map"
|
||||
"github.com/portainer/portainer"
|
||||
)
|
||||
|
||||
// ProxyService represents a service used to manage Docker proxies.
|
||||
type ProxyService struct {
|
||||
proxyFactory *ProxyFactory
|
||||
proxies cmap.ConcurrentMap
|
||||
}
|
||||
|
||||
// NewProxyService initializes a new ProxyService
|
||||
func NewProxyService(resourceControlService portainer.ResourceControlService) *ProxyService {
|
||||
return &ProxyService{
|
||||
proxies: cmap.New(),
|
||||
proxyFactory: &ProxyFactory{
|
||||
ResourceControlService: resourceControlService,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// CreateAndRegisterProxy creates a new HTTP reverse proxy and adds it to the registered proxies.
|
||||
// It can also be used to create a new HTTP reverse proxy and replace an already registered proxy.
|
||||
func (service *ProxyService) CreateAndRegisterProxy(endpoint *portainer.Endpoint) (http.Handler, error) {
|
||||
var proxy http.Handler
|
||||
|
||||
endpointURL, err := url.Parse(endpoint.URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if endpointURL.Scheme == "tcp" {
|
||||
if endpoint.TLS {
|
||||
proxy, err = service.proxyFactory.newHTTPSProxy(endpointURL, endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
proxy = service.proxyFactory.newHTTPProxy(endpointURL)
|
||||
}
|
||||
} else {
|
||||
// Assume unix:// scheme
|
||||
proxy = service.proxyFactory.newSocketProxy(endpointURL.Path)
|
||||
}
|
||||
|
||||
service.proxies.Set(string(endpoint.ID), proxy)
|
||||
return proxy, nil
|
||||
}
|
||||
|
||||
// GetProxy returns the proxy associated to a key
|
||||
func (service *ProxyService) GetProxy(key string) http.Handler {
|
||||
proxy, ok := service.proxies.Get(key)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return proxy.(http.Handler)
|
||||
}
|
||||
|
||||
// DeleteProxy deletes the proxy associated to a key
|
||||
func (service *ProxyService) DeleteProxy(key string) {
|
||||
service.proxies.Remove(key)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue