Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move jwt generator #1501

Merged
merged 3 commits into from
Dec 18, 2024
Merged

chore: move jwt generator #1501

merged 3 commits into from
Dec 18, 2024

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Dec 17, 2024

Description

This PR is mostly a mechanical change to move the jwtGenerator into a separate package. It was already well structured enough to do this. I've also added a package doc and renamed the NewJWTGenerator function to simply New.

The package has been renamed to jujuauth.

Fixes JUJU-7272

@kian99 kian99 requested a review from a team as a code owner December 17, 2024 13:41
Copy link
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we could make this a bit less repetitive and have a jwt package with a NewGenerator constructor that would return jwt.Generator

@@ -0,0 +1,180 @@
// Copyright 2024 Canonical.

// jwtgenerator generates JWT tokens to authenticate
Copy link
Collaborator

@alesstimec alesstimec Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package godoc usually starts with Package <name>


// jwtGeneratorDatabase specifies the database interface used by the
// JWT generator.
type jwtGeneratorDatabase interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think these three interfaces should be exported as they are parameter types for the exported constructor

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also interface names do not need the jwt prefix now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove the jwt prefix, but why do they need to be exported? Maybe for a caller to verify that a struct satisfies the interface with a _ = jwtGeneratorDatabase but even that's a stretch because the caller can just call New() with whatever struct it has to satisfy the interface.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the thing is that you don't know what interface you need to satisfy without looking at the code since it is unexported. generally having exported methods with unexported argument types or returns is an anti-pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the thing is that you don't know what interface you need to satisfy without looking at the code since it is unexported

But even if it was exported, how would you know how to satisfy the interface without looking at the code?

@@ -0,0 +1,357 @@
// Copyright 2024 Canonical.
package jwtgenerator_test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line, please

@kian99
Copy link
Contributor Author

kian99 commented Dec 17, 2024

i wonder if we could make this a bit less repetitive and have a jwt package with a NewGenerator constructor that would return jwt.Generator

@alesstimec What aspect is repetitive?

@kian99
Copy link
Contributor Author

kian99 commented Dec 17, 2024

@alesstimec
I was also thinking we could rename this package to something like jujuTokens to highlight that this is an business logic thing that relies on the JWT service primitive.

@alesstimec
Copy link
Collaborator

@kian99 jwtgenerator.Generator sounds a bit repetitive, does it not?

@kian99 kian99 requested a review from alesstimec December 17, 2024 14:38
internal/jimm/jujuauth/jwtgenerator.go Outdated Show resolved Hide resolved
internal/jimm/jujuauth/jwtgenerator.go Outdated Show resolved Hide resolved
Copy link
Contributor

@SimoneDutto SimoneDutto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


// generatorDatabase specifies the database interface used by the
// JWT generator.
type generatorDatabase interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to go in this direction of having <package_name>Database? since it is unexported wouldn't be nice just to have database?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it back to being exported. It could still be database but I don't mind much.

@kian99 kian99 requested a review from alesstimec December 18, 2024 11:05
@kian99 kian99 merged commit 5cf6fc6 into canonical:v3 Dec 18, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants