Skip to content

Commit

Permalink
chore: change exported surface of jujuauth pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Jan 6, 2025
1 parent edfb0ab commit 4bf6903
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 7 additions & 2 deletions internal/jimm/jujuauth/factory.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
package jujuauth

// Factory holds the necessary components for producing new stateful
// Juju authenticator objects. Because these objects are
// stateful, it is expected that a new one is used for each connection.
type Factory struct {
db GeneratorDatabase
jwtService JWTService
accessChecker GeneratorAccessChecker
}

// NewFactory returns a new factory object.
func NewFactory(db GeneratorDatabase, jwtService JWTService, accessChecker GeneratorAccessChecker) *Factory {
return &Factory{
db: db,
Expand All @@ -15,6 +19,7 @@ func NewFactory(db GeneratorDatabase, jwtService JWTService, accessChecker Gener
}
}

// New returns a new Juju token generator.
func (f *Factory) New() TokenGenerator {
return New(f.db, f.accessChecker, f.jwtService)
return new(f.db, f.accessChecker, f.jwtService)
}
6 changes: 3 additions & 3 deletions internal/jimm/jujuauth/jwtgenerator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

// Package jujuauth generates JWT tokens to
// authenticate and authorize messages to Juju controllers.
Expand Down Expand Up @@ -56,8 +56,8 @@ type TokenGenerator struct {
callCount int
}

// New returns a new JWTGenerator.
func New(database GeneratorDatabase, accessChecker GeneratorAccessChecker, jwtService JWTService) TokenGenerator {
// new returns a new JWTGenerator.
func new(database GeneratorDatabase, accessChecker GeneratorAccessChecker, jwtService JWTService) TokenGenerator {
return TokenGenerator{
database: database,
accessChecker: accessChecker,
Expand Down
10 changes: 6 additions & 4 deletions internal/jimm/jujuauth/jwtgenerator_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package jujuauth_test

Expand Down Expand Up @@ -238,7 +238,8 @@ func TestJWTGeneratorMakeLoginToken(t *testing.T) {
}}

for _, test := range tests {
generator := jujuauth.New(test.database, test.accessChecker, test.jwtService)
authFactory := jujuauth.NewFactory(test.database, test.jwtService, test.accessChecker)
generator := authFactory.New()
generator.SetTags(mt, ct)

i, err := dbmodel.NewIdentity(test.username)
Expand Down Expand Up @@ -311,7 +312,7 @@ func TestJWTGeneratorMakeToken(t *testing.T) {
}}

for _, test := range tests {
generator := jujuauth.New(
authFactory := jujuauth.NewFactory(
&testDatabase{
ctl: dbmodel.Controller{
CloudRegions: []dbmodel.CloudRegionControllerPriority{{
Expand All @@ -323,6 +324,7 @@ func TestJWTGeneratorMakeToken(t *testing.T) {
}},
},
},
test.jwtService,
&testAccessChecker{
modelAccess: map[string]string{
mt.String(): "admin",
Expand All @@ -336,8 +338,8 @@ func TestJWTGeneratorMakeToken(t *testing.T) {
permissions: test.checkPermissions,
permissionCheckErr: test.checkPermissionsError,
},
test.jwtService,
)
generator := authFactory.New()
generator.SetTags(mt, ct)

i, err := dbmodel.NewIdentity("[email protected]")
Expand Down

0 comments on commit 4bf6903

Please sign in to comment.