Skip to content
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
19 changes: 10 additions & 9 deletions docs/content/getting-started/create-store.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class MyProgram {
import os
import openfga_sdk
from openfga_sdk.api import open_fga_api
from openfga_sdk.model.create_store_request import CreateStoreRequest
from openfga_sdk.models.create_store_request import CreateStoreRequest


configuration = openfga_sdk.Configuration(
Expand All @@ -114,14 +114,15 @@ configuration = openfga_sdk.Configuration(
# Create an instance of the API class
fga_client_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))

try:
# Create a store
body = CreateStoreRequest(
name = "FGA Demo",
)
api_response = fga_client_instance.create_store(body)
except openfga_sdk.ApiException as e:
print("Exception when calling OpenFgaApi->create_store: %s\n" % e)
async def create_store():
try:
# Create a store
body = CreateStoreRequest(
name = "FGA Demo",
)
api_response = await fga_client_instance.create_store(body)
except openfga_sdk.ApiException as e:
print("Exception when calling OpenFgaApi->create_store: %s\n" % e)

```

Expand Down
5 changes: 3 additions & 2 deletions docs/content/getting-started/setup-sdk-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ from open_fga_api.credentials import Credentials, CredentialConfiguration
credentials = Credentials(method='api_token',
configuration=CredentialConfiguration(api_token=os.environ.get(FGA_BEARER_TOKEN)))
configuration = openfga_sdk.Configuration(
scheme = os.environ.get(OPENFGA_API_SCHEME),
api_host = os.environ.get(OPENFGA_API_HOST),
api_scheme = os.environ.get(FGA_API_SCHEME), # optional, defaults to "https"
api_host = os.environ.get(FGA_API_HOST), # required, define without the scheme (e.g. api.openfga.example instead of https://api.openfga.example)
store_id = os.environ.get(FGA_STORE_ID), # optional, not needed for `CreateStore` and `ListStores`, required before calling for all other methods
credentials = credentials)

# Create an instance of the API class
Expand Down
53 changes: 26 additions & 27 deletions src/components/Docs/SnippetViewer/CheckRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,34 @@ var response = await fgaClient.Check(new CheckRequest(new TupleKey() {
// response.Allowed = ${allowed}`;
case SupportedLanguage.PYTHON_SDK:
return `
# from openfga_sdk.model.check_request import CheckRequest
# from openfga_sdk.model.tuple_key import TupleKey
# from openfga_sdk.model.contextual_tuple_keys import ContextualTupleKeys
# from openfga_sdk.models.check_request import CheckRequest
# from openfga_sdk.models.tuple_key import TupleKey
# from openfga_sdk.models.contextual_tuple_keys import ContextualTupleKeys

# Run a check

body = CheckRequest(
tuple_key=TupleKey(
user="${user}",
relation="${relation}",
object="${object}",
),
${
contextualTuples
? `
contextual_tuples=ContextualTupleKeys(
tuple_keys=[
${contextualTuples
.map((tuple) => `TupleKey(user="${tuple.user}", relation="${tuple.relation}", object="${tuple.object}")`)
.join(',\n ')}
],
),
`
: ``
}
)
response = fga_client_instance.check(body)
# response.allowed = ${allowed}

async def check():
body = CheckRequest(
tuple_key=TupleKey(
user="${user}",
relation="${relation}",
object="${object}",
), ${
contextualTuples
? `
contextual_tuples=ContextualTupleKeys(
tuple_keys=[
${contextualTuples
.map(
(tuple) => `TupleKey(user="${tuple.user}", relation="${tuple.relation}", object="${tuple.object}")`,
)
.join(',\n ')}
],
),`
: ``
}
)
response = await fga_client_instance.check(body)
# response.allowed = ${allowed}
`;
case SupportedLanguage.RPC:
return `check(
Expand Down
21 changes: 11 additions & 10 deletions src/components/Docs/SnippetViewer/ExpandRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ Reply: {tree:...}`;

case SupportedLanguage.PYTHON_SDK:
return `
# from openfga_sdk.model.expand_request import ExpandRequest
# from openfga_sdk.model.expand_response import ExpandResponse
# from openfga_sdk.model.tuple_key import TupleKey
# from openfga_sdk.models.expand_request import ExpandRequest
# from openfga_sdk.models.expand_response import ExpandResponse
# from openfga_sdk.models.tuple_key import TupleKey

body = ExpandRequest(
tuple_key=TupleKey(
relation: "${opts.relation}",
object: "${opts.object}",
async def expand():
body = ExpandRequest(
tuple_key=TupleKey(
relation: "${opts.relation}",
object: "${opts.object}",
)
)
)
response = fga_client_instance.expand(body)
# response = ExpandResponse({"tree":...})
response = await fga_client_instance.expand(body)
# response = ExpandResponse({"tree":...})
`;

case SupportedLanguage.PLAYGROUND:
Expand Down
43 changes: 22 additions & 21 deletions src/components/Docs/SnippetViewer/ListObjectsRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,33 @@ var response = await openFgaApi.ListObjects(body);
// response.ObjectIds = [${expectedResults.map((r) => `"${r}"`).join(', ')}]`;
case SupportedLanguage.PYTHON_SDK:
return `
# from openfga_sdk.model.list_objects_request import ListObjectsRequest
# from openfga_sdk.model.tuple_key import TupleKey
# from openfga_sdk.model.contextual_tuple_keys import ContextualTupleKeys
# from openfga_sdk.models.list_objects_request import ListObjectsRequest
# from openfga_sdk.models.tuple_key import TupleKey
# from openfga_sdk.models.contextual_tuple_keys import ContextualTupleKeys

body = ListObjectsRequest(${authorizationModelId ? `authorization_model_id="${authorizationModelId}",` : ``}
user="${user}",
relation="${relation}",
type="${objectType}",${
async def list_objects():
body = ListObjectsRequest(${authorizationModelId ? `authorization_model_id="${authorizationModelId}",` : ``}
user="${user}",
relation="${relation}",
type="${objectType}",${
contextualTuples?.length
? `
contextual_tuples=ContextualTupleKeys(
tuple_keys=[
${contextualTuples
.map(
(tupleKey) => `TupleKey(
user="${tupleKey.user}",
relation="${tupleKey.relation}",
object="${tupleKey.object}")`,
)
.join(',\n ')}
]
)`
contextual_tuples=ContextualTupleKeys(
tuple_keys=[
${contextualTuples
.map(
(tupleKey) => `TupleKey(
user="${tupleKey.user}",
relation="${tupleKey.relation}",
object="${tupleKey.object}")`,
)
.join(',\n ')}
]
)`
: ``
}
)
response = fga_client_instance.list_objects(body)
)
response = await fga_client_instance.list_objects(body)
`;
case SupportedLanguage.RPC:
return `listObjects(
Expand Down
19 changes: 10 additions & 9 deletions src/components/Docs/SnippetViewer/ReadChangesRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,24 @@ await fgaClient.ReadChanges(type, pageSize, continuationToken);`;

case SupportedLanguage.PYTHON_SDK: {
return `
response = fga_client_instance.read_changes(${
opts.type
? `
type="${opts.type}",`
: ``
}${
async def read_changes():
response = await fga_client_instance.read_changes(${
opts.type
? `
type="${opts.type}",`
: ``
}${
opts.pageSize
? `
page_size="${opts.pageSize}",`
page_size="${opts.pageSize}",`
: ``
}${
opts.continuationToken
? `
continuation_token="${opts.continuationToken}",`
continuation_token="${opts.continuationToken}",`
: ``
}
)`;
)`;
}

default: {
Expand Down
23 changes: 12 additions & 11 deletions src/components/Docs/SnippetViewer/ReadRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,23 @@ var response = fgaClient.Read(new ReadRequest(new TupleKey() {
}
case SupportedLanguage.PYTHON_SDK: {
const requestTuples =
(opts.user ? ` user="${opts.user}",\n` : '') +
(opts.relation ? ` relation="${opts.relation}",\n` : '') +
` object="${opts.object}",\n`;
(opts.user ? ` user="${opts.user}",\n` : '') +
(opts.relation ? ` relation="${opts.relation}",\n` : '') +
` object="${opts.object}",\n`;

return `
# from openfga_sdk.model.read_request import ReadRequest
# from openfga_sdk.model.read_response import ReadResponse
# from openfga_sdk.model.tuple_key import TupleKey
# from openfga_sdk.models.read_request import ReadRequest
# from openfga_sdk.models.read_response import ReadResponse
# from openfga_sdk.models.tuple_key import TupleKey

body = ReadRequest(
tuple_key=TupleKey(
async def read():
body = ReadRequest(
tuple_key=TupleKey(
${requestTuples}
)
)
)
response = fga_client_instance.read(body)
# response = ReadResponse({"tuples":[${readTuples}]})`;
response = await fga_client_instance.read(body)
# response = ReadResponse({"tuples":[${readTuples}]})`;
}
case SupportedLanguage.RPC: {
const objectOrType = opts.object.slice(-1) === ':' ? 'type' : 'object';
Expand Down
6 changes: 3 additions & 3 deletions src/components/Docs/SnippetViewer/SdkSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class MyProgram {
${importSdkStatement(lang, languageMappings)}

configuration = openfga_sdk.Configuration(
api_scheme = os.environ.get('FGA_API_SCHEME'),
api_host = os.environ.get('FGA_API_HOST'),
store_id = os.environ.get('FGA_STORE_ID')
api_scheme = os.environ.get('FGA_API_SCHEME'), # Either "http" or "https", defaults to "https"
api_host = os.environ.get('FGA_API_HOST'), # required, define without the scheme (e.g. api.openfga.example instead of https://api.openfga.example)
store_id = os.environ.get('FGA_STORE_ID') # optional, not needed for \`CreateStore\` and \`ListStores\`, required before calling for all other methods
)

# Create an instance of the API class
Expand Down
27 changes: 14 additions & 13 deletions src/components/Docs/SnippetViewer/WriteAuthzModelViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ function writeAuthZModelViewerDotnet(authorizationModel: AuthorizationModel): st

function writeAuthZModelViewerPython(authorizationModel: AuthorizationModel): string {
return `
# from openfga_sdk.model.type_definitions import TypeDefinitions

body_string = ${JSON.stringify(JSON.stringify(authorizationModel))}
type_definitions = openfga_sdk.model_utils.validate_and_convert_types(
json.loads(body_string),
(TypeDefinitions,),
['TypeDefinitions'],
True,
True,
configuration=configuration
)
response = fga_client_instance.write_authorization_model(type_definitions)
# response.authorization_model_id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw"
# from openfga_sdk.models.write_authorization_model_request import WriteAuthorizationModelRequest

async def write_authorization_model():
body_string = ${JSON.stringify(JSON.stringify(authorizationModel))}
body = openfga_sdk.model_utils.validate_and_convert_types(
json.loads(body_string),
(WriteAuthorizationModelRequest,),
['WriteAuthorizationModelRequest'],
True,
True,
configuration=configuration
)
response = await fga_client_instance.write_authorization_model(body)
# response.authorization_model_id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw"
`;
}

Expand Down
47 changes: 24 additions & 23 deletions src/components/Docs/SnippetViewer/WriteRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,46 +162,47 @@ await fgaClient.Write(new WriteRequest{
? opts.relationshipTuples
.map(
({ user, relation, object, _description }) => `
TupleKey(
${_description ? ` # ${_description}\n ` : ' '}user= "${user}",
relation= "${relation}",
object="${object}",
),`,
TupleKey(
${_description ? ` # ${_description}\n ` : ' '}user="${user}",
relation="${relation}",
object="${object}",
),`,
)
.join('')
: '';
const deleteTuples = opts.deleteRelationshipTuples
? opts.deleteRelationshipTuples
.map(
({ user, relation, object, _description }) => `
TupleKey(
${_description ? ` # ${_description}\n ` : ' '}user= "${user}",
relation= "${relation}",
object="${object}",
),`,
TupleKey(
${_description ? ` # ${_description}\n ` : ' '}user="${user}",
relation="${relation}",
object="${object}",
),`,
)
.join('')
: '';
const writes = ` writes=TupleKeys(
tuple_keys= [${writeTuples}
],
),
tuple_keys=[${writeTuples}
],
),
`;
const deletes = ` deletes=TupleKeys(
tuple_keys= [${deleteTuples}
],
),
tuple_keys=[${deleteTuples}
],
),
`;

return `
# from openfga_sdk.model.tuple_key import TupleKey
# from openfga_sdk.model.tuple_keys import TupleKeys
# from openfga_sdk.model.write_request import WriteRequest
# from openfga_sdk.models.tuple_key import TupleKey
# from openfga_sdk.models.tuple_keys import TupleKeys
# from openfga_sdk.models.write_request import WriteRequest

body = WriteRequest(
${opts.relationshipTuples ? writes : ''}${opts.deleteRelationshipTuples ? deletes : ''}
)
response = fga_client_instance.write(body)
async def write():
body = WriteRequest(
${opts.relationshipTuples ? writes : ''}${opts.deleteRelationshipTuples ? deletes : ''}
)
await fga_client_instance.write(body)
`;
}

Expand Down