Skip to content

Exposing functions to independently apply actions pre-request and post-response #94

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

Merged
merged 4 commits into from
Mar 25, 2025

Conversation

jordan83
Copy link
Collaborator

No description provided.

@jordan83 jordan83 changed the title Breakup actions 2 Exposing functions to independently apply actions pre-request and post-response Mar 24, 2025
@jordan83 jordan83 requested review from bsurmanski and yaya1721 March 24, 2025 21:20
@@ -83,7 +86,7 @@ class TestContext extends RecaptchaContext {
log_messages: Array<[LogLevel, string[]]> = [];

constructor(config: RecaptchaConfig) {
super(config);
super(JSON.parse(JSON.stringify(config)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

the config should already be a JS object? why is this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The config needed to be deep-copied. It's global and there are tests that modify it so I had failures when making new tests. We can also have a function that creates a new literal. Do you have a preference?

Copy link
Collaborator

Choose a reason for hiding this comment

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

wild that there is no good way to do a deep copy.

I've been using the spread operator {...config} for stuff like this. though in cases where the object is nested (not here) it doesn't work.

Object.assign({}, config) would also work here (though (not relevant) strips methods and prototypes)

or consider just adding a comment so the motivation for the serialization is clear

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding a comment for now. We can always revisit.

name: "test-policy",
description: "test-description",
path: "/teste2e",
// 'type' isn't a part of the interface, but is added for testing.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I don't think the 'type' addition is required anymore; was previously helpful with Zod.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, will remove.

src/policy.ts Outdated
*/
export async function processRequest(context: RecaptchaContext, req: EdgeRequest): Promise<EdgeResponse> {
export async function getActions(context: RecaptchaContext, req: EdgeRequest): Promise<action.Action[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

'getActions' sounds like a lightweight operation, where this can actually call 2 RPCs (ListFirewallPolicies (cachable) and CreateAssessment).

consider something like:
FetchActions, RetrieveActions, AcquireActions, ProduceActions, EvaluatePolicyProduceActions....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, good idea. Will do.

- getActions => fetchActions
- removing type field from actions in tests
- deep copy is clear when copying the config in tests
@jordan83 jordan83 merged commit 643a7f1 into main Mar 25, 2025
22 checks passed
@jordan83 jordan83 deleted the breakup-actions-2 branch March 25, 2025 15:05
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.

2 participants