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 16 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
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ 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="accountKey">The cosmos account key or resource token to use to create the client.</param>
ausfeldt marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="clientOptions">(Optional) client options</param>
/// <example>
/// The CosmosClient is created with the AccountEndpoint, AccountKey and configured to use "East US 2" region.
Expand Down Expand Up @@ -284,7 +284,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 @@ -537,7 +537,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 @@ -547,7 +547,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
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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="accountKey">The key to the account or resource token.</param>
/// <example>
/// The example below creates a new <see cref="CosmosClientBuilder"/>
/// <code language="c#">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos
{
using Microsoft.Azure.Documents;

/// <summary>
/// The cosmos container request options
/// </summary>
public class PermissionRequestOptions : RequestOptions
{
/// <summary>
/// Gets or sets the expiry time for resource token. Used when creating/updating/reading permissions in the Azure Cosmos DB service.
/// </summary>
/// <value>
/// The expiry time in seconds for the resource token.
/// </value>
/// <remarks>
/// When working with Azure Cosmos DB Users and Permissions, the way to instantiate an instance of <see cref="Microsoft.Azure.Cosmos.CosmosClient"/> is to
/// get the <see cref="PermissionProperties.Token"/> for the resource the <see cref="User"/> wants to access and pass this
/// to the authKeyOrResourceToken parameter of <see cref="Microsoft.Azure.Cosmos.CosmosClient"/> constructor
/// <para>
/// When requesting this Token, a RequestOption for ResourceTokenExpirySeconds can be used to set the length of time to elapse before the token expires.
/// This value can range from 10 seconds, to 5 hours (or 18,000 seconds)
ausfeldt marked this conversation as resolved.
Show resolved Hide resolved
/// The default value for this, should none be supplied is 1 hour (or 3,600 seconds).
ausfeldt marked this conversation as resolved.
Show resolved Hide resolved
/// </para>
/// </remarks>
/// <seealso cref="Microsoft.Azure.Cosmos.CosmosClient"/>
/// <seealso cref="Microsoft.Azure.Cosmos.PermissionProperties"/>
/// <seealso cref="Microsoft.Azure.Cosmos.UserProperties"/>
public int? ResourceTokenExpirySeconds { get; set; }

/// <summary>
/// Fill the CosmosRequestMessage headers with the set properties
/// </summary>
/// <param name="request">The <see cref="RequestMessage"/></param>
internal override void PopulateRequestOptions(RequestMessage request)
{
if (this.ResourceTokenExpirySeconds != null)
{
request.Headers.Add(HttpConstants.HttpHeaders.ResourceTokenExpiry, this.ResourceTokenExpirySeconds.ToString());
}

base.PopulateRequestOptions(request);
}
}
}
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 user,
Task<ResponseMessage> cosmosResponseMessageTask)
{
return this.ProcessMessageAsync(cosmosResponseMessageTask, (cosmosResponseMessage) =>
{
PermissionProperties permissionProperties = this.ToObjectInternal<PermissionProperties>(cosmosResponseMessage, this.propertiesSerializer);
return new PermissionResponse(
cosmosResponseMessage.StatusCode,
cosmosResponseMessage.Headers,
permissionProperties,
user);
});
}

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