From e5c9ac1e85e80bf24c0552ff666dc871b5d7ff20 Mon Sep 17 00:00:00 2001 From: Max Asnaashari Date: Thu, 18 Apr 2024 17:59:19 +0000 Subject: [PATCH] microcloud/service: Use AuthProxy for LXD Signed-off-by: Max Asnaashari --- microcloud/service/lxd.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/microcloud/service/lxd.go b/microcloud/service/lxd.go index f8a6a1a7b..d89e14d55 100644 --- a/microcloud/service/lxd.go +++ b/microcloud/service/lxd.go @@ -5,8 +5,6 @@ import ( "context" "fmt" "net" - "net/http" - "net/url" "os" "strings" "time" @@ -19,6 +17,7 @@ import ( "github.com/canonical/microcluster/microcluster" "github.com/canonical/microcloud/microcloud/api/types" + cloudCli "github.com/canonical/microcloud/microcloud/client" "github.com/canonical/microcloud/microcloud/mdns" ) @@ -57,14 +56,7 @@ func (s LXDService) Client(ctx context.Context, secret string) (lxd.InstanceServ return lxd.ConnectLXDUnixWithContext(ctx, s.m.FileSystem.ControlSocket().URL.Host, &lxd.ConnectionArgs{ HTTPClient: c.Client.Client, SkipGetServer: true, - Proxy: func(r *http.Request) (*url.URL, error) { - r.Header.Set("X-MicroCloud-Auth", secret) - if !strings.HasPrefix(r.URL.Path, "/1.0/services/lxd") { - r.URL.Path = "/1.0/services/lxd" + r.URL.Path - } - - return shared.ProxyFromEnvironment(r) - }, + Proxy: cloudCli.AuthProxy(secret, types.LXD), }) } @@ -80,14 +72,7 @@ func (s LXDService) remoteClient(secret string, address string, port int64) (lxd HTTPClient: c.Client.Client, InsecureSkipVerify: true, SkipGetServer: true, - Proxy: func(r *http.Request) (*url.URL, error) { - r.Header.Set("X-MicroCloud-Auth", secret) - if !strings.HasPrefix(r.URL.Path, "/1.0/services/lxd") { - r.URL.Path = "/1.0/services/lxd" + r.URL.Path - } - - return shared.ProxyFromEnvironment(r) - }, + Proxy: cloudCli.AuthProxy(secret, types.LXD), }) if err != nil { return nil, err