1# Copyright 2015 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Define class for the custom encryption configuration."""
16
17import copy
18
19
20class EncryptionConfiguration(object):
21 """Custom encryption configuration (e.g., Cloud KMS keys).
22
23 Args:
24 kms_key_name (str): resource ID of Cloud KMS key used for encryption
25 """
26
27 def __init__(self, kms_key_name=None) -> None:
28 self._properties = {}
29 if kms_key_name is not None:
30 self._properties["kmsKeyName"] = kms_key_name
31
32 @property
33 def kms_key_name(self):
34 """str: Resource ID of Cloud KMS key
35
36 Resource ID of Cloud KMS key or :data:`None` if using default
37 encryption.
38 """
39 return self._properties.get("kmsKeyName")
40
41 @kms_key_name.setter
42 def kms_key_name(self, value):
43 self._properties["kmsKeyName"] = value
44
45 @classmethod
46 def from_api_repr(cls, resource):
47 """Construct an encryption configuration from its API representation
48
49 Args:
50 resource (Dict[str, object]):
51 An encryption configuration representation as returned from
52 the API.
53
54 Returns:
55 google.cloud.bigquery.table.EncryptionConfiguration:
56 An encryption configuration parsed from ``resource``.
57 """
58 config = cls()
59 config._properties = copy.deepcopy(resource)
60 return config
61
62 def to_api_repr(self):
63 """Construct the API resource representation of this encryption
64 configuration.
65
66 Returns:
67 Dict[str, object]:
68 Encryption configuration as represented as an API resource
69 """
70 return copy.deepcopy(self._properties)
71
72 def __eq__(self, other):
73 if not isinstance(other, EncryptionConfiguration):
74 return NotImplemented
75 return self.kms_key_name == other.kms_key_name
76
77 def __ne__(self, other):
78 return not self == other
79
80 def __hash__(self):
81 return hash(self.kms_key_name)
82
83 def __repr__(self):
84 return "EncryptionConfiguration({})".format(self.kms_key_name)