Skip to content

Commit 1a9e36f

Browse files
lingyinwcopybara-github
authored andcommitted
feat: add encryption_spec_key_name to MatchingEngineIndex create_tree_ah_index and
`create_brute_force_index` PiperOrigin-RevId: 580908192
1 parent 36d4086 commit 1a9e36f

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

google/cloud/aiplatform/matching_engine/matching_engine_index.py

+45
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from google.cloud.aiplatform.compat.types import (
2424
matching_engine_deployed_index_ref as gca_matching_engine_deployed_index_ref,
2525
matching_engine_index as gca_matching_engine_index,
26+
encryption_spec as gca_encryption_spec,
2627
)
2728
from google.cloud.aiplatform import initializer
2829
from google.cloud.aiplatform.matching_engine import (
@@ -109,6 +110,7 @@ def _create(
109110
request_metadata: Optional[Sequence[Tuple[str, str]]] = (),
110111
sync: bool = True,
111112
index_update_method: Optional[str] = None,
113+
encryption_spec_key_name: Optional[str] = None,
112114
) -> "MatchingEngineIndex":
113115
"""Creates a MatchingEngineIndex resource.
114116
@@ -162,6 +164,18 @@ def _create(
162164
Optional. The update method to use with this index. Choose
163165
stream_update or batch_update. If not set, batch update will be
164166
used by default.
167+
encryption_spec_key_name (str):
168+
Optional. The Cloud KMS resource identifier of the customer
169+
managed encryption key used to protect the index. Has the
170+
form:
171+
``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``.
172+
The key needs to be in the same region as where the compute
173+
resource is created.
174+
175+
If set, this index and all sub-resources of this index will be
176+
secured by this key.
177+
The key needs to be in the same region as where the index is
178+
created.
165179
166180
Returns:
167181
MatchingEngineIndex - Index resource object
@@ -181,6 +195,9 @@ def _create(
181195
"contentsDeltaUri": contents_delta_uri,
182196
},
183197
index_update_method=index_update_method_enum,
198+
encryption_spec=gca_encryption_spec.EncryptionSpec(
199+
kms_key_name=encryption_spec_key_name
200+
),
184201
)
185202

186203
if labels:
@@ -394,6 +411,7 @@ def create_tree_ah_index(
394411
request_metadata: Optional[Sequence[Tuple[str, str]]] = (),
395412
sync: bool = True,
396413
index_update_method: Optional[str] = None,
414+
encryption_spec_key_name: Optional[str] = None,
397415
) -> "MatchingEngineIndex":
398416
"""Creates a MatchingEngineIndex resource that uses the tree-AH algorithm.
399417
@@ -472,6 +490,18 @@ def create_tree_ah_index(
472490
Optional. The update method to use with this index. Choose
473491
STREAM_UPDATE or BATCH_UPDATE. If not set, batch update will be
474492
used by default.
493+
encryption_spec_key_name (str):
494+
Optional. The Cloud KMS resource identifier of the customer
495+
managed encryption key used to protect the index. Has the
496+
form:
497+
``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``.
498+
The key needs to be in the same region as where the compute
499+
resource is created.
500+
501+
If set, this index and all sub-resources of this index will be
502+
secured by this key.
503+
The key needs to be in the same region as where the index is
504+
created.
475505
476506
Returns:
477507
MatchingEngineIndex - Index resource object
@@ -502,6 +532,7 @@ def create_tree_ah_index(
502532
request_metadata=request_metadata,
503533
sync=sync,
504534
index_update_method=index_update_method,
535+
encryption_spec_key_name=encryption_spec_key_name,
505536
)
506537

507538
@classmethod
@@ -521,6 +552,7 @@ def create_brute_force_index(
521552
request_metadata: Optional[Sequence[Tuple[str, str]]] = (),
522553
sync: bool = True,
523554
index_update_method: Optional[str] = None,
555+
encryption_spec_key_name: Optional[str] = None,
524556
) -> "MatchingEngineIndex":
525557
"""Creates a MatchingEngineIndex resource that uses the brute force algorithm.
526558
@@ -588,6 +620,18 @@ def create_brute_force_index(
588620
Optional. The update method to use with this index. Choose
589621
stream_update or batch_update. If not set, batch update will be
590622
used by default.
623+
encryption_spec_key_name (str):
624+
Optional. The Cloud KMS resource identifier of the customer
625+
managed encryption key used to protect the index. Has the
626+
form:
627+
``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``.
628+
The key needs to be in the same region as where the compute
629+
resource is created.
630+
631+
If set, this index and all sub-resources of this index will be
632+
secured by this key.
633+
The key needs to be in the same region as where the index is
634+
created.
591635
592636
Returns:
593637
MatchingEngineIndex - Index resource object
@@ -614,6 +658,7 @@ def create_brute_force_index(
614658
request_metadata=request_metadata,
615659
sync=sync,
616660
index_update_method=index_update_method,
661+
encryption_spec_key_name=encryption_spec_key_name,
617662
)
618663

619664

tests/unit/aiplatform/test_matching_engine_index.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
index_service_client,
3333
)
3434

35-
from google.cloud.aiplatform.compat.types import index as gca_index
35+
from google.cloud.aiplatform.compat.types import (
36+
index as gca_index,
37+
encryption_spec as gca_encryption_spec,
38+
)
3639
import constants as test_constants
3740

3841
# project
@@ -104,6 +107,9 @@
104107
_TEST_INDEX_INVALID_UPDATE_METHOD: None,
105108
}
106109

110+
# Encryption spec
111+
_TEST_ENCRYPTION_SPEC_KEY_NAME = "TEST_ENCRYPTION_SPEC"
112+
107113

108114
def uuid_mock():
109115
return uuid.UUID(int=1)
@@ -309,6 +315,7 @@ def test_create_tree_ah_index(self, create_index_mock, sync, index_update_method
309315
labels=_TEST_LABELS,
310316
sync=sync,
311317
index_update_method=index_update_method,
318+
encryption_spec_key_name=_TEST_ENCRYPTION_SPEC_KEY_NAME,
312319
)
313320

314321
if not sync:
@@ -337,6 +344,9 @@ def test_create_tree_ah_index(self, create_index_mock, sync, index_update_method
337344
index_update_method=_TEST_INDEX_UPDATE_METHOD_EXPECTED_RESULT_MAP[
338345
index_update_method
339346
],
347+
encryption_spec=gca_encryption_spec.EncryptionSpec(
348+
kms_key_name=_TEST_ENCRYPTION_SPEC_KEY_NAME
349+
),
340350
)
341351

342352
create_index_mock.assert_called_once_with(
@@ -370,6 +380,7 @@ def test_create_brute_force_index(
370380
labels=_TEST_LABELS,
371381
sync=sync,
372382
index_update_method=index_update_method,
383+
encryption_spec_key_name=_TEST_ENCRYPTION_SPEC_KEY_NAME,
373384
)
374385

375386
if not sync:
@@ -393,6 +404,9 @@ def test_create_brute_force_index(
393404
index_update_method=_TEST_INDEX_UPDATE_METHOD_EXPECTED_RESULT_MAP[
394405
index_update_method
395406
],
407+
encryption_spec=gca_encryption_spec.EncryptionSpec(
408+
kms_key_name=_TEST_ENCRYPTION_SPEC_KEY_NAME
409+
),
396410
)
397411

398412
create_index_mock.assert_called_once_with(

0 commit comments

Comments
 (0)