bosa-connectors-binary 0.1.5b1__cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bosa_connectors/__init__.pyi +6 -0
- bosa_connectors/action.pyi +80 -0
- bosa_connectors/action_response.pyi +86 -0
- bosa_connectors/auth/__init__.pyi +4 -0
- bosa_connectors/auth/api_key.pyi +19 -0
- bosa_connectors/auth/base.pyi +12 -0
- bosa_connectors/connector.pyi +161 -0
- bosa_connectors/helpers/__init__.pyi +0 -0
- bosa_connectors/helpers/authenticator.pyi +45 -0
- bosa_connectors/helpers/integrations.pyi +49 -0
- bosa_connectors/helpers/model_request_generator.pyi +14 -0
- bosa_connectors/models/__init__.pyi +0 -0
- bosa_connectors/models/action.pyi +16 -0
- bosa_connectors/models/file.pyi +8 -0
- bosa_connectors/models/result.pyi +6 -0
- bosa_connectors/models/token.pyi +10 -0
- bosa_connectors/models/user.pyi +27 -0
- bosa_connectors/module.pyi +76 -0
- bosa_connectors/tool.pyi +46 -0
- bosa_connectors.build/.gitignore +1 -0
- bosa_connectors.cpython-312-darwin.so +0 -0
- bosa_connectors.pyi +31 -0
- bosa_connectors_binary-0.1.5b1.dist-info/METADATA +422 -0
- bosa_connectors_binary-0.1.5b1.dist-info/RECORD +26 -0
- bosa_connectors_binary-0.1.5b1.dist-info/WHEEL +6 -0
- bosa_connectors_binary-0.1.5b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
from .connector import BosaConnector as BosaConnector
|
2
|
+
from .module import BosaConnectorModule as BosaConnectorModule
|
3
|
+
from .tool import BOSAConnectorToolGenerator as BOSAConnectorToolGenerator
|
4
|
+
from bosa_connectors.helpers.authenticator import BosaAuthenticator as BosaAuthenticator
|
5
|
+
|
6
|
+
__all__ = ['BosaAuthenticator', 'BosaConnector', 'BosaConnectorModule', 'BOSAConnectorToolGenerator']
|
@@ -0,0 +1,80 @@
|
|
1
|
+
from bosa_connectors.action_response import ActionResponse as ActionResponse
|
2
|
+
from bosa_connectors.auth import BaseAuthenticator as BaseAuthenticator
|
3
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
4
|
+
from bosa_connectors.module import BosaConnectorModule as BosaConnectorModule
|
5
|
+
from typing import Any
|
6
|
+
|
7
|
+
class ActionExecutor:
|
8
|
+
"""Represents a specific action execution for a service.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
# Direct execution with raw response
|
12
|
+
data, status = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .execute()
|
13
|
+
|
14
|
+
# Or with pagination support
|
15
|
+
response = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .run()
|
16
|
+
|
17
|
+
# Get data and handle pagination
|
18
|
+
data = response.get_data()
|
19
|
+
while response.has_next():
|
20
|
+
response = response.next_page()
|
21
|
+
data = response.get_data()
|
22
|
+
"""
|
23
|
+
DEFAULT_MAX_ATTEMPTS: int
|
24
|
+
DEFAULT_TIMEOUT: int
|
25
|
+
def __init__(self, module: BosaConnectorModule, authenticator: BaseAuthenticator, action: str) -> None:
|
26
|
+
"""Initialize the action executor.
|
27
|
+
|
28
|
+
Args:
|
29
|
+
module: The connector module to execute against
|
30
|
+
authenticator: The authenticator to use for requests
|
31
|
+
action: The action name to execute
|
32
|
+
"""
|
33
|
+
def params(self, params: dict[str, Any]) -> ActionExecutor:
|
34
|
+
"""Set additional parameters."""
|
35
|
+
def headers(self, headers: dict[str, str]) -> ActionExecutor:
|
36
|
+
"""Set request headers."""
|
37
|
+
def max_attempts(self, attempts: int) -> ActionExecutor:
|
38
|
+
"""Set maximum retry attempts."""
|
39
|
+
def token(self, token: str | None) -> ActionExecutor:
|
40
|
+
"""Set the BOSA user token for this action."""
|
41
|
+
def timeout(self, timeout: int | None) -> ActionExecutor:
|
42
|
+
"""Set the timeout for the request."""
|
43
|
+
def execute(self) -> tuple[dict[str, Any] | ConnectorFile, int]:
|
44
|
+
"""Execute request and return raw response.
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
Tuple of (response_data, status_code)
|
48
|
+
"""
|
49
|
+
def run(self) -> ActionResponse:
|
50
|
+
"""Execute request and return paginated response.
|
51
|
+
|
52
|
+
Returns an ActionResponse that supports pagination for list responses.
|
53
|
+
For single item responses, pagination methods will return the same item.
|
54
|
+
|
55
|
+
Returns:
|
56
|
+
ActionResponse with pagination support
|
57
|
+
"""
|
58
|
+
|
59
|
+
class Action:
|
60
|
+
"""Base class for plugins to prepare action execution.
|
61
|
+
|
62
|
+
Example:
|
63
|
+
# Create a GitHub connector
|
64
|
+
github = bosa.connect('github')
|
65
|
+
|
66
|
+
# Execute with raw response
|
67
|
+
data, status = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .execute()
|
68
|
+
|
69
|
+
# Or with pagination support
|
70
|
+
response = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .run()
|
71
|
+
"""
|
72
|
+
def __init__(self, module: BosaConnectorModule, authenticator: BaseAuthenticator) -> None:
|
73
|
+
"""Initialize the action builder.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
module: The connector module to use
|
77
|
+
authenticator: The authenticator to use for requests
|
78
|
+
"""
|
79
|
+
def action(self, action: str) -> ActionExecutor:
|
80
|
+
"""Create a new action executor for a service."""
|
@@ -0,0 +1,86 @@
|
|
1
|
+
from bosa_connectors.models.action import ActionResponseData as ActionResponseData, InitialExecutorRequest as InitialExecutorRequest
|
2
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
3
|
+
from typing import Any, Callable
|
4
|
+
|
5
|
+
class ActionResponse:
|
6
|
+
'''Represents the response from an action execution.
|
7
|
+
|
8
|
+
Currently supports 2 pagination modes:
|
9
|
+
1. Page-based pagination: Using page numbers (page=1, page=2, etc.)
|
10
|
+
2. Cursor-based pagination: Using cursor tokens for forwards and backwards navigation
|
11
|
+
|
12
|
+
The class automatically detects which pagination mode to use based on the response metadata:
|
13
|
+
- If "forwards_cursor" and "backwards_cursor" are present, cursor-based pagination is used
|
14
|
+
- Otherwise, it falls back to page-based pagination using "page" parameter
|
15
|
+
|
16
|
+
Common pagination attributes:
|
17
|
+
- total: Total number of items
|
18
|
+
- total_page: Total number of pages
|
19
|
+
- has_next: Whether there is a next page
|
20
|
+
- has_prev: Whether there is a previous page
|
21
|
+
|
22
|
+
Followed by optional attributes
|
23
|
+
Cursor-based pagination attributes:
|
24
|
+
- forwards_cursor: Cursor for next page
|
25
|
+
- backwards_cursor: Cursor for previous page
|
26
|
+
|
27
|
+
Page-based pagination attributes:
|
28
|
+
- page: Current page number
|
29
|
+
- limit: Number of items per page
|
30
|
+
|
31
|
+
If the response is ConnectorFile, it will not support pagination and will return the file directly.
|
32
|
+
'''
|
33
|
+
def __init__(self, response_data: dict[str, Any] | ConnectorFile | None, status: int, response_creator: Callable[..., 'ActionResponse'], initial_executor_request: dict[str, Any]) -> None:
|
34
|
+
'''Initialize response wrapper.
|
35
|
+
|
36
|
+
Args:
|
37
|
+
response_data: Response data which could be:
|
38
|
+
- List response: {"data": [...], "meta": {...}}
|
39
|
+
- Single item response: {"data": {...}, "meta": {...}}
|
40
|
+
status: HTTP status code
|
41
|
+
response_creator: Callable to create a new ActionResponse
|
42
|
+
initial_executor_request: Initial action request attributes as dict
|
43
|
+
'''
|
44
|
+
def get_data(self) -> list[dict[str, Any]] | dict[str, Any] | ConnectorFile:
|
45
|
+
"""Get the current page data.
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
List of objects for paginated responses, or
|
49
|
+
Single object for single item responses
|
50
|
+
"""
|
51
|
+
def get_meta(self) -> dict[str, Any]:
|
52
|
+
"""Get the meta data."""
|
53
|
+
def get_status(self) -> int:
|
54
|
+
"""Get the HTTP status code."""
|
55
|
+
def is_list(self) -> bool:
|
56
|
+
"""Check if the response data is a list."""
|
57
|
+
def has_next(self) -> bool:
|
58
|
+
"""Check if there is a next page.
|
59
|
+
|
60
|
+
Returns False if this is a single item response.
|
61
|
+
"""
|
62
|
+
def has_prev(self) -> bool:
|
63
|
+
"""Check if there is a previous page.
|
64
|
+
|
65
|
+
Returns False if this is a single item response.
|
66
|
+
"""
|
67
|
+
def next_page(self) -> ActionResponse:
|
68
|
+
"""Move to the next page and get the response.
|
69
|
+
|
70
|
+
Supports both page-based and cursor-based navigation:
|
71
|
+
1. If forwards_cursor is available, uses cursor-based navigation
|
72
|
+
2. Otherwise, falls back to page-based navigation
|
73
|
+
|
74
|
+
Returns self if this is a single item response or there is no next page.
|
75
|
+
"""
|
76
|
+
def prev_page(self) -> ActionResponse:
|
77
|
+
"""Move to the previous page and get the response.
|
78
|
+
|
79
|
+
Supports both page-based and cursor-based navigation:
|
80
|
+
1. If backwards_cursor is available, uses cursor-based navigation
|
81
|
+
2. Otherwise, falls back to page-based navigation
|
82
|
+
|
83
|
+
Returns self if this is a single item data or there is no previous page.
|
84
|
+
"""
|
85
|
+
def get_all_items(self) -> list[Any]:
|
86
|
+
"""Get all items from all pages."""
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth.base import BaseAuthenticator as BaseAuthenticator
|
3
|
+
|
4
|
+
class ApiKeyAuthenticator(BaseAuthenticator):
|
5
|
+
"""Injects API Key Headers to BOSA API for Authentication."""
|
6
|
+
API_KEY_HEADER: str
|
7
|
+
api_key: Incomplete
|
8
|
+
def __init__(self, api_key: str) -> None:
|
9
|
+
"""Initializes the ApiKeyAuthenticator with the provided API key.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
api_key (str): The API key for authentication.
|
13
|
+
"""
|
14
|
+
def authenticate(self):
|
15
|
+
"""Authenticates the request.
|
16
|
+
|
17
|
+
Raises:
|
18
|
+
AuthenticationError: If authentication fails.
|
19
|
+
"""
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import abc
|
2
|
+
from abc import ABC, abstractmethod
|
3
|
+
|
4
|
+
class BaseAuthenticator(ABC, metaclass=abc.ABCMeta):
|
5
|
+
"""Base authenticator for BOSA API."""
|
6
|
+
@abstractmethod
|
7
|
+
def authenticate(self):
|
8
|
+
"""Authenticates the request.
|
9
|
+
|
10
|
+
Raises:
|
11
|
+
AuthenticationError: If authentication fails.
|
12
|
+
"""
|
@@ -0,0 +1,161 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.action import Action as Action
|
3
|
+
from bosa_connectors.action_response import ActionResponse as ActionResponse
|
4
|
+
from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
|
5
|
+
from bosa_connectors.helpers.authenticator import BosaAuthenticator as BosaAuthenticator
|
6
|
+
from bosa_connectors.helpers.integrations import BosaIntegrationHelper as BosaIntegrationHelper
|
7
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
8
|
+
from bosa_connectors.models.result import ActionResult as ActionResult
|
9
|
+
from bosa_connectors.models.token import BosaToken as BosaToken
|
10
|
+
from bosa_connectors.models.user import BosaUser as BosaUser, CreateUserResponse as CreateUserResponse
|
11
|
+
from bosa_connectors.module import BosaConnectorError as BosaConnectorError, BosaConnectorModule as BosaConnectorModule
|
12
|
+
from typing import Any
|
13
|
+
|
14
|
+
class BosaConnector:
|
15
|
+
"""Main connector class that manages all BOSA connector modules."""
|
16
|
+
DEFAULT_TIMEOUT: int
|
17
|
+
DEFAULT_MAX_ATTEMPTS: int
|
18
|
+
OAUTH2_FLOW_ENDPOINT: str
|
19
|
+
INTEGRATION_CHECK_ENDPOINT: str
|
20
|
+
api_base_url: Incomplete
|
21
|
+
auth_scheme: Incomplete
|
22
|
+
bosa_authenticator: Incomplete
|
23
|
+
bosa_integration_helper: Incomplete
|
24
|
+
def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
|
25
|
+
"""Initialization."""
|
26
|
+
def get_available_modules(self) -> list[str]:
|
27
|
+
"""Scan and cache all available connector modules.
|
28
|
+
|
29
|
+
Returns:
|
30
|
+
List of available modules
|
31
|
+
"""
|
32
|
+
def create_bosa_user(self, identifier: str) -> CreateUserResponse:
|
33
|
+
"""Create a BOSA User in the scope of BOSA API.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
identifier: BOSA Username
|
37
|
+
|
38
|
+
Returns:
|
39
|
+
BOSA User Data with the secret
|
40
|
+
"""
|
41
|
+
def authenticate_bosa_user(self, identifier: str, secret: str) -> BosaToken:
|
42
|
+
"""Triggers the authentication of the BOSA User in the scope of BOSA API.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
identifier: BOSA Username
|
46
|
+
secret: BOSA Password
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
BOSA User Token
|
50
|
+
"""
|
51
|
+
def initiate_connector_auth(self, app_name: str, token: str, callback_uri: str) -> str:
|
52
|
+
"""Triggers the OAuth2 flow for a connector for this API Key and User Token.
|
53
|
+
|
54
|
+
Args:
|
55
|
+
app_name: The name of the app/connector to use
|
56
|
+
token: The BOSA User Token
|
57
|
+
callback_uri: The callback URL to be used for the integration
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
The redirect URL to be used for the integration
|
61
|
+
"""
|
62
|
+
def get_user_info(self, token: str) -> BosaUser:
|
63
|
+
"""Gets the user information for a given token.
|
64
|
+
|
65
|
+
Args:
|
66
|
+
token: The BOSA User Token
|
67
|
+
|
68
|
+
Returns:
|
69
|
+
BOSA User
|
70
|
+
"""
|
71
|
+
def user_has_integration(self, app_name: str, token: str) -> bool:
|
72
|
+
"""Checks whether or not a user has an integration for a given app in this client.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
app_name: The name of the app/connector to use
|
76
|
+
token: The BOSA User Token
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
True if the user has an integration for the given app
|
80
|
+
"""
|
81
|
+
def remove_integration(self, app_name: str, token: str) -> ActionResult:
|
82
|
+
"""Removes a 3rd party integration for a user against a certain client.
|
83
|
+
|
84
|
+
Args:
|
85
|
+
app_name: The name of the app/connector to use
|
86
|
+
token: The BOSA User Token
|
87
|
+
|
88
|
+
Returns:
|
89
|
+
Result that contains an error message (if any), and the success status.
|
90
|
+
"""
|
91
|
+
def get_connector(self, app_name: str) -> BosaConnectorModule:
|
92
|
+
"""Get or create an instance of a connector module.
|
93
|
+
|
94
|
+
Args:
|
95
|
+
app_name: The name of the app/connector to use
|
96
|
+
|
97
|
+
Returns:
|
98
|
+
BosaConnectorModule: The connector module
|
99
|
+
"""
|
100
|
+
def refresh_connector(self, app_name: str) -> None:
|
101
|
+
"""Refresh the connector module."""
|
102
|
+
def connect(self, app_name: str) -> Action:
|
103
|
+
"""Connect to a specific module and prepare for action execution.
|
104
|
+
|
105
|
+
Creates an Action instance for the specified connector..
|
106
|
+
|
107
|
+
Example:
|
108
|
+
# Create action builders for different connectors
|
109
|
+
github = bosa.connect('github')
|
110
|
+
gdrive = bosa.connect('google_drive') # This is just an example
|
111
|
+
|
112
|
+
Args:
|
113
|
+
app_name: The name of the app/connector to use (eg: 'github', 'google_drive', etc)
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
Action: A new Action instance for the specified connector
|
117
|
+
"""
|
118
|
+
def execute(self, app_name: str, action: str, *, max_attempts: int = ..., input_: dict[str, Any] = None, token: str | None = None, headers: dict[str, str] | None = None, timeout: int | None = ..., **kwargs) -> tuple[dict[str, Any] | ConnectorFile, int]:
|
119
|
+
"""Execute an action on a specific module and return raw response.
|
120
|
+
|
121
|
+
The method supports both ways of passing parameters:
|
122
|
+
1. As a dictionary: execute(app_name, action, params_dict)
|
123
|
+
2. As keyword arguments: execute(app_name, action, param1=value1, param2=value2)
|
124
|
+
|
125
|
+
Args:
|
126
|
+
app_name: The name of the app/connector to use
|
127
|
+
action: The action to execute
|
128
|
+
input_: Optional input data for the action
|
129
|
+
token: The BOSA User Token
|
130
|
+
headers: Optional headers to include in the request
|
131
|
+
max_attempts: The number of times the request can be retried for. Default is 0 (does not retry). Note that
|
132
|
+
the backoff factor is 2^(N - 1) with the basic value being 1 second (1, 2, 4, 8, 16, 32, ...).
|
133
|
+
Maximum number of retries is 10 with a maximum of 64 seconds per retry.
|
134
|
+
timeout: Optional timeout for the request in seconds. Default is 30 seconds.
|
135
|
+
**kwargs: Optional keyword arguments
|
136
|
+
|
137
|
+
Returns:
|
138
|
+
Tuple of (response, status_code) where response is the API response and status_code is the HTTP status code
|
139
|
+
"""
|
140
|
+
def run(self, app_name: str, action: str, *, max_attempts: int = ..., input_: dict[str, Any] = None, token: str | None = None, headers: dict[str, str] | None = None, timeout: int | None = ..., **kwargs) -> ActionResponse:
|
141
|
+
"""Execute an action on a specific module and return paginated response.
|
142
|
+
|
143
|
+
The method supports both ways of passing parameters:
|
144
|
+
1. As a dictionary: execute(app_name, action, input_dict)
|
145
|
+
2. As keyword arguments: execute(app_name, action, param1=value1, param2=value2)
|
146
|
+
|
147
|
+
Args:
|
148
|
+
app_name: The name of the app/connector to use
|
149
|
+
action: The action to execute
|
150
|
+
input_: Optional input data for the action
|
151
|
+
token: The BOSA User Token
|
152
|
+
headers: Optional headers to include in the request
|
153
|
+
max_attempts: The number of times the request can be retried for. Default is 0 (does not retry). Note that
|
154
|
+
the backoff factor is 2^(N - 1) with the basic value being 1 second (1, 2, 4, 8, 16, 32, ...).
|
155
|
+
Maximum number of retries is 10 with a maximum of 64 seconds per retry.
|
156
|
+
timeout: Optional timeout for the request in seconds. Default is 30 seconds.
|
157
|
+
**kwargs: Optional keyword arguments
|
158
|
+
|
159
|
+
Returns:
|
160
|
+
ActionResponse: Response wrapper with pagination support
|
161
|
+
"""
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
|
3
|
+
from bosa_connectors.models.token import BosaToken as BosaToken
|
4
|
+
from bosa_connectors.models.user import BosaUser as BosaUser, CreateUserResponse as CreateUserResponse
|
5
|
+
|
6
|
+
class BosaAuthenticator:
|
7
|
+
"""Authenticator for BOSA API."""
|
8
|
+
DEFAULT_TIMEOUT: int
|
9
|
+
api_base_url: Incomplete
|
10
|
+
auth_scheme: Incomplete
|
11
|
+
def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
|
12
|
+
'''Initialize the BosaAuthenticator with the provided API key.
|
13
|
+
|
14
|
+
Args:
|
15
|
+
api_base_url (str): The base URL for the BOSA API. Defaults to "https://api.bosa.id".
|
16
|
+
api_key (str): The API key for authentication. Defaults to "bosa".
|
17
|
+
'''
|
18
|
+
def register(self, identifier: str) -> CreateUserResponse:
|
19
|
+
"""Register a BOSA User in the scope of BOSA API.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
identifier: BOSA Username
|
23
|
+
|
24
|
+
Returns:
|
25
|
+
BOSA User Data with the secret
|
26
|
+
"""
|
27
|
+
def authenticate(self, identifier: str, secret: str) -> BosaToken:
|
28
|
+
"""Authenticate a BOSA User in the scope of BOSA API.
|
29
|
+
|
30
|
+
Args:
|
31
|
+
identifier: BOSA Username
|
32
|
+
secret: BOSA Password
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
BOSA User Token
|
36
|
+
"""
|
37
|
+
def get_user(self, token: str) -> BosaUser:
|
38
|
+
"""Get the current user from BOSA API.
|
39
|
+
|
40
|
+
Args:
|
41
|
+
token: The BOSA User Token
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
BOSA User
|
45
|
+
"""
|
@@ -0,0 +1,49 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
|
3
|
+
from bosa_connectors.models.result import ActionResult as ActionResult
|
4
|
+
|
5
|
+
class BosaIntegrationHelper:
|
6
|
+
"""Helper class for BOSA API integrations."""
|
7
|
+
OAUTH2_FLOW_ENDPOINT: str
|
8
|
+
INTEGRATION_CHECK_ENDPOINT: str
|
9
|
+
DEFAULT_TIMEOUT: int
|
10
|
+
api_base_url: Incomplete
|
11
|
+
auth_scheme: Incomplete
|
12
|
+
def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
|
13
|
+
'''Initializes the BosaIntegrationHelper with the provided API key.
|
14
|
+
|
15
|
+
Args:
|
16
|
+
api_base_url (str): The base URL for the BOSA API. Defaults to "https://api.bosa.id".
|
17
|
+
api_key (str): The API key for authentication. Defaults to "bosa".
|
18
|
+
'''
|
19
|
+
def user_has_integration(self, app_name: str, token: str) -> bool:
|
20
|
+
"""Checks whether or not a user has an integration for a given app in this client.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
app_name: The name of the app/connector to use
|
24
|
+
token: The BOSA User Token
|
25
|
+
|
26
|
+
Returns:
|
27
|
+
True if the user has an integration for the given app
|
28
|
+
"""
|
29
|
+
def initiate_integration(self, app_name: str, token: str, callback_uri: str) -> str:
|
30
|
+
"""Initiates a 3rd party integration for a user against a certain client.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
app_name: The name of the app/connector to use
|
34
|
+
token: The BOSA User Token
|
35
|
+
callback_uri: The callback URL to be used for the integration
|
36
|
+
|
37
|
+
Returns:
|
38
|
+
The integration URL
|
39
|
+
"""
|
40
|
+
def remove_integration(self, app_name: str, token: str) -> ActionResult:
|
41
|
+
"""Removes a 3rd party integration for a user against a certain client.
|
42
|
+
|
43
|
+
Args:
|
44
|
+
app_name: The name of the app/connector to use
|
45
|
+
token: The BOSA User Token
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
Result that contains an error message (if any), and the success status.
|
49
|
+
"""
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from pydantic import BaseModel
|
2
|
+
|
3
|
+
def create_request_model(endpoint_name: str, schema: dict, service_prefix: str = 'Google', requires_auth: bool = False) -> type[BaseModel]:
|
4
|
+
'''Create a Pydantic model for the request schema.
|
5
|
+
|
6
|
+
Args:
|
7
|
+
endpoint_name (str): The name of the endpoint.
|
8
|
+
schema (dict): The schema definition for the endpoint.
|
9
|
+
service_prefix (str, optional): The prefix for the service. Defaults to "Google".
|
10
|
+
requires_auth (bool, optional): Whether the endpoint requires authentication. Defaults to False.
|
11
|
+
|
12
|
+
Returns:
|
13
|
+
Type[BaseModel]: The generated Pydantic model.
|
14
|
+
'''
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
2
|
+
from pydantic import BaseModel
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
class ActionResponseData(BaseModel):
|
6
|
+
"""Response data model with data and meta information."""
|
7
|
+
data: list[Any] | dict[str, Any] | ConnectorFile
|
8
|
+
meta: dict[str, Any] | None
|
9
|
+
|
10
|
+
class InitialExecutorRequest(BaseModel):
|
11
|
+
"""Initial executor request model."""
|
12
|
+
params: dict[str, Any]
|
13
|
+
headers: dict[str, str] | None
|
14
|
+
max_attempts: int | None
|
15
|
+
token: str | None
|
16
|
+
timeout: int | None
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from pydantic import BaseModel
|
2
|
+
from uuid import UUID
|
3
|
+
|
4
|
+
class ThirdPartyIntegrationAuthBasic(BaseModel):
|
5
|
+
"""Basic model for a third party integration authentication."""
|
6
|
+
id: UUID
|
7
|
+
client_id: UUID
|
8
|
+
user_id: UUID
|
9
|
+
connector: str
|
10
|
+
user_identifier: str
|
11
|
+
|
12
|
+
class BosaUser(BaseModel):
|
13
|
+
"""Model for a BOSA User."""
|
14
|
+
id: UUID
|
15
|
+
client_id: UUID
|
16
|
+
identifier: str
|
17
|
+
secret_preview: str
|
18
|
+
is_active: bool
|
19
|
+
integrations: list[ThirdPartyIntegrationAuthBasic]
|
20
|
+
|
21
|
+
class CreateUserResponse(BaseModel):
|
22
|
+
"""Model for a BOSA User creation response."""
|
23
|
+
id: UUID
|
24
|
+
identifier: str
|
25
|
+
secret: str
|
26
|
+
secret_preview: str
|
27
|
+
is_active: bool
|
@@ -0,0 +1,76 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth import BaseAuthenticator as BaseAuthenticator
|
3
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
4
|
+
from pydantic import BaseModel as BaseModel
|
5
|
+
from typing import Any
|
6
|
+
|
7
|
+
class BosaConnectorError(Exception):
|
8
|
+
"""Base exception for BOSA connector errors."""
|
9
|
+
|
10
|
+
class BosaConnectorModule:
|
11
|
+
"""Base class for all BOSA connector modules."""
|
12
|
+
app_name: str
|
13
|
+
DEFAULT_TIMEOUT: int
|
14
|
+
MAX_RETRY: int
|
15
|
+
MAX_BACKOFF_SECONDS: int
|
16
|
+
INFO_PATH: str
|
17
|
+
EXCLUDED_ENDPOINTS: Incomplete
|
18
|
+
@staticmethod
|
19
|
+
def is_retryable_error(status_code: int) -> bool:
|
20
|
+
"""Check if the status code indicates a retryable error (429 or 5xx).
|
21
|
+
|
22
|
+
Args:
|
23
|
+
status_code: HTTP status code to check
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
bool: True if the error is retryable
|
27
|
+
"""
|
28
|
+
api_base_url: Incomplete
|
29
|
+
info_path: Incomplete
|
30
|
+
def __init__(self, app_name: str, api_base_url: str = 'https://api.bosa.id', info_path: str = ...) -> None:
|
31
|
+
"""Initialize a new connector module.
|
32
|
+
|
33
|
+
This constructor should only be called by BosaConnector.
|
34
|
+
"""
|
35
|
+
def get_actions(self) -> list[tuple[str, str, str]]:
|
36
|
+
"""Return list of available actions for this module."""
|
37
|
+
def get_action_parameters(self, action: str):
|
38
|
+
"""Get flattened parameter information for an action.
|
39
|
+
|
40
|
+
Args:
|
41
|
+
action: The action endpoint
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
List of parameter info dicts with name, type, and required fields.
|
45
|
+
Nested objects are flattened using dot notation, e.g.:
|
46
|
+
object.attr1, object.attr2, object.attr3.attr21
|
47
|
+
"""
|
48
|
+
def validate_request(self, action: str, params: dict[str, Any]) -> tuple[dict[str, Any] | None, dict[str, str]]:
|
49
|
+
"""Validate and clean request parameters.
|
50
|
+
|
51
|
+
Args:
|
52
|
+
action: The action endpoint
|
53
|
+
params: Dict of parameter values
|
54
|
+
|
55
|
+
Returns:
|
56
|
+
Tuple of (cleaned_params, error_details) where error_details is empty if validation passed
|
57
|
+
"""
|
58
|
+
def execute(self, action: str, max_attempts: int, input_: dict = None, token: str | None = None, authenticator: BaseAuthenticator | None = None, headers: dict[str, str] | None = None, timeout: int | None = ...) -> tuple[dict[str, Any] | ConnectorFile, int]:
|
59
|
+
"""Execute an action with validated parameters and return typed response.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
action: The action to execute
|
63
|
+
max_attempts: Maximum number of attempts for failed requests (429 or 5xx errors). Must be at least 1.
|
64
|
+
Will be capped at MAX_RETRY (10) to prevent excessive retries.
|
65
|
+
input_: Optional dictionary of parameters
|
66
|
+
token: Optional BOSA User Token. If not provided, will use the default token
|
67
|
+
authenticator: Optional authenticator to use for the request
|
68
|
+
headers: Optional headers to include in the request
|
69
|
+
|
70
|
+
The method supports both ways of passing parameters:
|
71
|
+
1. As a dictionary: execute(action, params_dict)
|
72
|
+
2. As keyword arguments: execute(action, param1=value1, param2=value2)
|
73
|
+
|
74
|
+
Raises:
|
75
|
+
ValueError: If action is invalid, parameters are invalid, or max_attempts is less than 1
|
76
|
+
"""
|
bosa_connectors/tool.pyi
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
from .connector import BosaConnector as BosaConnector
|
2
|
+
from .helpers.model_request_generator import create_request_model as create_request_model
|
3
|
+
from _typeshed import Incomplete
|
4
|
+
from langchain_core.tools import BaseTool
|
5
|
+
from pydantic import BaseModel as BaseModel
|
6
|
+
|
7
|
+
class BosaConnectorToolError(Exception):
|
8
|
+
"""Base exception for BOSA connector errors."""
|
9
|
+
|
10
|
+
class BOSAConnectorToolGenerator:
|
11
|
+
"""Tool Generator for BOSA Connectors.
|
12
|
+
|
13
|
+
This class generates tools based on OpenAPI schemas for various services.
|
14
|
+
|
15
|
+
Attributes:
|
16
|
+
api_base_url (str): The base URL for the API.
|
17
|
+
api_key (str): The API key for authentication.
|
18
|
+
info_path (str): The path to the API information endpoint.
|
19
|
+
DEFAULT_TIMEOUT (int): Default timeout for API requests.
|
20
|
+
app_name (str): The name of the application.
|
21
|
+
schema_data (dict): The schema data for the services.
|
22
|
+
|
23
|
+
Methods:
|
24
|
+
generate_tools(): Generates tools for the specified services.
|
25
|
+
"""
|
26
|
+
api_base_url: str
|
27
|
+
api_key: str
|
28
|
+
INFO_PATH: str
|
29
|
+
DEFAULT_TIMEOUT: int
|
30
|
+
app_name: str
|
31
|
+
schema_data: dict
|
32
|
+
EXCLUDED_ENDPOINTS: Incomplete
|
33
|
+
def __init__(self, api_base_url: str, api_key: str, app_name: str) -> None:
|
34
|
+
"""Initialize the tool generator with API base URL, info path, and app name.
|
35
|
+
|
36
|
+
Args:
|
37
|
+
api_base_url (str): The base URL for the API.
|
38
|
+
api_key (str): The API key for authentication.
|
39
|
+
app_name (str): The name of the application.
|
40
|
+
"""
|
41
|
+
def generate_tools(self) -> list[BaseTool]:
|
42
|
+
"""Generate tools based on the BOSA API OpenAPI schemas.
|
43
|
+
|
44
|
+
Returns:
|
45
|
+
Dict[str, Type[BaseTool]]: A dictionary of generated tool classes.
|
46
|
+
"""
|
@@ -0,0 +1 @@
|
|
1
|
+
*
|
Binary file
|
bosa_connectors.pyi
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# This file was generated by Nuitka
|
2
|
+
|
3
|
+
# Stubs included by default
|
4
|
+
from bosa_connectors.helpers.authenticator import BosaAuthenticator
|
5
|
+
from module import BosaConnectorModule
|
6
|
+
from tool import BOSAConnectorToolGenerator
|
7
|
+
from connector import BosaConnector
|
8
|
+
|
9
|
+
|
10
|
+
__name__ = ...
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# Modules used internally, to allow implicit dependencies to be seen:
|
15
|
+
import os
|
16
|
+
import typing
|
17
|
+
import bosa_connectors.auth.BaseAuthenticator
|
18
|
+
import abc
|
19
|
+
import logging
|
20
|
+
import requests
|
21
|
+
import requests.exceptions
|
22
|
+
import bosa_connectors.auth.ApiKeyAuthenticator
|
23
|
+
import pydantic
|
24
|
+
import uuid
|
25
|
+
import random
|
26
|
+
import time
|
27
|
+
import cgi
|
28
|
+
import legacy_cgi
|
29
|
+
import inspect
|
30
|
+
import langchain_core
|
31
|
+
import langchain_core.tools
|
@@ -0,0 +1,422 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: bosa-connectors-binary
|
3
|
+
Version: 0.1.5b1
|
4
|
+
Summary: BOSA Connectors
|
5
|
+
Author-email: Bosa Engineers <bosa-eng@gdplabs.id>
|
6
|
+
Requires-Python: <3.14,>=3.11
|
7
|
+
Description-Content-Type: text/markdown
|
8
|
+
Requires-Dist: pydantic-settings<3.0.0,>=2.7.1
|
9
|
+
Requires-Dist: pydantic<3.0.0,>=2.9.2
|
10
|
+
Requires-Dist: requests<3.0.0,>=2.31.0
|
11
|
+
Requires-Dist: langchain-core<1.0.0,>=0.3.65
|
12
|
+
Requires-Dist: legacy-cgi<3.0.0,>=2.6.3
|
13
|
+
Requires-Dist: urllib3<3.0.0,>=2.5.0
|
14
|
+
Provides-Extra: dev
|
15
|
+
Requires-Dist: pytest<9.0.0,>=8.1.1; extra == "dev"
|
16
|
+
Requires-Dist: pre-commit<4.0.0,>=3.6.2; extra == "dev"
|
17
|
+
Requires-Dist: pytest-cov<6.0.0,>=5.0.0; extra == "dev"
|
18
|
+
Requires-Dist: pytest-asyncio<1.0.0,>=0.23.6; extra == "dev"
|
19
|
+
Requires-Dist: pydocstyle<7.0.0,>=6.3.0; extra == "dev"
|
20
|
+
Requires-Dist: ruff<1.0.0,>=0.9.9; extra == "dev"
|
21
|
+
Requires-Dist: mypy<2.0.0,>=1.11.2; extra == "dev"
|
22
|
+
Provides-Extra: flag-embedding
|
23
|
+
Requires-Dist: FlagEmbedding; extra == "flag-embedding"
|
24
|
+
Requires-Dist: langchain-huggingface; extra == "flag-embedding"
|
25
|
+
Provides-Extra: semantic-router
|
26
|
+
Requires-Dist: semantic-router; extra == "semantic-router"
|
27
|
+
Requires-Dist: azure-search-documents; extra == "semantic-router"
|
28
|
+
Requires-Dist: cohere; extra == "semantic-router"
|
29
|
+
Provides-Extra: langchain-huggingface
|
30
|
+
Requires-Dist: langchain-huggingface; extra == "langchain-huggingface"
|
31
|
+
|
32
|
+
# BOSA API SDK (Bosa Connector)
|
33
|
+
|
34
|
+
A Python SDK for seamlessly connecting to APIs that implement BOSA's Plugin Architecture under HTTP Interface. This connector acts as a proxy, simplifying the integration with BOSA-compatible APIs.
|
35
|
+
|
36
|
+
## Features
|
37
|
+
|
38
|
+
- Simple and intuitive API for connecting to BOSA-compatible services
|
39
|
+
- Automatic endpoint discovery and schema validation
|
40
|
+
- Built-in authentication support (BOSA API Key and User Token)
|
41
|
+
- User management and OAuth2 integration flow support
|
42
|
+
- Type-safe parameter validation
|
43
|
+
- Flexible parameter passing (dictionary or keyword arguments)
|
44
|
+
- Retry support for requests that fail (429 or 5xx)
|
45
|
+
- Response fields filtering based on action and output
|
46
|
+
|
47
|
+
## Prerequisites
|
48
|
+
After the `bosa-api` ready, you can perform the following tasks:
|
49
|
+
- Ensure Bosa API is running. If you want to test locally, or you can use Staging or Production environments.
|
50
|
+
- Create Client
|
51
|
+
- You can send a `create-client` request to the `bosa-api` using Postman with the following header and body:
|
52
|
+
- Header
|
53
|
+
- `x-api-user`: KEY1
|
54
|
+
- Body
|
55
|
+
- `name`: "`{client name}`"
|
56
|
+
- Response :
|
57
|
+
```json
|
58
|
+
{
|
59
|
+
"data": {
|
60
|
+
"id": "{client_id}",
|
61
|
+
"name": "admin",
|
62
|
+
"api_key": "{client_api_key}",
|
63
|
+
"is_active": true
|
64
|
+
},
|
65
|
+
"meta": null
|
66
|
+
}
|
67
|
+
```
|
68
|
+
- Register the user, see the details [here](/python/bosa-connectors/README.md#user-authentication).
|
69
|
+
|
70
|
+
|
71
|
+
## Installation
|
72
|
+
|
73
|
+
### Prerequisites
|
74
|
+
- Python 3.11+ - [Install here](https://www.python.org/downloads/)
|
75
|
+
- Pip (if using Pip) - [Install here](https://pip.pypa.io/en/stable/installation/)
|
76
|
+
- Poetry 2.1.3+ (if using Poetry) - [Install here](https://python-poetry.org/docs/#installation)
|
77
|
+
- Git (if using Git) - [Install here](https://git-scm.com/downloads)
|
78
|
+
- For git installation:
|
79
|
+
- Access to the [GDP Labs SDK github repository](https://github.com/GDP-ADMIN/bosa-sdk)
|
80
|
+
|
81
|
+
### 1. Installation from Pypi
|
82
|
+
Choose one of the following methods to install the package:
|
83
|
+
|
84
|
+
#### Using pip
|
85
|
+
```bash
|
86
|
+
pip install bosa-connectors-binary
|
87
|
+
```
|
88
|
+
|
89
|
+
#### Using Poetry
|
90
|
+
```bash
|
91
|
+
poetry add bosa-connectors-binary
|
92
|
+
```
|
93
|
+
|
94
|
+
### 2. Development Installation (Git)
|
95
|
+
For development purposes, you can install directly from the Git repository:
|
96
|
+
```bash
|
97
|
+
poetry add "git+ssh://git@github.com/GDP-ADMIN/bosa-sdk.git#subdirectory=python/bosa-connectors"
|
98
|
+
```
|
99
|
+
|
100
|
+
## Quick Start
|
101
|
+
|
102
|
+
Here's a simple example of how to use the BOSA Connector with API key authentication and user token.
|
103
|
+
|
104
|
+
### Initialization
|
105
|
+
|
106
|
+
Before using the connector, you need to initialize it with your BOSA API base URL and API key.
|
107
|
+
|
108
|
+
```python
|
109
|
+
from bosa_connectors.connector import BosaConnector
|
110
|
+
|
111
|
+
# Initialize the connector
|
112
|
+
bosa = BosaConnector(api_base_url="YOUR_BOSA_API_BASE_URL", api_key="YOUR_API_KEY")
|
113
|
+
```
|
114
|
+
|
115
|
+
### Authentication
|
116
|
+
|
117
|
+
After initializing the connector, you can authenticate with your BOSA API key.
|
118
|
+
|
119
|
+
|
120
|
+
```python
|
121
|
+
# User token from authentication
|
122
|
+
user_token = "Enter your key (bearer token) here from authentication, or refer to User Authentication section below"
|
123
|
+
|
124
|
+
# Check if a user has an integration for a connector
|
125
|
+
has_integration = bosa.user_has_integration("github", user_token)
|
126
|
+
|
127
|
+
if not has_integration:
|
128
|
+
# Initiate the OAuth2 flow for a connector
|
129
|
+
auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
|
130
|
+
# Redirect the user to auth_url to complete authentication, we exit here.
|
131
|
+
print("Integration with GitHub not found.")
|
132
|
+
print(f"Please visit {auth_url} to complete authentication.")
|
133
|
+
exit()
|
134
|
+
```
|
135
|
+
|
136
|
+
Alternatively, you can authenticate the user first and then use their token:
|
137
|
+
|
138
|
+
```python
|
139
|
+
user = bosa.authenticate_bosa_user("username", "password")
|
140
|
+
|
141
|
+
# Get user token
|
142
|
+
user_token = user.token
|
143
|
+
```
|
144
|
+
|
145
|
+
### Basic Example (Direct Execution)
|
146
|
+
|
147
|
+
It is the basic way to execute actions, where you need to provide the connector name, action name, and user token. The response will contain the data and status:
|
148
|
+
|
149
|
+
```python
|
150
|
+
# Prepare input parameters
|
151
|
+
params = {
|
152
|
+
"repo": "my-local-repo", # try to use your local repo for testing
|
153
|
+
"owner": "rexywjy",
|
154
|
+
}
|
155
|
+
|
156
|
+
# Execute the action with user token
|
157
|
+
data, status = bosa.execute("github", "list_collaborators", token=user_token, max_attempts=1, input_=params)
|
158
|
+
print(data)
|
159
|
+
print(status)
|
160
|
+
```
|
161
|
+
More details about parameters and actions in bosa-api docs `{domain}/docs`
|
162
|
+
|
163
|
+
### Alternative Approach (Fluent Interface)
|
164
|
+
|
165
|
+
For more complex scenarios or more control over the execution, you can use the fluent interface. We're recommending this approach if you:
|
166
|
+
|
167
|
+
- Need to execute multiple actions with different parameters
|
168
|
+
- Expecting list response
|
169
|
+
- Need to execute actions in a loop
|
170
|
+
|
171
|
+
```python
|
172
|
+
# Prepare input parameters
|
173
|
+
params = {
|
174
|
+
"owner": "gdp-admin",
|
175
|
+
"author": "samuellusandi",
|
176
|
+
"per_page": 1,
|
177
|
+
"sort": "author_date",
|
178
|
+
"created_date_start": "2025-02-01",
|
179
|
+
"created_date_end": "2025-02-02"
|
180
|
+
}
|
181
|
+
|
182
|
+
# Create a connector instance to a service
|
183
|
+
github = bosa.connect('github')
|
184
|
+
|
185
|
+
# Execute actions with fluent interface
|
186
|
+
response = github.action('list_pull_requests')\
|
187
|
+
.params(params)\
|
188
|
+
.max_attempts(3)\
|
189
|
+
.token('user-token')\
|
190
|
+
.run() # Execute and return ActionResponse for advanced data handling
|
191
|
+
|
192
|
+
# Get initial data
|
193
|
+
initial_data = response.get_data()
|
194
|
+
|
195
|
+
# Iterate the following next pages
|
196
|
+
while response.has_next():
|
197
|
+
response = response.next_page()
|
198
|
+
data = response.get_data()
|
199
|
+
# Process data here
|
200
|
+
...
|
201
|
+
|
202
|
+
# You can also navigate backwards
|
203
|
+
while response.has_prev():
|
204
|
+
response = response.prev_page()
|
205
|
+
data = response.get_data()
|
206
|
+
# Process data here
|
207
|
+
...
|
208
|
+
|
209
|
+
# Execute multiple independent actions using the same connector instance
|
210
|
+
commits_response = github.action('list_commits')\
|
211
|
+
.params({
|
212
|
+
'owner': 'GDP-ADMIN',
|
213
|
+
'repo': 'bosa',
|
214
|
+
'page': 1,
|
215
|
+
'per_page': 10
|
216
|
+
})\
|
217
|
+
.token('user-token')\
|
218
|
+
.run()
|
219
|
+
```
|
220
|
+
|
221
|
+
`run` method also available for direct execution from connector instance, without using fluent interface.
|
222
|
+
|
223
|
+
```python
|
224
|
+
# Prepare input parameters
|
225
|
+
params = {
|
226
|
+
"owner": "gdp-admin",
|
227
|
+
"author": "samuellusandi",
|
228
|
+
"per_page": 1,
|
229
|
+
"sort": "author_date",
|
230
|
+
"created_date_start": "2025-02-01",
|
231
|
+
"created_date_end": "2025-02-02"
|
232
|
+
}
|
233
|
+
|
234
|
+
# Execute actions with run method
|
235
|
+
response = bosa.run('github', 'list_pull_requests', params)
|
236
|
+
print(response.get_data())
|
237
|
+
```
|
238
|
+
|
239
|
+
### Working with Files using ConnectorFile
|
240
|
+
|
241
|
+
When working with APIs that require file uploads or return file downloads, use the `ConnectorFile` model:
|
242
|
+
|
243
|
+
```python
|
244
|
+
from bosa_connectors.models.file import ConnectorFile
|
245
|
+
|
246
|
+
# For uploads: Create a ConnectorFile object
|
247
|
+
with open("document.pdf", "rb") as f:
|
248
|
+
upload_file = ConnectorFile(
|
249
|
+
file=f.read(),
|
250
|
+
filename="document.pdf",
|
251
|
+
content_type="application/pdf"
|
252
|
+
)
|
253
|
+
|
254
|
+
params = {
|
255
|
+
"file": upload_file,
|
256
|
+
"name": "My Document"
|
257
|
+
}
|
258
|
+
|
259
|
+
# Include in your parameters
|
260
|
+
result, status = bosa.execute("google_drive", "upload_file", input_=params)
|
261
|
+
|
262
|
+
# For downloads: Check response type
|
263
|
+
file_result, status = bosa.execute("google_drive", "download_file", input_={"file_id": "123"})
|
264
|
+
if isinstance(file_result, ConnectorFile):
|
265
|
+
# Save to disk
|
266
|
+
with open(file_result.filename or "downloaded_file", "wb") as f:
|
267
|
+
f.write(file_result.file)
|
268
|
+
```
|
269
|
+
|
270
|
+
## Available Methods
|
271
|
+
|
272
|
+
### Connector Instance Methods
|
273
|
+
|
274
|
+
The connector instance provides several methods for configuring and executing actions:
|
275
|
+
|
276
|
+
- `connect(name)`: Create a connector instance to a service
|
277
|
+
- `action(name)`: Specify the action to execute
|
278
|
+
- `params(dict)`: Set request parameters (including pagination parameters like page and per_page). Note that params for each plugin and action could be different
|
279
|
+
- `token(str)`: Set the BOSA user token
|
280
|
+
- `headers(dict)`: Set custom request headers
|
281
|
+
- `max_attempts(number)`: Set the maximum number of retry attempts (default: 1)
|
282
|
+
Execution Methods:
|
283
|
+
|
284
|
+
- `run()`: Execute and return ActionResponse for advanced data handling
|
285
|
+
- `execute()`: Execute and return data and status for basic data handling. The data part of the return value can be a ConnectorFile object when the API returns a non-JSON response (such as a file download).
|
286
|
+
|
287
|
+
### Response Handling (ActionResponse)
|
288
|
+
|
289
|
+
The ActionResponse class provides methods for handling the response and pagination:
|
290
|
+
|
291
|
+
- `get_data()`: Get the current page data (returns the data field from the response). This can return a ConnectorFile object when the API returns a non-JSON response (such as a file download).
|
292
|
+
- `get_meta()`: Get the metadata information from the response (e.g., pagination details, total count)
|
293
|
+
- `get_status()`: Get the HTTP status code
|
294
|
+
- `is_list()`: Check if response is a list
|
295
|
+
- `has_next()`: Check if there is a next page
|
296
|
+
- `has_prev()`: Check if there is a previous page
|
297
|
+
- `next_page()`: Move to and execute next page
|
298
|
+
- `prev_page()`: Move to and execute previous page
|
299
|
+
- `get_all_items()`: Get all items from all pages (returns a list of objects containing data and meta for each page)
|
300
|
+
|
301
|
+
## Data Models
|
302
|
+
|
303
|
+
The SDK uses the following data models:
|
304
|
+
|
305
|
+
- `ActionResponseData`: Contains the response data structure with `data` (list, object, or ConnectorFile instance) and `meta` (metadata) fields
|
306
|
+
- `InitialExecutorRequest`: Stores the initial request parameters used for pagination and subsequent requests
|
307
|
+
- `ConnectorFile`: Represents a file in requests and responses with these properties:
|
308
|
+
- `file`: Raw bytes content of the file
|
309
|
+
- `filename`: Optional name of the file
|
310
|
+
- `content_type`: Optional MIME type of the file
|
311
|
+
- `headers`: Optional HTTP headers for the file
|
312
|
+
|
313
|
+
## Configuration Parameters
|
314
|
+
|
315
|
+
- `api_base_url`: The base URL of your BOSA API endpoint (default: "https://api.bosa.id"). This parameter is extremely important as it determines the URL of the BOSA API you are connecting to, and it will be used to populate the available actions/endpoints and their parameters upon initialization.
|
316
|
+
- `api_key`: Your BOSA API key for authentication. This is different from plugin-specific API keys, which are managed separately by the BOSA system.
|
317
|
+
|
318
|
+
## Execution Parameters
|
319
|
+
|
320
|
+
- `connector`: The name of the connector to use. This parameter is used to determine the connector's available actions and their parameters.
|
321
|
+
- `action`: The name of the action to execute. This parameter is automatically populated by the connector based on the available actions and their parameters. The list of available actions per connector can be found in https://api.bosa.id/docs and are populated through https://api.bosa.id/connectors.
|
322
|
+
- `max_attempts`: The maximum number of attempts to make the API request. If the request fails, the connector will retry the request up to this number of times. The default value is 1 if not provided.
|
323
|
+
- The retries are handled automatically by the connector, with exponential backoff.
|
324
|
+
- The retries are only done for errors that are considered retryable (429 or 5xx).
|
325
|
+
- `input_`: The input parameters for the action. This parameter is a dictionary that contains the parameters for the action. The connector will validate the input parameters against the action's schema.
|
326
|
+
- To filter response fields, simply add the `response_fields` parameter to the input dictionary. This parameter is a list of field names that will be returned in the response. For nested fields, you can use dot notation, e.g. `user.login` will return the following:
|
327
|
+
```json
|
328
|
+
{
|
329
|
+
"user": {
|
330
|
+
"login": "userlogin"
|
331
|
+
}
|
332
|
+
}
|
333
|
+
```
|
334
|
+
- `token`: Optional BOSA User Token for authenticating requests. When provided, the connector will include this token in the request headers. This is required for user-specific actions or when working with third-party integrations.
|
335
|
+
|
336
|
+
## How It Works
|
337
|
+
|
338
|
+
1. **Initialization**: When you create a `BosaConnector` instance, and trigger an `execute()`, the connector will first populate and cache the available actions and their parameters. This is done automatically.
|
339
|
+
|
340
|
+
2. **Action Discovery**: The connector expects the BOSA API to expose an endpoint that lists all available actions and their parameters. This is handled automatically by BOSA's HTTP Interface.
|
341
|
+
|
342
|
+
3. **Execution**: When you call `execute()`, the connector:
|
343
|
+
- Validates your input parameters against the action's schema
|
344
|
+
- Handles authentication
|
345
|
+
- Makes the API request
|
346
|
+
- Returns the formatted response
|
347
|
+
|
348
|
+
## Compatibility
|
349
|
+
|
350
|
+
While primarily tested with BOSA's HTTP Interface, this connector should theoretically work with any API that implements BOSA's Plugin Architecture, as long as it:
|
351
|
+
|
352
|
+
1. Exposes an endpoint listing available actions and their parameters
|
353
|
+
2. Follows BOSA's standard HTTP Interface specifications (through the Plugin Architecture)
|
354
|
+
- All actions must be exposed as `POST` endpoints.
|
355
|
+
3. Implements the required authentication mechanisms
|
356
|
+
|
357
|
+
## Error Handling
|
358
|
+
|
359
|
+
The connector includes built-in error handling for:
|
360
|
+
|
361
|
+
- Invalid parameters
|
362
|
+
- Authentication failures
|
363
|
+
- Connection issues
|
364
|
+
- API response errors
|
365
|
+
|
366
|
+
## User Authentication
|
367
|
+
|
368
|
+
The BOSA Connector supports user-based authentication which allows for user-specific actions and third-party integrations:
|
369
|
+
|
370
|
+
```python
|
371
|
+
# Step 1: Create a new BOSA user
|
372
|
+
user_data = bosa.create_bosa_user("username")
|
373
|
+
# Save the secret for later use
|
374
|
+
user_secret = user_data.secret
|
375
|
+
|
376
|
+
# Step 2: Authenticate the user and obtain their token
|
377
|
+
token = bosa.authenticate_bosa_user("username", user_secret)
|
378
|
+
|
379
|
+
# Step 3: Retrieve user information using the obtained token
|
380
|
+
user_info = bosa.get_user_info(token.token)
|
381
|
+
```
|
382
|
+
|
383
|
+
### ❗ Important Notes
|
384
|
+
|
385
|
+
***🛡️ Best Practice:*** Since bearer tokens can have a long lifespan, it is highly recommended to **reuse existing tokens** whenever possible. While creating new tokens is functionally acceptable, be aware that older tokens may become dangling and can pose a security risk if they are exposed or misused.
|
386
|
+
|
387
|
+
***⚠️ Security Reminder:*** When you register a new BOSA user, you will receive a token that starts with **"sk-user-..."**. It is essential to keep this token safe, as it **cannot be recovered if lost**, and currently, there is **no option to reset** it.
|
388
|
+
|
389
|
+
|
390
|
+
## Integration Management
|
391
|
+
|
392
|
+
The BOSA Connector provides methods to manage third-party integrations for authenticated users:
|
393
|
+
|
394
|
+
```python
|
395
|
+
# Check if a user has an integration for a connector
|
396
|
+
has_integration = bosa.user_has_integration("github", user_token)
|
397
|
+
|
398
|
+
# Initiate the OAuth2 flow for a connector
|
399
|
+
auth_url = bosa.initiate_connector_auth("github", user_token, "https://your-callback-uri.com")
|
400
|
+
# Redirect the user to auth_url to complete authentication
|
401
|
+
|
402
|
+
# Remove an integration
|
403
|
+
remove_result = bosa.remove_integration("github", user_token)
|
404
|
+
```
|
405
|
+
|
406
|
+
## References
|
407
|
+
|
408
|
+
Product Requirements Documents(PRD):
|
409
|
+
|
410
|
+
- [BOSA Connector - Product Document](https://docs.google.com/document/d/1R6JIGWnKzNg2kRMRSiZ-wwPGe9pOR9rkkEI0Uz-Wtdw/edit?tab=t.y617gs6jfk15#heading=h.uss0d453lcbs)
|
411
|
+
|
412
|
+
Architecture Documents:
|
413
|
+
|
414
|
+
- [BOSA Connector - Architecture Document](https://docs.google.com/document/d/1HHUBAkbFAM8sM_Dtx6tmoatR1HeuM6VBfsWEjpgVCtg/edit?tab=t.0#heading=h.bj79ljx9eqg8)
|
415
|
+
|
416
|
+
Design Documents:
|
417
|
+
|
418
|
+
- [BOSA Connector - Design Document](https://docs.google.com/document/d/1PghW7uOJcEbT3WNSlZ0FI99o4y24ys0LCyAG8hg3T9o/edit?tab=t.0#heading=h.bj79ljx9eqg8)
|
419
|
+
|
420
|
+
Implementation Documents:
|
421
|
+
|
422
|
+
- [BOSA Connector - Implementation Document](https://docs.google.com/document/d/1a8BvggPu5a6PBStgUu2ILse075FjAAgoehUuvxxAajM/edit?tab=t.0#heading=h.bj79ljx9eqg8)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
bosa_connectors.cpython-312-darwin.so,sha256=K-gB-A2OPyU72V0aa1klO3dpUIhO2FGmqfgd_pTJU88,902984
|
2
|
+
bosa_connectors.pyi,sha256=nHURoVUwcgMfcsbiXPeT96DBCaaiRIuNm0va3oT_wC8,676
|
3
|
+
bosa_connectors/__init__.pyi,sha256=WWB74z-l47ZA70CxIw75ElOnqFeKACWkcvTLA4ucqTw,384
|
4
|
+
bosa_connectors/action.pyi,sha256=zGqRYx9bD7H0V4cMKwF83OLlwuVaDd_Oi4LG7gp7Lfc,3358
|
5
|
+
bosa_connectors/action_response.pyi,sha256=8Dj8YZsgvS6hGS-wyb-4VUxZzNLZqisCouYe3V9_DKY,3674
|
6
|
+
bosa_connectors/connector.pyi,sha256=CARDA0JaXJkwbvHmqfAHq4VMhaQhPxgW6eH7ZmPxi20,7279
|
7
|
+
bosa_connectors/module.pyi,sha256=O72bNcKGdfDL5yZzkUOth4BXTDjyUg4YAhYn2TiEgKs,3277
|
8
|
+
bosa_connectors/tool.pyi,sha256=GeCDaOIUWutPLDYk61z7YwNPhWMYU8bV_lb62BUynp8,1725
|
9
|
+
bosa_connectors/auth/__init__.pyi,sha256=gpzI0J6hSddF7xEZ7j5M1Lcy-MaICCTj5dJFhcaqxXc,177
|
10
|
+
bosa_connectors/auth/api_key.pyi,sha256=uFKPef2dqRaQ-2N-3J1kYU3Oh-PsDuh4q2_3jB2KSNY,630
|
11
|
+
bosa_connectors/auth/base.pyi,sha256=hjN2euyXyAuFGsxClgIFz_pOy-Q9jV3-vUcinZ-3J-Q,317
|
12
|
+
bosa_connectors/helpers/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
+
bosa_connectors/helpers/authenticator.pyi,sha256=QwsQ1a0U4Ah2Wg4xnco9Rf2jIsF7EYPvhSyUxxPpStk,1521
|
14
|
+
bosa_connectors/helpers/integrations.pyi,sha256=v2PkmsotlT8eo3RAB7hiIC30BN3MN5BO8UjeCRoDu6Q,1961
|
15
|
+
bosa_connectors/helpers/model_request_generator.pyi,sha256=ZmFPKfku3HA7zuTwcUMZ5Ba4qvkzoC3-FmvtFRTWdJc,628
|
16
|
+
bosa_connectors/models/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
bosa_connectors/models/action.pyi,sha256=Ru4n0xZflIp8Pjoqq-9eJoaDCacrWIA0OvMXmFwOZ7w,531
|
18
|
+
bosa_connectors/models/file.pyi,sha256=PBZZkodDAeW1oysX5R5pJ9-d8yd5eKWVccAh1oYcjXM,237
|
19
|
+
bosa_connectors/models/result.pyi,sha256=ISmHBFlkyVzyAxeQXwVVEqNXd4SZQI4YV1vd8i8S-NM,136
|
20
|
+
bosa_connectors/models/token.pyi,sha256=NN7VfzoudeojK5oWVUmCi4Qo02RUjbveKzDpbh1RrGU,206
|
21
|
+
bosa_connectors/models/user.pyi,sha256=KsVrc0MYB1z6fikCv1qSrjnP8ISWChxr9Fx0T0nbsKw,661
|
22
|
+
bosa_connectors.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
|
23
|
+
bosa_connectors_binary-0.1.5b1.dist-info/METADATA,sha256=7G0LP6fPTftuULIQ8-2jePYlB29f6j7HjAkJuWxw4Ok,16629
|
24
|
+
bosa_connectors_binary-0.1.5b1.dist-info/WHEEL,sha256=trxUU7_pg6d91g1-CF5uxl-oRlQMCnUB8urRbjNrIjs,139
|
25
|
+
bosa_connectors_binary-0.1.5b1.dist-info/top_level.txt,sha256=3UzTb-ce0A17T_gQLs-Bhq-ilOx6tosXQJkZbGsRWW8,16
|
26
|
+
bosa_connectors_binary-0.1.5b1.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
bosa_connectors
|