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

feat: Support for start time in read changes request #92

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Unreleased](https://github.com/openfga/dotnet-sdk/compare/v0.5.1...HEAD)
- feat: support start time option in read changes requests
- feat: change default retry policy - thanks @ovindu-a

## v0.5.1

### [0.5.1](https://github.com/openfga/dotnet-sdk/compare/v0.5.0...v0.5.1) (2024-09-09)
Expand Down Expand Up @@ -136,7 +140,7 @@ Updated to include support for [OpenFGA 0.3.0](https://github.com/openfga/openfg

Changes:
- [BREAKING] feat(list-objects)!: response has been changed to include the object type
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:roadmap"]}`
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]}`

Fixes:
- fix(models): update interfaces that had incorrectly optional fields to make them required
Expand Down
71 changes: 37 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Search for and install `OpenFga.Sdk` in each of their respective package manager

We strongly recommend you initialize the `OpenFgaClient` only once and then re-use it throughout your app, otherwise you will incur the cost of having to re-initialize multiple times or at every request, the cost of reduced connection pooling and re-use, and would be particularly costly in the client credentials flow, as that flow will be preformed on every request.

> The `OpenFga.SdkClient` will by default retry API requests up to 15 times on 429 and 5xx errors.
> The `OpenFga.SdkClient` will by default retry API requests up to 3 times on 429 and 5xx errors.

#### No Credentials

Expand Down Expand Up @@ -379,7 +379,8 @@ Reads the list of historical relationship tuple writes and deletes.
[API Documentation](https://openfga.dev/api/service#/Relationship%20Tuples/ReadChanges)

```csharp
var body = new ClientReadChangesRequest { Type = "document" };
var startTime = DateTime.Parse("2022-01-01T00:00:00Z");
var body = new ClientReadChangesRequest { Type = "document", StartTime = startTime };
var options = new ClientReadChangesOptions {
PageSize = 10,
ContinuationToken = "...",
Expand All @@ -405,13 +406,13 @@ Reads the relationship tuples stored in the database. It does not evaluate nor e
var body = new ClientReadRequest() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Find all relationship tuples where a certain user has a relationship as any relation to a certain document
var body = new ClientReadRequest() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Find all relationship tuples where a certain user is a viewer of any document
Expand All @@ -424,7 +425,7 @@ var body = new ClientReadRequest() {
// Find all relationship tuples where any user has a relationship as any relation with a particular document

var body = new ClientReadRequest() {
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Read all stored relationship tuples
Expand Down Expand Up @@ -457,19 +458,19 @@ var body = new ClientWriteRequest() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:budget",
Object = "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
}
},
Deletes = new List<ClientTupleKeyWithoutCondition> {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
};
Expand All @@ -492,19 +493,19 @@ var body = new ClientWriteRequest() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:budget",
Object = "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
}
},
Deletes = new List<ClientTupleKeyWithoutCondition> {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
};
Expand Down Expand Up @@ -536,7 +537,7 @@ var options = new ClientCheckOptions {
var body = new ClientCheckRequest {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:roadmap"
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
};
var response = await fgaClient.Check(body, options);
// response.Allowed = true
Expand All @@ -545,7 +546,7 @@ var response = await fgaClient.Check(body, options);
##### Batch Check

Run a set of [checks](#check). Batch Check will return `allowed: false` if it encounters an error, and will return the error in the body.
If 429s or 5xxs are encountered, the underlying check will retry up to 15 times before giving up.
If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.

```csharp
var options = new ClientBatchCheckOptions {
Expand All @@ -557,36 +558,36 @@ var body = new List<ClientCheckRequest>(){
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples = new List<ClientTupleKey>() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "editor",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "admin",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples = new List<ClientTupleKey>() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "editor",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "creator",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "deleter",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
};

Expand All @@ -598,39 +599,39 @@ response.Responses = [{
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples: [{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "editor",
Object: "document:roadmap"
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}
}, {
Allowed: false,
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "admin",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples: [{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "editor",
Object: "document:roadmap"
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}
}, {
Allowed: false,
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "creator",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
Error: <FgaError ...>
}, {
Allowed: true,
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "deleter",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}},
]
*/
Expand All @@ -649,11 +650,11 @@ var options = new ClientCheckOptions {
};
var body = new ClientExpandRequest {
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};
var response = await fgaClient.Expand(body, options);

// response.Tree.Root = {"name":"document:roadmap#viewer","leaf":{"users":{"users":["user:81684243-9356-4421-8fbf-a4f8d36aa31b","user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"]}}}
// response.Tree.Root = {"name":"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a#viewer","leaf":{"users":{"users":["user:81684243-9356-4421-8fbf-a4f8d36aa31b","user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"]}}}
```

##### List Objects
Expand All @@ -675,13 +676,13 @@ var body = new ClientListObjectsRequest {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:budget",
Object = "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
},
},
};
var response = await fgaClient.ListObjects(body, options);

