forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cosmos Key Credential holds the key credentials, and supports key rotations. User can update the key in CosmosKeyCredential object, and that will be reflected in SDK on the fly.
- Loading branch information
1 parent
3a55073
commit d6e9e0e
Showing
21 changed files
with
651 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...osmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/CosmosKeyCredential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.data.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 CosmosClient} | ||
*/ | ||
public class CosmosKeyCredential { | ||
|
||
private String key; | ||
|
||
// Stores key's hashcode for performance improvements | ||
private int keyHashCode; | ||
|
||
public CosmosKeyCredential(String key) { | ||
this.key = key; | ||
this.keyHashCode = key.hashCode(); | ||
} | ||
|
||
/** | ||
* Returns the key stored in Cosmos Key Credential | ||
* @return key | ||
*/ | ||
public String key() { | ||
return key; | ||
} | ||
|
||
/** | ||
* Sets the key to be used in CosmosKeyCredential | ||
* @param key key to be used in CosmosKeyCredential | ||
* @return current CosmosKeyCredential | ||
*/ | ||
public CosmosKeyCredential key(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 | ||
*/ | ||
public int keyHashCode() { | ||
return this.keyHashCode; | ||
} | ||
} |
Oops, something went wrong.