|
1 | 1 | importos |
2 | | -fromstringimportTemplate |
| 2 | +fromtypingimport ( |
| 3 | +Literal, |
| 4 | +Optional, |
| 5 | +) |
3 | 6 |
|
4 | 7 | from .clientimport ( |
5 | 8 | AsyncClient, |
|
8 | 11 | from .environmentimportPipedreamEnvironment |
9 | 12 |
|
10 | 13 |
|
| 14 | +classOAuthCredentials: |
| 15 | + |
| 16 | +def__init__( |
| 17 | +self, |
| 18 | +client_id:Optional[str]=None, |
| 19 | +client_secret:Optional[str]=None, |
| 20 | + ): |
| 21 | +self.client_id=client_idoros.getenv("PIPEDREAM_CLIENT_ID") |
| 22 | +self.client_secret=client_secretoros.getenv( |
| 23 | +"PIPEDREAM_CLIENT_SECRET") |
| 24 | + |
| 25 | +ifnotself.client_idornotself.client_secret: |
| 26 | +raiseValueError("OAuth client ID and secret are required") |
| 27 | + |
| 28 | + |
11 | 29 | classPipedream(Client): |
| 30 | + |
12 | 31 | def__init__( |
13 | 32 | self, |
14 | | -project_id:str, |
15 | | -environment:PipedreamEnvironment=PipedreamEnvironment.PROD, |
16 | | -*args, |
| 33 | +*, |
| 34 | +credentials:OAuthCredentials=OAuthCredentials(), |
| 35 | +project_id:Optional[str]=None, |
| 36 | +environment:Literal["production","development"]="production", |
| 37 | +api_environment:PipedreamEnvironment=PipedreamEnvironment.PROD, |
17 | 38 | **kwargs, |
18 | 39 | ): |
19 | | -super().__init__(base_url=_get_base_url(environment),*args,**kwargs) |
20 | | -self.project_id=project_id |
| 40 | +project_id=project_idoros.getenv("PIPEDREAM_PROJECT_ID") |
| 41 | +ifnotproject_id: |
| 42 | +raiseValueError("Project ID is required") |
| 43 | + |
| 44 | +ifnotcredentials.client_idornotcredentials.client_secret: |
| 45 | +raiseValueError("OAuth client ID and secret are required") |
| 46 | + |
| 47 | +super().__init__( |
| 48 | +client_id=credentials.client_id, |
| 49 | +client_secret=credentials.client_secret, |
| 50 | +environment=api_environment, |
| 51 | +project_id=project_id, |
| 52 | +x_pd_environment=environment, |
| 53 | +**kwargs, |
| 54 | + ) |
21 | 55 |
|
22 | 56 |
|
23 | 57 | classAsyncPipedream(AsyncClient): |
| 58 | + |
24 | 59 | def__init__( |
25 | 60 | self, |
26 | | -project_id:str, |
27 | | -environment:PipedreamEnvironment=PipedreamEnvironment.PROD, |
28 | | -*args, |
| 61 | +*, |
| 62 | +credentials:OAuthCredentials=OAuthCredentials(), |
| 63 | +project_id:Optional[str]=None, |
| 64 | +environment:Literal["production","development"]="production", |
| 65 | +api_environment:PipedreamEnvironment=PipedreamEnvironment.PROD, |
29 | 66 | **kwargs, |
30 | 67 | ): |
31 | | -super().__init__(base_url=_get_base_url(environment),*args,**kwargs) |
32 | | -self.project_id=project_id |
33 | | - |
| 68 | +project_id=project_idoros.getenv("PIPEDREAM_PROJECT_ID") |
| 69 | +ifnotproject_id: |
| 70 | +raiseValueError("Project ID is required") |
34 | 71 |
|
35 | | -def_get_base_url(environment:PipedreamEnvironment)->str: |
36 | | -ifnotenvironment: |
37 | | -raiseException("Please pass environment to construct the client") |
| 72 | +ifnotcredentials.client_idornotcredentials.client_secret: |
| 73 | +raiseValueError("OAuth client ID and secret are required") |
38 | 74 |
|
39 | | -user=os.getenv("DEV_NAMESPACE","") |
40 | | -returnTemplate(environment.value).substitute( |
41 | | - { |
42 | | -"user":user, |
43 | | - } |
44 | | - ) |
| 75 | +super().__init__( |
| 76 | +client_id=credentials.client_id, |
| 77 | +client_secret=credentials.client_secret, |
| 78 | +environment=api_environment, |
| 79 | +project_id=project_id, |
| 80 | +x_pd_environment=environment, |
| 81 | +**kwargs, |
| 82 | + ) |