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

Auth Manager API part 2: AuthManager #11809

Merged
merged 6 commits into from
Dec 20, 2024
Merged

Conversation

adutra
Copy link
Contributor

@adutra adutra commented Dec 18, 2024

Second PR for the Auth Manager API.

This PR introduces the AuthManager itself, along with 2 simple implementations: Basic and Noop. This PR does not turn the manager on yet.

\cc @nastra @danielcweeks

@github-actions github-actions bot added the core label Dec 18, 2024
* when the session is no longer needed. Implementations should override {@link #close()} to release
* any resources.
*/
public interface AuthSession extends AutoCloseable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The naming issue from the previous PR is still pending. @nastra and myself agreed recently on HTTPAuthSession@danielcweeks is that OK with you?

Copy link
Contributor

Choose a reason for hiding this comment

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

I talked with @danielcweeks and we probably want to go with what you have here as we should eventually deprecate the AuthSession in OAuth2Util and so we shouldn't have an issue with conflicting names for too long

* <p>It is not required to cache the returned session internally, as the catalog will keep it
* alive for the lifetime of the catalog.
*/
AuthSession mainSession(RESTClient sharedClient, Map<String, String> properties);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like catalogSession makes more sense here instead of mainSession

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry I forgot to start this discussion :-)

But wdyt about components like the signer and the credential refreshers? They will also use the auth manager. But in those places, it doesn't make sense to talk about a "catalog" session. WDYT?

Copy link
Contributor

@danielcweeks danielcweeks Dec 19, 2024

Choose a reason for hiding this comment

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

I'm not too concerned about using catalogSession in other places because it actually reflects the session provided to the catalog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted to catalogSession.

* <p>This method is called when the owning catalog is closed.
*/
@Override
default void close() {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any value in having a default impl that doesn't do anything? I feel like this should be just left to the actual auth manager implementations


@Test
void authenticate() {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary newline here and in the other test methods in this class

private AuthManagers() {}

public static AuthManager loadAuthManager(String name, Map<String, String> properties) {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary newline

Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

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

LGTM pending the two points around renames

DynConstructors.builder(AuthManager.class)
.loader(AuthManagers.class.getClassLoader())
.impl(impl, String.class) // with name
.impl(impl) // without name
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unnecessary. I couldn't find other places where we try for multiple constructors. I think we lean toward one convention (though I may have missed examples).

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 took this idea from org.apache.iceberg.LocationProviders. I found it interesting because the name may be of relevance for some impls (e.g. the Oauth2 manager will use it to name the token refresh executor threads) but will be useless for more simple impls, and forcing those impls to declare a constructor with an unused parameter seemed overkill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are specific tests for this feature in org.apache.iceberg.TestLocationProvider.

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 use the name anywhere? Seems like if we use it, we should require it. If we don't use it, we should just get rid of it. Overall, I prefer having an opinionated path as opposed to providing lots of options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I kept only the constructor with name.

@danielcweeks
Copy link
Contributor

Couple minor things. I think we should revert to the original names (per the comments)

* the cache, or the cache itself is closed.
*/
@Override
void close();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nastra per your previous comment, I thought you would prefer this method to be non-default as well.

@danielcweeks danielcweeks merged commit cdf748e into apache:main Dec 20, 2024
49 checks passed
@adutra adutra deleted the auth-manager-2 branch December 21, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants