diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java index 27dc71a185c7..87080578fd21 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java @@ -5,6 +5,7 @@ import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.Constants; +import com.azure.cosmos.implementation.CosmosError; import com.azure.cosmos.implementation.CosmosItemProperties; import com.azure.cosmos.implementation.DatabaseAccount; import com.azure.cosmos.implementation.Document; @@ -27,7 +28,6 @@ import com.azure.cosmos.implementation.query.metrics.ClientSideMetrics; import com.azure.cosmos.implementation.routing.PartitionKeyInternal; import com.azure.cosmos.models.CosmosAsyncItemResponse; -import com.azure.cosmos.implementation.CosmosError; import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.CosmosStoredProcedureProperties; import com.azure.cosmos.models.FeedResponse; @@ -442,11 +442,6 @@ public static CosmosItemProperties getProperties(CosmosItemResponse cosmo return ModelBridgeInternal.getCosmosItemProperties(cosmosItemResponse); } - @Warning(value = INTERNAL_USE_ONLY_WARNING) - public static int getHashCode(CosmosKeyCredential keyCredential) { - return keyCredential.getKeyHashCode(); - } - @Warning(value = INTERNAL_USE_ONLY_WARNING) public static String getLink(CosmosAsyncContainer cosmosAsyncContainer) { return cosmosAsyncContainer.getLink(); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java index 42808d6a210b..bcdcb5febc70 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java @@ -3,6 +3,7 @@ package com.azure.cosmos; import com.azure.core.annotation.ServiceClient; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.implementation.AsyncDocumentClient; import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.ConnectionPolicy; @@ -48,7 +49,7 @@ public final class CosmosAsyncClient implements Closeable { private final ConsistencyLevel desiredConsistencyLevel; private final List permissions; private final CosmosAuthorizationTokenResolver cosmosAuthorizationTokenResolver; - private final CosmosKeyCredential cosmosKeyCredential; + private final AzureKeyCredential credential; private final boolean sessionCapturingOverride; private final boolean enableTransportClientSharing; private final boolean contentResponseOnWriteEnabled; @@ -61,7 +62,7 @@ public final class CosmosAsyncClient implements Closeable { this.desiredConsistencyLevel = builder.getConsistencyLevel(); this.permissions = builder.getPermissions(); this.cosmosAuthorizationTokenResolver = builder.getAuthorizationTokenResolver(); - this.cosmosKeyCredential = builder.getKeyCredential(); + this.credential = builder.getCredential(); this.sessionCapturingOverride = builder.isSessionCapturingOverrideEnabled(); this.enableTransportClientSharing = builder.isConnectionSharingAcrossClientsEnabled(); this.contentResponseOnWriteEnabled = builder.isContentResponseOnWriteEnabled(); @@ -73,7 +74,7 @@ public final class CosmosAsyncClient implements Closeable { .withSessionCapturingOverride(this.sessionCapturingOverride) .withConfigs(this.configs) .withTokenResolver(this.cosmosAuthorizationTokenResolver) - .withCosmosKeyCredential(this.cosmosKeyCredential) + .withCredential(this.credential) .withTransportClientSharing(this.enableTransportClientSharing) .withContentResponseOnWriteEnabled(this.contentResponseOnWriteEnabled) .build(); @@ -160,12 +161,12 @@ CosmosAuthorizationTokenResolver getCosmosAuthorizationTokenResolver() { } /** - * Gets the cosmos key credential + * Gets the azure key credential * - * @return cosmos key credential + * @return azure key credential */ - CosmosKeyCredential cosmosKeyCredential() { - return cosmosKeyCredential; + AzureKeyCredential credential() { + return credential; } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosBridgeInternal.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosBridgeInternal.java index 0ab8ce775bae..476939832026 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosBridgeInternal.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosBridgeInternal.java @@ -80,7 +80,7 @@ public static CosmosClientBuilder cloneCosmosClientBuilder(CosmosClientBuilder b .directMode(builder.getDirectConnectionConfig()) .gatewayMode(builder.getGatewayConnectionConfig()) .consistencyLevel(builder.getConsistencyLevel()) - .keyCredential(builder.getKeyCredential()) + .credential(builder.getCredential()) .permissions(builder.getPermissions()) .authorizationTokenResolver(builder.getAuthorizationTokenResolver()) .resourceToken(builder.getResourceToken()) diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java index 94934c3d8fc1..c8c350efdb74 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java @@ -3,6 +3,7 @@ package com.azure.cosmos; import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.ConnectionPolicy; import com.azure.cosmos.implementation.CosmosAuthorizationTokenResolver; @@ -38,7 +39,7 @@ public class CosmosClientBuilder { private ConsistencyLevel desiredConsistencyLevel; private List permissions; private CosmosAuthorizationTokenResolver cosmosAuthorizationTokenResolver; - private CosmosKeyCredential cosmosKeyCredential; + private AzureKeyCredential credential; private boolean sessionCapturingOverrideEnabled; private boolean connectionSharingAcrossClientsEnabled; private boolean contentResponseOnWriteEnabled; @@ -273,22 +274,22 @@ ConnectionPolicy getConnectionPolicy() { } /** - * Gets the {@link CosmosKeyCredential} to be used + * Gets the {@link AzureKeyCredential} to be used * - * @return cosmosKeyCredential + * @return {@link AzureKeyCredential} */ - CosmosKeyCredential getKeyCredential() { - return cosmosKeyCredential; + AzureKeyCredential getCredential() { + return credential; } /** - * Sets the {@link CosmosKeyCredential} to be used + * Sets the {@link AzureKeyCredential} to be used * - * @param cosmosKeyCredential {@link CosmosKeyCredential} + * @param credential {@link AzureKeyCredential} * @return current cosmosClientBuilder */ - public CosmosClientBuilder keyCredential(CosmosKeyCredential cosmosKeyCredential) { - this.cosmosKeyCredential = cosmosKeyCredential; + public CosmosClientBuilder credential(AzureKeyCredential credential) { + this.credential = credential; return this; } @@ -634,10 +635,10 @@ private void validateConfig() { ifThrowIllegalArgException(this.serviceEndpoint == null, "cannot buildAsyncClient client without service endpoint"); ifThrowIllegalArgException( - this.keyOrResourceToken == null && (permissions == null || permissions.isEmpty()) && this.cosmosKeyCredential == null, + this.keyOrResourceToken == null && (permissions == null || permissions.isEmpty()) && this.credential == null, "cannot buildAsyncClient client without any one of key, resource token, permissions, and " - + "cosmos key credential"); - ifThrowIllegalArgException(cosmosKeyCredential != null && StringUtils.isEmpty(cosmosKeyCredential.getKey()), + + "azure key credential"); + ifThrowIllegalArgException(credential != null && StringUtils.isEmpty(credential.getKey()), "cannot buildAsyncClient client without key credential"); ifThrowIllegalArgException(directConnectionConfig == null && gatewayConnectionConfig == null, "cannot buildAsyncClient client without connection config"); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosKeyCredential.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosKeyCredential.java deleted file mode 100644 index ffe8a7388ac7..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosKeyCredential.java +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.cosmos; - -/** - * Cosmos Key Credential is used to store key credentials, in order to support dynamic key rotation. - * Singleton instance should be used to support multiple keys. - * Azure client library for Cosmos ensures to use the updated key provided in the same singleton instance - * which was used when building {@link CosmosAsyncClient} - */ -public class CosmosKeyCredential { - - private String key; - - // Stores key's hashcode for performance improvements - private int keyHashCode; - - /** - * Instantiates a new Cosmos key credential. - * - * @param key the key - */ - public CosmosKeyCredential(String key) { - this.key = key; - this.keyHashCode = key.hashCode(); - } - - /** - * Returns the key stored in Cosmos Key Credential - * - * @return key - */ - public String getKey() { - return key; - } - - /** - * Sets the key to be used in CosmosKeyCredential - * - * @param key key to be used in CosmosKeyCredential - * @return current CosmosKeyCredential - */ - public CosmosKeyCredential setKey(String key) { - this.key = key; - this.keyHashCode = key.hashCode(); - return this; - } - - /** - * CosmosKeyCredential stores the computed hashcode of the key for performance improvements. - * - * @return hashcode of the key - */ - int getKeyHashCode() { - return this.keyHashCode; - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java index cfc315ce1449..4b74aff1a453 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java @@ -2,8 +2,8 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.ConsistencyLevel; -import com.azure.cosmos.CosmosKeyCredential; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.models.FeedOptions; import com.azure.cosmos.models.FeedResponse; @@ -71,7 +71,7 @@ class Builder { String masterKeyOrResourceToken; URI serviceEndpoint; CosmosAuthorizationTokenResolver cosmosAuthorizationTokenResolver; - CosmosKeyCredential cosmosKeyCredential; + AzureKeyCredential credential; boolean sessionCapturingOverride; boolean transportClientSharing; boolean contentResponseOnWriteEnabled; @@ -148,11 +148,11 @@ public Builder withTransportClientSharing(boolean transportClientSharing) { return this; } - public Builder withCosmosKeyCredential(CosmosKeyCredential cosmosKeyCredential) { - if (cosmosKeyCredential != null && StringUtils.isEmpty(cosmosKeyCredential.getKey())) { + public Builder withCredential(AzureKeyCredential credential) { + if (credential != null && StringUtils.isEmpty(credential.getKey())) { throw new IllegalArgumentException("Cannot buildAsyncClient client with empty key credential"); } - this.cosmosKeyCredential = cosmosKeyCredential; + this.credential = credential; return this; } @@ -183,10 +183,10 @@ public AsyncDocumentClient build() { ifThrowIllegalArgException(this.serviceEndpoint == null, "cannot buildAsyncClient client without service endpoint"); ifThrowIllegalArgException( this.masterKeyOrResourceToken == null && (permissionFeed == null || permissionFeed.isEmpty()) - && this.cosmosKeyCredential == null, + && this.credential == null, "cannot buildAsyncClient client without any one of masterKey, " + - "resource token, permissionFeed and cosmos key credential"); - ifThrowIllegalArgException(cosmosKeyCredential != null && StringUtils.isEmpty(cosmosKeyCredential.getKey()), + "resource token, permissionFeed and azure key credential"); + ifThrowIllegalArgException(credential != null && StringUtils.isEmpty(credential.getKey()), "cannot buildAsyncClient client without key credential"); RxDocumentClientImpl client = new RxDocumentClientImpl(serviceEndpoint, @@ -196,7 +196,7 @@ public AsyncDocumentClient build() { desiredConsistencyLevel, configs, cosmosAuthorizationTokenResolver, - cosmosKeyCredential, + credential, sessionCapturingOverride, transportClientSharing, contentResponseOnWriteEnabled); @@ -260,8 +260,8 @@ public void setCosmosAuthorizationTokenResolver(CosmosAuthorizationTokenResolver this.cosmosAuthorizationTokenResolver = cosmosAuthorizationTokenResolver; } - public CosmosKeyCredential getCosmosKeyCredential() { - return cosmosKeyCredential; + public AzureKeyCredential getCredential() { + return credential; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/BaseAuthorizationTokenProvider.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/BaseAuthorizationTokenProvider.java index 001a3902c745..bbfff00cd555 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/BaseAuthorizationTokenProvider.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/BaseAuthorizationTokenProvider.java @@ -3,11 +3,10 @@ package com.azure.cosmos.implementation; -import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.CosmosKeyCredential; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; -import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.implementation.directconnectivity.HttpUtils; +import com.azure.cosmos.models.ModelBridgeInternal; import javax.crypto.Mac; import javax.crypto.SecretKey; @@ -28,14 +27,14 @@ public class BaseAuthorizationTokenProvider implements AuthorizationTokenProvider { private static final String AUTH_PREFIX = "type=master&ver=1.0&sig="; - private final CosmosKeyCredential cosmosKeyCredential; + private final AzureKeyCredential credential; private final Mac macInstance; // stores current master key's hashcode for performance reasons. private int masterKeyHashCode; - public BaseAuthorizationTokenProvider(CosmosKeyCredential cosmosKeyCredential) { - this.cosmosKeyCredential = cosmosKeyCredential; + public BaseAuthorizationTokenProvider(AzureKeyCredential credential) { + this.credential = credential; this.macInstance = getMacInstance(); } @@ -120,7 +119,7 @@ public String generateKeyAuthorizationSignature(RequestVerb verb, throw new IllegalArgumentException("headers"); } - if (StringUtils.isEmpty(this.cosmosKeyCredential.getKey())) { + if (StringUtils.isEmpty(this.credential.getKey())) { throw new IllegalArgumentException("key credentials cannot be empty"); } @@ -246,11 +245,11 @@ private String generateKeyAuthorizationSignatureNew(RequestVerb verb, String res } private Mac getMacInstance() { - int masterKeyLatestHashCode = BridgeInternal.getHashCode(this.cosmosKeyCredential); + int masterKeyLatestHashCode = this.credential.getKey().hashCode(); // Master key has changed, or this is the first time we are getting mac instance if (masterKeyLatestHashCode != this.masterKeyHashCode) { - byte[] masterKeyBytes = this.cosmosKeyCredential.getKey().getBytes(StandardCharsets.UTF_8); + byte[] masterKeyBytes = this.credential.getKey().getBytes(StandardCharsets.UTF_8); byte[] masterKeyDecodedBytes = Utils.Base64Decoder.decode(masterKeyBytes); SecretKey signingKey = new SecretKeySpec(masterKeyDecodedBytes, "HMACSHA256"); try { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java index 4456303a5756..f4e5061e7dee 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java @@ -2,10 +2,10 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.ConsistencyLevel; -import com.azure.cosmos.CosmosKeyCredential; import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.models.FeedOptions; import com.azure.cosmos.models.FeedResponse; @@ -87,7 +87,7 @@ public class RxDocumentClientImpl implements AsyncDocumentClient, IAuthorization private final boolean hasAuthKeyResourceToken; private final Configs configs; private final boolean connectionSharingAcrossClientsEnabled; - private CosmosKeyCredential cosmosKeyCredential; + private AzureKeyCredential credential; private CosmosAuthorizationTokenResolver cosmosAuthorizationTokenResolver; private SessionContainer sessionContainer; private String firstResourceTokenFromPermissionFeed = StringUtils.EMPTY; @@ -129,12 +129,12 @@ public RxDocumentClientImpl(URI serviceEndpoint, ConsistencyLevel consistencyLevel, Configs configs, CosmosAuthorizationTokenResolver cosmosAuthorizationTokenResolver, - CosmosKeyCredential cosmosKeyCredential, + AzureKeyCredential credential, boolean sessionCapturingOverride, boolean connectionSharingAcrossClientsEnabled, boolean contentResponseOnWriteEnabled) { this(serviceEndpoint, masterKeyOrResourceToken, permissionFeed, connectionPolicy, consistencyLevel, configs, - cosmosKeyCredential, sessionCapturingOverride, connectionSharingAcrossClientsEnabled, contentResponseOnWriteEnabled); + credential, sessionCapturingOverride, connectionSharingAcrossClientsEnabled, contentResponseOnWriteEnabled); this.cosmosAuthorizationTokenResolver = cosmosAuthorizationTokenResolver; } @@ -144,12 +144,12 @@ private RxDocumentClientImpl(URI serviceEndpoint, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, - CosmosKeyCredential cosmosKeyCredential, + AzureKeyCredential credential, boolean sessionCapturingOverrideEnabled, boolean connectionSharingAcrossClientsEnabled, boolean contentResponseOnWriteEnabled) { this(serviceEndpoint, masterKeyOrResourceToken, connectionPolicy, consistencyLevel, configs, - cosmosKeyCredential, sessionCapturingOverrideEnabled, connectionSharingAcrossClientsEnabled, contentResponseOnWriteEnabled); + credential, sessionCapturingOverrideEnabled, connectionSharingAcrossClientsEnabled, contentResponseOnWriteEnabled); if (permissionFeed != null && permissionFeed.size() > 0) { this.resourceTokensMap = new HashMap<>(); for (Permission permission : permissionFeed) { @@ -197,7 +197,7 @@ private RxDocumentClientImpl(URI serviceEndpoint, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, - CosmosKeyCredential cosmosKeyCredential, + AzureKeyCredential credential, boolean sessionCapturingOverrideEnabled, boolean connectionSharingAcrossClientsEnabled, boolean contentResponseOnWriteEnabled) { @@ -211,19 +211,19 @@ private RxDocumentClientImpl(URI serviceEndpoint, this.configs = configs; this.masterKeyOrResourceToken = masterKeyOrResourceToken; this.serviceEndpoint = serviceEndpoint; - this.cosmosKeyCredential = cosmosKeyCredential; + this.credential = credential; this.contentResponseOnWriteEnabled = contentResponseOnWriteEnabled; - if (this.cosmosKeyCredential != null) { + if (this.credential != null) { hasAuthKeyResourceToken = false; - this.authorizationTokenProvider = new BaseAuthorizationTokenProvider(this.cosmosKeyCredential); + this.authorizationTokenProvider = new BaseAuthorizationTokenProvider(this.credential); } else if (masterKeyOrResourceToken != null && ResourceTokenAuthorizationHelper.isResourceToken(masterKeyOrResourceToken)) { this.authorizationTokenProvider = null; hasAuthKeyResourceToken = true; } else if(masterKeyOrResourceToken != null && !ResourceTokenAuthorizationHelper.isResourceToken(masterKeyOrResourceToken)){ - this.cosmosKeyCredential = new CosmosKeyCredential(this.masterKeyOrResourceToken); + this.credential = new AzureKeyCredential(this.masterKeyOrResourceToken); hasAuthKeyResourceToken = false; - this.authorizationTokenProvider = new BaseAuthorizationTokenProvider(this.cosmosKeyCredential); + this.authorizationTokenProvider = new BaseAuthorizationTokenProvider(this.credential); } else { hasAuthKeyResourceToken = false; this.authorizationTokenProvider = null; @@ -1089,7 +1089,7 @@ private Mono getCreateDocumentRequest(DocumentClientRe private void populateHeaders(RxDocumentServiceRequest request, RequestVerb httpMethod) { request.getHeaders().put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); if (this.masterKeyOrResourceToken != null || this.resourceTokensMap != null - || this.cosmosAuthorizationTokenResolver != null || this.cosmosKeyCredential != null) { + || this.cosmosAuthorizationTokenResolver != null || this.credential != null) { String resourceName = request.getResourceAddress(); String authorization = this.getUserAuthorizationToken( @@ -1124,7 +1124,7 @@ public String getUserAuthorizationToken(String resourceName, if (this.cosmosAuthorizationTokenResolver != null) { return this.cosmosAuthorizationTokenResolver.getAuthorizationToken(requestVerb, resourceName, this.resolveCosmosResourceType(resourceType), properties != null ? Collections.unmodifiableMap(properties) : null); - } else if (cosmosKeyCredential != null) { + } else if (credential != null) { return this.authorizationTokenProvider.generateKeyAuthorizationSignature(requestVerb, resourceName, resourceType, headers); } else if (masterKeyOrResourceToken != null && hasAuthKeyResourceToken && resourceTokensMap == null) { diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosKeyCredentialTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/AzureKeyCredentialTest.java similarity index 82% rename from sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosKeyCredentialTest.java rename to sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/AzureKeyCredentialTest.java index bd847263e6a3..07ed345d91d4 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosKeyCredentialTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/AzureKeyCredentialTest.java @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CosmosKeyCredentialTest extends TestSuiteBase { +public class AzureKeyCredentialTest extends TestSuiteBase { private static final int TIMEOUT = 50000; private static final int SETUP_TIMEOUT = 20000; @@ -49,7 +49,7 @@ public class CosmosKeyCredentialTest extends TestSuiteBase { private CosmosAsyncContainer container; @Factory(dataProvider = "clientBuildersWithDirectSession") - public CosmosKeyCredentialTest(CosmosClientBuilder clientBuilder) { + public AzureKeyCredentialTest(CosmosClientBuilder clientBuilder) { super(clientBuilder); this.subscriberValidationTimeout = TIMEOUT; } @@ -91,9 +91,9 @@ public void createCollectionWithSecondaryKey(String collectionName) throws Inter CosmosContainerProperties collectionDefinition = getCollectionDefinition(collectionName); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); Mono createObservable = database .createContainer(collectionDefinition); @@ -103,7 +103,7 @@ public void createCollectionWithSecondaryKey(String collectionName) throws Inter validateSuccess(createObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); safeDeleteAllCollections(database); } @@ -112,12 +112,12 @@ public void readCollectionWithSecondaryKey(String collectionName) throws Interru CosmosContainerProperties collectionDefinition = getCollectionDefinition(collectionName); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); Mono createObservable = database.createContainer(collectionDefinition); CosmosAsyncContainer collection = createObservable.block().getContainer(); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); Mono readObservable = collection.read(); CosmosResponseValidator validator = @@ -126,7 +126,7 @@ public void readCollectionWithSecondaryKey(String collectionName) throws Interru validateSuccess(readObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); safeDeleteAllCollections(database); } @@ -135,12 +135,12 @@ public void deleteCollectionWithSecondaryKey(String collectionName) throws Inter CosmosContainerProperties collectionDefinition = getCollectionDefinition(collectionName); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); Mono createObservable = database.createContainer(collectionDefinition); CosmosAsyncContainer collection = createObservable.block().getContainer(); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); Mono deleteObservable = collection.delete(); CosmosResponseValidator validator = new CosmosResponseValidator.Builder() @@ -148,7 +148,7 @@ public void deleteCollectionWithSecondaryKey(String collectionName) throws Inter validateSuccess(deleteObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); } @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "crudArgProvider", retryAnalyzer = RetryAnalyzer.class) @@ -159,13 +159,13 @@ public void replaceCollectionWithSecondaryKey(String collectionName) throws Inte CosmosAsyncContainer collection = createObservable.block().getContainer(); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); CosmosContainerProperties collectionSettings = collection.read().block().getProperties(); // sanity check assertThat(collectionSettings.getIndexingPolicy().getIndexingMode()).isEqualTo(IndexingMode.CONSISTENT); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); // replace indexing mode IndexingPolicy indexingMode = new IndexingPolicy(); @@ -179,7 +179,7 @@ public void replaceCollectionWithSecondaryKey(String collectionName) throws Inte validateSuccess(readObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); safeDeleteAllCollections(database); } @@ -187,9 +187,9 @@ public void replaceCollectionWithSecondaryKey(String collectionName) throws Inte public void createDocumentWithSecondaryKey(String documentId) throws InterruptedException { // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); CosmosItemProperties properties = getDocumentDefinition(documentId); Mono> createObservable = container.createItem(properties, new CosmosItemRequestOptions()); @@ -201,16 +201,16 @@ public void createDocumentWithSecondaryKey(String documentId) throws Interrupted validateItemSuccess(createObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); } @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "crudArgProvider", retryAnalyzer = RetryAnalyzer.class) public void readDocumentWithSecondaryKey(String documentId) throws InterruptedException { // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); CosmosItemProperties docDefinition = getDocumentDefinition(documentId); container.createItem(docDefinition, new CosmosItemRequestOptions()).block(); @@ -231,16 +231,16 @@ public void readDocumentWithSecondaryKey(String documentId) throws InterruptedEx validateItemSuccess(readObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); } @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "crudArgProvider", retryAnalyzer = RetryAnalyzer.class) public void deleteDocumentWithSecondaryKey(String documentId) throws InterruptedException { // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); CosmosItemProperties docDefinition = getDocumentDefinition(documentId); @@ -267,15 +267,15 @@ public void deleteDocumentWithSecondaryKey(String documentId) throws Interrupted validateItemFailure(readObservable, notFoundValidator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); } @Test(groups = { "simple" }, timeOut = TIMEOUT, retryAnalyzer = RetryAnalyzer.class) public void createDatabaseWithSecondaryKey() throws Exception { // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); CosmosDatabaseProperties databaseDefinition = new CosmosDatabaseProperties(CosmosDatabaseForTest.generateId()); databases.add(databaseDefinition.getId()); @@ -287,15 +287,15 @@ public void createDatabaseWithSecondaryKey() throws Exception { .withId(databaseDefinition.getId()).build(); validateSuccess(createObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); } @Test(groups = { "simple" }, timeOut = TIMEOUT, retryAnalyzer = RetryAnalyzer.class) public void readDatabaseWithSecondaryKey() throws Exception { // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); // read database Mono readObservable = client.getDatabase(databaseId).read(); @@ -305,15 +305,15 @@ public void readDatabaseWithSecondaryKey() throws Exception { .withId(databaseId).build(); validateSuccess(readObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); } @Test(groups = { "simple" }, timeOut = TIMEOUT, retryAnalyzer = RetryAnalyzer.class) public void deleteDatabaseWithSecondaryKey() throws Exception { // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey(TestConfigurations.SECONDARY_MASTER_KEY); + credential.update(TestConfigurations.SECONDARY_MASTER_KEY); // create the database CosmosDatabaseProperties databaseDefinition = new CosmosDatabaseProperties(CosmosDatabaseForTest.generateId()); @@ -328,7 +328,7 @@ public void deleteDatabaseWithSecondaryKey() throws Exception { .nullResource().build(); validateSuccess(deleteObservable, validator); // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.SECONDARY_MASTER_KEY); } @Test(groups = { "simple" }, timeOut = TIMEOUT, @@ -336,9 +336,9 @@ public void deleteDatabaseWithSecondaryKey() throws Exception { expectedExceptionsMessageRegExp = "Illegal base64 character .*") public void invalidSecondaryKey() throws Exception { // sanity check - assertThat(client.cosmosKeyCredential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); + assertThat(client.credential().getKey()).isEqualTo(TestConfigurations.MASTER_KEY); - cosmosKeyCredential.setKey("Invalid Secondary Key"); + credential.update("Invalid Secondary Key"); // create the database, and this should throw Illegal Argument Exception for secondary key CosmosDatabaseProperties databaseDefinition = new CosmosDatabaseProperties(CosmosDatabaseForTest.generateId()); @@ -353,11 +353,11 @@ public void beforeMethod() throws Exception { @AfterMethod(groups = { "simple" }, timeOut = SETUP_TIMEOUT) public void afterMethod() { // Set back master getKey before every test - cosmosKeyCredential.setKey(TestConfigurations.MASTER_KEY); + credential.update(TestConfigurations.MASTER_KEY); } @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void before_CosmosKeyCredentialTest() { + public void before_AzureKeyCredentialTest() { client = getClientBuilder().buildAsyncClient(); database = createDatabase(client, databaseId); container = getSharedMultiPartitionCosmosContainer(client); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java index 9b5c5617905e..8e735acb3ffc 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java @@ -17,7 +17,7 @@ public ClientUnderTestBuilder(CosmosClientBuilder builder) { this.consistencyLevel(builder.getConsistencyLevel()); this.key(builder.getKey()); this.endpoint(builder.getEndpoint()); - this.keyCredential(builder.getKeyCredential()); + this.credential(builder.getCredential()); this.contentResponseOnWriteEnabled(builder.isContentResponseOnWriteEnabled()); this.userAgentSuffix(builder.getUserAgentSuffix()); this.throttlingRetryOptions(builder.getThrottlingRetryOptions()); @@ -38,7 +38,7 @@ public CosmosAsyncClient buildAsyncClient() { this.getConnectionPolicy(), this.getConsistencyLevel(), this.configs(), - this.getKeyCredential(), + this.getCredential(), this.isContentResponseOnWriteEnabled()); } catch (URISyntaxException e) { throw new IllegalArgumentException(e.getMessage()); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java index d6255910bc5e..e7ffc753bf23 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java @@ -2,9 +2,9 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.ClientUnderTestBuilder; import com.azure.cosmos.ConsistencyLevel; -import com.azure.cosmos.CosmosKeyCredential; import com.azure.cosmos.implementation.http.HttpClient; import com.azure.cosmos.implementation.http.HttpRequest; import com.azure.cosmos.implementation.http.HttpResponse; @@ -35,9 +35,9 @@ public RxDocumentClientUnderTest(URI serviceEndpoint, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, - CosmosKeyCredential cosmosKeyCredential, + AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, cosmosKeyCredential, false, false, contentResponseOnWriteEnabled); + super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential, false, false, contentResponseOnWriteEnabled); init(); } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java index 08cabe715196..705b1f255037 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java @@ -11,7 +11,7 @@ public SpyClientBuilder(AsyncDocumentClient.Builder builder) { super.desiredConsistencyLevel = builder.desiredConsistencyLevel; super.masterKeyOrResourceToken = builder.masterKeyOrResourceToken; super.serviceEndpoint = builder.serviceEndpoint; - super.cosmosKeyCredential = builder.cosmosKeyCredential; + super.credential = builder.credential; super.contentResponseOnWriteEnabled = builder.contentResponseOnWriteEnabled; } @@ -22,7 +22,7 @@ public SpyClientUnderTestFactory.ClientUnderTest build() { connectionPolicy, desiredConsistencyLevel, configs, - cosmosKeyCredential, + credential, contentResponseOnWriteEnabled); } @@ -33,7 +33,7 @@ public SpyClientUnderTestFactory.ClientWithGatewaySpy buildWithGatewaySpy() { connectionPolicy, desiredConsistencyLevel, configs, - cosmosKeyCredential, + credential, contentResponseOnWriteEnabled); } @@ -43,7 +43,7 @@ public SpyClientUnderTestFactory.DirectHttpsClientUnderTest buildWithDirectHttps masterKeyOrResourceToken, connectionPolicy, desiredConsistencyLevel, - cosmosKeyCredential, + credential, contentResponseOnWriteEnabled); } } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java index 4a342c26becf..c8b76e6a0afb 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java @@ -2,9 +2,9 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.ConsistencyLevel; -import com.azure.cosmos.CosmosKeyCredential; import com.azure.cosmos.implementation.directconnectivity.Protocol; import com.azure.cosmos.implementation.directconnectivity.ReflectionUtils; import com.azure.cosmos.implementation.http.HttpClient; @@ -31,8 +31,8 @@ public class SpyClientUnderTestFactory { public static abstract class SpyBaseClass extends RxDocumentClientImpl { - public SpyBaseClass(URI serviceEndpoint, String masterKeyOrResourceToken, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, CosmosKeyCredential cosmosKeyCredential, boolean contentResponseOnWriteEnabled) { - super(serviceEndpoint, masterKeyOrResourceToken, connectionPolicy, consistencyLevel, configs, cosmosKeyCredential, false, false, contentResponseOnWriteEnabled); + public SpyBaseClass(URI serviceEndpoint, String masterKeyOrResourceToken, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { + super(serviceEndpoint, masterKeyOrResourceToken, connectionPolicy, consistencyLevel, configs, credential, false, false, contentResponseOnWriteEnabled); } public abstract List getCapturedRequests(); @@ -54,8 +54,8 @@ public static class ClientWithGatewaySpy extends SpyBaseClass requests; - ClientWithGatewaySpy(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, CosmosKeyCredential cosmosKeyCredential, boolean contentResponseOnWriteEnabled) { - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, cosmosKeyCredential, contentResponseOnWriteEnabled); + ClientWithGatewaySpy(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { + super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential, contentResponseOnWriteEnabled); init(); } @@ -116,8 +116,8 @@ public static class ClientUnderTest extends SpyBaseClass { List>> requestsResponsePairs = Collections.synchronizedList(new ArrayList<>()); - ClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, CosmosKeyCredential cosmosKeyCredential, boolean contentResponseOnWriteEnabled) { - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, cosmosKeyCredential, contentResponseOnWriteEnabled); + ClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { + super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential, contentResponseOnWriteEnabled); init(); } @@ -168,8 +168,8 @@ public static class DirectHttpsClientUnderTest extends SpyBaseClass List>> requestsResponsePairs = Collections.synchronizedList(new ArrayList<>()); - DirectHttpsClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, CosmosKeyCredential cosmosKeyCredential, boolean contentResponseOnWriteEnabled) { - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, createConfigsSpy(Protocol.HTTPS), cosmosKeyCredential, contentResponseOnWriteEnabled); + DirectHttpsClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { + super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, createConfigsSpy(Protocol.HTTPS), credential, contentResponseOnWriteEnabled); assert connectionPolicy.getConnectionMode() == ConnectionMode.DIRECT; init(); @@ -229,9 +229,9 @@ public static ClientWithGatewaySpy createClientWithGatewaySpy(URI serviceEndpoin ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, - CosmosKeyCredential cosmosKeyCredential, + AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { - return new ClientWithGatewaySpy(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, cosmosKeyCredential, contentResponseOnWriteEnabled); + return new ClientWithGatewaySpy(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential, contentResponseOnWriteEnabled); } public static ClientUnderTest createClientUnderTest(AsyncDocumentClient.Builder builder) { @@ -247,9 +247,9 @@ public static ClientUnderTest createClientUnderTest(URI serviceEndpoint, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, - CosmosKeyCredential cosmosKeyCredential, + AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { - return new ClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, cosmosKeyCredential, contentResponseOnWriteEnabled) { + return new ClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential, contentResponseOnWriteEnabled) { @Override RxGatewayStoreModel createRxGatewayProxy(ISessionContainer sessionContainer, @@ -277,8 +277,8 @@ RxGatewayStoreModel createRxGatewayProxy(ISessionContainer sessionContainer, }; } - public static DirectHttpsClientUnderTest createDirectHttpsClientUnderTest(URI serviceEndpoint, String masterKey, - ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, CosmosKeyCredential cosmosKeyCredential, boolean contentResponseOnWriteEnabled) { - return new DirectHttpsClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, cosmosKeyCredential, contentResponseOnWriteEnabled); + public static DirectHttpsClientUnderTest createDirectHttpsClientUnderTest( + URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) { + return new DirectHttpsClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, credential, contentResponseOnWriteEnabled); } } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/RntbdTransportClientTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/RntbdTransportClientTest.java index b893de6f8447..c7b247824277 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/RntbdTransportClientTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/RntbdTransportClientTest.java @@ -3,10 +3,10 @@ package com.azure.cosmos.implementation.directconnectivity; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.implementation.BadRequestException; import com.azure.cosmos.implementation.ConflictException; import com.azure.cosmos.CosmosException; -import com.azure.cosmos.CosmosKeyCredential; import com.azure.cosmos.implementation.ConnectionPolicy; import com.azure.cosmos.implementation.ForbiddenException; import com.azure.cosmos.implementation.GoneException; @@ -617,7 +617,7 @@ public void verifyGoneResponseMapsToGoneException() throws Exception { try (final RntbdTransportClient transportClient = new RntbdTransportClient(options, sslContext)) { final BaseAuthorizationTokenProvider authorizationTokenProvider = new BaseAuthorizationTokenProvider( - new CosmosKeyCredential(RntbdTestConfiguration.AccountKey) + new AzureKeyCredential(RntbdTestConfiguration.AccountKey) ); final Uri physicalAddress = new Uri("rntbd://" diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/CosmosPartitionKeyTests.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/CosmosPartitionKeyTests.java index 5dd24d0072a3..77f125610654 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/CosmosPartitionKeyTests.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/CosmosPartitionKeyTests.java @@ -2,6 +2,7 @@ // Licensed under the MIT License. package com.azure.cosmos.models; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.implementation.ConnectionPolicy; import com.azure.cosmos.CosmosAsyncClient; @@ -9,7 +10,6 @@ import com.azure.cosmos.CosmosAsyncDatabase; import com.azure.cosmos.CosmosAsyncStoredProcedure; import com.azure.cosmos.CosmosClientBuilder; -import com.azure.cosmos.CosmosKeyCredential; import com.azure.cosmos.implementation.RequestVerb; import com.azure.cosmos.util.CosmosPagedFlux; import com.azure.cosmos.implementation.BaseAuthorizationTokenProvider; @@ -94,7 +94,7 @@ private void createContainerWithoutPk() throws URISyntaxException, IOException { HashMap headers = new HashMap(); headers.put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); headers.put(HttpConstants.HttpHeaders.VERSION, "2018-09-17"); - BaseAuthorizationTokenProvider base = new BaseAuthorizationTokenProvider(new CosmosKeyCredential(TestConfigurations.MASTER_KEY)); + BaseAuthorizationTokenProvider base = new BaseAuthorizationTokenProvider(new AzureKeyCredential(TestConfigurations.MASTER_KEY)); String authorization = base.generateKeyAuthorizationSignature(RequestVerb.POST, resourceId, Paths.COLLECTIONS_PATH_SEGMENT, headers); headers.put(HttpConstants.HttpHeaders.AUTHORIZATION, URLEncoder.encode(authorization, "UTF-8")); RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Create, diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java index 24f3f531afa0..104d45632de7 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java @@ -2,6 +2,7 @@ // Licensed under the MIT License. package com.azure.cosmos.rx; +import com.azure.core.credential.AzureKeyCredential; import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosAsyncClient; @@ -15,7 +16,6 @@ import com.azure.cosmos.CosmosException; import com.azure.cosmos.CosmosDatabase; import com.azure.cosmos.CosmosDatabaseForTest; -import com.azure.cosmos.CosmosKeyCredential; import com.azure.cosmos.CosmosResponseValidator; import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.GatewayConnectionConfig; @@ -108,7 +108,7 @@ public class TestSuiteBase extends CosmosAsyncClientTest { private static final ImmutableList desiredConsistencies; private static final ImmutableList protocols; - protected static final CosmosKeyCredential cosmosKeyCredential; + protected static final AzureKeyCredential credential; protected int subscriberValidationTimeout = TIMEOUT; @@ -157,7 +157,7 @@ protected static CosmosAsyncContainer getSharedSinglePartitionCosmosContainer(Co objectMapper.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA, true); objectMapper.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true); - cosmosKeyCredential = new CosmosKeyCredential(TestConfigurations.MASTER_KEY); + credential = new AzureKeyCredential(TestConfigurations.MASTER_KEY); } protected TestSuiteBase() { @@ -1056,7 +1056,7 @@ static protected CosmosClientBuilder createGatewayHouseKeepingDocumentClient(boo options.setMaxRetryWaitTime(Duration.ofSeconds(SUITE_SETUP_TIMEOUT)); GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig(); return new CosmosClientBuilder().endpoint(TestConfigurations.HOST) - .keyCredential(cosmosKeyCredential) + .credential(credential) .gatewayMode(gatewayConnectionConfig) .throttlingRetryOptions(options) .contentResponseOnWriteEnabled(contentResponseOnWriteEnabled) @@ -1067,7 +1067,7 @@ static protected CosmosClientBuilder createGatewayRxDocumentClient(ConsistencyLe List preferredRegions, boolean contentResponseOnWriteEnabled) { GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig(); return new CosmosClientBuilder().endpoint(TestConfigurations.HOST) - .keyCredential(cosmosKeyCredential) + .credential(credential) .gatewayMode(gatewayConnectionConfig) .multipleWriteRegionsEnabled(multiMasterEnabled) .preferredRegions(preferredRegions) @@ -1085,7 +1085,7 @@ static protected CosmosClientBuilder createDirectRxDocumentClient(ConsistencyLev List preferredRegions, boolean contentResponseOnWriteEnabled) { CosmosClientBuilder builder = new CosmosClientBuilder().endpoint(TestConfigurations.HOST) - .keyCredential(cosmosKeyCredential) + .credential(credential) .directMode(DirectConnectionConfig.getDefaultConfig()) .contentResponseOnWriteEnabled(contentResponseOnWriteEnabled) .consistencyLevel(consistencyLevel);