Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
</Compile>
<Compile Include="azure\cli\tests\test_profile.py" />
<Compile Include="azure\cli\_argparse.py" />
<Compile Include="azure\cli\commands\_command_creation.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\cli\_debug.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\cli\_logging.py" />
<Compile Include="azure\cli\_profile.py" />
<Compile Include="azure\cli\_session.py">
Expand Down
11 changes: 11 additions & 0 deletions src/azure/cli/_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

def allow_debug_connection(client):
if should_allow_debug_connection():
client.config.connection.verify = False

def should_allow_debug_connection():
try:
return bool(os.environ['AllowDebug'])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use get instead of try catch
change var name

except KeyError:
return False
8 changes: 8 additions & 0 deletions src/azure/cli/commands/_command_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .._profile import Profile
import azure.cli._debug as _debug

def get_service_client(clientType, configType):
profile = Profile()
client = clientType(configType(*profile.get_login_credentials()))
_debug.allow_debug_connection(client)
return client
3 changes: 2 additions & 1 deletion src/azure/cli/commands/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .._profile import Profile
from .._util import TableOutput
from ..commands import command, description, option
import azure.cli._debug as _debug

CLIENT_ID = '04b07795-8ddb-461a-bbee-02f9e1bf7b46'

Expand All @@ -20,7 +21,7 @@ def login(args, unexpected):
import getpass
password = getpass.getpass(_('Password: '))

credentials = UserPassCredentials(username, password, client_id=CLIENT_ID)
credentials = UserPassCredentials(username, password, client_id=CLIENT_ID, verify=_debug.should_allow_debug_connection())
client = SubscriptionClient(SubscriptionClientConfiguration(credentials))
subscriptions = client.subscriptions.list()

Expand Down
11 changes: 4 additions & 7 deletions src/azure/cli/commands/storage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from ..main import SESSION
from .._logging import logging
from .._logging import logger
from .._util import TableOutput
from ..commands import command, description, option
from .._profile import Profile
from ._command_creation import get_service_client

@command('storage account list')
@description(_('List storage accounts'))
Expand All @@ -13,10 +13,7 @@ def list_accounts(args, unexpected):
from azure.mgmt.storage.models import StorageAccount
from msrestazure.azure_active_directory import UserPassCredentials

profile = Profile()
smc = StorageManagementClient(StorageManagementClientConfiguration(
*profile.get_login_credentials(),
))
smc = get_service_client(StorageManagementClient, StorageManagementClientConfiguration)

group = args.get('resource-group')
if group:
Expand All @@ -39,7 +36,7 @@ def list_accounts(args, unexpected):
def checkname(args, unexpected):
from azure.mgmt.storage import StorageManagementClient, StorageManagementClientConfiguration

smc = StorageManagementClient(StorageManagementClientConfiguration())
smc = get_service_client(StorageManagementClient, StorageManagementClientConfiguration)
logger.warn(smc.storage_accounts.check_name_availability(args.account_name))