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

docs(cli): document usage of context/condition and continuation token #622

Merged
merged 3 commits into from
Jan 10, 2024
Merged
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
5 changes: 5 additions & 0 deletions docs/content/modeling/conditions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ For example, we can give `user:anne` viewer access to `document:1` for 10 minute
allowedLanguages={[
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
/>
Expand All @@ -151,6 +152,7 @@ Now that we have written a [Conditional Relationship Tuple](../concepts.mdx#what
allowedLanguages={[
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
/>
Expand All @@ -167,6 +169,7 @@ but if the current time is outside the grant window then you get a deny decision
allowedLanguages={[
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
/>
Expand All @@ -183,6 +186,7 @@ Similarly, we can use the [ListObjects API](https://openfga.dev/api/service#/Rel
allowedLanguages={[
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
/>
Expand All @@ -199,6 +203,7 @@ but if the current time is outside the grant window then we don't get the object
allowedLanguages={[
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ On the "transaction" type:

Now that we have updated our authorization model to take time and ip address into consideration, you will notice that Anne has lost access because nothing indicates that Anne is connecting from an approved ip address and time. You can verify that by issuing the following check:

<CheckRequestViewer user={'anne'} relation={'can_view'} object={'transaction:A'} allowed={false} />
<CheckRequestViewer user={'user:anne'} relation={'can_view'} object={'transaction:A'} allowed={false} />

We need to add relationship tuples to mark some approved timeslots and ip address ranges:

Expand Down
6 changes: 3 additions & 3 deletions src/components/Docs/SnippetViewer/CheckRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ ${
case SupportedLanguage.CLI:
return `fga query check --store-id=$FGA_STORE_ID --model-id=${modelId} ${user} ${relation} ${object}${
contextualTuples
? ` --contextual_tuples ${contextualTuples
.map((tuple) => `"${tuple.user} ${tuple.relation} ${tuple.object}"`)
? `${contextualTuples
.map((tuple) => ` --contextual-tuple "${tuple.user} ${tuple.relation} ${tuple.object}"`)
.join(' ')}`
: ''
}
}${context ? ` --context='${JSON.stringify(context)}'` : ''}

# Response: {"allowed":${allowed}}`;
case SupportedLanguage.CURL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ function listObjectsRequestViewer(lang: SupportedLanguage, opts: ListObjectsRequ
case SupportedLanguage.CLI:
return `fga query list-objects --store-id=\${FGA_STORE_ID} --model-id=${modelId} ${user} ${relation} ${objectType}${
contextualTuples
? ` --contextual_tuples ${contextualTuples
.map((tuple) => `"${tuple.user} ${tuple.relation} ${tuple.object}"`)
? `${contextualTuples
.map((tuple) => ` --contextual-tuple "${tuple.user} ${tuple.relation} ${tuple.object}"`)
.join(' ')}`
: ''
}
}${context ? ` --context='${JSON.stringify(context)}'` : ''}

# Response: {"objects": [${expectedResults.map((r) => `"${r}"`).join(', ')}]}`;
case SupportedLanguage.CURL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ interface ReadChangesRequestViewerOpts {
function readChangesRequestViewer(lang: SupportedLanguage, opts: ReadChangesRequestViewerOpts) {
switch (lang) {
case SupportedLanguage.CLI: {
return `fga tuple changes --store-id=\${FGA_STORE_ID}${opts.type ? ` --type ${opts.type}` : ''}`;
return `fga tuple changes --store-id=\${FGA_STORE_ID}${opts.type ? ` --type ${opts.type}` : ''}${
opts.continuationToken ? ` --continuation-token ${opts.continuationToken}` : ''
}`;
}
case SupportedLanguage.CURL: {
const typeString = `${opts.type ? '"type": ' + opts.type + '", ' : ''}`;
Expand Down
10 changes: 9 additions & 1 deletion src/components/Docs/SnippetViewer/WriteRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ function writeRequestViewer(lang: SupportedLanguage, opts: WriteRequestViewerOpt
? opts.relationshipTuples
.map(
(tuple) =>
`fga tuple write --store-id=\${FGA_STORE_ID} --model-id=${modelId} ${tuple.user} ${tuple.relation} ${tuple.object}`,
`fga tuple write --store-id=\${FGA_STORE_ID} --model-id=${modelId} ${tuple.user} ${tuple.relation} ${
tuple.object
} ${
tuple.condition
? `--condition-name ${tuple.condition.name} --condition-context '${JSON.stringify(
tuple.condition.context,
)}'`
: ''
}`,
)
.join('\n')
: ''
Expand Down
Loading