diff --git a/docs/oslogin_v1/common/types.rst b/docs/oslogin_v1/common/types.rst index 009e245..c5cf90b 100644 --- a/docs/oslogin_v1/common/types.rst +++ b/docs/oslogin_v1/common/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Oslogin Common API .. automodule:: google.cloud.oslogin_v1.common :members: + :undoc-members: :show-inheritance: diff --git a/docs/oslogin_v1/os_login_service.rst b/docs/oslogin_v1/os_login_service.rst new file mode 100644 index 0000000..588b1fb --- /dev/null +++ b/docs/oslogin_v1/os_login_service.rst @@ -0,0 +1,6 @@ +OsLoginService +-------------------------------- + +.. automodule:: google.cloud.oslogin_v1.services.os_login_service + :members: + :inherited-members: diff --git a/docs/oslogin_v1/services.rst b/docs/oslogin_v1/services.rst index dbdb8bf..10a7155 100644 --- a/docs/oslogin_v1/services.rst +++ b/docs/oslogin_v1/services.rst @@ -1,6 +1,6 @@ Services for Google Cloud Oslogin v1 API ======================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.oslogin_v1.services.os_login_service - :members: - :inherited-members: + os_login_service diff --git a/docs/oslogin_v1/types.rst b/docs/oslogin_v1/types.rst index ad7f7fe..202b5bb 100644 --- a/docs/oslogin_v1/types.rst +++ b/docs/oslogin_v1/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Oslogin v1 API .. automodule:: google.cloud.oslogin_v1.types :members: + :undoc-members: :show-inheritance: diff --git a/google/cloud/oslogin_v1/common/types/common.py b/google/cloud/oslogin_v1/common/types/common.py index 52dc2e0..50a0437 100644 --- a/google/cloud/oslogin_v1/common/types/common.py +++ b/google/cloud/oslogin_v1/common/types/common.py @@ -59,7 +59,7 @@ class PosixAccount(proto.Message): empty value is used. account_id (str): Output only. A POSIX account identifier. - operating_system_type (~.common.OperatingSystemType): + operating_system_type (google.cloud.oslogin.v1.types.OperatingSystemType): The operating system type where this account applies. name (str): diff --git a/google/cloud/oslogin_v1/services/os_login_service/async_client.py b/google/cloud/oslogin_v1/services/os_login_service/async_client.py index ef0c8bf..dd29fc1 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/async_client.py +++ b/google/cloud/oslogin_v1/services/os_login_service/async_client.py @@ -87,6 +87,7 @@ class OsLoginServiceAsyncClient: OsLoginServiceClient.parse_common_location_path ) + from_service_account_info = OsLoginServiceClient.from_service_account_info from_service_account_file = OsLoginServiceClient.from_service_account_file from_service_account_json = from_service_account_file @@ -163,7 +164,7 @@ async def delete_posix_account( r"""Deletes a POSIX account. Args: - request (:class:`~.oslogin.DeletePosixAccountRequest`): + request (:class:`google.cloud.oslogin_v1.types.DeletePosixAccountRequest`): The request object. A request message for deleting a POSIX account entry. name (:class:`str`): @@ -171,6 +172,7 @@ async def delete_posix_account( POSIX accounts are identified by the project ID they are associated with. A reference to the POSIX account is in format ``users/{user}/projects/{project}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -238,7 +240,7 @@ async def delete_ssh_public_key( r"""Deletes an SSH public key. Args: - request (:class:`~.oslogin.DeleteSshPublicKeyRequest`): + request (:class:`google.cloud.oslogin_v1.types.DeleteSshPublicKeyRequest`): The request object. A request message for deleting an SSH public key. name (:class:`str`): @@ -246,6 +248,7 @@ async def delete_ssh_public_key( Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -314,12 +317,13 @@ async def get_login_profile( to a virtual machine on Google Compute Engine. Args: - request (:class:`~.oslogin.GetLoginProfileRequest`): + request (:class:`google.cloud.oslogin_v1.types.GetLoginProfileRequest`): The request object. A request message for retrieving the login profile information for a user. name (:class:`str`): Required. The unique ID for the user in format ``users/{user}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -331,7 +335,7 @@ async def get_login_profile( sent along with the request as metadata. Returns: - ~.oslogin.LoginProfile: + google.cloud.oslogin_v1.types.LoginProfile: The user profile information used for logging in to a virtual machine on Google Compute Engine. @@ -395,7 +399,7 @@ async def get_ssh_public_key( r"""Retrieves an SSH public key. Args: - request (:class:`~.oslogin.GetSshPublicKeyRequest`): + request (:class:`google.cloud.oslogin_v1.types.GetSshPublicKeyRequest`): The request object. A request message for retrieving an SSH public key. name (:class:`str`): @@ -403,6 +407,7 @@ async def get_ssh_public_key( Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -414,7 +419,7 @@ async def get_ssh_public_key( sent along with the request as metadata. Returns: - ~.common.SshPublicKey: + google.cloud.oslogin.v1.common_pb2.SshPublicKey: The SSH public key information associated with a Google account. @@ -482,24 +487,27 @@ async def import_ssh_public_key( profile. Args: - request (:class:`~.oslogin.ImportSshPublicKeyRequest`): + request (:class:`google.cloud.oslogin_v1.types.ImportSshPublicKeyRequest`): The request object. A request message for importing an SSH public key. parent (:class:`str`): Required. The unique ID for the user in format ``users/{user}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (:class:`~.common.SshPublicKey`): + ssh_public_key (:class:`google.cloud.oslogin.v1.common_pb2.SshPublicKey`): Optional. The SSH public key and expiration time. + This corresponds to the ``ssh_public_key`` field on the ``request`` instance; if ``request`` is provided, this should not be set. project_id (:class:`str`): The project ID of the Google Cloud Platform project. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -511,7 +519,7 @@ async def import_ssh_public_key( sent along with the request as metadata. Returns: - ~.oslogin.ImportSshPublicKeyResponse: + google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse: A response message for importing an SSH public key. @@ -581,7 +589,7 @@ async def update_ssh_public_key( information. This method supports patch semantics. Args: - request (:class:`~.oslogin.UpdateSshPublicKeyRequest`): + request (:class:`google.cloud.oslogin_v1.types.UpdateSshPublicKeyRequest`): The request object. A request message for updating an SSH public key. name (:class:`str`): @@ -589,18 +597,21 @@ async def update_ssh_public_key( Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (:class:`~.common.SshPublicKey`): + ssh_public_key (:class:`google.cloud.oslogin.v1.common_pb2.SshPublicKey`): Required. The SSH public key and expiration time. + This corresponds to the ``ssh_public_key`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Mask to control which fields get updated. Updates all if not present. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -612,7 +623,7 @@ async def update_ssh_public_key( sent along with the request as metadata. Returns: - ~.common.SshPublicKey: + google.cloud.oslogin.v1.common_pb2.SshPublicKey: The SSH public key information associated with a Google account. diff --git a/google/cloud/oslogin_v1/services/os_login_service/client.py b/google/cloud/oslogin_v1/services/os_login_service/client.py index 88ca09c..bf9a483 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/client.py +++ b/google/cloud/oslogin_v1/services/os_login_service/client.py @@ -115,6 +115,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: + OsLoginServiceClient: 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 @@ -127,7 +143,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + OsLoginServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -243,10 +259,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.OsLoginServiceTransport]): The + transport (Union[str, OsLoginServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -356,14 +372,15 @@ def delete_posix_account( r"""Deletes a POSIX account. Args: - request (:class:`~.oslogin.DeletePosixAccountRequest`): + request (google.cloud.oslogin_v1.types.DeletePosixAccountRequest): The request object. A request message for deleting a POSIX account entry. - name (:class:`str`): + name (str): Required. A reference to the POSIX account to update. POSIX accounts are identified by the project ID they are associated with. A reference to the POSIX account is in format ``users/{user}/projects/{project}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -424,14 +441,15 @@ def delete_ssh_public_key( r"""Deletes an SSH public key. Args: - request (:class:`~.oslogin.DeleteSshPublicKeyRequest`): + request (google.cloud.oslogin_v1.types.DeleteSshPublicKeyRequest): The request object. A request message for deleting an SSH public key. - name (:class:`str`): + name (str): Required. The fingerprint of the public key to update. Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -493,12 +511,13 @@ def get_login_profile( to a virtual machine on Google Compute Engine. Args: - request (:class:`~.oslogin.GetLoginProfileRequest`): + request (google.cloud.oslogin_v1.types.GetLoginProfileRequest): The request object. A request message for retrieving the login profile information for a user. - name (:class:`str`): + name (str): Required. The unique ID for the user in format ``users/{user}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -510,7 +529,7 @@ def get_login_profile( sent along with the request as metadata. Returns: - ~.oslogin.LoginProfile: + google.cloud.oslogin_v1.types.LoginProfile: The user profile information used for logging in to a virtual machine on Google Compute Engine. @@ -567,14 +586,15 @@ def get_ssh_public_key( r"""Retrieves an SSH public key. Args: - request (:class:`~.oslogin.GetSshPublicKeyRequest`): + request (google.cloud.oslogin_v1.types.GetSshPublicKeyRequest): The request object. A request message for retrieving an SSH public key. - name (:class:`str`): + name (str): Required. The fingerprint of the public key to retrieve. Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -586,7 +606,7 @@ def get_ssh_public_key( sent along with the request as metadata. Returns: - ~.common.SshPublicKey: + google.cloud.oslogin.v1.common_pb2.SshPublicKey: The SSH public key information associated with a Google account. @@ -647,24 +667,27 @@ def import_ssh_public_key( profile. Args: - request (:class:`~.oslogin.ImportSshPublicKeyRequest`): + request (google.cloud.oslogin_v1.types.ImportSshPublicKeyRequest): The request object. A request message for importing an SSH public key. - parent (:class:`str`): + parent (str): Required. The unique ID for the user in format ``users/{user}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (:class:`~.common.SshPublicKey`): + ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): Optional. The SSH public key and expiration time. + This corresponds to the ``ssh_public_key`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - project_id (:class:`str`): + project_id (str): The project ID of the Google Cloud Platform project. + This corresponds to the ``project_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -676,7 +699,7 @@ def import_ssh_public_key( sent along with the request as metadata. Returns: - ~.oslogin.ImportSshPublicKeyResponse: + google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse: A response message for importing an SSH public key. @@ -739,26 +762,29 @@ def update_ssh_public_key( information. This method supports patch semantics. Args: - request (:class:`~.oslogin.UpdateSshPublicKeyRequest`): + request (google.cloud.oslogin_v1.types.UpdateSshPublicKeyRequest): The request object. A request message for updating an SSH public key. - name (:class:`str`): + name (str): Required. The fingerprint of the public key to update. Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - ssh_public_key (:class:`~.common.SshPublicKey`): + ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): Required. The SSH public key and expiration time. + This corresponds to the ``ssh_public_key`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Mask to control which fields get updated. Updates all if not present. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -770,7 +796,7 @@ def update_ssh_public_key( sent along with the request as metadata. Returns: - ~.common.SshPublicKey: + google.cloud.oslogin.v1.common_pb2.SshPublicKey: The SSH public key information associated with a Google account. diff --git a/google/cloud/oslogin_v1/types/oslogin.py b/google/cloud/oslogin_v1/types/oslogin.py index 360ee71..03ad5f8 100644 --- a/google/cloud/oslogin_v1/types/oslogin.py +++ b/google/cloud/oslogin_v1/types/oslogin.py @@ -44,10 +44,10 @@ class LoginProfile(proto.Message): Attributes: name (str): Required. A unique user ID. - posix_accounts (Sequence[~.common.PosixAccount]): + posix_accounts (Sequence[google.cloud.oslogin.v1.common_pb2.PosixAccount]): The list of POSIX accounts associated with the user. - ssh_public_keys (Sequence[~.oslogin.LoginProfile.SshPublicKeysEntry]): + ssh_public_keys (Sequence[google.cloud.oslogin_v1.types.LoginProfile.SshPublicKeysEntry]): A map from SSH public key fingerprint to the associated key object. """ @@ -135,7 +135,7 @@ class ImportSshPublicKeyRequest(proto.Message): parent (str): Required. The unique ID for the user in format ``users/{user}``. - ssh_public_key (~.common.SshPublicKey): + ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): Optional. The SSH public key and expiration time. project_id (str): @@ -154,7 +154,7 @@ class ImportSshPublicKeyResponse(proto.Message): r"""A response message for importing an SSH public key. Attributes: - login_profile (~.oslogin.LoginProfile): + login_profile (google.cloud.oslogin_v1.types.LoginProfile): The login profile information for the user. """ @@ -170,10 +170,10 @@ class UpdateSshPublicKeyRequest(proto.Message): Public keys are identified by their SHA-256 fingerprint. The fingerprint of the public key is in format ``users/{user}/sshPublicKeys/{fingerprint}``. - ssh_public_key (~.common.SshPublicKey): + ssh_public_key (google.cloud.oslogin.v1.common_pb2.SshPublicKey): Required. The SSH public key and expiration time. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Mask to control which fields get updated. Updates all if not present. """ diff --git a/synth.metadata b/synth.metadata index 1fea369..9adf02b 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-oslogin.git", - "sha": "ed84bb127eac218e845468d5d07a476af410ce71" + "sha": "0c70391551868ff8f8a2ee63ce9ec6548ef2517a" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907", - "internalRef": "347055288" + "sha": "520682435235d9c503983a360a2090025aa47cd1", + "internalRef": "350246057" } }, { @@ -89,6 +89,7 @@ "docs/conf.py", "docs/multiprocessing.rst", "docs/oslogin_v1/common/types.rst", + "docs/oslogin_v1/os_login_service.rst", "docs/oslogin_v1/services.rst", "docs/oslogin_v1/types.rst", "google/cloud/oslogin/__init__.py", diff --git a/tests/unit/gapic/oslogin_v1/test_os_login_service.py b/tests/unit/gapic/oslogin_v1/test_os_login_service.py index 435b0f6..1b35f2e 100644 --- a/tests/unit/gapic/oslogin_v1/test_os_login_service.py +++ b/tests/unit/gapic/oslogin_v1/test_os_login_service.py @@ -85,8 +85,21 @@ def test__get_default_mtls_endpoint(): ) +def test_os_login_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 = OsLoginServiceClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "oslogin.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [OsLoginServiceClient, OsLoginServiceAsyncClient] + "client_class", [OsLoginServiceClient, OsLoginServiceAsyncClient,] ) def test_os_login_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -105,7 +118,10 @@ def test_os_login_service_client_from_service_account_file(client_class): def test_os_login_service_client_get_transport_class(): transport = OsLoginServiceClient.get_transport_class() - assert transport == transports.OsLoginServiceGrpcTransport + available_transports = [ + transports.OsLoginServiceGrpcTransport, + ] + assert transport in available_transports transport = OsLoginServiceClient.get_transport_class("grpc") assert transport == transports.OsLoginServiceGrpcTransport @@ -1904,7 +1920,7 @@ def test_os_login_service_host_with_port(): def test_os_login_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.OsLoginServiceGrpcTransport( @@ -1916,7 +1932,7 @@ def test_os_login_service_grpc_transport_channel(): def test_os_login_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.OsLoginServiceGrpcAsyncIOTransport( @@ -1941,7 +1957,7 @@ def test_os_login_service_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1997,7 +2013,7 @@ def test_os_login_service_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel