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

Pass RealmContext instance to all API methods #566

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

adutra
Copy link
Contributor

@adutra adutra commented Dec 16, 2024

This is a first step towards fixing #463. RealmContext is now passed as an argument to every API and Service method generated from OpenAPI specs. Passing the RealmContext is also a prerequisite for including the realm ID as a custom tag in generated metrics.

AuthenticatedPolarisPrincipal authenticatedPrincipal =
(AuthenticatedPolarisPrincipal) securityContext.getUserPrincipal();
if (authenticatedPrincipal == null) {
throw new NotAuthorizedException("Failed to find authenticatedPrincipal in SecurityContext");
}

PolarisEntityManager entityManager =
entityManagerFactory.getOrCreateEntityManager(callContext.getRealmContext());
entityManagerFactory.getOrCreateEntityManager(realmContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can RealmContext be a @RequestScoped injectable (constructor) property as opposed to an explicit method parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, for 2 reasons: 1) DW does not "understand" request-scoped REST resources, and 2) Quarkus will need the parameter anyway, to add the realm id to the generated metric tags. IOW, later on the parameter will be annotated with @MeterTag as follows:

@Context 
@MeterTag(key="realm_id",expression="realmIdentifier") 
RealmContext realmContext,

Copy link
Contributor

Choose a reason for hiding this comment

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

I see 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Hypothetically: is it possible to manually produce a @RequestScoped bean for the realm context data in the generated API code?

CallContext callContext = CallContext.getCurrentContext();
PolarisCallContext polarisCallContext = callContext.getPolarisCallContext();
PolarisCallContext polarisRealmContext =
CallContext.getCurrentContext().getPolarisCallContext();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why rename this variable?.. It looks like its value did not change? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sorry, result of successive refactorings 🤦‍♂️

@adutra adutra merged commit 261c4fa into apache:main Dec 19, 2024
5 checks passed
@adutra adutra deleted the inject-realm-context branch December 19, 2024 12:55
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