Skip to content

Commit de824c0

Browse files
committed
Add back the custom client wrapper
1 parent 2510e08 commit de824c0

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

src/pipedream/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
tokens,
158158
triggers,
159159
users,
160+
workflows,
160161
)
161162
from .actions import ActionsListRequestRegistry
162163
from .apps import AppsListRequestSortDirection, AppsListRequestSortKey
@@ -325,6 +326,7 @@
325326
"tokens": ".tokens",
326327
"triggers": ".triggers",
327328
"users": ".users",
329+
"workflows": ".workflows",
328330
}
329331

330332

@@ -509,4 +511,5 @@ def __dir__():
509511
"tokens",
510512
"triggers",
511513
"users",
514+
"workflows",
512515
]

src/pipedream/pipedream.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import os
2+
from typing import Optional
3+
4+
from .client import (
5+
AsyncClient,
6+
Client,
7+
)
8+
from .environment import PipedreamEnvironment
9+
from .types.project_environment import ProjectEnvironment
10+
from .workflows.client import (
11+
AsyncWorkflowsClient,
12+
WorkflowsClient,
13+
)
14+
15+
16+
class Pipedream(Client):
17+
18+
def __init__(
19+
self,
20+
*,
21+
access_token: Optional[str] = os.getenv("PIPEDREAM_ACCESS_TOKEN"),
22+
client_id: Optional[str] = os.getenv("PIPEDREAM_CLIENT_ID"),
23+
client_secret: Optional[str] = os.getenv("PIPEDREAM_CLIENT_SECRET"),
24+
project_id: Optional[str] = os.getenv("PIPEDREAM_PROJECT_ID"),
25+
project_environment: ProjectEnvironment = os.getenv(
26+
"PIPEDREAM_PROJECT_ENVIRONMENT",
27+
"production",
28+
),
29+
environment: PipedreamEnvironment = PipedreamEnvironment.PROD,
30+
workflow_domain: Optional[str] = None,
31+
):
32+
if not project_id:
33+
raise ValueError("Project ID is required")
34+
35+
if access_token:
36+
super().__init__(
37+
base_url=_get_base_url(environment),
38+
project_environment=project_environment,
39+
project_id=project_id,
40+
token=(lambda: access_token),
41+
)
42+
else:
43+
super().__init__(
44+
base_url=_get_base_url(environment),
45+
project_environment=project_environment,
46+
project_id=project_id,
47+
client_id=client_id,
48+
client_secret=client_secret,
49+
)
50+
51+
if not workflow_domain:
52+
workflow_domain = _get_default_workflow_domain(environment)
53+
54+
self.workflows = WorkflowsClient(
55+
client_wrapper=self._client_wrapper,
56+
workflow_domain=workflow_domain,
57+
)
58+
59+
@property
60+
def raw_access_token(self) -> Optional[str]:
61+
"""
62+
Returns an access token that can be used to authenticate API requests
63+
"""
64+
return self._client_wrapper._get_token()
65+
66+
67+
class AsyncPipedream(AsyncClient):
68+
69+
def __init__(
70+
self,
71+
*,
72+
access_token: Optional[str] = os.getenv("PIPEDREAM_ACCESS_TOKEN"),
73+
client_id: Optional[str] = os.getenv("PIPEDREAM_CLIENT_ID"),
74+
client_secret: Optional[str] = os.getenv("PIPEDREAM_CLIENT_SECRET"),
75+
project_id: Optional[str] = os.getenv("PIPEDREAM_PROJECT_ID"),
76+
project_environment: ProjectEnvironment = os.getenv(
77+
"PIPEDREAM_PROJECT_ENVIRONMENT",
78+
"production",
79+
),
80+
environment: PipedreamEnvironment = PipedreamEnvironment.PROD,
81+
workflow_domain: Optional[str] = None,
82+
):
83+
if not project_id:
84+
raise ValueError("Project ID is required")
85+
86+
if access_token:
87+
super().__init__(
88+
base_url=_get_base_url(environment),
89+
project_environment=project_environment,
90+
project_id=project_id,
91+
token=(lambda: access_token),
92+
)
93+
else:
94+
super().__init__(
95+
base_url=_get_base_url(environment),
96+
project_environment=project_environment,
97+
project_id=project_id,
98+
client_id=client_id,
99+
client_secret=client_secret,
100+
)
101+
102+
if not workflow_domain:
103+
workflow_domain = _get_default_workflow_domain(environment)
104+
105+
self.workflows = AsyncWorkflowsClient(
106+
client_wrapper=self._client_wrapper,
107+
workflow_domain=workflow_domain,
108+
)
109+
110+
@property
111+
def raw_access_token(self) -> Optional[str]:
112+
"""
113+
Returns an access token that can be used to authenticate API requests
114+
"""
115+
return self._client_wrapper._get_token()
116+
117+
118+
def _get_base_url(environment: PipedreamEnvironment) -> str:
119+
"""
120+
Returns the base URL for the given environment.
121+
"""
122+
return os.path.expandvars(environment.value)
123+
124+
125+
def _get_default_workflow_domain(environment: PipedreamEnvironment) -> str:
126+
"""
127+
Returns the default workflow domain.
128+
"""
129+
if environment == PipedreamEnvironment.DEV:
130+
return "m.d.pipedream.net"
131+
return "m.pipedream.net"

0 commit comments

Comments
 (0)