// response.Objects = ["document:roadmap"]
// response.Objects = ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]
```

##### List Relations
Expand All @@ -692,13 +693,13 @@ List the relations a user has on an object.
ListRelationsRequest body =
new ListRelationsRequest() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
Relations = new List<string> {"can_view", "can_edit", "can_delete", "can_rename"},
ContextualTuples = new List<ClientTupleKey>() {
new ClientTupleKey {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "editor",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
}
};
Expand Down Expand Up @@ -742,7 +743,7 @@ const response = await fgaClient.listUsers({
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}, options);

Expand Down Expand Up @@ -779,7 +780,7 @@ var options = new ClientWriteAssertionsOptions {
var body = new List<ClientAssertion>() {new ClientAssertion() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
Expectation = true,
}};
await fgaClient.WriteAssertions(body, options);
Expand All @@ -788,7 +789,7 @@ await fgaClient.WriteAssertions(body, options);

### Retries

If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 15 times with a minimum wait time of 100 milliseconds between each attempt.
If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 3 times with a minimum wait time of 100 milliseconds between each attempt.

To customize this behavior, create a `RetryParams` instance and assign values to the `MaxRetry` and `MinWaitInMs` constructor parameters. `MaxRetry` determines the maximum number of retries (up to 15), while `MinWaitInMs` sets the minimum wait time between retries in milliseconds.

Expand Down Expand Up @@ -851,6 +852,7 @@ namespace Example {
- [Model.Any](docs/Any.md)
- [Model.Assertion](docs/Assertion.md)
- [Model.AssertionTupleKey](docs/AssertionTupleKey.md)
- [Model.AuthErrorCode](docs/AuthErrorCode.md)
- [Model.AuthorizationModel](docs/AuthorizationModel.md)
- [Model.CheckRequest](docs/CheckRequest.md)
- [Model.CheckRequestTupleKey](docs/CheckRequestTupleKey.md)
Expand All @@ -869,6 +871,7 @@ namespace Example {
- [Model.ExpandRequestTupleKey](docs/ExpandRequestTupleKey.md)
- [Model.ExpandResponse](docs/ExpandResponse.md)
- [Model.FgaObject](docs/FgaObject.md)
- [Model.ForbiddenResponse](docs/ForbiddenResponse.md)
- [Model.GetStoreResponse](docs/GetStoreResponse.md)
- [Model.InternalErrorCode](docs/InternalErrorCode.md)
- [Model.InternalErrorMessageResponse](docs/InternalErrorMessageResponse.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/Assertion.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**TupleKey** | [**AssertionTupleKey**](AssertionTupleKey.md) | |
**Expectation** | **bool** | |
**ContextualTuples** | [**List&lt;TupleKey&gt;**](TupleKey.md) | | [optional]
**Context** | **Object** | Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

9 changes: 9 additions & 0 deletions docs/AuthErrorCode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# OpenFga.Sdk.Model.AuthErrorCode

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

2 changes: 1 addition & 1 deletion docs/ConsistencyPreference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OpenFga.Sdk.Model.ConsistencyPreference
- UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY - MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency. - HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency.
Controls the consistency preferences when calling the query APIs. - UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY. - MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency. - HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency.

## Properties

Expand Down
11 changes: 11 additions & 0 deletions docs/ForbiddenResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenFga.Sdk.Model.ForbiddenResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Code** | **AuthErrorCode** | | [optional]
**Message** | **string** | | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

Loading
Loading