-
Notifications
You must be signed in to change notification settings - Fork 42
Internal utilities and wrappers for Storage protocols #201
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
Draft
rodrigobr-msft
wants to merge
10
commits into
main
Choose a base branch
from
users/robrandao/storage-wrappers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8029318
Reorganizing storage modules
rodrigobr-msft 3426524
Adding storage wrappers
rodrigobr-msft 089ff32
Implementing MemoryCache
rodrigobr-msft 2b746aa
MemoryCache implementation
rodrigobr-msft b250532
Adding tests for namespaced storage
rodrigobr-msft 66e4b4a
Resolving merge conflict
rodrigobr-msft 76c92a6
Integrating new storage wrappers
rodrigobr-msft b1c79c9
Shelving this code
rodrigobr-msft 5402b1f
Refactoring Authorization and UserAuthorization
rodrigobr-msft 050fc04
ItemNamespace tests intro
rodrigobr-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from ._error_handling import ( | ||
| _raise_if_falsey, | ||
| _raise_if_none, | ||
| ) | ||
| from ._load_configuration import load_configuration_from_env | ||
|
|
||
| __all__ = [ | ||
| "_raise_if_falsey", | ||
| "_raise_if_none", | ||
| "load_configuration_from_env", | ||
| ] |
30 changes: 30 additions & 0 deletions
30
libraries/microsoft-agents-activity/microsoft_agents/activity/_utils/_error_handling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| def _raise_if_none(label: str, **kwargs) -> None: | ||
| """Raises an exception if any of the provided keyword arguments are None. | ||
|
|
||
| :param label: A label to include in the exception message. | ||
| :param kwargs: The keyword arguments to check. | ||
| :raises ValueError: If any of the provided keyword arguments are None. | ||
| """ | ||
|
|
||
| none_args = [name for name, value in kwargs.items() if value is None] | ||
| if none_args: | ||
| raise ValueError( | ||
| f"{label}: The following arguments must be set and non-None: {', '.join(none_args)}" | ||
| ) | ||
|
|
||
| def _raise_if_falsey(label: str, **kwargs) -> None: | ||
| """Raises an exception if any of the provided keyword arguments are falsey. | ||
|
|
||
| :param label: A label to include in the exception message. | ||
| :param kwargs: The keyword arguments to check. | ||
| :raises ValueError: If any of the provided keyword arguments are falsey. | ||
| """ | ||
|
|
||
| falsey_args = [name for name, value in kwargs.items() if not value] | ||
| if falsey_args: | ||
| raise ValueError( | ||
| f"{label}: The following arguments must be set and non-falsey (cannot be None or an empty string, for example): {', '.join(falsey_args)}" | ||
| ) |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 0 additions & 93 deletions
93
...icrosoft-agents-hosting-core/microsoft_agents/hosting/core/_oauth/_flow_storage_client.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,13 @@ | |
| _OAuthFlow, | ||
| _FlowResponse, | ||
| _FlowState, | ||
| _FlowStorageClient, | ||
| _FlowStateTag, | ||
| ) | ||
| from microsoft_agents.hosting.core.storage import ( | ||
| _ItemNamespace, | ||
| _Namespaces | ||
| ) | ||
|
|
||
| from .._sign_in_response import _SignInResponse | ||
| from ._authorization_handler import _AuthorizationHandler | ||
|
|
||
|
|
@@ -41,7 +45,7 @@ class _UserAuthorization(_AuthorizationHandler): | |
|
|
||
| async def _load_flow( | ||
| self, context: TurnContext | ||
| ) -> tuple[_OAuthFlow, _FlowStorageClient]: | ||
| ) -> tuple[_OAuthFlow, _ItemNamespace[_FlowState]]: | ||
| """Loads the OAuth flow for a specific auth handler. | ||
|
|
||
| A new flow is created in Storage if none exists for the channel, user, and handler | ||
|
|
@@ -72,9 +76,13 @@ async def _load_flow( | |
| ms_app_id = context.turn_state.get(context.adapter.AGENT_IDENTITY_KEY).claims[ | ||
| "aud" | ||
| ] | ||
|
|
||
| namespace = _Namespaces._USER_AUTHORIZATION.format( | ||
| channel_id=channel_id, | ||
| user_id=user_id, | ||
|
||
| ) | ||
| flow_storage_client = _ItemNamespace(namespace, self._storage, _FlowState) | ||
|
|
||
| # try to load existing state | ||
| flow_storage_client = _FlowStorageClient(channel_id, user_id, self._storage) | ||
| logger.info("Loading OAuth flow state from storage") | ||
| flow_state: _FlowState = await flow_storage_client.read(self._id) | ||
| if not flow_state: | ||
|
|
@@ -86,7 +94,6 @@ async def _load_flow( | |
| connection=self._handler.abs_oauth_connection_name, | ||
| ms_app_id=ms_app_id, | ||
| ) | ||
| # await flow_storage_client.write(flow_state) | ||
|
|
||
| flow = _OAuthFlow(flow_state, user_token_client) | ||
| return flow, flow_storage_client | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference to '_Namespaces._USER_AUTHORIZATION' is incorrect. The attribute in _namespaces.py is defined as 'USER_AUTHORIZATION' (without underscore prefix), so this should be '_Namespaces.USER_AUTHORIZATION'.