Skip to content

[Storage] added SessionProvider to create session - #48756

Open
anjaliratnam-msft wants to merge 1 commit into
Azure:feature/storage/create-sessionfrom
anjaliratnam-msft:session-provider
Open

[Storage] added SessionProvider to create session#48756
anjaliratnam-msft wants to merge 1 commit into
Azure:feature/storage/create-sessionfrom
anjaliratnam-msft:session-provider

Conversation

@anjaliratnam-msft

Copy link
Copy Markdown
Member

Summary
This PR introduces SessionProvider building off the previous session PR. Customers can optionally supply one via session_options.session_provider and reuse it across clients to share the cache. If it's not supplied, one is created and scoped to the client, so existing behavior is unchanged.

Not in this PR

  • Did not implement the async changes
  • SessionOptions.account_name. The optional signing override, with URL extraction as fallback and the custom-endpoint caveat documented.
  • Test updates. The existing session test reaches into internals that moved.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

StorageSensitiveHeaderCleanupPolicy(**kwargs),
]
use_session = bool(kwargs.pop("use_session", False))
session_options = kwargs.pop("session_options", None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should not take an options bag, instead just take each individual option as an individual kwarg. In this case session_provider.


session_provider = getattr(session_options, "session_provider", None)
if session_provider is None:
from .session_provider import ContainerSessionProvider # module-level import would cycle

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it create a cycle?

if account_name is None:
raise ValueError(
"Unable to determine the account name from the service URL. "
"Supply session_options.account_name when using a custom endpoint."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should handle account name a little differently than other languages. Will discuss offline.

:keyword str audience: The audience to use when requesting tokens for Azure Active Directory
authentication. Only has an effect when credential is of type TokenCredential. The value could be
https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
:keyword bool use_session: If True, enable session-based authentication for this container.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will need to add session provider argument anywhere we have this one.

self.position = position


class SessionOptions(object):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As mentioned before, we should just get rid of this.

Also, a little note if we were to keep this, we don't need to inherit from object anymore. That is something we had to do for older Python versions so you may see remnants in the code (and AI may pick up on them) but for any new classes, we don't need to do this.

use_session = bool(kwargs.pop("use_session", False))
session_options = kwargs.pop("session_options", None)
if use_session:
if not hasattr(credential, "get_token"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's let the session provider constructor handle this check now.

return status == 400 and error_code == StorageErrorCode.FEATURE_NOT_ENABLED


class ContainerSessionProvider:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Jus tone file. Put everything in session.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Storage Storage Service (Queues, Blobs, Files)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants