nevzheng commented on code in PR #12132: URL: https://github.com/apache/gravitino/pull/12132#discussion_r3633610446
########## api/src/main/java/org/apache/gravitino/encryption/kms/KmsKeyProperties.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.encryption.kms; + +import org.apache.gravitino.annotation.DeveloperApi; + +/** + * Common properties reported for a KMS key. + * + * <p>Capabilities describe downstream use; this API does not perform cryptographic operations. + */ Review Comment: Addressed in cf4a8c976 by making presence structural: `KmsClient.getKeyProperties` now returns `Optional<KmsKeyProperties>`, and `present()` is removed. `Optional.empty()` is reserved for authoritative provider not-found, while authentication, authorization, timeout, availability, and other indeterminate failures remain exceptions. `KmsKeyProperties` therefore only describes a located key, and its Javadocs now define the lifecycle and structural-capability semantics. ########## api/src/testFixtures/java/org/apache/gravitino/encryption/kms/TestKmsClientContract.java: ########## @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.encryption.kms; + +import java.util.Arrays; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** Common inspection contract for implemented KMS clients. */ +public abstract class TestKmsClientContract { + + /** + * Returns the client under test. + * + * @return the client + */ + protected abstract KmsClient client(); + + /** + * Returns a reference to an enabled key that supports wrapping and unwrapping. + * + * @return the usable key reference + */ + protected abstract KmsReference usableKey(); + + /** + * Returns a reference to a key that does not exist. + * + * @return the missing key reference + */ + protected abstract KmsReference missingKey(); + + @Test + void testReportsUsableKeyProperties() { + KmsReference reference = usableKey(); + KmsKeyProperties properties = client().getKeyProperties(reference); + + Assertions.assertEquals(reference, properties.reference()); + Assertions.assertTrue(properties.present()); + Assertions.assertTrue(properties.enabled()); + Assertions.assertTrue(properties.supportsWrapping()); + Assertions.assertTrue(properties.supportsUnwrapping()); + } + + @Test + void testReportsMissingKey() { + KmsReference reference = missingKey(); + KmsKeyProperties properties = client().getKeyProperties(reference); + + Assertions.assertEquals(reference, properties.reference()); + Assertions.assertFalse(properties.present()); + } Review Comment: Addressed in cf4a8c976. The reusable provider contract now requires a non-null `Optional`, asserts `Optional.of` for a found key, and asserts `Optional.empty` for authoritative not-found. The fake-client tests also cover a disabled-but-present key, so lifecycle state is independent from presence. API/common tests, Spotless, test-fixture packaging, and Javadocs pass. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
