Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
yugangw-msft committed Oct 26, 2018
1 parent 5d223e5 commit 17dbd90
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions msrestazure/azure_local_creds_prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
#pylint: disable=too-few-public-methods,missing-docstring

class CredsProber:

'''
Prober base class
'''
def __init__(self, resource):
self.enabled = True
self.resource = resource
Expand All @@ -64,7 +66,9 @@ def probe_subscription(self, creds): # pylint: disable=no-self-use


class ManagedServiceIdentityProber(CredsProber):

'''
Detect managed service identity coming with VM, VM scaleset, and App Service
'''
def probe(self):
if not self.enabled:
return None
Expand All @@ -78,20 +82,20 @@ def probe(self):

class ConnectionStrEnvProber(CredsProber):
'''
Detect environment variable AZURE_CONN_STR
Detect environment variable AZURE_CONNECTION_STRING
'''
def probe(self):
creds = None
if self.enabled and os.environ.get('AZURE_CONN_STR'):
auth_info = json.loads(os.environ.get('AZURE_CONN_STR'))
if self.enabled and os.environ.get('AZURE_CONNECTION_STRING'):
auth_info = json.loads(os.environ.get('AZURE_CONNECTION_STRING'))
creds = ServicePrincipalCredentials(client_id=auth_info['clientId'],
secret=auth_info['clientSecret'],
tennt_id=auth_info['tenantId'])
return creds
return None

def probe_subscription(self, creds):
return json.loads(os.environ.get('AZURE_CONN_STR'))['subscriptionId']
return json.loads(os.environ.get('AZURE_CONNECTION_STRING'))['subscriptionId']


class ServicePrincipalEnvProber(CredsProber):
Expand Down Expand Up @@ -157,7 +161,9 @@ def probe_subscription(self, creds):


class CLICredentials(BasicTokenAuthentication):

'''
Credentials objects for AAD token retrieved through sub-shelling "az account get-access-token"
'''
def __init__(self, cli_path, subscription_id=None):
super(CLICredentials, self).__init__(None)
self.cli_path = cli_path
Expand Down Expand Up @@ -224,6 +230,9 @@ def get_creds_through_local_probing(**kwargs):


def get_client_through_local_creds_probing(client_class, **kwargs):
'''
Helper method to create management client using probed local credentials
'''
creds, prober = _get_creds_through_local_probing(**kwargs)
subscription_id = kwargs.get('subscription_id')
if not subscription_id:
Expand Down

0 comments on commit 17dbd90

Please sign in to comment.