Skip to content

Commit

Permalink
Addressed pylint issues (lots of disabling)
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Treasure committed Feb 12, 2021
1 parent c95953d commit ce45bf5
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
except ImportError:
from urlparse import urlparse # type: ignore

from azure.core.credentials import AccessToken, AzureKeyCredential
from azure.core.credentials import AzureKeyCredential
from azure.core.tracing.decorator import distributed_trace
from azure.core.pipeline.policies import BearerTokenCredentialPolicy

Expand All @@ -24,7 +24,6 @@
if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Union
from azure.core.credentials import TokenCredential


class MixedRealityStsClient(object):
Expand Down Expand Up @@ -65,6 +64,7 @@ def __init__(self, account_id, account_domain, credential, **kwargs):
if not endpoint_url.lower().startswith('http'):
endpoint_url = "https://" + endpoint_url
except AttributeError:
#pylint: disable=raise-missing-from
raise ValueError("Host URL must be a string")

parsed_url = urlparse(endpoint_url.rstrip('/'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
# --------------------------------------------------------------------------
from typing import TYPE_CHECKING

from .static_access_token_credential import StaticAccessTokenCredential
from ...aio._client_async import MixedRealityStsClient

if TYPE_CHECKING:
from typing import Any
from azure.core.credentials import AccessToken
from azure.core.credentials_async import AsyncTokenCredential

from .static_access_token_credential import StaticAccessTokenCredential
from ...aio._client_async import MixedRealityStsClient

def get_mixedreality_credential(
account_id: str,
account_domain: str,
endpoint_url: str,
credential: "AsyncTokenCredential",
**kwargs):
if isinstance(credential, StaticAccessTokenCredential):
return credential
if isinstance(credential, StaticAccessTokenCredential):
return credential

return MixedRealityTokenCredential(
account_id=account_id,
account_domain=account_domain,
endpoint_url=endpoint_url,
credential=credential,
**kwargs)
return MixedRealityTokenCredential(
account_id=account_id,
account_domain=account_domain,
endpoint_url=endpoint_url,
credential=credential,
**kwargs)


class MixedRealityTokenCredential(object):
Expand All @@ -39,15 +39,21 @@ class MixedRealityTokenCredential(object):
:param TokenCredential credential: The credential used to access the Mixed Reality service.
"""

def __init__(self, account_id: str, account_domain: str, endpoint_url: str, credential: "AsyncTokenCredential", **kwargs):
def __init__(
self,
account_id: str,
account_domain: str,
endpoint_url: str,
credential: "AsyncTokenCredential",
**kwargs):
self.stsClient = MixedRealityStsClient(
account_id=account_id,
account_domain=account_domain,
endpoint_url=endpoint_url,
credential=credential,
**kwargs)

async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken": #pylint: disable=unused-argument
return await self.stsClient.get_token(**kwargs)

async def close(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, account_id, account_key):
self.account_id = account_id
self.account_key = account_key

async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken": #pylint: disable=unused-argument
token = self.account_id + ":" + self.account_key.key

# No way to know when an access token might expire, so we'll set it to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import asyncio
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -21,7 +20,11 @@ class StaticAccessTokenCredential(object):
def __init__(self, access_token: "AccessToken"):
self._access_token = access_token

async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
async def get_token(
self,
#pylint: disable=unused-argument
*scopes: str,
**kwargs: "Any") -> "AccessToken":
return self._access_token

async def close(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
# --------------------------------------------------------------------------
from typing import TYPE_CHECKING

from .static_access_token_credential import StaticAccessTokenCredential
from .._client import MixedRealityStsClient

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Union
from azure.core.credentials import AccessToken, TokenCredential

from .static_access_token_credential import StaticAccessTokenCredential
from .._client import MixedRealityStsClient

def get_mixedreality_credential(account_id, account_domain, endpoint_url, credential, **kwargs):
# type: (str, str, str, TokenCredential, Any) -> TokenCredential
if isinstance(credential, StaticAccessTokenCredential):
return credential
# type: (str, str, str, TokenCredential, Any) -> TokenCredential
if isinstance(credential, StaticAccessTokenCredential):
return credential

return MixedRealityTokenCredential(
account_id=account_id,
account_domain=account_domain,
endpoint_url=endpoint_url,
credential=credential,
**kwargs)
return MixedRealityTokenCredential(
account_id=account_id,
account_domain=account_domain,
endpoint_url=endpoint_url,
credential=credential,
**kwargs)


class MixedRealityTokenCredential(object):
Expand All @@ -44,6 +45,6 @@ def __init__(self, account_id, account_domain, endpoint_url, credential, **kwarg
credential=credential,
**kwargs)

def get_token(self, *scopes, **kwargs):
def get_token(self, *scopes, **kwargs): #pylint: disable=unused-argument
# type: (*str, **Any) -> AccessToken
return self.stsClient.get_token(**kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, account_id, account_key):
self.account_id = account_id
self.account_key = account_key

def get_token(self, *scopes, **kwargs):
def get_token(self, *scopes, **kwargs): #pylint: disable=unused-argument
# type: (*str, **Any) -> azure.core.credentials.AccessToken

token = self.account_id + ":" + self.account_key.key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def __init__(self, access_token):
# type: (AccessToken) -> None
self._access_token = access_token

def get_token(self, *scopes, **kwargs):
def get_token(self, *scopes, **kwargs): #pylint: disable=unused-argument
# type: (*str, **Any) -> AccessToken
return self._access_token
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ def retrieve_jwt_expiration_timestamp(jwt_value):
padded_base64_payload = base64.b64decode(parts[1])
payload = json.loads(padded_base64_payload)
except ValueError:
#pylint: disable=raise-missing-from
raise ValueError("Unable to decode the JWT.")

try:
exp = payload['exp']
except KeyError:
#pylint: disable=raise-missing-from
raise ValueError("Invalid JWT payload structure. No expiration.")

return int(exp)
Expand All @@ -65,6 +67,7 @@ def generate_cv_base():
"""
result = ''

#pylint: disable=unused-variable
for i in range(CV_BASE_LENGTH):
random_index = random.randint(0, len(BASE_64_CHAR_SET) - 1)
result += BASE_64_CHAR_SET[random_index]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# matches SEMVER
VERSION = "1.0.0b1"

SDK_MONIKER = "mixedreality-authentication/{}".format(VERSION) # type: str
SDK_MONIKER = "mixedreality-authentication/{}".format(VERSION) # type: str
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import TYPE_CHECKING

# pylint: disable=unused-import,ungrouped-imports
from typing import Any, TYPE_CHECKING, Union

try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse # type: ignore

# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Union

from azure.core.credentials import AzureKeyCredential
from azure.core.tracing.decorator_async import distributed_trace_async
from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy
Expand Down Expand Up @@ -45,7 +44,7 @@ class MixedRealityStsClient(object):
def __init__(self,
account_id: str,
account_domain: str,
credential: Union[AzureKeyCredential, "AsyncTokenCredential"],
credential: Union[AzureKeyCredential, "AsyncTokenCredential"], #pylint: disable=unsubscriptable-object
**kwargs) -> None:
if not account_id:
raise ValueError("account_id can not be None")
Expand All @@ -70,6 +69,7 @@ def __init__(self,
if not endpoint_url.lower().startswith('http'):
endpoint_url = "https://" + endpoint_url
except AttributeError:
#pylint: disable=raise-missing-from
raise ValueError("Host URL must be a string")

parsed_url = urlparse(endpoint_url.rstrip('/'))
Expand Down

0 comments on commit ce45bf5

Please sign in to comment.