Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: accept custom client_info (#41)
  • Loading branch information
yoshi-automation committed Aug 27, 2020
1 parent 9edcc9a commit 6688e80
Show file tree
Hide file tree
Showing 12 changed files with 1,401 additions and 406 deletions.
26 changes: 24 additions & 2 deletions google/cloud/kms_v1/proto/resources.proto
Expand Up @@ -20,6 +20,7 @@ import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";

option cc_enable_arenas = true;
Expand Down Expand Up @@ -48,8 +49,8 @@ message KeyRing {
// A [CryptoKey][google.cloud.kms.v1.CryptoKey] represents a logical key that can be used for cryptographic
// operations.
//
// A [CryptoKey][google.cloud.kms.v1.CryptoKey] is made up of one or more [versions][google.cloud.kms.v1.CryptoKeyVersion], which
// represent the actual key material used in cryptographic operations.
// A [CryptoKey][google.cloud.kms.v1.CryptoKey] is made up of zero or more [versions][google.cloud.kms.v1.CryptoKeyVersion],
// which represent the actual key material used in cryptographic operations.
message CryptoKey {
option (google.api.resource) = {
type: "cloudkms.googleapis.com/CryptoKey"
Expand Down Expand Up @@ -418,6 +419,27 @@ message PublicKey {
// The [Algorithm][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionAlgorithm] associated
// with this key.
CryptoKeyVersion.CryptoKeyVersionAlgorithm algorithm = 2;

// Integrity verification field. A CRC32C checksum of the returned
// [PublicKey.pem][google.cloud.kms.v1.PublicKey.pem]. An integrity check of [PublicKey.pem][google.cloud.kms.v1.PublicKey.pem] can be performed
// by computing the CRC32C checksum of [PublicKey.pem][google.cloud.kms.v1.PublicKey.pem] and
// comparing your results to this field. Discard the response in case of
// non-matching checksum values, and perform a limited number of retries. A
// persistent mismatch may indicate an issue in your computation of the CRC32C
// checksum.
// Note: This field is defined as int64 for reasons of compatibility across
// different languages. However, it is a non-negative integer, which will
// never exceed 2^32-1, and can be safely downconverted to uint32 in languages
// that support this type.
//
// NOTE: This field is in Beta.
google.protobuf.Int64Value pem_crc32c = 3;

// The [name][google.cloud.kms.v1.CryptoKeyVersion.name] of the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] public key.
// Provided here for verification.
//
// NOTE: This field is in Beta.
string name = 4;
}

// An [ImportJob][google.cloud.kms.v1.ImportJob] can be used to create [CryptoKeys][google.cloud.kms.v1.CryptoKey] and
Expand Down
222 changes: 222 additions & 0 deletions google/cloud/kms_v1/proto/service.proto

Large diffs are not rendered by default.

81 changes: 43 additions & 38 deletions google/cloud/kms_v1/services/key_management_service/async_client.py
Expand Up @@ -36,8 +36,9 @@
from google.protobuf import duration_pb2 as duration # type: ignore
from google.protobuf import field_mask_pb2 as field_mask # type: ignore
from google.protobuf import timestamp_pb2 as timestamp # type: ignore
from google.protobuf import wrappers_pb2 as wrappers # type: ignore

from .transports.base import KeyManagementServiceTransport
from .transports.base import KeyManagementServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import KeyManagementServiceGrpcAsyncIOTransport
from .client import KeyManagementServiceClient

Expand All @@ -62,16 +63,16 @@ class KeyManagementServiceAsyncClient:
DEFAULT_ENDPOINT = KeyManagementServiceClient.DEFAULT_ENDPOINT
DEFAULT_MTLS_ENDPOINT = KeyManagementServiceClient.DEFAULT_MTLS_ENDPOINT

crypto_key_path = staticmethod(KeyManagementServiceClient.crypto_key_path)

import_job_path = staticmethod(KeyManagementServiceClient.import_job_path)

crypto_key_version_path = staticmethod(
KeyManagementServiceClient.crypto_key_version_path
)

key_ring_path = staticmethod(KeyManagementServiceClient.key_ring_path)

crypto_key_path = staticmethod(KeyManagementServiceClient.crypto_key_path)

import_job_path = staticmethod(KeyManagementServiceClient.import_job_path)

from_service_account_file = KeyManagementServiceClient.from_service_account_file
from_service_account_json = from_service_account_file

Expand All @@ -86,6 +87,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, KeyManagementServiceTransport] = "grpc_asyncio",
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the key management service client.
Expand Down Expand Up @@ -119,7 +121,10 @@ def __init__(
"""

self._client = KeyManagementServiceClient(
credentials=credentials, transport=transport, client_options=client_options,
credentials=credentials,
transport=transport,
client_options=client_options,
client_info=client_info,
)

async def list_key_rings(
Expand Down Expand Up @@ -193,7 +198,7 @@ async def list_key_rings(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -285,7 +290,7 @@ async def list_crypto_keys(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -378,7 +383,7 @@ async def list_crypto_key_versions(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -470,7 +475,7 @@ async def list_import_jobs(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -560,7 +565,7 @@ async def get_key_ring(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -615,7 +620,7 @@ async def get_crypto_key(
operations.
A [CryptoKey][google.cloud.kms.v1.CryptoKey] is made up
of one or more
of zero or more
[versions][google.cloud.kms.v1.CryptoKeyVersion], which
represent the actual key material used in cryptographic
operations.
Expand Down Expand Up @@ -653,7 +658,7 @@ async def get_crypto_key(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -751,7 +756,7 @@ async def get_crypto_key_version(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -843,7 +848,7 @@ async def get_public_key(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -970,7 +975,7 @@ async def get_import_job(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1073,7 +1078,7 @@ async def create_key_ring(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1144,7 +1149,7 @@ async def create_crypto_key(
operations.
A [CryptoKey][google.cloud.kms.v1.CryptoKey] is made up
of one or more
of zero or more
[versions][google.cloud.kms.v1.CryptoKeyVersion], which
represent the actual key material used in cryptographic
operations.
Expand Down Expand Up @@ -1186,7 +1191,7 @@ async def create_crypto_key(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1290,7 +1295,7 @@ async def create_crypto_key_version(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.create_crypto_key_version,
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1361,7 +1366,7 @@ async def import_crypto_key_version(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.import_crypto_key_version,
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1509,7 +1514,7 @@ async def create_import_job(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1567,7 +1572,7 @@ async def update_crypto_key(
operations.
A [CryptoKey][google.cloud.kms.v1.CryptoKey] is made up
of one or more
of zero or more
[versions][google.cloud.kms.v1.CryptoKeyVersion], which
represent the actual key material used in cryptographic
operations.
Expand Down Expand Up @@ -1607,7 +1612,7 @@ async def update_crypto_key(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1727,7 +1732,7 @@ async def update_crypto_key_version(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1840,7 +1845,7 @@ async def encrypt(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -1937,7 +1942,7 @@ async def decrypt(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2036,7 +2041,7 @@ async def asymmetric_sign(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2135,7 +2140,7 @@ async def asymmetric_decrypt(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2198,7 +2203,7 @@ async def update_crypto_key_primary_version(
operations.
A [CryptoKey][google.cloud.kms.v1.CryptoKey] is made up
of one or more
of zero or more
[versions][google.cloud.kms.v1.CryptoKeyVersion], which
represent the actual key material used in cryptographic
operations.
Expand Down Expand Up @@ -2238,7 +2243,7 @@ async def update_crypto_key_primary_version(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2354,7 +2359,7 @@ async def destroy_crypto_key_version(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2461,7 +2466,7 @@ async def restore_crypto_key_version(
),
),
default_timeout=60.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2571,7 +2576,7 @@ async def set_iam_policy(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.set_iam_policy,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2682,7 +2687,7 @@ async def get_iam_policy(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_iam_policy,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -2734,7 +2739,7 @@ async def test_iam_permissions(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.test_iam_permissions,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand All @@ -2751,11 +2756,11 @@ async def test_iam_permissions(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution("google-cloud-kms",).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("KeyManagementServiceAsyncClient",)

0 comments on commit 6688e80

Please sign in to comment.