Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from azure.cli.core._environment import get_config_dir
from azure.cli.core._session import ACCOUNT
from azure.cli.core.util import get_file_json, in_cloud_console, open_page_in_browser, can_launch_browser
from azure.cli.core.util import get_file_json, in_cloud_console, open_page_in_browser, can_launch_browser,\
is_windows, is_wsl
from azure.cli.core.cloud import get_active_cloud, set_cloud_subscription

from knack.log import get_logger
Expand Down Expand Up @@ -1089,6 +1090,16 @@ def _get_authorization_code_worker(authority_url, resource, results):
import random

reply_url = None

# On Windows, HTTPServer by default doesn't throw error if the port is in-use
# https://github.com/Azure/azure-cli/issues/10578
if is_windows():
logger.debug('Windows is detected. Set HTTPServer.allow_reuse_address to False')
ClientRedirectServer.allow_reuse_address = False
elif is_wsl():
logger.debug('WSL is detected. Set HTTPServer.allow_reuse_address to False')
ClientRedirectServer.allow_reuse_address = False

for port in range(8400, 9000):
try:
web_server = ClientRedirectServer(('localhost', port), ClientRedirectHandler)
Expand Down
15 changes: 10 additions & 5 deletions src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ def sdk_no_wait(no_wait, func, *args, **kwargs):
def open_page_in_browser(url):
import subprocess
import webbrowser
platform_name, release = _get_platform_info()
platform_name, _ = _get_platform_info()

if _is_wsl(platform_name, release): # windows 10 linux subsystem
if is_wsl(): # windows 10 linux subsystem
try:
return subprocess.call(['cmd.exe', '/c', "start {}".format(url.replace('&', '^&'))])
except OSError: # WSL might be too old # FileNotFoundError introduced in Python 3
Expand All @@ -395,16 +395,21 @@ def _get_platform_info():
return platform_name.lower(), release.lower()


def _is_wsl(platform_name, release):
def is_wsl():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering why the original _is_wsl() is ignoring the passed in perameter platform_name, release and calls _get_platform_info() to overwrite them?

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.

Seems to be some forgotten logic.

platform_name, release = _get_platform_info()
return platform_name == 'linux' and release.split('-')[-1] == 'microsoft'


def is_windows():
platform_name, _ = _get_platform_info()
return platform_name == 'windows'


def can_launch_browser():
import os
import webbrowser
platform_name, release = _get_platform_info()
if _is_wsl(platform_name, release) or platform_name != 'linux':
platform_name, _ = _get_platform_info()
if is_wsl() or platform_name != 'linux':
return True
# per https://unix.stackexchange.com/questions/46305/is-there-a-way-to-retrieve-the-name-of-the-desktop-environment
# and https://unix.stackexchange.com/questions/193827/what-is-display-0
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Release History

* Polish error when running `az login -u {} -p {}` with Microsoft account
* Polish `SSLError` when running `az login` behind a proxy with self-signed root certificate
* Fix #10578: `az login` hangs when more than one instances are launched at the same time on Windows or WSL

**RBAC**

Expand Down