[lxc-devel] [lxd/master] candid: Cleanup code a bit

stgraber on Github lxc-bot at linuxcontainers.org
Tue Oct 2 21:27:04 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181002/5c2d1abd/attachment.bin>
-------------- next part --------------
From f12d912d23ad90e277286999d76d6fdef93bf19f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 2 Oct 2018 17:26:43 -0400
Subject: [PATCH] candid: Cleanup code a bit
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/remote.go |  3 +--
 lxd/daemon.go | 18 +++++++-----------
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/lxc/remote.go b/lxc/remote.go
index 3a418af9b0..d359a38728 100644
--- a/lxc/remote.go
+++ b/lxc/remote.go
@@ -235,8 +235,7 @@ func (c *cmdRemoteAdd) Run(cmd *cobra.Command, args []string) error {
 					uri.RawQuery = query.Encode()
 				}
 
-				fmt.Println(uri)
-				return nil
+				return httpbakery.OpenWebBrowser(uri)
 			},
 		},
 	})
diff --git a/lxd/daemon.go b/lxd/daemon.go
index 2a94c65cf9..5f670d29a8 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -182,9 +182,13 @@ func (d *Daemon) checkTrustedClient(r *http.Request) error {
 
 	if d.externalAuth != nil && r.Header.Get(httpbakery.BakeryProtocolHeader) != "" {
 		ctx := httpbakery.ContextWithRequest(context.TODO(), r)
-		authChecker := d.externalAuth.bakery.Checker.Auth(
-			httpbakery.RequestMacaroons(r)...)
-		ops := getBakeryOps(r)
+		authChecker := d.externalAuth.bakery.Checker.Auth(httpbakery.RequestMacaroons(r)...)
+
+		ops := []bakery.Op{{
+			Entity: r.URL.Path,
+			Action: r.Method,
+		}}
+
 		_, err := authChecker.Allow(ctx, ops...)
 		return err
 	}
@@ -198,14 +202,6 @@ func (d *Daemon) checkTrustedClient(r *http.Request) error {
 	return fmt.Errorf("unauthorized")
 }
 
-// Return the bakery operations implied by the given HTTP request
-func getBakeryOps(r *http.Request) []bakery.Op {
-	return []bakery.Op{{
-		Entity: r.URL.Path,
-		Action: r.Method,
-	}}
-}
-
 func writeMacaroonsRequiredResponse(b *identchecker.Bakery, r *http.Request, w http.ResponseWriter, derr *bakery.DischargeRequiredError, expiry int64) {
 	ctx := httpbakery.ContextWithRequest(context.TODO(), r)
 	caveats := append(derr.Caveats,


More information about the lxc-devel mailing list