N-times usage policy implementation #5000
Closed
carlosperezdengra777
started this conversation in
General
Replies: 1 comment 1 reply
-
What is your question? Please remember discussions are for specific topics regarding the codebase. If you have a user-related question, please use the Discord channel. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question: Implementing a usage-based access policy in EDC
Hello,
I'm currently working on a custom policy evaluation function that restricts access to an asset once it has been used more than N times (e.g., N successful transfers). I'm following the recommended pattern by:
resources/<...>/extensions.policy
PolicyFunctionsExtension
classUsageCountConstraintFunction
that retrieves the number of completed transfers for a givenassetId
My function currently tries to call the
/transferprocesses/request
API to count how many completed transfers exist for a given asset:However, the evaluation function is not triggered or doesn't behave as expected — I don't see it being logged even when policies are evaluated during negotiation. Regarding this topic, I have a few questions:
1.- Is it correct to assume that the number of "accesses" means the number of completed transfer processes, and not just contract negotiations?
2.- Is there a supported or recommended way to access assetId and connectorId inside the evaluation function during contract negotiation?
3.- I tried context.getContextData(...) but those values are not available at that point — as expected.
4.- I noticed that the sample LocationConstraintFunction uses claims configured externally (e.g., via the participant agent). Is this the only reliable way to inject dynamic context values into the policy evaluation at negotiation time?
5.- Finally, is calling an external API like /transferprocesses/request inside a policy evaluation function considered an anti-pattern? Or is there a more idiomatic way in EDC to query internal transfer state for policy logic?
Thank you very much in advance — any guidance, clarification or examples are greatly appreciated!
Similar questions have been related: #4032, but do not satisfy the reason of the consultation.
Beta Was this translation helpful? Give feedback.
All reactions