Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Expose Services to be configurable for account SAS generation
  • Loading branch information
vincenttran-msft committed Feb 21, 2024
commit 72bfc0c6eb6508f363862118ae2c969e2a87e4db
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,17 @@ def get_token(self):


def generate_account_sas(
account_name, # type: str
account_key, # type: str
resource_types, # type: Union[ResourceTypes, str]
permission, # type: Union[AccountSasPermissions, str]
expiry, # type: Union[datetime, str]
start=None, # type: Optional[Union[datetime, str]]
ip=None, # type: Optional[str]
**kwargs # type: Any
): # type: (...) -> str
account_name: str,
account_key: str,
resource_types: Union["ResourceTypes", str],
permission: Union["AccountSasPermissions", str],
expiry: Union["datetime", str],
start: Optional[Union["datetime", str]] = None,
ip: Optional[str] = None,
*,
services: Services = Services(blob=True),
**kwargs: Any
) -> str:
"""Generates a shared access signature for the blob service.

Use the returned signature with the credential parameter of any BlobServiceClient,
Expand Down Expand Up @@ -351,6 +353,9 @@ def generate_account_sas(
or address range specified on the SAS token, the request is not authenticated.
For example, specifying ip=168.1.5.65 or ip=168.1.5.60-168.1.5.70 on the SAS
restricts the request to those IP addresses.
:keyword Services services:
Specifies the services that the Shared Access Signature (sas) token will be able to be utilized with. Will default
to only this package (i.e. blobs) if not provided.
:keyword str protocol:
Specifies the protocol permitted for a request made. The default value is https.
:keyword str encryption_scope:
Expand All @@ -369,7 +374,7 @@ def generate_account_sas(
"""
sas = SharedAccessSignature(account_name, account_key)
return sas.generate_account(
services=Services(blob=True),
services=services,
resource_types=resource_types,
permission=permission,
expiry=expiry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from azure.storage.blob import generate_account_sas as generate_blob_account_sas
from azure.storage.blob import generate_container_sas, generate_blob_sas
from ._shared.models import Services
from ._shared.shared_access_signature import QueryStringConstants


Expand All @@ -26,13 +27,17 @@


def generate_account_sas(
account_name, # type: str
account_key, # type: str
resource_types, # type: Union[ResourceTypes, str]
permission, # type: Union[AccountSasPermissions, str]
expiry, # type: Union[datetime, str]
**kwargs # type: Any
): # type: (...) -> str
account_name: str,
account_key: str,
resource_types: Union["ResourceTypes", str],
permission: Union["AccountSasPermissions", str],
expiry: Union["datetime", str],
start: Optional[Union["datetime", str]] = None,
ip: Optional[str] = None,
*,
services: Services = Services(blob=True),
**kwargs: Any
) -> str:
"""Generates a shared access signature for the DataLake service.

Use the returned signature as the credential parameter of any DataLakeServiceClient,
Expand Down Expand Up @@ -67,6 +72,9 @@ def generate_account_sas(
or address range specified on the SAS token, the request is not authenticated.
For example, specifying ip=168.1.5.65 or ip=168.1.5.60-168.1.5.70 on the SAS
restricts the request to those IP addresses.
:keyword Services services:
Specifies the services that the Shared Access Signature (sas) token will be able to be utilized with. Will default
to only this package (i.e. blobs) if not provided.
:keyword str protocol:
Specifies the protocol permitted for a request made. The default value is https.
:keyword str encryption_scope:
Expand All @@ -80,6 +88,7 @@ def generate_account_sas(
resource_types=resource_types,
permission=permission,
expiry=expiry,
services=services,
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,17 @@ def get_value_to_append(query):


def generate_account_sas(
account_name, # type: str
account_key, # type: str
resource_types, # type: Union[ResourceTypes, str]
permission, # type: Union[AccountSasPermissions, str]
expiry, # type: Union[datetime, str]
start=None, # type: Optional[Union[datetime, str]]
ip=None, # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> str
account_name: str,
account_key: str,
resource_types: Union["ResourceTypes", str],
permission: Union["AccountSasPermissions", str],
expiry: Union["datetime", str],
start: Optional[Union["datetime", str]] = None,
ip: Optional[str] = None,
*,
services: Services = Services(fileshare=True),
**kwargs: Any
) -> str:
"""Generates a shared access signature for the file service.

Use the returned signature with the credential parameter of any ShareServiceClient,
Expand Down Expand Up @@ -284,6 +285,9 @@ def generate_account_sas(
or address range specified on the SAS token, the request is not authenticated.
For example, specifying sip=168.1.5.65 or sip=168.1.5.60-168.1.5.70 on the SAS
restricts the request to those IP addresses.
:keyword Services services:
Specifies the services that the Shared Access Signature (sas) token will be able to be utilized with. Will default
to only this package (i.e. fileshare) if not provided.
:keyword str protocol:
Specifies the protocol permitted for a request made. The default value is https.
:return: A Shared Access Signature (sas) token.
Expand All @@ -300,7 +304,7 @@ def generate_account_sas(
"""
sas = SharedAccessSignature(account_name, account_key)
return sas.generate_account(
services=Services(fileshare=True),
services=services,
resource_types=resource_types,
permission=permission,
expiry=expiry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def generate_account_sas(
expiry: Union["datetime", str],
start: Optional[Union["datetime", str]] = None,
ip: Optional[str] = None,
*,
services: Services = Services(queue=True),
**kwargs: Any
) -> str:
"""Generates a shared access signature for the queue service.
Expand Down Expand Up @@ -175,14 +177,17 @@ def generate_account_sas(
or address range specified on the SAS token, the request is not authenticated.
For example, specifying sip=168.1.5.65 or sip=168.1.5.60-168.1.5.70 on the SAS
restricts the request to those IP addresses.
:keyword Services services:
Specifies the services that the Shared Access Signature (sas) token will be able to be utilized with. Will default
to only this package (i.e. queue) if not provided.
:keyword str protocol:
Specifies the protocol permitted for a request made. The default value is https.
:return: A Shared Access Signature (sas) token.
:rtype: str
"""
sas = SharedAccessSignature(account_name, account_key)
return sas.generate_account(
services=Services(queue=True),
services=services,
resource_types=resource_types,
permission=permission,
expiry=expiry,
Expand Down