The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/5693
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From c19848cef9f259bc46cad39b9705fdf200bdf7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Thu, 18 Apr 2019 15:47:14 +0100 Subject: [PATCH] lxd/candid: Cleanup config handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxd/api_1.0.go | 13 ++++++------- lxd/api_cluster.go | 8 ++------ lxd/cluster/config.go | 22 +++------------------- lxd/daemon.go | 14 ++++++-------- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/lxd/api_1.0.go b/lxd/api_1.0.go index 9f87b89c90..6f194d76f1 100644 --- a/lxd/api_1.0.go +++ b/lxd/api_1.0.go @@ -92,9 +92,12 @@ func api10Get(d *Daemon, r *http.Request) Response { if err != nil { return err } - if config.CandidEndpoint() != "" { + + candidURL, _, _, _ := config.CandidServer() + if candidURL != "" { authMethods = append(authMethods, "candid") } + return nil }) if err != nil { @@ -491,12 +494,8 @@ func doApi10UpdateTriggers(d *Daemon, nodeChanged, clusterChanged map[string]str } if candidChanged { - endpoint := clusterConfig.CandidEndpoint() - endpointKey := clusterConfig.CandidEndpointKey() - expiry := clusterConfig.CandidExpiry() - domains := clusterConfig.CandidDomains() - - err := d.setupExternalAuthentication(endpoint, endpointKey, expiry, domains) + apiURL, apiKey, expiry, domains := clusterConfig.CandidServer() + err := d.setupExternalAuthentication(apiURL, apiKey, expiry, domains) if err != nil { return err } diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go index 3a5c5dfeea..b930c8a18c 100644 --- a/lxd/api_cluster.go +++ b/lxd/api_cluster.go @@ -523,12 +523,8 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) Response { } // Connect to Candid - endpoint := clusterConfig.CandidEndpoint() - endpointKey := clusterConfig.CandidEndpointKey() - expiry := clusterConfig.CandidExpiry() - domains := clusterConfig.CandidDomains() - - err = d.setupExternalAuthentication(endpoint, endpointKey, expiry, domains) + candidAPIURL, candidAPIKey, candidExpiry, candidDomains := clusterConfig.CandidServer() + err = d.setupExternalAuthentication(candidAPIURL, candidAPIKey, candidExpiry, candidDomains) if err != nil { return err } diff --git a/lxd/cluster/config.go b/lxd/cluster/config.go index 3b32f89d00..aa521424fa 100644 --- a/lxd/cluster/config.go +++ b/lxd/cluster/config.go @@ -64,25 +64,9 @@ func (c *Config) TrustPassword() string { return c.m.GetString("core.trust_password") } -// CandidEndpoint returns the address of the Candid endpoint to use for -// authentication, if any. -func (c *Config) CandidEndpoint() string { - return c.m.GetString("candid.api.url") -} - -// CandidEndpointKey returns the public key for the API endpoint -func (c *Config) CandidEndpointKey() string { - return c.m.GetString("candid.api.key") -} - -// CandidExpiry returns the cookie expiry of the macaroon. -func (c *Config) CandidExpiry() int64 { - return c.m.GetInt64("candid.expiry") -} - -// CandidDomains returns the valid domains. -func (c *Config) CandidDomains() string { - return c.m.GetString("candid.domains") +// CandidServer returns all the Candid settings needed to connect to a server. +func (c *Config) CandidServer() (string, string, int64, string) { + return c.m.GetString("candid.api.url"), c.m.GetString("candid.api.key"), c.m.GetInt64("candid.expiry"), c.m.GetString("candid.domains") } // AutoUpdateInterval returns the configured images auto update interval. diff --git a/lxd/daemon.go b/lxd/daemon.go index 23a8fd8fb4..96a373869d 100644 --- a/lxd/daemon.go +++ b/lxd/daemon.go @@ -719,10 +719,11 @@ func (d *Daemon) init() error { pruneLeftoverImages(d) /* Setup the proxy handler, external authentication and MAAS */ - var candidExpiry int64 + candidAPIURL := "" + candidAPIKey := "" candidDomains := "" - candidEndpoint := "" - candidEndpointKey := "" + candidExpiry := int64(0) + maasAPIURL := "" maasAPIKey := "" maasMachine := "" @@ -750,10 +751,7 @@ func (d *Daemon) init() error { d.proxy = shared.ProxyFromConfig( config.ProxyHTTPS(), config.ProxyHTTP(), config.ProxyIgnoreHosts(), ) - candidEndpoint = config.CandidEndpoint() - candidEndpointKey = config.CandidEndpointKey() - candidExpiry = config.CandidExpiry() - candidDomains = config.CandidDomains() + candidAPIURL, candidAPIKey, candidExpiry, candidDomains = config.CandidServer() maasAPIURL, maasAPIKey = config.MAASController() return nil }) @@ -761,7 +759,7 @@ func (d *Daemon) init() error { return err } - err = d.setupExternalAuthentication(candidEndpoint, candidEndpointKey, candidExpiry, candidDomains) + err = d.setupExternalAuthentication(candidAPIURL, candidAPIKey, candidExpiry, candidDomains) if err != nil { return err }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel