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

feat!: add agent context provider #898

Conversation

TimoGlastra
Copy link
Contributor

@TimoGlastra TimoGlastra commented Jun 21, 2022

Adds an AgentContextProvider with default DefaultAgentContextProvider implementation that always returns the same agent context (for a single tenant agent).

This allows the tenant module (will be added as a separate module) to implement its own TenantAgentContextProvider that will find provide the agent context for a specific tenant. This allows to keep the core lean, while providing more advanced usages of providing the agent context.

I added a contextCorrelationId to the AgentContext interface. For now this is not really needed, but this will become really useful when we add tenants. The contextCorrelationId allows to correlate the context with an identifier to make it easier to provide the context for an incoming message. By default we find the tenant based on the recipient public keys of a message, but there's numerous cases where we are processing plaintext messages. By providing the contextCorrelationId we can use this in the AgentContextProvider to correlate the message to a specific context. In the case of the TenantContextProvider the contextCorrelationId will be the tenantId.

BREAKING CHANGE: the agent.receiveMessage method should only be used if you want to process the message in the context of the current agent. This means it fine to use for e.g. processing plaintext connection-less messages, but it shouldn't be used anymore by outbound and inbound transports to process messages. Instead, inject the MessageReceiver class and call receiveMessage on that class instead.

@TimoGlastra TimoGlastra requested a review from a team as a code owner June 21, 2022 17:22
@TimoGlastra TimoGlastra added the multitenancy Tasks related to multi-tenancy label Jun 21, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2022

Codecov Report

Merging #898 (49c4d55) into main (6d88aa4) will increase coverage by 0.15%.
The diff coverage is 87.93%.

@@            Coverage Diff             @@
##             main     #898      +/-   ##
==========================================
+ Coverage   87.70%   87.86%   +0.15%     
==========================================
  Files         475      480       +5     
  Lines       11339    11436      +97     
  Branches     1874     1909      +35     
==========================================
+ Hits         9945    10048     +103     
+ Misses       1327     1322       -5     
+ Partials       67       66       -1     
Impacted Files Coverage Δ
packages/core/src/agent/AgentConfig.ts 90.16% <ø> (-0.47%) ⬇️
packages/core/src/agent/Events.ts 100.00% <ø> (ø)
packages/core/src/constants.ts 100.00% <ø> (ø)
...les/credentials/formats/CredentialFormatService.ts 100.00% <ø> (ø)
...cation/handlers/V1RevocationNotificationHandler.ts 71.42% <ø> (ø)
...cation/handlers/V2RevocationNotificationHandler.ts 71.42% <ø> (ø)
...ges/core/src/modules/credentials/services/index.ts 100.00% <ø> (ø)
...ore/src/modules/dids/methods/web/WebDidResolver.ts 60.00% <ø> (ø)
...c/modules/routing/handlers/MediationDenyHandler.ts 62.50% <0.00%> (+6.94%) ⬆️
packages/core/src/transport/WsOutboundTransport.ts 9.23% <0.00%> (-2.37%) ⬇️
... and 99 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d88aa4...49c4d55. Read the comment docs.

@TimoGlastra TimoGlastra force-pushed the feat/add-agent-context-provider branch 2 times, most recently from 7f8f809 to 150b0bf Compare June 28, 2022 09:42
@TimoGlastra TimoGlastra added the breaking change PR that introduces a breaking change label Jun 30, 2022
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
@TimoGlastra TimoGlastra force-pushed the feat/add-agent-context-provider branch from 150b0bf to 49c4d55 Compare July 3, 2022 09:52
@TimoGlastra
Copy link
Contributor Author

Superseded by #921

@TimoGlastra TimoGlastra closed this Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change PR that introduces a breaking change multitenancy Tasks related to multi-tenancy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants