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

Conversation

ausfeldt
Copy link
Contributor

@ausfeldt ausfeldt commented Aug 2, 2019

Description

Add Users and Permissions to the SDK. Constructor overload(s) to CosmosClient that supports multiple permissions/resource tokens is not included in this PR.

Because there is not SelfLinks or UriFactory like v2, constructor overloads were added to PermissionProperties which creates the ResourceLink from constructed LinkUri.

The resource token is a string just like account key and can be used as an alternative. I would like change the variable name in the signature but it would be a breaking change because it would break those that use named parameters. Also I can't create a second overload as it would be the same signature. I updated the constructor parameter documentation. I could always introduce a constructor overload for IEnumerable which will cover any user scenario and be more explicit.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update
//Database.cs
User GetUser(string id);

Task<UserResponse> CreateUserAsync(
	string id,
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));
	
Task<UserResponse> UpsertUserAsync(UserProperties userProperties, 
	RequestOptions requestOptions = null, 
	CancellationToken cancellationToken = default(CancellationToken));

FeedIterator<T> GetUserQueryIterator<T>(
	string queryText = null,
	string continuationToken = null,
	QueryRequestOptions requestOptions = null);

FeedIterator<T> GetUserQueryIterator<T>(
	QueryDefinition queryDefinition,
	string continuationToken = null,
	QueryRequestOptions requestOptions = null);
	
//User.cs
string Id { get; }

Task<UserResponse> ReadAsync(
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));
	
Task<UserResponse> ReplaceAsync(
	UserProperties userProperties,
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));
	
Task<UserResponse> DeleteAsync(
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));
	
Permission GetPermission(string id);

Task<PermissionResponse> CreatePermissionAsync(
	PermissionProperties permissionProperties,
	int? tokenExpiryInSeconds = null,
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));
			
Task<PermissionResponse> UpsertPermissionAsync(
	PermissionProperties permissionProperties,
	int? tokenExpiryInSeconds = null,
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));

FeedIterator<T> GetPermissionQueryIterator<T>(
	string queryText = null,
	string continuationToken = null,
	QueryRequestOptions requestOptions = null);

FeedIterator<T> GetPermissionQueryIterator<T>(
	QueryDefinition queryDefinition,
	string continuationToken = null,
	QueryRequestOptions requestOptions = null);
	
//Permission.cs
string Id { get; }

Task<PermissionResponse> ReadAsync(
	int? tokenExpiryInSeconds = null,
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));

Task<PermissionResponse> ReplaceAsync(
	PermissionProperties permissionProperties,
	int? tokenExpiryInSeconds = null,
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));
			
Task<PermissionResponse> DeleteAsync(
	RequestOptions requestOptions = null,
	CancellationToken cancellationToken = default(CancellationToken));
			

@ausfeldt ausfeldt added the feature-request New feature or request label Aug 2, 2019
@ausfeldt ausfeldt requested a review from kirillg as a code owner August 2, 2019 02:01
@ausfeldt ausfeldt self-assigned this Aug 2, 2019
@kirankumarkolli kirankumarkolli changed the title Users/gaausfel/add users and permissions ResourceToken support Aug 3, 2019
@kirankumarkolli
Copy link
Member

CosmosClient authKey rename -> authKeyOrResourceToken

@kirankumarkolli
Copy link
Member

Create a backlog item for Fluent versions of these API's

REDMOND\gaausfel added 2 commits August 20, 2019 11:03
ealsur
ealsur previously approved these changes Aug 20, 2019
Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs Outdated Show resolved Hide resolved
Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs Outdated Show resolved Hide resolved

public override User GetUser(string id)
{
if (string.IsNullOrEmpty(id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to just use: this.ClientContext.ValidateResource(userProperties.Id);

{
this.Id = id;
this.PermissionMode = permissionMode;
this.ResourceUri = ((ContainerCore)container).LinkUri.OriginalString;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can user UT this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make LinkUri public on Container, but I thought we don't want to do that.

@ausfeldt ausfeldt dismissed stale reviews from ealsur and kirankumarkolli via b3baea1 August 20, 2019 21:43
@kirankumarkolli
Copy link
Member

Please follow-up comments through issues.

@kirankumarkolli kirankumarkolli merged commit 620b709 into master Aug 21, 2019
@kirankumarkolli kirankumarkolli deleted the users/gaausfel/add_users_and_permissions branch August 21, 2019 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants