Coverage for mindsdb / integrations / handlers / sharepoint_handler / sharepoint_handler.py: 0%
51 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
1from mindsdb_sql_parser import parse_sql
3from mindsdb.integrations.handlers.sharepoint_handler.sharepoint_api import (
4 SharepointAPI,
5)
6from mindsdb.integrations.handlers.sharepoint_handler.sharepoint_tables import (
7 ListsTable,
8 SitesTable,
9 ListItemsTable,
10 SiteColumnsTable,
11)
12from mindsdb.integrations.libs.api_handler import APIHandler
13from mindsdb.integrations.libs.response import HandlerStatusResponse as StatusResponse
14from mindsdb.integrations.libs.const import HANDLER_CONNECTION_ARG_TYPE as ARG_TYPE
16from mindsdb.utilities import log
17from collections import OrderedDict
19logger = log.getLogger(__name__)
22class SharepointHandler(APIHandler):
23 """
24 The Sharepoint handler implementation.
25 """
27 name = "sharepoint"
29 def __init__(self, name: str, **kwargs):
30 """
31 Initialize the handler.
32 Args:
33 name (str): name of particular handler instance
34 **kwargs: arbitrary keyword arguments.
35 """
36 super().__init__(name)
38 connection_data = kwargs.get("connection_data", {})
39 self.connection_data = connection_data
40 self.kwargs = kwargs
42 if not (
43 self.connection_data["clientId"]
44 and (
45 self.connection_data["tenantId"]
46 and self.connection_data["clientSecret"]
47 )
48 ):
49 raise Exception(
50 "client params and tenant id is required for Sharepoint connection!"
51 )
53 self.connection = None
54 self.is_connected = False
55 self._client = None
56 lists_data = ListsTable(self)
57 self._register_table("lists", lists_data)
59 sites_data = SitesTable(self)
60 self._register_table("sites", sites_data)
62 site_columns_data = SiteColumnsTable(self)
63 self._register_table("siteColumns", site_columns_data)
65 list_items_data = ListItemsTable(self)
66 self._register_table("listItems", list_items_data)
68 def connect(self):
69 """
70 Set up the context connection required by the handler.
71 Returns
72 -------
73 StatusResponse
74 connection object
75 """
76 if self.is_connected is True:
77 return self.connection
78 self.connection = SharepointAPI(
79 tenant_id=self.connection_data["tenantId"],
80 client_id=self.connection_data["clientId"],
81 client_secret=self.connection_data["clientSecret"],
82 )
83 self.connection.get_bearer_token()
84 self.is_connected = True
85 return self.connection
87 def check_connection(self) -> StatusResponse:
88 """
89 Check connection to the handler.
90 Returns:
91 HandlerStatusResponse
92 """
94 response = StatusResponse(False)
96 try:
97 connection = self.connect()
98 response.success = connection.check_bearer_token_validity()
99 except Exception as e:
100 logger.error("Error connecting to Sharepoint! " + str(e))
101 response.error_message = str(e)
103 self.is_connected = response.success
105 return response
107 def native_query(self, query: str) -> StatusResponse:
108 """Receive and process a raw query.
109 Parameters
110 ----------
111 query : str
112 query in a native format
113 Returns
114 -------
115 StatusResponse
116 Request status
117 """
118 ast = parse_sql(query)
119 return self.query(ast)
122connection_args = OrderedDict(
123 clientId={
124 "type": ARG_TYPE.STR,
125 "description": "Client Id of the App",
126 "required": True,
127 "label": "Client ID",
128 },
129 clientSecret={
130 "type": ARG_TYPE.PWD,
131 "description": "Client Secret of the App",
132 "required": True,
133 "label": "Client Secret",
134 },
135 tenantId={
136 "type": ARG_TYPE.STR,
137 "description": "Tenant Id of the tenant of the App",
138 "required": True,
139 "label": "Tenant ID",
140 },
141)
143connection_args_example = OrderedDict(
144 clientId="xxxx-xxxx-xxxx-xxxx",
145 clientSecret="<secret>",
146 tenantId="xxxx-xxxx-xxxx-xxxx",
147)