Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCodeCredential supports Python 2.7 on Windows #12731

Merged
merged 2 commits into from
Jul 27, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
# ------------------------------------
import os
import json
import logging
import ctypes as ct
from .._constants import VSCODE_CREDENTIALS_SECTION

_LOGGER = logging.getLogger(__name__)


def _c_str(string):
return ct.c_char_p(string.encode("utf-8"))
Expand Down Expand Up @@ -96,5 +99,8 @@ def get_credentials():
environment_name = _get_user_settings()
credentials = _get_refresh_token(VSCODE_CREDENTIALS_SECTION, environment_name)
return credentials
except Exception: # pylint: disable=broad-except
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug(
'Exception retrieving VS Code credentials: "%s"', ex, exc_info=_LOGGER.isEnabledFor(logging.DEBUG)
)
return None
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
# ------------------------------------
import os
import json
import logging
from msal_extensions.osx import Keychain, KeychainError
from .._constants import VSCODE_CREDENTIALS_SECTION

_LOGGER = logging.getLogger(__name__)


def _get_user_settings_path():
app_data_folder = os.environ["USER"]
Expand Down Expand Up @@ -37,5 +40,8 @@ def get_credentials():
environment_name = _get_user_settings()
credentials = _get_refresh_token(VSCODE_CREDENTIALS_SECTION, environment_name)
return credentials
except Exception: # pylint: disable=broad-except
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug(
'Exception retrieving VS Code credentials: "%s"', ex, exc_info=_LOGGER.isEnabledFor(logging.DEBUG)
)
return None
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ------------------------------------
import os
import json
import logging
import ctypes as ct
from .._constants import VSCODE_CREDENTIALS_SECTION

Expand All @@ -12,6 +13,7 @@
except (IOError, ValueError):
pass

_LOGGER = logging.getLogger(__name__)

SUPPORTED_CREDKEYS = set(("Type", "TargetName", "Persist", "UserName", "Comment", "CredentialBlob"))

Expand Down Expand Up @@ -49,8 +51,7 @@ def _read_credential(service_name, account_name):
if _advapi.CredReadW(target, 1, 0, ct.byref(cred_ptr)):
cred_blob = cred_ptr.contents.CredentialBlob
cred_blob_size = cred_ptr.contents.CredentialBlobSize
password_as_list = [int.from_bytes(cred_blob[pos : pos + 1], "little") for pos in range(0, cred_blob_size)]
cred = "".join(map(chr, password_as_list))
cred = "".join(map(chr, cred_blob[:cred_blob_size]))
_advapi.CredFree(cred_ptr)
return cred
return None
Expand Down Expand Up @@ -81,5 +82,8 @@ def get_credentials():
environment_name = _get_user_settings()
credentials = _get_refresh_token(VSCODE_CREDENTIALS_SECTION, environment_name)
return credentials
except Exception: # pylint: disable=broad-except
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug(
'Exception retrieving VS Code credentials: "%s"', ex, exc_info=_LOGGER.isEnabledFor(logging.DEBUG)
)
return None