def get_access_token_from_cli():
<EOL>if '<STR_LIT>' in os.environ and '<STR_LIT>' in os.environ:<EOL><INDENT>endpoint = os.environ['<STR_LIT>']<EOL>headers = {'<STR_LIT>': '<STR_LIT:true>'}<EOL>body = {"<STR_LIT>": "<STR_LIT>"}<EOL>ret = requests.post(endpoint, headers=headers, data=body)<EOL>return ret.json()['<STR_LIT>']<EOL><DEDENT>else: <EOL><INDENT>home = os.path.expanduser('<STR_LIT>')<EOL>sub_username = "<STR_LIT>"<EOL>azure_profile_path = home + os.sep + '<STR_LIT>' + os.sep + '<STR_LIT>'<EOL>if os.path.isfile(azure_profile_path) is False:<EOL><INDENT>print('<STR_LIT>' + azure_profile_path)<EOL>return None<EOL><DEDENT>with codecs.open(azure_profile_path, '<STR_LIT:r>', '<STR_LIT>') as azure_profile_fd:<EOL><INDENT>subs = json.load(azure_profile_fd)<EOL><DEDENT>for sub in subs['<STR_LIT>']:<EOL><INDENT>if sub['<STR_LIT>'] == True:<EOL><INDENT>sub_username = sub['<STR_LIT:user>']['<STR_LIT:name>']<EOL><DEDENT><DEDENT>if sub_username == "<STR_LIT>":<EOL><INDENT>print('<STR_LIT>' +azure_profile_path)<EOL>return None<EOL><DEDENT>access_keys_path = home + os.sep + '<STR_LIT>' + os.sep + '<STR_LIT>'<EOL>if os.path.isfile(access_keys_path) is False:<EOL><INDENT>print('<STR_LIT>' + access_keys_path)<EOL>return None<EOL><DEDENT>with open(access_keys_path, '<STR_LIT:r>') as access_keys_fd:<EOL><INDENT>keys = json.load(access_keys_fd)<EOL><DEDENT>for key in keys:<EOL><INDENT>if key['<STR_LIT>'] == sub_username:<EOL><INDENT>if '<STR_LIT>' not in keys[<NUM_LIT:0>]:<EOL><INDENT>print('<STR_LIT>' +access_keys_path)<EOL>return None<EOL><DEDENT>if '<STR_LIT>' not in keys[<NUM_LIT:0>]:<EOL><INDENT>print('<STR_LIT>' +access_keys_path)<EOL>return None<EOL><DEDENT>if '<STR_LIT>' not in keys[<NUM_LIT:0>]:<EOL><INDENT>print('<STR_LIT>' +access_keys_path)<EOL>return None<EOL><DEDENT>expiry_date_str = key['<STR_LIT>']<EOL>if '<STR_LIT:T>' in expiry_date_str:<EOL><INDENT>exp_date = dt.strptime(key['<STR_LIT>'], '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>exp_date = dt.strptime(key['<STR_LIT>'], '<STR_LIT>')<EOL><DEDENT>if exp_date < dt.now():<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>return key['<STR_LIT>']<EOL><DEDENT><DEDENT><DEDENT>print('<STR_LIT>')<EOL>return None<EOL><DEDENT>
Get an Azure authentication token from CLI's cache.

    Will only work if CLI local cache has an unexpired auth token (i.e. you ran 'az login'
        recently), or if you are running in Azure Cloud Shell (aka cloud console)

    Returns:
        An Azure authentication token string.