Skip to content

Commit c4672c7

Browse files
committed
feat: add permission control to PicaClientOptions
1 parent e6aea24 commit c4672c7

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The `PicaClientOptions` class allows you to configure the Pica client with the f
2323
| server_url | str | No | https://api.picaos.com | URL for self-hosted Pica server. |
2424
| connectors | List[str] | No | [] | List of connector keys to filter by. Pass ["*"] to initialize all available connectors, or specific connector keys to filter. If empty, no connections will be initialized. |
2525
| actions | List[str] | No | None | List of action ids to filter by. Default is all actions. |
26+
| permissions | Literal["read", "write", "admin"] | No | None | Permission level to filter actions by. 'read' allows GET only, 'write' allows POST/PUT/PATCH, 'admin' allows all methods (default: 'admin') |
2627
| authkit | bool | No | False | If True, the SDK will use Authkit to connect to prompt the user to connect to a platform that they do not currently have access to |
2728
| identity | str | No | None | Filter connections by specific identity ID. |
2829
| identity_type | "user", "team", "organization", or "project" | No | None | Filter connections by identity type. |
@@ -54,7 +55,8 @@ pica_client = PicaClient(
5455
# identity="user-id",
5556
# authkit=True,
5657
# actions=[""], # Initialize specific action ids (e.g. ["conn_mod_def::F_JeJ_A_TKg::cc2kvVQQTiiIiLEDauy6zQ"])
57-
58+
# permissions="read", # Filter actions by permission level
59+
5860
connectors=["*"] # Initialize all available connections for this example
5961
)
6062
)

pica_langchain/client.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self, secret: str, options: Optional[PicaClientOptions] = None):
3939
- server_url: Custom server URL to use instead of the default.
4040
- connectors: List of connector keys to filter by.
4141
- actions: List of action IDs to filter by. Default is all actions.
42+
- permissions: Permission level to filter actions by. 'read' allows GET only, 'write' allows POST/PUT/PATCH, 'admin' allows all methods.
4243
- identity: Filter connections by specific identity ID.
4344
- identity_type: Filter connections by identity type (user, team, organization, or project).
4445
- authkit: Whether to use the AuthKit integration which enables the promptToConnectPlatform tool.
@@ -82,6 +83,10 @@ def __init__(self, secret: str, options: Optional[PicaClientOptions] = None):
8283
self._actions_filter = options.actions
8384
if self._actions_filter:
8485
logger.debug(f"Filtering actions by IDs: {self._actions_filter}")
86+
87+
self._permissions_filter = options.permissions
88+
if self._permissions_filter:
89+
logger.debug(f"Filtering actions by permissions: {self._permissions_filter}")
8590

8691
self.mcp_client = None
8792
self.mcp_tools = []
@@ -476,7 +481,29 @@ def get_available_actions(self, platform: str) -> ActionsResponse:
476481
filtered_actions.append(action)
477482

478483
all_actions = filtered_actions
479-
logger.info(f"After filtering, {len(all_actions)} actions remain")
484+
logger.info(f"After filtering by IDs, {len(all_actions)} actions remain")
485+
486+
# Filter actions by permissions if permissions filter is provided
487+
if self._permissions_filter:
488+
logger.debug(f"Filtering actions by permissions: {self._permissions_filter}")
489+
filtered_by_permissions = []
490+
491+
if self._permissions_filter == "read":
492+
for action in all_actions:
493+
method = action.method
494+
if method and method.upper() == "GET":
495+
filtered_by_permissions.append(action)
496+
elif self._permissions_filter == "write":
497+
for action in all_actions:
498+
method = action.method
499+
if method and method.upper() in ["POST", "PUT", "PATCH"]:
500+
filtered_by_permissions.append(action)
501+
# For "admin" or no permissions set, return all actions (no filtering)
502+
else:
503+
filtered_by_permissions = all_actions
504+
505+
all_actions = filtered_by_permissions
506+
logger.info(f"After filtering by permissions ({self._permissions_filter}), {len(all_actions)} actions remain")
480507

481508
# Create simplified action representations
482509
simplified_actions = []

pica_langchain/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class AvailableAction(BaseModel):
5757
path: Optional[str] = None
5858
base_url: Optional[str] = Field(None, alias="baseUrl")
5959
tags: Optional[List[str]] = Field(default_factory=list)
60+
method: Optional[str] = None
6061

6162
model_config = ConfigDict(
6263
populate_by_name=True,
@@ -261,6 +262,10 @@ class PicaClientOptions(BaseModel):
261262
default=None,
262263
description="List of action ids to filter by. Default is all actions."
263264
)
265+
permissions: Optional[Literal["read", "write", "admin"]] = Field(
266+
default=None,
267+
description="Permission level to filter actions by. 'read' allows GET only, 'write' allows POST/PUT/PATCH, 'admin' allows all methods (default: 'admin')"
268+
)
264269
identity: Optional[str] = Field(
265270
default=None,
266271
description="Filter connections by specific identity ID"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="pica-langchain",
5-
version="1.3.0",
5+
version="1.4.0",
66
packages=find_packages(),
77
install_requires=[
88
"langchain==0.3.20",

0 commit comments

Comments
 (0)