Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

added HelloWorld testing annotation (will remove later) + AutomationClientPermissionCheck #1079

Closed

Conversation

violetd12
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Jun 10, 2022

Coverage Status

Coverage increased (+0.1%) to 77.09% when pulling 1150bf2 on violet/cism-3872_AutomationClientPermissionCheck into f65286a on master.

Comment on lines 8 to 12
public class AutomationClientDelegatingPermissionCheck implements PermissionCheck{
private static final Logger logger = LoggerFactory.getLogger(
AutomationClientDelegatingPermissionCheck.class);

private PermissionCheck delegate;
Copy link
Contributor

Choose a reason for hiding this comment

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

So for this one I don't think we're going to need a delegate, this can just be a "terminal" permission check. I guess I would say that a permission check either has permission logic of its own (which this one does) or relying on a delegate's logic, but not both. The pass-through and always-allow are in the second category since they don't have any (non-trivial) permission check logic of their own.

Comment on lines 30 to 36
int hasPermissionSuccessMetricInt = hasPermission ? 1 : 0;
String successMetricName = MetricRegistry.name(AutomationClientDelegatingPermissionCheck.class, "isAllowed", "success", "histogram");
metricRegistry.histogram(successMetricName).update(hasPermissionSuccessMetricInt);

int hasPermissionFailureMetricInt = hasPermission ? 0 : 1;
String failureMetricName = MetricRegistry.name(AutomationClientDelegatingPermissionCheck.class, "isAllowed", "failure", "histogram");
metricRegistry.histogram(failureMetricName).update(hasPermissionFailureMetricInt);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to shorten things up a bit, you could move all the metrics stuff into an emitMetrics() helper method. That's actually one of the really nice things about the built-in metrics annotations is that they really hide all of this boilerplate and allow the method to just focus on the business logic.

Comment on lines 51 to 54
@Override
public void checkAllowedOrThrow(KeywhizPrincipal source, String action, Object target) {
String successMetricName = MetricRegistry.name(AutomationClientDelegatingPermissionCheck.class, "checkAllowedOrThrow", "success", "histogram");
String exceptionMetricName = MetricRegistry.name(AutomationClientDelegatingPermissionCheck.class, "checkAllowedOrThrow", "exception", "histogram");
Copy link
Contributor

Choose a reason for hiding this comment

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

If we gave up on having custom metric names for each entry point ("isAllowed" vs. "checkAllowedOrThrow"), could we just use the default implementation of this method (which just delegates to isAllowed?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what if we move all the custom metrics emission into a method defined in PermissionCheck interface directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would have to add MetricRegistry as a parameter...could be difficult

@violetd12 violetd12 changed the title added HelloWorld testing annotation added HelloWorld testing annotation (will remove later) + AutomationClientPermissionCheck Jun 15, 2022
@violetd12 violetd12 closed this Jun 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants