From 3fbc4434373de31cfdd0fe72f43f89aaf6e47943 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 9 Jun 2020 15:25:28 -0700 Subject: [PATCH 01/17] update --- .../_credentials/linux_vscode_adapter.py | 16 +++------------- .../tests/test_vscode_credential.py | 3 +++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index bfd45faeb484..2f7f92da6434 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -15,11 +15,11 @@ def _c_str(string): _libsecret = ct.cdll.LoadLibrary("libsecret-1.so.0") _libsecret.secret_schema_new.argtypes = [ ct.c_char_p, - ct.c_uint, + ct.c_int, ct.c_char_p, - ct.c_uint, + ct.c_int, ct.c_char_p, - ct.c_uint, + ct.c_int, ct.c_void_p, ] _libsecret.secret_password_lookup_sync.argtypes = [ @@ -58,16 +58,6 @@ def _get_refresh_token(service_name, account_name): if not _libsecret: return None - # _libsecret.secret_password_lookup_sync raises segment fault on Python 2.7 - # temporarily disable it on 2.7 - import sys - - if sys.version_info[0] < 3: - raise NotImplementedError("Not supported on Python 2.7") - - if sys.version_info >= (3, 8): - raise NotImplementedError("Not supported") - err = ct.c_int() schema = _libsecret.secret_schema_new( _c_str("org.freedesktop.Secret.Generic"), 2, _c_str("service"), 0, _c_str("account"), 0, None diff --git a/sdk/identity/azure-identity/tests/test_vscode_credential.py b/sdk/identity/azure-identity/tests/test_vscode_credential.py index e6dc70fffd00..d2572d2ab2ac 100644 --- a/sdk/identity/azure-identity/tests/test_vscode_credential.py +++ b/sdk/identity/azure-identity/tests/test_vscode_credential.py @@ -106,10 +106,13 @@ def test_no_obtain_token_if_cached(): @pytest.mark.skipif(not sys.platform.startswith("linux"), reason="This test only runs on Linux") def test_distro(): + from azure.identity._credentials.linux_vscode_adapter import _get_refresh_token mock_client = mock.Mock(spec=object) mock_client.obtain_token_by_refresh_token = mock.Mock(return_value=None) mock_client.get_cached_access_token = mock.Mock(return_value=None) + _get_refresh_token("test", "test") + with pytest.raises(CredentialUnavailableError): credential = VSCodeCredential(_client=mock_client) token = credential.get_token("scope") From d12edff9ddbd82bf820e9f5aa965b844c8724a9f Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 9 Jun 2020 15:48:10 -0700 Subject: [PATCH 02/17] update --- .../_credentials/linux_vscode_adapter.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index 2f7f92da6434..c3711ec29ead 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -11,6 +11,21 @@ def _c_str(string): return ct.c_char_p(string.encode("utf-8")) +class _SecretSchemaAttribute(ct.Structure): + _fields_ = [ + ("name", ct.c_char_p), + ("type", ct.c_uint), + ] +_PSecretSchemaAttribute = ct.Array(_SecretSchemaAttribute) + +class _SecretSchema(ct.Structure): + _fields_ = [ + ("name", ct.c_char_p), + ("flags", ct.c_uint), + ("attributes", _PSecretSchemaAttribute), + ] +_PSecretSchema = ct.POINTER(_SecretSchema) + try: _libsecret = ct.cdll.LoadLibrary("libsecret-1.so.0") _libsecret.secret_schema_new.argtypes = [ @@ -59,11 +74,16 @@ def _get_refresh_token(service_name, account_name): return None err = ct.c_int() - schema = _libsecret.secret_schema_new( - _c_str("org.freedesktop.Secret.Generic"), 2, _c_str("service"), 0, _c_str("account"), 0, None - ) + #schema = _libsecret.secret_schema_new( + # _c_str("org.freedesktop.Secret.Generic"), 2, _c_str("service"), 0, _c_str("account"), 0, None + #) + schema = _SecretSchema() + pschema = _PSecretSchema(schema) + ct.memset(pschema, 0, ct.sizeof(schema)) + setattr(schema, "name", _c_str("org.freedesktop.Secret.Generic")) + setattr(schema, "flags", 2) p_str = _libsecret.secret_password_lookup_sync( - schema, + pschema, None, ct.byref(err), _c_str("service"), From 057808c90e7b35fff56228dd95369cd1f6f0b461 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 9 Jun 2020 15:49:53 -0700 Subject: [PATCH 03/17] update --- .../azure/identity/_credentials/linux_vscode_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index c3711ec29ead..040aaf517a60 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -92,7 +92,7 @@ def _get_refresh_token(service_name, account_name): _c_str(account_name), None, ) - _libsecret.secret_schema_unref(schema) + #_libsecret.secret_schema_unref(schema) if err.value == 0: return p_str.decode("utf-8") From dcb07e41a85ccb071f524b79b62f4044956b950f Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 9 Jun 2020 16:05:09 -0700 Subject: [PATCH 04/17] update --- .../identity/_credentials/linux_vscode_adapter.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index 040aaf517a60..a6235c6680d3 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -16,13 +16,12 @@ class _SecretSchemaAttribute(ct.Structure): ("name", ct.c_char_p), ("type", ct.c_uint), ] -_PSecretSchemaAttribute = ct.Array(_SecretSchemaAttribute) class _SecretSchema(ct.Structure): _fields_ = [ ("name", ct.c_char_p), ("flags", ct.c_uint), - ("attributes", _PSecretSchemaAttribute), + ("attributes", _SecretSchemaAttribute * 2), ] _PSecretSchema = ct.POINTER(_SecretSchema) @@ -77,11 +76,20 @@ def _get_refresh_token(service_name, account_name): #schema = _libsecret.secret_schema_new( # _c_str("org.freedesktop.Secret.Generic"), 2, _c_str("service"), 0, _c_str("account"), 0, None #) + attribute1 = _SecretSchemaAttribute() + setattr(attribute1, "name", _c_str("service")) + setattr(attribute1, "type", 0) + attribute2 = _SecretSchemaAttribute() + setattr(attribute2, "name", _c_str("account")) + setattr(attribute2, "type", 0) + attributes = [attribute1, attribute2] + pattributes = (_SecretSchemaAttribute * 2)(*attributes) schema = _SecretSchema() pschema = _PSecretSchema(schema) ct.memset(pschema, 0, ct.sizeof(schema)) setattr(schema, "name", _c_str("org.freedesktop.Secret.Generic")) setattr(schema, "flags", 2) + setattr(schema, "attributes", pattributes) p_str = _libsecret.secret_password_lookup_sync( pschema, None, From 4dd9761595d048530ecab0f5f62c6b3cf94473ba Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 9 Jun 2020 16:21:23 -0700 Subject: [PATCH 05/17] update --- .../_credentials/linux_vscode_adapter.py | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index a6235c6680d3..a839a69d79c5 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -5,37 +5,31 @@ import os import json import ctypes as ct +from .._constants import VSCODE_CREDENTIALS_SECTION def _c_str(string): return ct.c_char_p(string.encode("utf-8")) -class _SecretSchemaAttribute(ct.Structure): +class _SECRET_SCHEMA_ATTRIBUTE(ct.Structure): _fields_ = [ ("name", ct.c_char_p), ("type", ct.c_uint), ] -class _SecretSchema(ct.Structure): + +class _SECRET_SCHEMA(ct.Structure): _fields_ = [ ("name", ct.c_char_p), ("flags", ct.c_uint), - ("attributes", _SecretSchemaAttribute * 2), + ("attributes", _SECRET_SCHEMA_ATTRIBUTE * 2), ] -_PSecretSchema = ct.POINTER(_SecretSchema) +_PSECRET_SCHEMA = ct.POINTER(_SECRET_SCHEMA) + try: _libsecret = ct.cdll.LoadLibrary("libsecret-1.so.0") - _libsecret.secret_schema_new.argtypes = [ - ct.c_char_p, - ct.c_int, - ct.c_char_p, - ct.c_int, - ct.c_char_p, - ct.c_int, - ct.c_void_p, - ] _libsecret.secret_password_lookup_sync.argtypes = [ ct.c_void_p, ct.c_void_p, @@ -47,7 +41,6 @@ class _SecretSchema(ct.Structure): ct.c_void_p, ] _libsecret.secret_password_lookup_sync.restype = ct.c_char_p - _libsecret.secret_schema_unref.argtypes = [ct.c_void_p] except OSError: _libsecret = None @@ -73,19 +66,16 @@ def _get_refresh_token(service_name, account_name): return None err = ct.c_int() - #schema = _libsecret.secret_schema_new( - # _c_str("org.freedesktop.Secret.Generic"), 2, _c_str("service"), 0, _c_str("account"), 0, None - #) - attribute1 = _SecretSchemaAttribute() + attribute1 = _SECRET_SCHEMA_ATTRIBUTE() setattr(attribute1, "name", _c_str("service")) setattr(attribute1, "type", 0) - attribute2 = _SecretSchemaAttribute() + attribute2 = _SECRET_SCHEMA_ATTRIBUTE() setattr(attribute2, "name", _c_str("account")) setattr(attribute2, "type", 0) attributes = [attribute1, attribute2] - pattributes = (_SecretSchemaAttribute * 2)(*attributes) - schema = _SecretSchema() - pschema = _PSecretSchema(schema) + pattributes = (_SECRET_SCHEMA_ATTRIBUTE * 2)(*attributes) + schema = _SECRET_SCHEMA() + pschema = _SECRET_SCHEMA(schema) ct.memset(pschema, 0, ct.sizeof(schema)) setattr(schema, "name", _c_str("org.freedesktop.Secret.Generic")) setattr(schema, "flags", 2) @@ -100,7 +90,6 @@ def _get_refresh_token(service_name, account_name): _c_str(account_name), None, ) - #_libsecret.secret_schema_unref(schema) if err.value == 0: return p_str.decode("utf-8") @@ -108,5 +97,9 @@ def _get_refresh_token(service_name, account_name): def get_credentials(): - # Disable linux support for further investigation - raise NotImplementedError("Not supported") + try: + environment_name = _get_user_settings() + credentials = _get_refresh_token(VSCODE_CREDENTIALS_SECTION, environment_name) + return credentials + except Exception: # pylint: disable=broad-except + return None From 8de38bfb4190616f27bfde62e7ccea7e4d9eabb7 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 9 Jun 2020 16:31:20 -0700 Subject: [PATCH 06/17] udpate --- .../azure/identity/_credentials/linux_vscode_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index a839a69d79c5..8a560f3e05bf 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -75,7 +75,7 @@ def _get_refresh_token(service_name, account_name): attributes = [attribute1, attribute2] pattributes = (_SECRET_SCHEMA_ATTRIBUTE * 2)(*attributes) schema = _SECRET_SCHEMA() - pschema = _SECRET_SCHEMA(schema) + pschema = _PSECRET_SCHEMA(schema) ct.memset(pschema, 0, ct.sizeof(schema)) setattr(schema, "name", _c_str("org.freedesktop.Secret.Generic")) setattr(schema, "flags", 2) From 7f130b322b2257d03fd10167620cfe90f098612b Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 9 Jun 2020 16:38:01 -0700 Subject: [PATCH 07/17] update --- .../identity/_credentials/vscode_credential.py | 10 +++------- .../identity/aio/_credentials/vscode_credential.py | 9 +++------ .../azure-identity/tests/test_vscode_credential.py | 2 +- .../tests/test_vscode_credential_async.py | 14 -------------- 4 files changed, 7 insertions(+), 28 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/vscode_credential.py b/sdk/identity/azure-identity/azure/identity/_credentials/vscode_credential.py index f2bfd660711a..c40636c24e96 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/vscode_credential.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/vscode_credential.py @@ -52,13 +52,9 @@ def get_token(self, *scopes, **kwargs): return token if not self._refresh_token: - try: - self._refresh_token = get_credentials() - if not self._refresh_token: - raise CredentialUnavailableError(message="No Azure user is logged in to Visual Studio Code.") - except NotImplementedError: # pylint:disable=try-except-raise - raise CredentialUnavailableError(message="Not supported") - + self._refresh_token = get_credentials() + if not self._refresh_token: + raise CredentialUnavailableError(message="No Azure user is logged in to Visual Studio Code.") token = self._client.obtain_token_by_refresh_token(scopes, self._refresh_token, **kwargs) return token diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode_credential.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode_credential.py index e2fdce06f19b..fcf392421294 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode_credential.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/vscode_credential.py @@ -56,12 +56,9 @@ async def get_token(self, *scopes, **kwargs): return token if not self._refresh_token: - try: - self._refresh_token = get_credentials() - if not self._refresh_token: - raise CredentialUnavailableError(message="No Azure user is logged in to Visual Studio Code.") - except NotImplementedError: # pylint:disable=try-except-raise - raise CredentialUnavailableError(message="Not supported") + self._refresh_token = get_credentials() + if not self._refresh_token: + raise CredentialUnavailableError(message="No Azure user is logged in to Visual Studio Code.") token = await self._client.obtain_token_by_refresh_token(scopes, self._refresh_token, **kwargs) return token diff --git a/sdk/identity/azure-identity/tests/test_vscode_credential.py b/sdk/identity/azure-identity/tests/test_vscode_credential.py index d2572d2ab2ac..f756ca09f0ab 100644 --- a/sdk/identity/azure-identity/tests/test_vscode_credential.py +++ b/sdk/identity/azure-identity/tests/test_vscode_credential.py @@ -105,7 +105,7 @@ def test_no_obtain_token_if_cached(): @pytest.mark.skipif(not sys.platform.startswith("linux"), reason="This test only runs on Linux") -def test_distro(): +def test_segfault(): from azure.identity._credentials.linux_vscode_adapter import _get_refresh_token mock_client = mock.Mock(spec=object) mock_client.obtain_token_by_refresh_token = mock.Mock(return_value=None) diff --git a/sdk/identity/azure-identity/tests/test_vscode_credential_async.py b/sdk/identity/azure-identity/tests/test_vscode_credential_async.py index 6bdbb430044c..1f26651d45d8 100644 --- a/sdk/identity/azure-identity/tests/test_vscode_credential_async.py +++ b/sdk/identity/azure-identity/tests/test_vscode_credential_async.py @@ -106,17 +106,3 @@ async def test_no_obtain_token_if_cached(): credential = VSCodeCredential(_client=mock_client) token = await credential.get_token("scope") assert token_by_refresh_token.call_count == 0 - - -@pytest.mark.skipif(not sys.platform.startswith("linux"), reason="This test only runs on Linux") -@pytest.mark.asyncio -async def test_distro(): - - mock_client = mock.Mock(spec=object) - token_by_refresh_token = mock.Mock(return_value=None) - mock_client.obtain_token_by_refresh_token = wrap_in_future(token_by_refresh_token) - mock_client.get_cached_access_token = mock.Mock(return_value=None) - - with pytest.raises(CredentialUnavailableError): - credential = VSCodeCredential(_client=mock_client) - token = await credential.get_token("scope") From ab64858aaaba59c49585ee869fbe198b63ac7c03 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 10 Jun 2020 16:06:43 -0700 Subject: [PATCH 08/17] update --- .../azure/identity/_credentials/linux_vscode_adapter.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index 8a560f3e05bf..b0474dea49be 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -66,13 +66,7 @@ def _get_refresh_token(service_name, account_name): return None err = ct.c_int() - attribute1 = _SECRET_SCHEMA_ATTRIBUTE() - setattr(attribute1, "name", _c_str("service")) - setattr(attribute1, "type", 0) - attribute2 = _SECRET_SCHEMA_ATTRIBUTE() - setattr(attribute2, "name", _c_str("account")) - setattr(attribute2, "type", 0) - attributes = [attribute1, attribute2] + attributes = [_SECRET_SCHEMA_ATTRIBUTE(_c_str("service"), 0), _SECRET_SCHEMA_ATTRIBUTE(_c_str("account"), 0)] pattributes = (_SECRET_SCHEMA_ATTRIBUTE * 2)(*attributes) schema = _SECRET_SCHEMA() pschema = _PSECRET_SCHEMA(schema) From 3dbabd070bd18c266b65d4335ed09126f37dc444 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 10 Jun 2020 16:18:39 -0700 Subject: [PATCH 09/17] secret_password_free --- .../azure/identity/_credentials/linux_vscode_adapter.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index b0474dea49be..279612bb7cdd 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -41,6 +41,7 @@ class _SECRET_SCHEMA(ct.Structure): ct.c_void_p, ] _libsecret.secret_password_lookup_sync.restype = ct.c_char_p + _libsecret.secret_password_free.argtypes = [ct.c_char_p] except OSError: _libsecret = None @@ -85,7 +86,9 @@ def _get_refresh_token(service_name, account_name): None, ) if err.value == 0: - return p_str.decode("utf-8") + password = p_str.decode("utf-8") + _libsecret.secret_password_free(p_str) + return password return None From f6572d861c01d23110989ce88a9bf2448920405e Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 10 Jun 2020 16:23:16 -0700 Subject: [PATCH 10/17] update --- .../azure/identity/_credentials/linux_vscode_adapter.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index 279612bb7cdd..ac2344e692f3 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -86,9 +86,7 @@ def _get_refresh_token(service_name, account_name): None, ) if err.value == 0: - password = p_str.decode("utf-8") - _libsecret.secret_password_free(p_str) - return password + return p_str.decode("utf-8") return None From c9446d8c3a441ba0a346dd2ca03c8b851adf8bc9 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 11 Jun 2020 10:06:29 -0700 Subject: [PATCH 11/17] update --- .../azure-identity/tests/test_vscode_credential.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/sdk/identity/azure-identity/tests/test_vscode_credential.py b/sdk/identity/azure-identity/tests/test_vscode_credential.py index f756ca09f0ab..a0b320410bc8 100644 --- a/sdk/identity/azure-identity/tests/test_vscode_credential.py +++ b/sdk/identity/azure-identity/tests/test_vscode_credential.py @@ -107,16 +107,8 @@ def test_no_obtain_token_if_cached(): @pytest.mark.skipif(not sys.platform.startswith("linux"), reason="This test only runs on Linux") def test_segfault(): from azure.identity._credentials.linux_vscode_adapter import _get_refresh_token - mock_client = mock.Mock(spec=object) - mock_client.obtain_token_by_refresh_token = mock.Mock(return_value=None) - mock_client.get_cached_access_token = mock.Mock(return_value=None) - _get_refresh_token("test", "test") - with pytest.raises(CredentialUnavailableError): - credential = VSCodeCredential(_client=mock_client) - token = credential.get_token("scope") - @pytest.mark.skipif(not sys.platform.startswith("darwin"), reason="This test only runs on MacOS") def test_mac_keychain_valid_value(): From e9ed70eeb669e9fd7725a48969363a5c99553434 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 16 Jun 2020 13:28:23 -0700 Subject: [PATCH 12/17] add manual test script for vscode credential --- .../tests/vscode-live/vscode.md | 22 +++++++++++++++++++ .../tests/vscode-live/vscode_test.py | 9 ++++++++ 2 files changed, 31 insertions(+) create mode 100644 sdk/identity/azure-identity/tests/vscode-live/vscode.md create mode 100644 sdk/identity/azure-identity/tests/vscode-live/vscode_test.py diff --git a/sdk/identity/azure-identity/tests/vscode-live/vscode.md b/sdk/identity/azure-identity/tests/vscode-live/vscode.md new file mode 100644 index 000000000000..ae328edd2dd2 --- /dev/null +++ b/sdk/identity/azure-identity/tests/vscode-live/vscode.md @@ -0,0 +1,22 @@ +# Testing visual studio code credential + +## Test matrix + +- Python 2.7, 3.5.3, 3.8 +- Windows, Ubuntu 18.04, Redhat Enterprise Linux 8.1, Debian 10, Mac OS + +## Test steps + +- Install Visual Studio Code from https://code.visualstudio.com/ + +- Launch Visual Studio Code and go to Extension tab. + +- Search and install Azure Storage extension + +- Go to Azure tab and log in with your credential + +- Open a terminal, install azure-core & azure-identity + +- Run vscode_test.py + +Expect: a valid access token is printed out. \ No newline at end of file diff --git a/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py b/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py new file mode 100644 index 000000000000..fd00465e6b1c --- /dev/null +++ b/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py @@ -0,0 +1,9 @@ +from azure.identity import VSCodeCredential + +def test_live(): + credential = VSCodeCredential() + str=credential.get_token('https://vault.azure.net/.default') + print(str) + +if __name__ == "__main__": + test_live() From 37043c90f1c8656652befa69e1e7fc6a8d144801 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 16 Jun 2020 13:31:06 -0700 Subject: [PATCH 13/17] add license --- sdk/identity/azure-identity/tests/vscode-live/vscode_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py b/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py index fd00465e6b1c..6b76e47ec5a6 100644 --- a/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py +++ b/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py @@ -1,3 +1,8 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + from azure.identity import VSCodeCredential def test_live(): From d602afc20d161b86fd776f30b1e79560b48f3d7e Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 16 Jun 2020 16:40:08 -0700 Subject: [PATCH 14/17] update --- .../tests/vscode-live/{vscode_test.py => run-test.py} | 0 sdk/identity/azure-identity/tests/vscode-live/vscode.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename sdk/identity/azure-identity/tests/vscode-live/{vscode_test.py => run-test.py} (100%) diff --git a/sdk/identity/azure-identity/tests/vscode-live/vscode_test.py b/sdk/identity/azure-identity/tests/vscode-live/run-test.py similarity index 100% rename from sdk/identity/azure-identity/tests/vscode-live/vscode_test.py rename to sdk/identity/azure-identity/tests/vscode-live/run-test.py diff --git a/sdk/identity/azure-identity/tests/vscode-live/vscode.md b/sdk/identity/azure-identity/tests/vscode-live/vscode.md index ae328edd2dd2..873d0b807892 100644 --- a/sdk/identity/azure-identity/tests/vscode-live/vscode.md +++ b/sdk/identity/azure-identity/tests/vscode-live/vscode.md @@ -17,6 +17,6 @@ - Open a terminal, install azure-core & azure-identity -- Run vscode_test.py +- Run run-test.py Expect: a valid access token is printed out. \ No newline at end of file From 40c28244bcaede59a6cfd72d631910b19f4c4640 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 17 Jun 2020 11:02:39 -0700 Subject: [PATCH 15/17] update --- sdk/identity/azure-identity/tests/vscode-live/run-test.py | 4 ++-- sdk/identity/azure-identity/tests/vscode-live/vscode.md | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sdk/identity/azure-identity/tests/vscode-live/run-test.py b/sdk/identity/azure-identity/tests/vscode-live/run-test.py index 6b76e47ec5a6..401d2f39706c 100644 --- a/sdk/identity/azure-identity/tests/vscode-live/run-test.py +++ b/sdk/identity/azure-identity/tests/vscode-live/run-test.py @@ -7,8 +7,8 @@ def test_live(): credential = VSCodeCredential() - str=credential.get_token('https://vault.azure.net/.default') - print(str) + token=credential.get_token('https://vault.azure.net/.default') + print(token) if __name__ == "__main__": test_live() diff --git a/sdk/identity/azure-identity/tests/vscode-live/vscode.md b/sdk/identity/azure-identity/tests/vscode-live/vscode.md index 873d0b807892..8b17e9fce8cb 100644 --- a/sdk/identity/azure-identity/tests/vscode-live/vscode.md +++ b/sdk/identity/azure-identity/tests/vscode-live/vscode.md @@ -15,8 +15,11 @@ - Go to Azure tab and log in with your credential -- Open a terminal, install azure-core & azure-identity +- Open a terminal, install latest azure-identity by running +```python +pip install azure-identity -i https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python%40Local/pypi/simple/ +``` - Run run-test.py -Expect: a valid access token is printed out. \ No newline at end of file +Expect: an access token is printed out. \ No newline at end of file From 06b15a13d8593ff247ff49bc5892748d2b131483 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 17 Jun 2020 12:40:53 -0700 Subject: [PATCH 16/17] updates --- .../azure/identity/_credentials/linux_vscode_adapter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index ac2344e692f3..3414f7040eac 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -72,9 +72,9 @@ def _get_refresh_token(service_name, account_name): schema = _SECRET_SCHEMA() pschema = _PSECRET_SCHEMA(schema) ct.memset(pschema, 0, ct.sizeof(schema)) - setattr(schema, "name", _c_str("org.freedesktop.Secret.Generic")) - setattr(schema, "flags", 2) - setattr(schema, "attributes", pattributes) + schema.name = _c_str("org.freedesktop.Secret.Generic") + schema.flags = 2 + schema.attributes = pattributes p_str = _libsecret.secret_password_lookup_sync( pschema, None, From adcdbedb29a6bcb9f66ee612dd3a44816ccf7ed7 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 17 Jun 2020 12:57:57 -0700 Subject: [PATCH 17/17] update --- .../azure/identity/_credentials/linux_vscode_adapter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py index 3414f7040eac..d31b202678df 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/linux_vscode_adapter.py @@ -72,9 +72,9 @@ def _get_refresh_token(service_name, account_name): schema = _SECRET_SCHEMA() pschema = _PSECRET_SCHEMA(schema) ct.memset(pschema, 0, ct.sizeof(schema)) - schema.name = _c_str("org.freedesktop.Secret.Generic") - schema.flags = 2 - schema.attributes = pattributes + schema.name = _c_str("org.freedesktop.Secret.Generic") # pylint: disable=attribute-defined-outside-init + schema.flags = 2 # pylint: disable=attribute-defined-outside-init + schema.attributes = pattributes # pylint: disable=attribute-defined-outside-init p_str = _libsecret.secret_password_lookup_sync( pschema, None,