Skip to content

Commit 09c3486

Browse files
More Changes for api review (Azure#27095)
* Change for api review * Making classes final for api review * Adding samples on clients and changefeed processor class doc * fixing build error on change feed builder doc * Adding closable on encryption clients
1 parent 4b5ab80 commit 09c3486

File tree

10 files changed

+70
-32
lines changed

10 files changed

+70
-32
lines changed

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/ChangeFeedEncryptionProcessorBuilder.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@
1818
import java.util.stream.Collectors;
1919

2020
/**
21-
* Helper class to build a encryption supported {@link ChangeFeedProcessor} instance.
21+
* Helper class to build a {@link ChangeFeedProcessor} instance for encryption feed container.
2222
*
23+
* <pre>
24+
* ChangeFeedProcessor changeFeedProcessor = new ChangeFeedProcessorBuilder&#40;&#41;
25+
* .hostName&#40;hostName&#41;
26+
* .feedContainer&#40;feedContainer&#41; // {@link CosmosEncryptionAsyncContainer}
27+
* .leaseContainer&#40;leaseContainer&#41;
28+
* .handleChanges&#40;docs -&gt; &#123;
29+
* for &#40;JsonNode item : docs&#41; &#123;
30+
* &#47;&#47; Implementation for handling and processing of each JsonNode item goes here
31+
* &#125;
32+
* &#125;&#41;
33+
* .buildChangeFeedProcessor&#40;&#41;;
34+
* </pre>
2335
*/
24-
public class ChangeFeedEncryptionProcessorBuilder {
36+
public final class ChangeFeedEncryptionProcessorBuilder {
2537

2638
private String hostName ;
2739
private ChangeFeedProcessorOptions changeFeedProcessorOptions;

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionAsyncClient.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@
2121
import org.slf4j.LoggerFactory;
2222
import reactor.core.publisher.Mono;
2323

24+
import java.io.Closeable;
25+
2426
/**
25-
* CosmosClient with encryption support.
27+
* CosmosAsyncClient with encryption support.
28+
* We have static method in this class which will takes two inputs
29+
* {@link CosmosAsyncClient} and {@link EncryptionKeyWrapProvider} and creates cosmosEncryptionAsyncClient as shown below.
30+
* <pre>
31+
* {@code
32+
* CosmosEncryptionAsyncClient cosmosEncryptionAsyncClient =
33+
* CosmosEncryptionAsyncClient.createCosmosEncryptionAsyncClient(cosmosAsyncClient, encryptionKeyWrapProvider);
34+
* }
35+
* </pre>
2636
*/
27-
public class CosmosEncryptionAsyncClient {
37+
public final class CosmosEncryptionAsyncClient implements Closeable {
2838
private final static Logger LOGGER = LoggerFactory.getLogger(CosmosEncryptionAsyncClient.class);
2939
private final CosmosAsyncClient cosmosAsyncClient;
3040
private final AsyncCache<String, CosmosContainerProperties> containerPropertiesCacheByContainerId;
@@ -175,6 +185,7 @@ public CosmosEncryptionAsyncDatabase getCosmosEncryptionAsyncDatabase(String dat
175185
/**
176186
* Close this {@link CosmosAsyncClient} instance and cleans up the resources.
177187
*/
188+
@Override
178189
public void close() {
179190
cosmosAsyncClient.close();
180191
}

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionAsyncContainer.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import com.azure.cosmos.models.CosmosBulkItemResponse;
3131
import com.azure.cosmos.models.CosmosBulkOperationResponse;
3232
import com.azure.cosmos.models.CosmosChangeFeedRequestOptions;
33-
import com.azure.cosmos.models.CosmosClientEncryptionKeyProperties;
34-
import com.azure.cosmos.models.CosmosContainerProperties;
3533
import com.azure.cosmos.models.CosmosItemOperation;
3634
import com.azure.cosmos.models.CosmosItemRequestOptions;
3735
import com.azure.cosmos.models.CosmosItemResponse;
@@ -68,7 +66,7 @@
6866
/**
6967
* CosmosAsyncContainer with encryption capabilities.
7068
*/
71-
public class CosmosEncryptionAsyncContainer {
69+
public final class CosmosEncryptionAsyncContainer {
7270
private final Scheduler encryptionScheduler;
7371
private final CosmosResponseFactory responseFactory = new CosmosResponseFactory();
7472
private final CosmosAsyncContainer container;
@@ -226,7 +224,7 @@ public <T> Mono<CosmosItemResponse<Object>> deleteItem(T item, CosmosItemRequest
226224
* @param requestOptions the request options.
227225
* @return an {@link Mono} containing the Cosmos item resource response.
228226
*/
229-
@Beta(value = Beta.SinceVersion.V1, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
227+
@Beta(value = Beta.SinceVersion.V1_0_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
230228
public Mono<CosmosItemResponse<Object>> deleteAllItemsByPartitionKey(PartitionKey partitionKey, CosmosItemRequestOptions requestOptions) {
231229
if (requestOptions == null) {
232230
requestOptions = new CosmosItemRequestOptions();
@@ -523,7 +521,7 @@ public <T> CosmosPagedFlux<T> queryItemsOnEncryptedProperties(SqlQuerySpecWithEn
523521
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained
524522
* items or an error.
525523
*/
526-
@Beta(value = Beta.SinceVersion.V1, warningText =
524+
@Beta(value = Beta.SinceVersion.V1_0_0, warningText =
527525
Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
528526
public <T> CosmosPagedFlux<T> queryChangeFeed(CosmosChangeFeedRequestOptions options, Class<T> classType) {
529527
checkNotNull(options, "Argument 'options' must not be null.");
@@ -955,8 +953,6 @@ public Function<CosmosPagedFluxOptions, Flux<FeedResponse<T>>> transform(Functio
955953
* Use {@link CosmosBatchResponse#isSuccessStatusCode} on the response returned to ensure that the
956954
* transactional batch succeeded.
957955
*/
958-
@Beta(value = Beta.SinceVersion.V1, warningText =
959-
Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
960956
public Mono<CosmosBatchResponse> executeCosmosBatch(CosmosBatch cosmosBatch) {
961957
return this.executeCosmosBatch(cosmosBatch, new CosmosBatchRequestOptions());
962958
}

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionAsyncDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* CosmosEncryptionAsyncDatabase with encryption capabilities.
2727
*/
28-
public class CosmosEncryptionAsyncDatabase {
28+
public final class CosmosEncryptionAsyncDatabase {
2929
private final CosmosAsyncDatabase cosmosAsyncDatabase;
3030
private final CosmosEncryptionAsyncClient cosmosEncryptionAsyncClient;
3131
private final static EncryptionImplementationBridgeHelpers.EncryptionKeyWrapProviderHelper.EncryptionKeyWrapProviderAccessor encryptionKeyWrapProviderAccessor =

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionClient.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@
88
import com.azure.cosmos.CosmosClient;
99
import com.azure.cosmos.CosmosDatabase;
1010
import com.azure.cosmos.encryption.keyprovider.EncryptionKeyWrapProvider;
11-
import com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientHelper.CosmosClientAccessor;
1211
import com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientHelper;
12+
import com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientHelper.CosmosClientAccessor;
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

16+
import java.io.Closeable;
17+
1618
/**
1719
* CosmosClient with encryption support.
20+
* We have static method in this class which will takes two inputs
21+
* {@link CosmosClient} and {@link EncryptionKeyWrapProvider} and creates cosmosEncryptionClient as shown below.
22+
* <pre>
23+
* {@code
24+
* CosmosEncryptionClient cosmosEncryptionClient =
25+
* CosmosEncryptionClient.createCosmosEncryptionClient(cosmosClient, encryptionKeyWrapProvider);
26+
* }
27+
* </pre>
1828
*/
19-
public class CosmosEncryptionClient {
29+
public final class CosmosEncryptionClient implements Closeable {
2030
private final static Logger LOGGER = LoggerFactory.getLogger(CosmosEncryptionAsyncClient.class);
2131
private final CosmosEncryptionAsyncClient cosmosEncryptionAsyncClient;
2232
private EncryptionKeyWrapProvider encryptionKeyWrapProvider;
@@ -89,4 +99,12 @@ public CosmosEncryptionDatabase getCosmosEncryptionDatabase(CosmosDatabase cosmo
8999
CosmosEncryptionAsyncClient getCosmosEncryptionAsyncClient() {
90100
return cosmosEncryptionAsyncClient;
91101
}
102+
103+
/**
104+
* Close this {@link CosmosClient} instance and cleans up the resources.
105+
*/
106+
@Override
107+
public void close() {
108+
cosmosClient.close();
109+
}
92110
}

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionContainer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* CosmosContainer with encryption capabilities.
3838
*/
39-
public class CosmosEncryptionContainer {
39+
public final class CosmosEncryptionContainer {
4040
private final CosmosContainer cosmosContainer;
4141
private final CosmosEncryptionAsyncContainer cosmosEncryptionAsyncContainer;
4242

@@ -124,7 +124,7 @@ public <T> CosmosItemResponse<Object> deleteItem(T item, CosmosItemRequestOption
124124
* @param options the options.
125125
* @return the Cosmos item response
126126
*/
127-
@Beta(value = Beta.SinceVersion.V1, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
127+
@Beta(value = Beta.SinceVersion.V1_0_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
128128
public CosmosItemResponse<Object> deleteAllItemsByPartitionKey(PartitionKey partitionKey, CosmosItemRequestOptions options) {
129129
return this.blockDeleteItemResponse(this.cosmosEncryptionAsyncContainer.deleteAllItemsByPartitionKey(partitionKey, options));
130130
}
@@ -278,7 +278,7 @@ public <T> CosmosPagedIterable<T> queryItemsOnEncryptedProperties(SqlQuerySpecWi
278278
* @param classType the class type.
279279
* @return a {@link CosmosPagedFlux} containing one feed response page
280280
*/
281-
@Beta(value = Beta.SinceVersion.V1, warningText =
281+
@Beta(value = Beta.SinceVersion.V1_0_0, warningText =
282282
Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
283283
public <T> CosmosPagedIterable<T> queryChangeFeed(
284284
CosmosChangeFeedRequestOptions options,

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* CosmosEncryptionDatabase with encryption capabilities.
1818
*/
19-
public class CosmosEncryptionDatabase {
19+
public final class CosmosEncryptionDatabase {
2020
private final CosmosDatabase cosmosDatabase;
2121
private final CosmosEncryptionAsyncDatabase cosmosEncryptionAsyncDatabase;
2222

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/keyprovider/AzureKeyVaultKeyWrapProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.azure.cosmos.encryption.implementation.mdesrc.azurekeyvaultprovider.AzureKeyVaultKeyStoreProvider;
88
import com.azure.cosmos.encryption.implementation.mdesrc.cryptography.KeyEncryptionKeyAlgorithm;
99
import com.azure.cosmos.encryption.implementation.mdesrc.cryptography.MicrosoftDataEncryptionException;
10+
import com.azure.cosmos.encryption.models.KeyEncryptionAlgorithm;
1011
import com.azure.cosmos.implementation.HttpConstants;
1112
import com.azure.cosmos.implementation.ImplementationBridgeHelpers;
1213

@@ -30,7 +31,7 @@
3031
* <p>
3132
* signature: Signature of the entire byte array. Signature is validated before decrypting the data encryption key.
3233
*/
33-
public class AzureKeyVaultKeyWrapProvider extends EncryptionKeyWrapProvider {
34+
public final class AzureKeyVaultKeyWrapProvider extends EncryptionKeyWrapProvider {
3435
private AzureKeyVaultKeyStoreProvider azureKeyVaultKeyStoreProvider;
3536
private final static ImplementationBridgeHelpers.CosmosExceptionHelper.CosmosExceptionAccessor cosmosExceptionAccessor =
3637
ImplementationBridgeHelpers.CosmosExceptionHelper.getCosmosExceptionAccessor();
@@ -71,7 +72,7 @@ public String getProviderName() {
7172
@Override
7273
public byte[] unwrapKey(String encryptionKeyId, String cosmosKeyEncryptionKeyAlgorithm, byte[] encryptedKey) {
7374
try {
74-
if (!com.azure.cosmos.encryption.models.KeyEncryptionKeyAlgorithm.RSA_OAEP.getName().equals(cosmosKeyEncryptionKeyAlgorithm)) {
75+
if (!KeyEncryptionAlgorithm.RSA_OAEP.getName().equals(cosmosKeyEncryptionKeyAlgorithm)) {
7576
throw new IllegalArgumentException("The specified KeyEncryptionAlgorithm is not supported. Please " +
7677
"refer to https://aka.ms/CosmosClientEncryption for more details. ");
7778
}
@@ -93,7 +94,7 @@ public byte[] unwrapKey(String encryptionKeyId, String cosmosKeyEncryptionKeyAlg
9394
@Override
9495
public byte[] wrapKey(String encryptionKeyId, String cosmosKeyEncryptionKeyAlgorithm, byte[] key) {
9596
try {
96-
if (!com.azure.cosmos.encryption.models.KeyEncryptionKeyAlgorithm.RSA_OAEP.getName().equals(cosmosKeyEncryptionKeyAlgorithm)) {
97+
if (!KeyEncryptionAlgorithm.RSA_OAEP.getName().equals(cosmosKeyEncryptionKeyAlgorithm)) {
9798
throw new IllegalArgumentException("The specified KeyEncryptionAlgorithm is not supported. Please " +
9899
"refer to https://aka.ms/CosmosClientEncryption for more details. ");
99100
}

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/models/KeyEncryptionKeyAlgorithm.java renamed to sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/models/KeyEncryptionAlgorithm.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
* Represents the encryption algorithms supported for key encryption.
1212
*
1313
*/
14-
public enum KeyEncryptionKeyAlgorithm {
14+
public enum KeyEncryptionAlgorithm {
1515
/**
1616
* RSA public key cryptography algorithm with Optimal Asymmetric Encryption Padding (OAEP) padding.
1717
*/
1818
RSA_OAEP("RSA_OAEP");
1919

2020
private final String keyEncryptionKeyAlgorithmName;
21-
private static final Map<String, KeyEncryptionKeyAlgorithm> ENUM_MAP;
21+
private static final Map<String, KeyEncryptionAlgorithm> ENUM_MAP;
2222

23-
KeyEncryptionKeyAlgorithm(String keyEncryptionKeyAlgorithmName) {
23+
KeyEncryptionAlgorithm(String keyEncryptionKeyAlgorithmName) {
2424
this.keyEncryptionKeyAlgorithmName = keyEncryptionKeyAlgorithmName;
2525
}
2626

@@ -45,19 +45,19 @@ public String getName() {
4545
// Any Map impl can be used.
4646

4747
static {
48-
Map<String, KeyEncryptionKeyAlgorithm> map = new ConcurrentHashMap<>();
49-
for (KeyEncryptionKeyAlgorithm instance : KeyEncryptionKeyAlgorithm.values()) {
48+
Map<String, KeyEncryptionAlgorithm> map = new ConcurrentHashMap<>();
49+
for (KeyEncryptionAlgorithm instance : KeyEncryptionAlgorithm.values()) {
5050
map.put(instance.getName(), instance);
5151
}
5252
ENUM_MAP = Collections.unmodifiableMap(map);
5353
}
5454

5555
/**
56-
* Gets the KeyEncryptionKeyAlgorithm enum back from the string value
56+
* Gets the KeyEncryptionAlgorithm enum back from the string value
5757
* @param name the string value
58-
* @return KeyEncryptionKeyAlgorithm enum
58+
* @return KeyEncryptionAlgorithm enum
5959
*/
60-
public static KeyEncryptionKeyAlgorithm get(String name) {
60+
public static KeyEncryptionAlgorithm get(String name) {
6161
return ENUM_MAP.get(name);
6262
}
6363
}

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/util/Beta.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
/**
3939
* @return the version number when the annotated API was first introduced to the library as in Beta
4040
*/
41-
SinceVersion value() default SinceVersion.V1;
41+
SinceVersion value() default SinceVersion.V1_0_0;
4242

4343
/**
4444
* Azure library version numbers
4545
*/
4646
enum SinceVersion {
47-
/** v1 */
48-
V1
47+
/** v1_0_0 */
48+
V1_0_0
4949
}
5050
}

0 commit comments

Comments
 (0)