diff --git a/google/cloud/osconfig_v1/services/os_config_service/async_client.py b/google/cloud/osconfig_v1/services/os_config_service/async_client.py index 0c4c1e6..0042cef 100644 --- a/google/cloud/osconfig_v1/services/os_config_service/async_client.py +++ b/google/cloud/osconfig_v1/services/os_config_service/async_client.py @@ -89,6 +89,7 @@ class OsConfigServiceAsyncClient: OsConfigServiceClient.parse_common_location_path ) + from_service_account_info = OsConfigServiceClient.from_service_account_info from_service_account_file = OsConfigServiceClient.from_service_account_file from_service_account_json = from_service_account_file diff --git a/google/cloud/osconfig_v1/services/os_config_service/client.py b/google/cloud/osconfig_v1/services/os_config_service/client.py index d74daa2..f1101be 100644 --- a/google/cloud/osconfig_v1/services/os_config_service/client.py +++ b/google/cloud/osconfig_v1/services/os_config_service/client.py @@ -117,6 +117,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + {@api.name}: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials diff --git a/synth.metadata b/synth.metadata index 89d1394..787bb07 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-os-config.git", - "sha": "b84dce022c84d79e8193c6881338fb3f79345740" + "sha": "628ada4004b1add04f5c2d95b9b1cad48616cf2c" } }, { diff --git a/tests/unit/gapic/osconfig_v1/test_os_config_service.py b/tests/unit/gapic/osconfig_v1/test_os_config_service.py index 188b5d3..2affe12 100644 --- a/tests/unit/gapic/osconfig_v1/test_os_config_service.py +++ b/tests/unit/gapic/osconfig_v1/test_os_config_service.py @@ -93,6 +93,19 @@ def test__get_default_mtls_endpoint(): ) +def test_os_config_service_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = OsConfigServiceClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "osconfig.googleapis.com:443" + + @pytest.mark.parametrize( "client_class", [OsConfigServiceClient, OsConfigServiceAsyncClient] )