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 May 3, 2024
1 parent 05c2608 commit 802a215
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 @@ -20,6 +18,7 @@ import (
"golang.org/x/mod/semver"

"github.com/canonical/microcloud/microcloud/api/types"
cloudCli "github.com/canonical/microcloud/microcloud/client"
"github.com/canonical/microcloud/microcloud/mdns"
)

Expand Down Expand Up @@ -58,14 +57,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 @@ -81,14 +73,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 802a215

Please sign in to comment.