Skip to content

Commit 7012218

Browse files
base python sdk for fga
1 parent 716622c commit 7012218

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

src/workos/fga.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
"""
2+
DEPRECATED: This module is deprecated and will be removed in a future version.
3+
Please use workos.authorization instead for Fine-Grained Authorization (FGA) functionality.
4+
5+
See authorization.py for the new resource-based FGA APIs:
6+
- get_resource, create_resource, update_resource, delete_resource, list_resources
7+
- get_resource_by_external_id, update_resource_by_external_id, delete_resource_by_external_id
8+
- check, assign_role, remove_role, list_role_assignments, remove_role_assignment
9+
- list_resources_for_membership, list_memberships_for_resource, list_memberships_for_resource_by_external_id
10+
"""
11+
112
import json
213
from typing import Any, Mapping, Optional, Protocol, Sequence
14+
315
from workos.types.fga import (
416
CheckOperation,
517
CheckResponse,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Mock fixture for AuthorizationResource used in testing new FGA APIs.
2+
3+
This fixture represents the new organization-scoped authorization resource model
4+
used in the Advanced FGA APIs, distinct from the legacy warrant-based resources.
5+
"""
6+
7+
from typing import Optional
8+
9+
10+
class MockAuthorizationResource:
11+
"""Mock authorization resource for testing the new FGA resource-based APIs.
12+
13+
Attributes:
14+
id: Internal WorkOS resource ID.
15+
external_id: Customer-provided external identifier for the resource.
16+
name: Human-readable name for the resource.
17+
description: Optional description of the resource.
18+
resource_type_slug: The type of resource (e.g., "document", "folder").
19+
organization_id: The organization this resource belongs to.
20+
parent_resource_id: Optional parent resource ID for hierarchical resources.
21+
"""
22+
23+
def __init__(
24+
self,
25+
id: str = "authz_resource_01HXYZ123ABC456DEF789ABC",
26+
external_id: str = "doc-456",
27+
name: str = "Q4 Budget Report",
28+
description: Optional[str] = "Financial report for Q4 2025",
29+
resource_type_slug: str = "document",
30+
organization_id: str = "org_01HXYZ123ABC456DEF789ABC",
31+
parent_resource_id: Optional[str] = None,
32+
):
33+
self.id = id
34+
self.external_id = external_id
35+
self.name = name
36+
self.description = description
37+
self.resource_type_slug = resource_type_slug
38+
self.organization_id = organization_id
39+
self.parent_resource_id = parent_resource_id
40+
41+
def dict(self) -> dict:
42+
"""Return the resource as a dictionary matching API response format."""
43+
return {
44+
"object": "authorization_resource",
45+
"id": self.id,
46+
"external_id": self.external_id,
47+
"name": self.name,
48+
"description": self.description,
49+
"resource_type_slug": self.resource_type_slug,
50+
"organization_id": self.organization_id,
51+
"parent_resource_id": self.parent_resource_id,
52+
"created_at": "2024-01-15T09:30:00.000Z",
53+
"updated_at": "2024-01-15T09:30:00.000Z",
54+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Mock fixture for RoleAssignment used in testing new FGA APIs.
2+
3+
This fixture represents role assignments that grant a role to an organization
4+
membership on a specific resource.
5+
"""
6+
7+
8+
class MockRoleAssignment:
9+
"""Mock role assignment for testing the new FGA role assignment APIs.
10+
11+
Attributes:
12+
id: Internal WorkOS role assignment ID.
13+
role_slug: The slug of the role being assigned (e.g., "editor", "viewer").
14+
resource_id: The internal ID of the resource the role is assigned on.
15+
resource_external_id: The external ID of the resource.
16+
resource_type_slug: The type of resource (e.g., "document", "folder").
17+
"""
18+
19+
def __init__(
20+
self,
21+
id: str = "role_assignment_01HXYZ123ABC456DEF789ABC",
22+
role_slug: str = "editor",
23+
resource_id: str = "resource_01HXYZ123ABC456DEF789XYZ",
24+
resource_external_id: str = "doc-123",
25+
resource_type_slug: str = "document",
26+
):
27+
self.id = id
28+
self.role_slug = role_slug
29+
self.resource_id = resource_id
30+
self.resource_external_id = resource_external_id
31+
self.resource_type_slug = resource_type_slug
32+
33+
def dict(self) -> dict:
34+
"""Return the role assignment as a dictionary matching API response format."""
35+
return {
36+
"object": "role_assignment",
37+
"id": self.id,
38+
"role": {"slug": self.role_slug},
39+
"resource": {
40+
"id": self.resource_id,
41+
"external_id": self.resource_external_id,
42+
"resource_type_slug": self.resource_type_slug,
43+
},
44+
"created_at": "2024-01-15T09:30:00.000Z",
45+
"updated_at": "2024-01-15T09:30:00.000Z",
46+
}

0 commit comments

Comments
 (0)