Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceToken support #622

Merged
merged 33 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a625a4c
start implementing User
Jul 25, 2019
b540498
implement user CRUD with tests
Jul 26, 2019
e068240
finish implementing users
Jul 26, 2019
c0da94a
start implementing permissions
Jul 26, 2019
e474ec5
add factory methods to PermissionProperties for each resource
Jul 28, 2019
5819466
implement permission create and query iterators
Jul 29, 2019
c058195
finish implmenting permission CRUD
Jul 29, 2019
4711546
implement permission CRUD tests
Jul 29, 2019
f07fd4a
add permission iterator tests
Jul 30, 2019
0442680
assert permission token after create
Jul 30, 2019
e665f1d
Add contaier resource permission test
Jul 30, 2019
0e30c2e
fix bug where it was not using the client with resource token
Jul 30, 2019
b5ce5b7
add permission resource tests
Aug 2, 2019
7415435
update baseline
Aug 5, 2019
915aae3
address PR comments
Aug 6, 2019
01e0a97
move user and permission test to CosmosBasicQueryTests
Aug 7, 2019
e62cc9a
address PR comments
Aug 8, 2019
4ef3a1b
fix typos
Aug 8, 2019
b36a9e3
remove factory methods for constructor overloads. remove permissions …
Aug 8, 2019
afeea56
remove PermissionRequestOptions. promote ResourceTokenExpirySeconds t…
Aug 8, 2019
2441f38
add ResourceTokenExpirySecondsHeaderIsAdded test
Aug 9, 2019
e6404a4
add upsert operation for user and permissions and update baseline
Aug 10, 2019
ce5e299
address PR comments
Aug 13, 2019
080379e
address PR comments and update baseline
Aug 14, 2019
6f58084
typo
Aug 14, 2019
5923181
one arg per line
Aug 14, 2019
d6577eb
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
Aug 15, 2019
f671c75
fix errors from pervious master pull
Aug 15, 2019
dfd6a6e
change accountKey to authKeyOrResourceToken
Aug 15, 2019
fe6dcfa
fix tests
Aug 15, 2019
3145b74
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
Aug 20, 2019
9e34a4b
fix test
Aug 20, 2019
b3baea1
fix typos
Aug 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Microsoft.Azure.Cosmos
/// </example>
/// <example>
/// This example create a <see cref="CosmosClient"/>, <see cref="Database"/>, and a <see cref="Container"/>.
/// The CosmosClient is created with the AccountEndpoint, AccountKey and configured to use "East US 2" region.
/// The CosmosClient is created with the AccountEndpoint, AccountKey or ResourceToken and configured to use "East US 2" region.
/// <code language="c#">
/// <![CDATA[
/// using Microsoft.Azure.Cosmos;
Expand Down Expand Up @@ -167,10 +167,10 @@ public CosmosClient(
/// performance guide at <see href="https://docs.microsoft.com/azure/cosmos-db/performance-tips"/>.
/// </summary>
/// <param name="accountEndpoint">The cosmos service endpoint to use</param>
/// <param name="accountKey">The cosmos account key to use to create the client.</param>
/// <param name="authKeyOrResourceToken">The cosmos account key or resource token to use to create the client.</param>
/// <param name="clientOptions">(Optional) client options</param>
/// <example>
/// The CosmosClient is created with the AccountEndpoint, AccountKey and configured to use "East US 2" region.
/// The CosmosClient is created with the AccountEndpoint, AccountKey or ResourceToken and configured to use "East US 2" region.
/// <code language="c#">
/// <![CDATA[
/// using Microsoft.Azure.Cosmos;
Expand All @@ -195,17 +195,17 @@ public CosmosClient(
/// </remarks>
public CosmosClient(
string accountEndpoint,
string accountKey,
string authKeyOrResourceToken,
CosmosClientOptions clientOptions = null)
{
if (accountEndpoint == null)
{
throw new ArgumentNullException(nameof(accountEndpoint));
}

if (accountKey == null)
if (authKeyOrResourceToken == null)
{
throw new ArgumentNullException(nameof(accountKey));
throw new ArgumentNullException(nameof(authKeyOrResourceToken));
}

if (clientOptions == null)
Expand All @@ -214,7 +214,7 @@ public CosmosClient(
}

this.Endpoint = new Uri(accountEndpoint);
this.AccountKey = accountKey;
this.AccountKey = authKeyOrResourceToken;
CosmosClientOptions clientOptionsClone = clientOptions.Clone();

DocumentClient documentClient = new DocumentClient(
Expand All @@ -238,7 +238,7 @@ public CosmosClient(
/// </summary>
internal CosmosClient(
string accountEndpoint,
string accountKey,
string authKeyOrResourceToken,
CosmosClientOptions cosmosClientOptions,
DocumentClient documentClient)
{
Expand All @@ -247,9 +247,9 @@ internal CosmosClient(
throw new ArgumentNullException(nameof(accountEndpoint));
}

if (accountKey == null)
if (authKeyOrResourceToken == null)
{
throw new ArgumentNullException(nameof(accountKey));
throw new ArgumentNullException(nameof(authKeyOrResourceToken));
}

if (cosmosClientOptions == null)
Expand All @@ -263,7 +263,7 @@ internal CosmosClient(
}

this.Endpoint = new Uri(accountEndpoint);
this.AccountKey = accountKey;
this.AccountKey = authKeyOrResourceToken;

this.Init(cosmosClientOptions, documentClient);
}
Expand All @@ -283,7 +283,7 @@ internal CosmosClient(
public virtual Uri Endpoint { get; }

/// <summary>
/// Gets the AuthKey used by the client from the Azure Cosmos DB service.
/// Gets the AuthKey or resource token used by the client from the Azure Cosmos DB service.
/// </summary>
/// <value>
/// The AuthKey used by the client.
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public DocumentClient(Uri serviceEndpoint,
/// <seealso cref="ConsistencyLevel"/>
public DocumentClient(
Uri serviceEndpoint,
IList<Permission> permissionFeed,
IList<Documents.Permission> permissionFeed,
ConnectionPolicy connectionPolicy = null,
Documents.ConsistencyLevel? desiredConsistencyLevel = null)
: this(serviceEndpoint,
Expand All @@ -543,7 +543,7 @@ public DocumentClient(
{
}

private static List<ResourceToken> GetResourceTokens(IList<Permission> permissionFeed)
private static List<ResourceToken> GetResourceTokens(IList<Documents.Permission> permissionFeed)
{
if (permissionFeed == null)
{
Expand Down
18 changes: 9 additions & 9 deletions Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class CosmosClientBuilder
/// Initialize a new CosmosConfiguration class that holds all the properties the CosmosClient requires.
/// </summary>
/// <param name="accountEndpoint">The Uri to the Cosmos Account. Example: https://{Cosmos Account Name}.documents.azure.com:443/ </param>
/// <param name="accountKey">The key to the account.</param>
/// <param name="authKeyOrResourceToken">The key to the account or resource token.</param>
/// <example>
/// The example below creates a new <see cref="CosmosClientBuilder"/>
/// <code language="c#">
/// <![CDATA[
/// CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
/// accountEndpoint: "https://testcosmos.documents.azure.com:443/",
/// accountKey: "SuperSecretKey");
/// authKeyOrResourceToken: "SuperSecretKey");
/// CosmosClient client = cosmosClientBuilder.Build();
/// ]]>
/// </code>
Expand All @@ -41,7 +41,7 @@ public class CosmosClientBuilder
/// <![CDATA[
/// CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
/// accountEndpoint: "https://testcosmos.documents.azure.com:443/",
/// accountKey: "SuperSecretKey")
/// authKeyOrResourceToken: "SuperSecretKey")
/// .WithConsistencyLevel(ConsistencyLevel.Strong)
/// .WithApplicationRegion("East US 2");
/// CosmosClient client = cosmosClientBuilder.Build();
Expand All @@ -50,27 +50,27 @@ public class CosmosClientBuilder
/// </example>
public CosmosClientBuilder(
string accountEndpoint,
string accountKey)
string authKeyOrResourceToken)
{
if (accountEndpoint == null)
{
throw new ArgumentNullException(nameof(CosmosClientBuilder.accountEndpoint));
}

if (accountKey == null)
if (authKeyOrResourceToken == null)
{
throw new ArgumentNullException(nameof(accountKey));
throw new ArgumentNullException(nameof(authKeyOrResourceToken));
}

this.accountEndpoint = accountEndpoint;
this.accountKey = accountKey;
this.accountKey = authKeyOrResourceToken;
}

/// <summary>
/// Extracts the account endpoint and key from the connection string.
/// </summary>
/// <example>"AccountEndpoint=https://mytestcosmosaccount.documents.azure.com:443/;AccountKey={SecretAccountKey};"</example>
/// <param name="connectionString">The connection string must contain AccountEndpoint and AccountKey.</param>
/// <param name="connectionString">The connection string must contain AccountEndpoint and AccountKey or ResourceToken.</param>
public CosmosClientBuilder(string connectionString)
{
if (connectionString == null)
Expand Down Expand Up @@ -131,7 +131,7 @@ public CosmosClientBuilder WithApplicationName(string applicationName)
/// <![CDATA[
/// CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
/// accountEndpoint: "https://testcosmos.documents.azure.com:443/",
/// accountKey: "SuperSecretKey")
/// authKeyOrResourceToken: "SuperSecretKey")
/// .WithApplicationRegion("East US 2");
/// CosmosClient client = cosmosClientBuilder.Build();
/// ]]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public abstract Task<ResponseMessage> ReplaceContainerStreamAsync(
/// <example>
/// <code language="c#">
/// <![CDATA[
/// Container container = this.database.Containers["containerId"];
/// Container container = this.database.GetContainer("containerId");
/// ContainerResponse response = await container.DeleteContainerAsync();
/// ]]>
/// </code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Routing;
Expand Down
30 changes: 30 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/CosmosResponseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ internal Task<ContainerResponse> CreateContainerResponseAsync(
});
}

internal Task<UserResponse> CreateUserResponseAsync(
User user,
Task<ResponseMessage> cosmosResponseMessageTask)
{
return this.ProcessMessageAsync(cosmosResponseMessageTask, (cosmosResponseMessage) =>
{
UserProperties userProperties = this.ToObjectInternal<UserProperties>(cosmosResponseMessage, this.propertiesSerializer);
return new UserResponse(
cosmosResponseMessage.StatusCode,
cosmosResponseMessage.Headers,
userProperties,
user);
});
}

internal Task<PermissionResponse> CreatePermissionResponseAsync(
Permission permission,
Task<ResponseMessage> cosmosResponseMessageTask)
{
return this.ProcessMessageAsync(cosmosResponseMessageTask, (cosmosResponseMessage) =>
{
PermissionProperties permissionProperties = this.ToObjectInternal<PermissionProperties>(cosmosResponseMessage, this.propertiesSerializer);
return new PermissionResponse(
cosmosResponseMessage.StatusCode,
cosmosResponseMessage.Headers,
permissionProperties,
permission);
});
}

internal Task<DatabaseResponse> CreateDatabaseResponseAsync(
Database database,
Task<ResponseMessage> cosmosResponseMessageTask)
Expand Down
Loading