From 9611d80a90a0a3115bb6b0c344de28ba30582489 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Wed, 17 Jan 2024 14:33:15 +0000 Subject: [PATCH] Rename `Controller.AdminUser` to `AdminIdentityName` Signed-off-by: Babak K. Shandiz --- cmd/jimmctl/cmd/jimmsuite_test.go | 12 ++++---- internal/dbmodel/controller.go | 8 +++--- internal/dbmodel/controller_test.go | 16 +++++------ internal/jimm/controller.go | 4 +-- internal/jimm/controller_test.go | 36 ++++++++++++------------ internal/jimm/jimm.go | 2 +- internal/jimmtest/env.go | 6 ++-- internal/jimmtest/suite.go | 12 ++++---- internal/jujuapi/jimm.go | 12 ++++---- internal/jujuclient/client_test.go | 12 ++++---- internal/jujuclient/dial_test.go | 12 ++++---- internal/jujuclient/modelwatcher_test.go | 12 ++++---- internal/jujuclient/ping_test.go | 12 ++++---- internal/jujuclient/storage_test.go | 36 ++++++++++++------------ 14 files changed, 96 insertions(+), 96 deletions(-) diff --git a/cmd/jimmctl/cmd/jimmsuite_test.go b/cmd/jimmctl/cmd/jimmsuite_test.go index 620fd56d7..9fc1c5b0a 100644 --- a/cmd/jimmctl/cmd/jimmsuite_test.go +++ b/cmd/jimmctl/cmd/jimmsuite_test.go @@ -183,12 +183,12 @@ func (s *jimmSuite) userBakeryClient(username string) *httpbakery.Client { func (s *jimmSuite) AddController(c *gc.C, name string, info *api.Info) { ctl := &dbmodel.Controller{ - UUID: info.ControllerUUID, - Name: name, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - CACertificate: info.CACert, - Addresses: nil, + UUID: info.ControllerUUID, + Name: name, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + CACertificate: info.CACert, + Addresses: nil, } ctl.Addresses = make(dbmodel.HostPorts, 0, len(info.Addrs)) for _, addr := range info.Addrs { diff --git a/internal/dbmodel/controller.go b/internal/dbmodel/controller.go index 941b4ec41..3ceacca81 100644 --- a/internal/dbmodel/controller.go +++ b/internal/dbmodel/controller.go @@ -28,9 +28,9 @@ type Controller struct { // purposes. UUID string `gorm:"not null"` - // AdminUser is the username that JIMM uses to connect to the + // AdminIdentityName is the identity name that JIMM uses to connect to the // controller. - AdminUser string + AdminIdentityName string // AdminPassword is the password that JIMM uses to connect to the // controller. @@ -104,7 +104,7 @@ func (c Controller) ToAPIControllerInfo() apiparams.ControllerInfo { var ci apiparams.ControllerInfo ci.Name = c.Name ci.UUID = c.UUID - ci.Username = c.AdminUser + ci.Username = c.AdminIdentityName ci.PublicAddress = c.PublicAddress for _, hps := range c.Addresses { for _, hp := range hps { @@ -114,7 +114,7 @@ func (c Controller) ToAPIControllerInfo() apiparams.ControllerInfo { ci.CACertificate = c.CACertificate ci.CloudTag = names.NewCloudTag(c.CloudName).String() ci.CloudRegion = c.CloudRegion - ci.Username = c.AdminUser + ci.Username = c.AdminIdentityName ci.AgentVersion = c.AgentVersion if c.UnavailableSince.Valid { ci.Status = jujuparams.EntityStatus{ diff --git a/internal/dbmodel/controller_test.go b/internal/dbmodel/controller_test.go index 068668a82..720abb730 100644 --- a/internal/dbmodel/controller_test.go +++ b/internal/dbmodel/controller_test.go @@ -39,13 +39,13 @@ func TestController(t *testing.T) { c.Assert(result.Error, qt.IsNil) ctl := dbmodel.Controller{ - Name: "test-controller", - UUID: "00000000-0000-0000-0000-000000000001", - AdminUser: "admin", - AdminPassword: "pw", - CACertificate: "ca-cert", - PublicAddress: "controller.example.com:443", - CloudName: "test-cloud", + Name: "test-controller", + UUID: "00000000-0000-0000-0000-000000000001", + AdminIdentityName: "admin", + AdminPassword: "pw", + CACertificate: "ca-cert", + PublicAddress: "controller.example.com:443", + CloudName: "test-cloud", Addresses: dbmodel.HostPorts([][]jujuparams.HostPort{{{ Address: jujuparams.Address{ Value: "1.1.1.1", @@ -166,7 +166,7 @@ func TestToAPIControllerInfo(t *testing.T) { CloudRegion: cl.Regions[0], Priority: dbmodel.CloudRegionControllerPriorityDeployed, }} - ctl.AdminUser = "admin" + ctl.AdminIdentityName = "admin" ctl.AgentVersion = "1.2.3" ci := ctl.ToAPIControllerInfo() diff --git a/internal/jimm/controller.go b/internal/jimm/controller.go index f6792581a..1b637fa33 100644 --- a/internal/jimm/controller.go +++ b/internal/jimm/controller.go @@ -92,7 +92,7 @@ func (j *JIMM) AddController(ctx context.Context, user *openfga.User, ctl *dbmod credentialsStored := false if j.CredentialStore != nil { - err := j.CredentialStore.PutControllerCredentials(ctx, ctl.Name, ctl.AdminUser, ctl.AdminPassword) + err := j.CredentialStore.PutControllerCredentials(ctx, ctl.Name, ctl.AdminIdentityName, ctl.AdminPassword) if err != nil { return errors.E(op, err, "failed to store controller credentials") } @@ -145,7 +145,7 @@ func (j *JIMM) AddController(ctx context.Context, user *openfga.User, ctl *dbmod // if we already stored controller credentials in CredentialStore // we should not store them plain text in JIMM's DB. if credentialsStored { - ctl.AdminUser = "" + ctl.AdminIdentityName = "" ctl.AdminPassword = "" } if err := tx.AddController(ctx, ctl); err != nil { diff --git a/internal/jimm/controller_test.go b/internal/jimm/controller_test.go index 0680f80fd..3d94c0e7a 100644 --- a/internal/jimm/controller_test.go +++ b/internal/jimm/controller_test.go @@ -157,10 +157,10 @@ func TestAddController(t *testing.T) { c.Assert(err, qt.IsNil) ctl1 := dbmodel.Controller{ - Name: "test-controller", - AdminUser: "admin", - AdminPassword: "5ecret", - PublicAddress: "example.com:443", + Name: "test-controller", + AdminIdentityName: "admin", + AdminPassword: "5ecret", + PublicAddress: "example.com:443", } err = j.AddController(context.Background(), alice, &ctl1) c.Assert(err, qt.IsNil) @@ -173,10 +173,10 @@ func TestAddController(t *testing.T) { c.Check(ctl2, qt.CmpEquals(cmpopts.EquateEmpty(), cmpopts.IgnoreTypes(dbmodel.CloudRegion{})), ctl1) ctl3 := dbmodel.Controller{ - Name: "test-controller-2", - AdminUser: "admin", - AdminPassword: "5ecret", - PublicAddress: "example.com:443", + Name: "test-controller-2", + AdminIdentityName: "admin", + AdminPassword: "5ecret", + PublicAddress: "example.com:443", } err = j.AddController(context.Background(), alice, &ctl3) c.Assert(err, qt.IsNil) @@ -325,14 +325,14 @@ func TestAddControllerWithVault(t *testing.T) { c.Assert(err, qt.IsNil) ctl1 := dbmodel.Controller{ - Name: "test-controller", - AdminUser: "admin", - AdminPassword: "5ecret", - PublicAddress: "example.com:443", + Name: "test-controller", + AdminIdentityName: "admin", + AdminPassword: "5ecret", + PublicAddress: "example.com:443", } err = j.AddController(context.Background(), alice, &ctl1) c.Assert(err, qt.IsNil) - c.Assert(ctl1.AdminUser, qt.Equals, "") + c.Assert(ctl1.AdminIdentityName, qt.Equals, "") c.Assert(ctl1.AdminPassword, qt.Equals, "") ctl2 := dbmodel.Controller{ @@ -348,14 +348,14 @@ func TestAddControllerWithVault(t *testing.T) { c.Assert(password, qt.Equals, "5ecret") ctl3 := dbmodel.Controller{ - Name: "test-controller-2", - AdminUser: "admin", - AdminPassword: "5ecretToo", - PublicAddress: "example.com:443", + Name: "test-controller-2", + AdminIdentityName: "admin", + AdminPassword: "5ecretToo", + PublicAddress: "example.com:443", } err = j.AddController(context.Background(), alice, &ctl3) c.Assert(err, qt.IsNil) - c.Assert(ctl3.AdminUser, qt.Equals, "") + c.Assert(ctl3.AdminIdentityName, qt.Equals, "") c.Assert(ctl3.AdminPassword, qt.Equals, "") ctl4 := dbmodel.Controller{ diff --git a/internal/jimm/jimm.go b/internal/jimm/jimm.go index 60fb94de3..742a389b0 100644 --- a/internal/jimm/jimm.go +++ b/internal/jimm/jimm.go @@ -517,7 +517,7 @@ func fillMigrationTarget(db db.Database, credStore credentials.CredentialStore, if err != nil { return jujuparams.MigrationTargetInfo{}, 0, err } - adminUser := dbController.AdminUser + adminUser := dbController.AdminIdentityName adminPass := dbController.AdminPassword if adminPass == "" { u, p, err := credStore.GetControllerCredentials(ctx, controllerName) diff --git a/internal/jimmtest/env.go b/internal/jimmtest/env.go index 133536bd2..4d5e2133c 100644 --- a/internal/jimmtest/env.go +++ b/internal/jimmtest/env.go @@ -180,9 +180,9 @@ func (m Model) addModelRelations(c *qt.C, jimmTag names.ControllerTag, db db.Dat // addControllerRelations adds permissions the model should have and adds permissions for users to the controller. func (ctl Controller) addControllerRelations(c *qt.C, jimmTag names.ControllerTag, db db.Database, client *openfga.OFGAClient) { - if ctl.dbo.AdminUser != "" { + if ctl.dbo.AdminIdentityName != "" { user := openfga.NewUser(&dbmodel.Identity{ - Name: ctl.dbo.AdminUser, + Name: ctl.dbo.AdminIdentityName, }, client) err := user.SetControllerAccess(context.Background(), ctl.dbo.ResourceTag(), ofganames.AdministratorRelation) c.Assert(err, qt.IsNil) @@ -387,7 +387,7 @@ func (ctl *Controller) DBObject(c *qt.C, db db.Database) dbmodel.Controller { ctl.dbo.Name = ctl.Name ctl.dbo.UUID = ctl.UUID ctl.dbo.AgentVersion = ctl.AgentVersion - ctl.dbo.AdminUser = ctl.AdminUser + ctl.dbo.AdminIdentityName = ctl.AdminUser ctl.dbo.AdminPassword = ctl.AdminPassword ctl.dbo.CloudName = ctl.Cloud ctl.dbo.CloudRegion = ctl.CloudRegion diff --git a/internal/jimmtest/suite.go b/internal/jimmtest/suite.go index da07b6513..4f3602e1b 100644 --- a/internal/jimmtest/suite.go +++ b/internal/jimmtest/suite.go @@ -151,12 +151,12 @@ func (s *JIMMSuite) NewUser(u *dbmodel.Identity) *openfga.User { func (s *JIMMSuite) AddController(c *gc.C, name string, info *api.Info) { ctl := &dbmodel.Controller{ - UUID: info.ControllerUUID, - Name: name, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - CACertificate: info.CACert, - Addresses: nil, + UUID: info.ControllerUUID, + Name: name, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + CACertificate: info.CACert, + Addresses: nil, } ctl.Addresses = make(dbmodel.HostPorts, 0, len(info.Addrs)) for _, addr := range info.Addrs { diff --git a/internal/jujuapi/jimm.go b/internal/jujuapi/jimm.go index 7fcb0fc8d..70033cada 100644 --- a/internal/jujuapi/jimm.go +++ b/internal/jujuapi/jimm.go @@ -165,12 +165,12 @@ func (r *controllerRoot) AddController(ctx context.Context, req apiparams.AddCon } ctl := dbmodel.Controller{ - UUID: req.UUID, - Name: req.Name, - PublicAddress: req.PublicAddress, - CACertificate: req.CACertificate, - AdminUser: req.Username, - AdminPassword: req.Password, + UUID: req.UUID, + Name: req.Name, + PublicAddress: req.PublicAddress, + CACertificate: req.CACertificate, + AdminIdentityName: req.Username, + AdminPassword: req.Password, } nphps, err := network.ParseProviderHostPorts(req.APIAddresses...) if err != nil { diff --git a/internal/jujuclient/client_test.go b/internal/jujuclient/client_test.go index 5abec889d..243bc0880 100644 --- a/internal/jujuclient/client_test.go +++ b/internal/jujuclient/client_test.go @@ -38,12 +38,12 @@ func (s *clientSuite) TestStatus(c *gc.C) { info := s.APIInfo(c) ctl := dbmodel.Controller{ - UUID: info.ControllerUUID, - Name: s.ControllerConfig.ControllerName(), - CACertificate: info.CACert, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - PublicAddress: info.Addrs[0], + UUID: info.ControllerUUID, + Name: s.ControllerConfig.ControllerName(), + CACertificate: info.CACert, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + PublicAddress: info.Addrs[0], } models, err := s.API.UpdateCredential(ctx, cred) diff --git a/internal/jujuclient/dial_test.go b/internal/jujuclient/dial_test.go index cdf7db353..7ba5bc3f8 100644 --- a/internal/jujuclient/dial_test.go +++ b/internal/jujuclient/dial_test.go @@ -71,12 +71,12 @@ var _ = gc.Suite(&dialSuite{}) func (s *dialSuite) TestDial(c *gc.C) { info := s.APIInfo(c) ctl := dbmodel.Controller{ - UUID: s.ControllerConfig.ControllerUUID(), - Name: s.ControllerConfig.ControllerName(), - CACertificate: info.CACert, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - PublicAddress: info.Addrs[0], + UUID: s.ControllerConfig.ControllerUUID(), + Name: s.ControllerConfig.ControllerName(), + CACertificate: info.CACert, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + PublicAddress: info.Addrs[0], } api, err := s.Dialer.Dial(context.Background(), &ctl, names.ModelTag{}, nil) c.Assert(err, gc.Equals, nil) diff --git a/internal/jujuclient/modelwatcher_test.go b/internal/jujuclient/modelwatcher_test.go index b2797846d..81f11d518 100644 --- a/internal/jujuclient/modelwatcher_test.go +++ b/internal/jujuclient/modelwatcher_test.go @@ -42,12 +42,12 @@ func (s *modelWatcherSuite) SetUpTest(c *gc.C) { }}) } ctl := dbmodel.Controller{ - UUID: s.ControllerConfig.ControllerUUID(), - Name: s.ControllerConfig.ControllerName(), - CACertificate: info.CACert, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - Addresses: hpss, + UUID: s.ControllerConfig.ControllerUUID(), + Name: s.ControllerConfig.ControllerName(), + CACertificate: info.CACert, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + Addresses: hpss, } s.API, err = s.Dialer.Dial(context.Background(), &ctl, s.Model.ModelTag(), nil) diff --git a/internal/jujuclient/ping_test.go b/internal/jujuclient/ping_test.go index 8e80b5cdb..54ab09c61 100644 --- a/internal/jujuclient/ping_test.go +++ b/internal/jujuclient/ping_test.go @@ -21,12 +21,12 @@ func (s *pingSuite) TestPing(c *gc.C) { info := s.APIInfo(c) ctl := dbmodel.Controller{ - UUID: s.ControllerConfig.ControllerUUID(), - Name: s.ControllerConfig.ControllerName(), - CACertificate: info.CACert, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - PublicAddress: info.Addrs[0], + UUID: s.ControllerConfig.ControllerUUID(), + Name: s.ControllerConfig.ControllerName(), + CACertificate: info.CACert, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + PublicAddress: info.Addrs[0], } api, err := s.Dialer.Dial(ctx, &ctl, names.ModelTag{}, nil) c.Assert(err, gc.Equals, nil) diff --git a/internal/jujuclient/storage_test.go b/internal/jujuclient/storage_test.go index 20ec0a983..6f449bc64 100644 --- a/internal/jujuclient/storage_test.go +++ b/internal/jujuclient/storage_test.go @@ -35,12 +35,12 @@ func (s *storageSuite) TestListFilesystems(c *gc.C) { info := s.APIInfo(c) ctl := dbmodel.Controller{ - UUID: s.ControllerConfig.ControllerUUID(), - Name: s.ControllerConfig.ControllerName(), - CACertificate: info.CACert, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - PublicAddress: info.Addrs[0], + UUID: s.ControllerConfig.ControllerUUID(), + Name: s.ControllerConfig.ControllerName(), + CACertificate: info.CACert, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + PublicAddress: info.Addrs[0], } models, err := s.API.UpdateCredential(ctx, cred) @@ -81,12 +81,12 @@ func (s *storageSuite) TestListVolumes(c *gc.C) { info := s.APIInfo(c) ctl := dbmodel.Controller{ - UUID: s.ControllerConfig.ControllerUUID(), - Name: s.ControllerConfig.ControllerName(), - CACertificate: info.CACert, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - PublicAddress: info.Addrs[0], + UUID: s.ControllerConfig.ControllerUUID(), + Name: s.ControllerConfig.ControllerName(), + CACertificate: info.CACert, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + PublicAddress: info.Addrs[0], } models, err := s.API.UpdateCredential(ctx, cred) @@ -127,12 +127,12 @@ func (s *storageSuite) TestListStorageDetails(c *gc.C) { info := s.APIInfo(c) ctl := dbmodel.Controller{ - UUID: s.ControllerConfig.ControllerUUID(), - Name: s.ControllerConfig.ControllerName(), - CACertificate: info.CACert, - AdminUser: info.Tag.Id(), - AdminPassword: info.Password, - PublicAddress: info.Addrs[0], + UUID: s.ControllerConfig.ControllerUUID(), + Name: s.ControllerConfig.ControllerName(), + CACertificate: info.CACert, + AdminIdentityName: info.Tag.Id(), + AdminPassword: info.Password, + PublicAddress: info.Addrs[0], } models, err := s.API.UpdateCredential(ctx, cred)