Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ def _convert_datetime_to_utc_int(expires_on):
epoch = time.mktime(datetime(1970, 1, 1).timetuple())
return epoch-time.mktime(expires_on.timetuple())


def parse_connection_str(conn_str):
# type: (str) -> Tuple[str, str, str, str]
if conn_str is None:
raise ValueError(
"Connection string is undefined."
)
endpoint = None
shared_access_key = None
for element in conn_str.split(";"):
Expand All @@ -33,8 +36,8 @@ def parse_connection_str(conn_str):
shared_access_key = value
if not all([endpoint, shared_access_key]):
raise ValueError(
"Invalid connection string. Should be in the format: "
"endpoint=sb://<FQDN>/;accesskey=<KeyValue>"
"Invalid connection string. You can get the connection string from your resource page in the Azure Portal. "
"The format should be as follows: endpoint=https://<ResourceUrl>/;accesskey=<KeyValue>"
)
left_slash_pos = cast(str, endpoint).find("//")
if left_slash_pos != -1:
Expand All @@ -44,7 +47,6 @@ def parse_connection_str(conn_str):

return host, str(shared_access_key)


def get_current_utc_time():
# type: () -> str
return str(datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT"
Expand All @@ -55,7 +57,6 @@ def get_current_utc_as_int():
current_utc_datetime = datetime.utcnow().replace(tzinfo=TZ_UTC)
return _convert_datetime_to_utc_int(current_utc_datetime)


def create_access_token(token):
# type: (str) -> azure.core.credentials.AccessToken
"""Creates an instance of azure.core.credentials.AccessToken from a
Expand Down Expand Up @@ -84,7 +85,6 @@ def create_access_token(token):
except ValueError:
raise ValueError(token_parse_err_msg)


def get_authentication_policy(
endpoint, # type: str
credential, # type: TokenCredential or str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
from msrest.serialization import TZ_UTC
from azure.core.credentials import AccessToken

def _convert_datetime_to_utc_int(expires_on):
epoch = time.mktime(datetime(1970, 1, 1).timetuple())
return epoch-time.mktime(expires_on.timetuple())

def parse_connection_str(conn_str):
# type: (str) -> Tuple[str, str, str, str]
if conn_str is None:
raise ValueError(
"Connection string is undefined."
)
endpoint = None
shared_access_key = None
for element in conn_str.split(";"):
Expand All @@ -27,8 +35,8 @@ def parse_connection_str(conn_str):
shared_access_key = value
if not all([endpoint, shared_access_key]):
raise ValueError(
"Invalid connection string. Should be in the format: "
"endpoint=sb://<FQDN>/;accesskey=<KeyValue>"
"Invalid connection string. You can get the connection string from your resource page in the Azure Portal. "
"The format should be as follows: endpoint=https://<ResourceUrl>/;accesskey=<KeyValue>"
)
left_slash_pos = cast(str, endpoint).find("//")
if left_slash_pos != -1:
Expand All @@ -38,11 +46,15 @@ def parse_connection_str(conn_str):

return host, str(shared_access_key)


def get_current_utc_time():
# type: () -> str
return str(datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT"

def get_current_utc_as_int():
# type: () -> int
current_utc_datetime = datetime.utcnow().replace(tzinfo=TZ_UTC)
return _convert_datetime_to_utc_int(current_utc_datetime)

def create_access_token(token):
# type: (str) -> azure.core.credentials.AccessToken
"""Creates an instance of azure.core.credentials.AccessToken from a
Expand All @@ -67,15 +79,14 @@ def create_access_token(token):
padded_base64_payload = base64.b64decode(parts[1] + "==").decode('ascii')
payload = json.loads(padded_base64_payload)
return AccessToken(token,
_convert_expires_on_datetime_to_utc_int(datetime.fromtimestamp(payload['exp']).replace(tzinfo=TZ_UTC)))
_convert_datetime_to_utc_int(datetime.fromtimestamp(payload['exp']).replace(tzinfo=TZ_UTC)))
except ValueError:
raise ValueError(token_parse_err_msg)

def _convert_expires_on_datetime_to_utc_int(expires_on):
epoch = time.mktime(datetime(1970, 1, 1).timetuple())
return epoch-time.mktime(expires_on.timetuple())


