Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit d8d921f

Browse files
feat: add from_service_account_info (#31)
1 parent 628ada4 commit d8d921f

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎google/cloud/osconfig_v1/services/os_config_service/async_client.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class OsConfigServiceAsyncClient:
8989
OsConfigServiceClient.parse_common_location_path
9090
)
9191

92+
from_service_account_info = OsConfigServiceClient.from_service_account_info
9293
from_service_account_file = OsConfigServiceClient.from_service_account_file
9394
from_service_account_json = from_service_account_file
9495

‎google/cloud/osconfig_v1/services/os_config_service/client.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ def _get_default_mtls_endpoint(api_endpoint):
117117
DEFAULT_ENDPOINT
118118
)
119119

120+
@classmethod
121+
def from_service_account_info(cls, info: dict, *args, **kwargs):
122+
"""Creates an instance of this client using the provided credentials info.
123+
124+
Args:
125+
info (dict): The service account private key info.
126+
args: Additional arguments to pass to the constructor.
127+
kwargs: Additional arguments to pass to the constructor.
128+
129+
Returns:
130+
{@api.name}: The constructed client.
131+
"""
132+
credentials = service_account.Credentials.from_service_account_info(info)
133+
kwargs["credentials"] = credentials
134+
return cls(*args, **kwargs)
135+
120136
@classmethod
121137
def from_service_account_file(cls, filename: str, *args, **kwargs):
122138
"""Creates an instance of this client using the provided credentials

‎synth.metadata‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"git": {
55
"name": ".",
66
"remote": "https://github.com/googleapis/python-os-config.git",
7-
"sha": "b84dce022c84d79e8193c6881338fb3f79345740"
7+
"sha": "628ada4004b1add04f5c2d95b9b1cad48616cf2c"
88
}
99
},
1010
{

‎tests/unit/gapic/osconfig_v1/test_os_config_service.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ def test__get_default_mtls_endpoint():
9393
)
9494

9595

96+
def test_os_config_service_client_from_service_account_info():
97+
creds = credentials.AnonymousCredentials()
98+
with mock.patch.object(
99+
service_account.Credentials, "from_service_account_info"
100+
) as factory:
101+
factory.return_value = creds
102+
info = {"valid": True}
103+
client = OsConfigServiceClient.from_service_account_info(info)
104+
assert client.transport._credentials == creds
105+
106+
assert client.transport._host == "osconfig.googleapis.com:443"
107+
108+
96109
@pytest.mark.parametrize(
97110
"client_class", [OsConfigServiceClient, OsConfigServiceAsyncClient]
98111
)

0 commit comments

Comments
 (0)