Skip to content

Commit

Permalink
Rename Controller.AdminUser to AdminIdentityName
Browse files Browse the repository at this point in the history
Signed-off-by: Babak K. Shandiz <[email protected]>
  • Loading branch information
babakks committed Jan 17, 2024
1 parent 418a569 commit 9611d80
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 96 deletions.
12 changes: 6 additions & 6 deletions cmd/jimmctl/cmd/jimmsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/dbmodel/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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{
Expand Down
16 changes: 8 additions & 8 deletions internal/dbmodel/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions internal/jimm/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 18 additions & 18 deletions internal/jimm/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/jimm/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/jimmtest/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions internal/jimmtest/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions internal/jujuapi/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions internal/jujuclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions internal/jujuclient/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions internal/jujuclient/modelwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions internal/jujuclient/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 18 additions & 18 deletions internal/jujuclient/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9611d80

Please sign in to comment.