def get_authentication_policy(
endpoint, # type: str
credential, # type: TokenCredential or str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
from msrest.serialization import TZ_UTC
from azure.core.credentials import AccessToken

def _convert_datetime_to_utc_int(expires_on):
epoch = time.mktime(datetime(1970, 1, 1).timetuple())
return epoch-time.mktime(expires_on.timetuple())

def parse_connection_str(conn_str):
# type: (str) -> Tuple[str, str, str, str]
if conn_str is None:
raise ValueError(
"Connection string is undefined."
)
endpoint = None
shared_access_key = None
for element in conn_str.split(";"):
Expand All @@ -27,8 +35,8 @@ def parse_connection_str(conn_str):
shared_access_key = value
if not all([endpoint, shared_access_key]):
raise ValueError(
"Invalid connection string. Should be in the format: "
"endpoint=sb://<FQDN>/;accesskey=<KeyValue>"
"Invalid connection string. You can get the connection string from your resource page in the Azure Portal. "
"The format should be as follows: endpoint=https://<ResourceUrl>/;accesskey=<KeyValue>"
)
left_slash_pos = cast(str, endpoint).find("//")
if left_slash_pos != -1:
Expand All @@ -38,11 +46,15 @@ def parse_connection_str(conn_str):

return host, str(shared_access_key)


def get_current_utc_time():
# type: () -> str
return str(datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT"

def get_current_utc_as_int():
# type: () -> int
current_utc_datetime = datetime.utcnow().replace(tzinfo=TZ_UTC)
return _convert_datetime_to_utc_int(current_utc_datetime)

def create_access_token(token):
# type: (str) -> azure.core.credentials.AccessToken
"""Creates an instance of azure.core.credentials.AccessToken from a
Expand All @@ -67,7 +79,7 @@ def create_access_token(token):
padded_base64_payload = base64.b64decode(parts[1] + "==").decode('ascii')
payload = json.loads(padded_base64_payload)
return AccessToken(token,
_convert_expires_on_datetime_to_utc_int(datetime.fromtimestamp(payload['exp']).replace(tzinfo=TZ_UTC)))
_convert_datetime_to_utc_int(datetime.fromtimestamp(payload['exp']).replace(tzinfo=TZ_UTC)))
except ValueError:
raise ValueError(token_parse_err_msg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
from msrest.serialization import TZ_UTC
from azure.core.credentials import AccessToken

def _convert_datetime_to_utc_int(expires_on):
epoch = time.mktime(datetime(1970, 1, 1).timetuple())
return epoch-time.mktime(expires_on.timetuple())

def parse_connection_str(conn_str):
# type: (str) -> Tuple[str, str, str, str]
if conn_str is None:
raise ValueError(
"Connection string is undefined."
)
endpoint = None
shared_access_key = None
for element in conn_str.split(";"):
Expand All @@ -27,8 +35,8 @@ def parse_connection_str(conn_str):
shared_access_key = value
if not all([endpoint, shared_access_key]):
raise ValueError(
"Invalid connection string. Should be in the format: "
"endpoint=sb://<FQDN>/;accesskey=<KeyValue>"
"Invalid connection string. You can get the connection string from your resource page in the Azure Portal. "
"The format should be as follows: endpoint=https://<ResourceUrl>/;accesskey=<KeyValue>"
)
left_slash_pos = cast(str, endpoint).find("//")
if left_slash_pos != -1:
Expand All @@ -38,11 +46,15 @@ def parse_connection_str(conn_str):

return host, str(shared_access_key)


def get_current_utc_time():
# type: () -> str
return str(datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT"

def get_current_utc_as_int():
# type: () -> int
current_utc_datetime = datetime.utcnow().replace(tzinfo=TZ_UTC)
return _convert_datetime_to_utc_int(current_utc_datetime)

def create_access_token(token):
# type: (str) -> azure.core.credentials.AccessToken
"""Creates an instance of azure.core.credentials.AccessToken from a
Expand All @@ -67,7 +79,7 @@ def create_access_token(token):
padded_base64_payload = base64.b64decode(parts[1] + "==").decode('ascii')
payload = json.loads(padded_base64_payload)
return AccessToken(token,
_convert_expires_on_datetime_to_utc_int(datetime.fromtimestamp(payload['exp']).replace(tzinfo=TZ_UTC)))
_convert_datetime_to_utc_int(datetime.fromtimestamp(payload['exp']).replace(tzinfo=TZ_UTC)))
except ValueError:
raise ValueError(token_parse_err_msg)

Expand Down Expand Up @@ -101,7 +113,3 @@ def get_authentication_policy(

raise TypeError("Unsupported credential: {}. Use an access token string to use HMACCredentialsPolicy"
"or a token credential from azure.identity".format(type(credential)))

def _convert_expires_on_datetime_to_utc_int(expires_on):
epoch = time.mktime(datetime(1970, 1, 1).timetuple())
return epoch-time.mktime(expires_on.timetuple())