From 5061b659c92f17fbcc784e24aea73a5d08e85efb Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 29 Jun 2021 18:52:38 +0200 Subject: [PATCH] aperture: allow updating services at runtime In order to be able to dynamically update the proxy's backend configuration, we add a new method that can overwrite the list of backend services. --- aperture.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/aperture.go b/aperture.go index bf070c9..a5e09b3 100644 --- a/aperture.go +++ b/aperture.go @@ -124,6 +124,7 @@ type Aperture struct { challenger *LndChallenger httpsServer *http.Server torHTTPServer *http.Server + proxy *proxy.Proxy wg sync.WaitGroup quit chan struct{} @@ -172,11 +173,11 @@ func (a *Aperture) Start(errChan chan error) error { } // Create the proxy and connect it to lnd. - servicesProxy, err := createProxy(a.cfg, a.challenger, a.etcdClient) + a.proxy, err = createProxy(a.cfg, a.challenger, a.etcdClient) if err != nil { return err } - handler := http.HandlerFunc(servicesProxy.ServeHTTP) + handler := http.HandlerFunc(a.proxy.ServeHTTP) a.httpsServer = &http.Server{ Addr: a.cfg.ListenAddr, Handler: handler, @@ -255,6 +256,13 @@ func (a *Aperture) Start(errChan chan error) error { return nil } +// UpdateServices instructs the proxy to re-initialize its internal +// configuration of backend services. This can be used to add or remove backends +// at run time or enable/disable authentication on the fly. +func (a *Aperture) UpdateServices(services []*proxy.Service) error { + return a.proxy.UpdateServices(services) +} + // Stop gracefully shuts down the Aperture service. func (a *Aperture) Stop() error { var returnErr error