Skip to content

Commit

Permalink
Merge branch 'master' into feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Courtney (CJ) Oka authored May 5, 2017
2 parents 72a996d + 743b4fb commit e3f7506
Show file tree
Hide file tree
Showing 140 changed files with 11,477 additions and 916 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ src/build
/.vs/config/applicationhost.config
.vscode/settings.json
.vscode/.ropeproject/
.vscode/cSpell.json
.project
.pydevproject

Expand Down
13 changes: 0 additions & 13 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,6 @@
<Compile Include="command_modules\azure-cli-configure\azure\cli\command_modules\configure\__init__.py" />
<Compile Include="command_modules\azure-cli-configure\azure_bdist_wheel.py" />
<Compile Include="command_modules\azure-cli-configure\setup.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\commands.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\custom.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\_help.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\_params.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\__init__.py" />
<Compile Include="command_modules\azure-cli-container\azure_bdist_wheel.py" />
<Compile Include="command_modules\azure-cli-container\setup.py" />
<Compile Include="command_modules\azure-cli-dla\azure\cli\command_modules\dla\commands.py" />
<Compile Include="command_modules\azure-cli-dla\azure\cli\command_modules\dla\custom.py" />
<Compile Include="command_modules\azure-cli-dla\azure\cli\command_modules\dla\_client_factory.py" />
Expand Down Expand Up @@ -720,11 +713,6 @@
<Folder Include="command_modules\azure-cli-configure\azure\cli\" />
<Folder Include="command_modules\azure-cli-configure\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-configure\azure\cli\command_modules\configure\" />
<Folder Include="command_modules\azure-cli-container\" />
<Folder Include="command_modules\azure-cli-container\azure\" />
<Folder Include="command_modules\azure-cli-container\azure\cli\" />
<Folder Include="command_modules\azure-cli-container\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-container\azure\cli\command_modules\container\" />
<Folder Include="command_modules\azure-cli-dla\" />
<Folder Include="command_modules\azure-cli-dla\azure\" />
<Folder Include="command_modules\azure-cli-dla\azure\cli\" />
Expand Down Expand Up @@ -899,7 +887,6 @@
<Content Include="command_modules\azure-cli-cognitiveservices\README.rst" />
<Content Include="command_modules\azure-cli-component\HISTORY.rst" />
<Content Include="command_modules\azure-cli-configure\HISTORY.rst" />
<Content Include="command_modules\azure-cli-container\HISTORY.rst" />
<Content Include="command_modules\azure-cli-dla\HISTORY.rst" />
<Content Include="command_modules\azure-cli-dla\MANIFEST.in" />
<Content Include="command_modules\azure-cli-dla\README.rst" />
Expand Down
11 changes: 0 additions & 11 deletions azure-cli2017.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@
<Compile Include="command_modules\azure-cli-configure\azure\cli\command_modules\configure\_utils.py" />
<Compile Include="command_modules\azure-cli-configure\azure\cli\command_modules\configure\__init__.py" />
<Compile Include="command_modules\azure-cli-configure\setup.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\commands.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\custom.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\_help.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\_params.py" />
<Compile Include="command_modules\azure-cli-container\azure\cli\command_modules\container\__init__.py" />
<Compile Include="command_modules\azure-cli-container\setup.py" />
<Compile Include="command_modules\azure-cli-documentdb\azure\cli\command_modules\documentdb\commands.py" />
<Compile Include="command_modules\azure-cli-documentdb\azure\cli\command_modules\documentdb\custom.py" />
<Compile Include="command_modules\azure-cli-documentdb\azure\cli\command_modules\documentdb\_client_factory.py" />
Expand Down Expand Up @@ -497,11 +491,6 @@
<Folder Include="command_modules\azure-cli-configure\azure\cli\" />
<Folder Include="command_modules\azure-cli-configure\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-configure\azure\cli\command_modules\configure\" />
<Folder Include="command_modules\azure-cli-container\" />
<Folder Include="command_modules\azure-cli-container\azure\" />
<Folder Include="command_modules\azure-cli-container\azure\cli\" />
<Folder Include="command_modules\azure-cli-container\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-container\azure\cli\command_modules\container\" />
<Folder Include="command_modules\azure-cli-documentdb\" />
<Folder Include="command_modules\azure-cli-documentdb\azure\" />
<Folder Include="command_modules\azure-cli-documentdb\azure\cli\" />
Expand Down
3 changes: 1 addition & 2 deletions doc/sphinx/azhelpgen/doc_source_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"batch": "src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_help.py",
"cloud": "src/command_modules/azure-cli-cloud/azure/cli/command_modules/cloud/_help.py",
"component": "src/command_modules/azure-cli-component/azure/cli/command_modules/component/_help.py",
"container": "src/command_modules/azure-cli-container/azure/cli/command_modules/container/_help.py",
"feature": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py",
"group": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py",
"iot": "src/command_modules/azure-cli-iot/azure/cli/command_modules/iot/_help.py",
Expand All @@ -21,7 +20,7 @@
"policy": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py",
"provider": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py",
"redis": "src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py",
"resource": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py",
"resource": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py",
"role": "src/command_modules/azure-cli-role/azure/cli/command_modules/role/_help.py",
"sql": "src/command_modules/azure-cli-sql/azure/cli/command_modules/sql/help.py",
"storage": "src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_help.py",
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.1_python27.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ azure-cli-batch==0.1.1b4
azure-cli-cloud==0.1.2rc2
azure-cli-component==0.1.1rc2
azure-cli-configure==0.1.2rc2
azure-cli-container==0.1.1b3
azure-cli-core==0.1.2rc2
azure-cli-documentdb==0.1.1b2
azure-cli-feedback==0.1.2rc1
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.1_python35.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ azure-cli-batch==0.1.1b4
azure-cli-cloud==0.1.2rc2
azure-cli-component==0.1.1rc2
azure-cli-configure==0.1.2rc2
azure-cli-container==0.1.1b3
azure-cli-core==0.1.2rc2
azure-cli-documentdb==0.1.1b2
azure-cli-feedback==0.1.2rc1
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.2_python27.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ azure-cli-batch==0.1.1b4
azure-cli-cloud==2.0.0
azure-cli-component==2.0.0
azure-cli-configure==2.0.0
azure-cli-container==0.1.1b4
azure-cli-core==2.0.0
azure-cli-documentdb==0.1.1b2
azure-cli-feedback==2.0.0
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.2_python35.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ azure-cli-batch==0.1.1b4
azure-cli-cloud==2.0.0
azure-cli-component==2.0.0
azure-cli-configure==2.0.0
azure-cli-container==0.1.1b4
azure-cli-core==2.0.0
azure-cli-documentdb==0.1.1b2
azure-cli-feedback==2.0.0
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.3_python27.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ azure-cli-batch==0.1.1b5
azure-cli-cloud==2.0.0
azure-cli-component==2.0.0
azure-cli-configure==2.0.1
azure-cli-container==0.1.1b4
azure-cli-core==2.0.1
azure-cli-documentdb==0.1.1b2
azure-cli-feedback==2.0.0
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.3_python35.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ azure-cli-batch==0.1.1b5
azure-cli-cloud==2.0.0
azure-cli-component==2.0.0
azure-cli-configure==2.0.1
azure-cli-container==0.1.1b4
azure-cli-core==2.0.1
azure-cli-documentdb==0.1.1b2
azure-cli-feedback==2.0.0
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.4_python27.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ azure-cli-batch==2.0.0
azure-cli-cloud==2.0.0
azure-cli-component==2.0.0
azure-cli-configure==2.0.2
azure-cli-container==0.1.2
azure-cli-core==2.0.2
azure-cli-documentdb==0.1.2
azure-cli-feedback==2.0.0
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.4_python35.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ azure-cli-batch==2.0.0
azure-cli-cloud==2.0.0
azure-cli-component==2.0.0
azure-cli-configure==2.0.2
azure-cli-container==0.1.2
azure-cli-core==2.0.2
azure-cli-documentdb==0.1.2
azure-cli-feedback==2.0.0
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.5_python27.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ azure-cli-batch==2.0.1
azure-cli-cloud==2.0.1
azure-cli-component==2.0.1
azure-cli-configure==2.0.3
azure-cli-container==0.1.3
azure-cli-core==2.0.3
azure-cli-documentdb==0.1.3
azure-cli-feedback==2.0.1
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.5_python35.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ azure-cli-batch==2.0.1
azure-cli-cloud==2.0.1
azure-cli-component==2.0.1
azure-cli-configure==2.0.3
azure-cli-container==0.1.3
azure-cli-core==2.0.3
azure-cli-documentdb==0.1.3
azure-cli-feedback==2.0.1
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.6_python27.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ azure-cli-cloud==2.0.2
azure-cli-command-modules-nspkg==2.0.0
azure-cli-component==2.0.2
azure-cli-configure==2.0.4
azure-cli-container==0.1.4
azure-cli-core==2.0.4
azure-cli-documentdb==0.1.4
azure-cli-feedback==2.0.2
Expand Down
1 change: 0 additions & 1 deletion packaged_releases/pip_requirements/0.2.6_python35.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ azure-cli-cloud==2.0.2
azure-cli-command-modules-nspkg==2.0.0
azure-cli-component==2.0.2
azure-cli-configure==2.0.4
azure-cli-container==0.1.4
azure-cli-core==2.0.4
azure-cli-documentdb==0.1.4
azure-cli-feedback==2.0.2
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ adal==0.4.3
applicationinsights==0.10.0
argcomplete==1.8.0
colorama==0.3.7
humanfriendly==2.4
jmespath
mock==1.3.0
paramiko==2.0.2
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli-core/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release History
^^^^^^^^^^^^^^^^^^
* core: capture exceptions caused by unregistered provider and auto-register it
* login: avoid the bad exception when the user account has no subscription and no tenants
* perf: persist adal token cache in memory till process exits (#2603)

2.0.4 (2017-04-28)
^^^^^^^^^^^^^^^^^^
Expand Down
47 changes: 33 additions & 14 deletions src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,20 @@ class CredentialType(Enum): # pylint: disable=too-few-public-methods
rbac = CLOUD.endpoints.active_directory_graph_resource_id


_GLOBAL_CREDS_CACHE = None


class Profile(object):
def __init__(self, storage=None, auth_ctx_factory=None):
def __init__(self, storage=None, auth_ctx_factory=None, use_global_creds_cache=True):
self._storage = storage or ACCOUNT
self.auth_ctx_factory = auth_ctx_factory or _AUTH_CTX_FACTORY
self._creds_cache = CredsCache(self.auth_ctx_factory)
if use_global_creds_cache:
global _GLOBAL_CREDS_CACHE # pylint: disable=global-statement
if _GLOBAL_CREDS_CACHE is None:
_GLOBAL_CREDS_CACHE = CredsCache(self.auth_ctx_factory, async_persist=True)
self._creds_cache = _GLOBAL_CREDS_CACHE
else:
self._creds_cache = CredsCache(self.auth_ctx_factory, async_persist=False)
self._management_resource_uri = CLOUD.endpoints.management
self._ad_resource_uri = CLOUD.endpoints.active_directory_resource_id

Expand Down Expand Up @@ -470,29 +479,39 @@ class CredsCache(object):
also be handled
'''

def __init__(self, auth_ctx_factory=None):
def __init__(self, auth_ctx_factory=None, async_persist=True):
# AZURE_ACCESS_TOKEN_FILE is used by Cloud Console and not meant to be user configured
self._token_file = (os.environ.get('AZURE_ACCESS_TOKEN_FILE', None) or
os.path.join(get_config_dir(), 'accessTokens.json'))
self._service_principal_creds = []
self._auth_ctx_factory = auth_ctx_factory or _AUTH_CTX_FACTORY
self._adal_token_cache_attr = None
self._should_flush_to_disk = False
self._async_persist = async_persist
if async_persist:
import atexit
atexit.register(self.flush_to_disk)

def persist_cached_creds(self):
with os.fdopen(os.open(self._token_file, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o600),
'w+') as cred_file:
items = self.adal_token_cache.read_items()
all_creds = [entry for _, entry in items]
self._should_flush_to_disk = True
if not self._async_persist:
self.flush_to_disk()
self.adal_token_cache.has_state_changed = False

# trim away useless fields (needed for cred sharing with xplat)
for i in all_creds:
for key in TOKEN_FIELDS_EXCLUDED_FROM_PERSISTENCE:
i.pop(key, None)
def flush_to_disk(self):
if self._should_flush_to_disk:
with os.fdopen(os.open(self._token_file, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o600),
'w+') as cred_file:
items = self.adal_token_cache.read_items()
all_creds = [entry for _, entry in items]

all_creds.extend(self._service_principal_creds)
cred_file.write(json.dumps(all_creds))
# trim away useless fields (needed for cred sharing with xplat)
for i in all_creds:
for key in TOKEN_FIELDS_EXCLUDED_FROM_PERSISTENCE:
i.pop(key, None)

self.adal_token_cache.has_state_changed = False
all_creds.extend(self._service_principal_creds)
cred_file.write(json.dumps(all_creds))

def retrieve_token_for_user(self, username, tenant, resource):
authority = get_authority_url(tenant)
Expand Down
6 changes: 6 additions & 0 deletions src/azure-cli-core/azure/cli/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import azure.cli.core.azlogging as azlogging
from azure.cli.core.util import todict, truncate_text, CLIError, read_file_content
from azure.cli.core._config import az_config
import azure.cli.core.commands.progress as progress

import azure.cli.core.telemetry as telemetry

Expand Down Expand Up @@ -127,6 +128,11 @@ def __init__(self, configuration=None):

self.parser = AzCliCommandParser(prog='az', parents=[self.global_parser])
self.configuration = configuration
self.progress_controller = progress.ProgressHook()

def get_progress_controller(self):
self.progress_controller.init_progress(progress.get_progress_view())
return self.progress_controller

def initialize(self, configuration):
self.configuration = configuration
Expand Down
Loading

0 comments on commit e3f7506

Please sign in to comment.