Skip to content

Commit

Permalink
microcloud/service: Use AuthProxy for LXD
Browse files Browse the repository at this point in the history
Signed-off-by: Max Asnaashari <[email protected]>
  • Loading branch information
masnax committed Apr 19, 2024
1 parent dcc57dd commit e5c9ac1
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions microcloud/service/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"context"
"fmt"
"net"
"net/http"
"net/url"
"os"
"strings"
"time"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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),
})
}

Expand All @@ -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
Expand Down

0 comments on commit e5c9ac1

Please sign in to comment.