diff --git a/charms/jimm-k8s/src/charm.py b/charms/jimm-k8s/src/charm.py index b42a766fc..dbe5b8819 100755 --- a/charms/jimm-k8s/src/charm.py +++ b/charms/jimm-k8s/src/charm.py @@ -290,9 +290,9 @@ def _update_workload(self, event): if dashboard_relation and self.unit.is_leader(): dashboard_relation.data[self.app].update( { - "controller-url": "wss://{}".format(dns_name), - "identity-provider-url": self.config.get("candid-url"), - "is-juju": str(False), + "controller_url": "wss://{}".format(dns_name), + "identity_provider_url": self.config.get("candid-url"), + "is_juju": str(False), } ) @@ -319,9 +319,9 @@ def _on_dashboard_relation_joined(self, event: RelationJoinedEvent): event.relation.data[self.app].update( { - "controller-url": "wss://{}".format(dns_name), - "identity-provider-url": self.config["candid-url"], - "is-juju": str(False), + "controller_url": "wss://{}".format(dns_name), + "identity_provider_url": self.config["candid-url"], + "is_juju": str(False), } ) diff --git a/charms/jimm-k8s/tests/unit/test_charm.py b/charms/jimm-k8s/tests/unit/test_charm.py index c0b34f78b..9c72b3be4 100644 --- a/charms/jimm-k8s/tests/unit/test_charm.py +++ b/charms/jimm-k8s/tests/unit/test_charm.py @@ -253,11 +253,11 @@ def test_dashboard_relation_joined(self): self.assertTrue(data) self.assertEqual( - data["controller-url"], + data["controller_url"], "wss://juju-jimm-k8s-0.juju-jimm-k8s-endpoints.None.svc.cluster.local", ) - self.assertEqual(data["identity-provider-url"], "https://candid.example.com") - self.assertEqual(data["is-juju"], "False") + self.assertEqual(data["identity_provider_url"], "https://candid.example.com") + self.assertEqual(data["is_juju"], "False") @patch("src.charm.JimmOperatorCharm._get_network_address") @patch("socket.gethostname") diff --git a/charms/jimm/src/charm.py b/charms/jimm/src/charm.py index c36b12bd1..6f543d58f 100755 --- a/charms/jimm/src/charm.py +++ b/charms/jimm/src/charm.py @@ -386,9 +386,9 @@ def _snap(self, *args): def _on_dashboard_relation_joined(self, event): event.relation.data[self.app].update( { - "controller-url": "wss://{}".format(self.config["dns-name"]), - "identity-provider-url": self.config["candid-url"], - "is-juju": str(False), + "controller_url": "wss://{}".format(self.config["dns-name"]), + "identity_provider_url": self.config["candid-url"], + "is_juju": str(False), } ) diff --git a/charms/jimm/tests/test_charm.py b/charms/jimm/tests/test_charm.py index 9563d6ea5..47ab07351 100644 --- a/charms/jimm/tests/test_charm.py +++ b/charms/jimm/tests/test_charm.py @@ -488,9 +488,9 @@ def test_dashboard_relation_joined(self): harness.add_relation_unit(id, "juju-dashboard/0") data = harness.get_relation_data(id, "juju-jimm") self.assertTrue(data) - self.assertEqual(data["controller-url"], "wss://jimm.example.com") - self.assertEqual(data["identity-provider-url"], "https://candid.example.com") - self.assertEqual(data["is-juju"], "False") + self.assertEqual(data["controller_url"], "wss://jimm.example.com") + self.assertEqual(data["identity_provider_url"], "https://candid.example.com") + self.assertEqual(data["is_juju"], "False") class VersionHTTPRequestHandler(BaseHTTPRequestHandler): diff --git a/internal/dashboard/dashboard.go b/internal/dashboard/dashboard.go index d2e1ddc93..0e2540921 100644 --- a/internal/dashboard/dashboard.go +++ b/internal/dashboard/dashboard.go @@ -31,7 +31,7 @@ const ( // handler will redirect to that URL. If the location is a path on the disk // then the handler will serve the files from that path. Otherwise a // NotFoundHandler will be returned. -func Handler(ctx context.Context, loc string) http.Handler { +func Handler(ctx context.Context, loc string, publicDNSname string) http.Handler { mux := http.NewServeMux() u, err := url.Parse(loc) @@ -85,6 +85,7 @@ func Handler(ctx context.Context, loc string) http.Handler { continue } var w bytes.Buffer + configParams["baseControllerURL"] = publicDNSname if err := t.Execute(&w, configParams); err != nil { zapctx.Error(ctx, "error executing config.js.go", zap.Error(err)) continue diff --git a/internal/dashboard/dashboard_test.go b/internal/dashboard/dashboard_test.go index 8bb3283b0..4df31a9b2 100644 --- a/internal/dashboard/dashboard_test.go +++ b/internal/dashboard/dashboard_test.go @@ -19,7 +19,7 @@ import ( const ( configFile = `var jujuDashboardConfig = { // API host to allow app to connect and retrieve models - baseControllerURL: null, + baseControllerURL: "{{.baseControllerURL}}", // Configurable base url to allow deploying to different paths. baseAppURL: "{{.baseAppURL}}", // If true then identity will be provided by a third party provider. @@ -38,7 +38,7 @@ const ( func TestDashboardNotConfigured(t *testing.T) { c := qt.New(t) - hnd := dashboard.Handler(context.Background(), "") + hnd := dashboard.Handler(context.Background(), "", "") rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/dashboard", nil) c.Assert(err, qt.IsNil) @@ -50,7 +50,7 @@ func TestDashboardNotConfigured(t *testing.T) { func TestDashboardRedirect(t *testing.T) { c := qt.New(t) - hnd := dashboard.Handler(context.Background(), "https://example.com/dashboard") + hnd := dashboard.Handler(context.Background(), "https://example.com/dashboard", "http://jimm.canonical.com") rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/dashboard", nil) c.Assert(err, qt.IsNil) @@ -71,7 +71,7 @@ func TestDashboardFromPath(t *testing.T) { err = os.WriteFile(filepath.Join(dir, "test"), []byte(testFile), 0444) c.Assert(err, qt.Equals, nil) - hnd := dashboard.Handler(context.Background(), dir) + hnd := dashboard.Handler(context.Background(), dir, "http://jimm.canonical.com") rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/dashboard", nil) c.Assert(err, qt.IsNil) @@ -100,7 +100,7 @@ func TestDashboardFromPath(t *testing.T) { c.Assert(err, qt.IsNil) c.Check(string(buf), qt.Equals, `var jujuDashboardConfig = { // API host to allow app to connect and retrieve models - baseControllerURL: null, + baseControllerURL: "http://jimm.canonical.com", // Configurable base url to allow deploying to different paths. baseAppURL: "/", // If true then identity will be provided by a third party provider. @@ -136,7 +136,7 @@ func TestDashboardFromPath(t *testing.T) { func TestInvalidLocation(t *testing.T) { c := qt.New(t) - hnd := dashboard.Handler(context.Background(), ":::") + hnd := dashboard.Handler(context.Background(), ":::", "http://jimm.canonical.com") rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/dashboard", nil) c.Assert(err, qt.IsNil) @@ -152,7 +152,7 @@ func TestLocationNotDirectory(t *testing.T) { err := os.WriteFile(filepath.Join(dir, "test"), []byte(testFile), 0444) c.Assert(err, qt.Equals, nil) - hnd := dashboard.Handler(context.Background(), filepath.Join(dir, "test")) + hnd := dashboard.Handler(context.Background(), filepath.Join(dir, "test"), "http://jimm.canonical.com") rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/dashboard", nil) c.Assert(err, qt.IsNil) @@ -174,7 +174,7 @@ func TestGUIArchiveEndpoint(t *testing.T) { err = os.WriteFile(filepath.Join(dir, "version.json"), []byte(versionFile), 0444) c.Assert(err, qt.Equals, nil) - hnd := dashboard.Handler(context.Background(), dir) + hnd := dashboard.Handler(context.Background(), dir, "http://jimm.canonical.com") rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/gui-archive", nil) c.Assert(err, qt.IsNil) diff --git a/internal/jimm/cloud.go b/internal/jimm/cloud.go index a2da8bc3e..1159b05d9 100644 --- a/internal/jimm/cloud.go +++ b/internal/jimm/cloud.go @@ -393,12 +393,14 @@ func (j *JIMM) AddHostedCloud(ctx context.Context, u *dbmodel.User, tag names.Cl } // Update the cloud in the database. dbCloud.FromJujuCloud(*ccloud) + zapctx.Debug(ctx, "received cloud info from controller", zap.Any("cloud", dbCloud)) for i := range dbCloud.Regions { dbCloud.Regions[i].Controllers = []dbmodel.CloudRegionControllerPriority{{ - ControllerID: region.Controllers[0].ID, + ControllerID: controller.ID, Priority: dbmodel.CloudRegionControllerPrioritySupported, }} } + zapctx.Debug(ctx, "received cloud info from controller", zap.Any("cloud", dbCloud)) if err := j.Database.UpdateCloud(ctx, &dbCloud); err != nil { // At this point the cloud has been created on the diff --git a/service.go b/service.go index 264a3ed0e..32c12fe77 100644 --- a/service.go +++ b/service.go @@ -239,7 +239,7 @@ func NewService(ctx context.Context, p Params) (*Service, error) { // If the request is not for a known path assume it is part of the dashboard. // If dashboard location env var is not defined, do not handle a dashboard. if p.DashboardLocation != "" { - s.mux.Handle("/", dashboard.Handler(ctx, p.DashboardLocation)) + s.mux.Handle("/", dashboard.Handler(ctx, p.DashboardLocation, p.PublicDNSName)) } return s, nil