gateway/modules/connectors/connectorSharepoint.py
2025-09-03 17:16:42 +02:00

55 lines
1.7 KiB
Python

"""Connector for CRUD sharepoint operations."""
from dataclasses import dataclass
from office365.sharepoint.client_context import ClientContext
@dataclass
class ConnectorSharepoint:
ctx: ClientContext
@classmethod
async def create(cls, ctx: ClientContext) -> "ConnectorSharepoint":
"""Creates an instance of the Sharepoint connector.
Params:
ctx: The ClientContext instance.
Returns:
ConnectorSharepoint: An instance of the Sharepoint connector.
"""
return cls(ctx=ctx)
@classmethod
def get_client_context_from_username_password(
cls, site_url: str, username: str, password: str
) -> ClientContext:
"""Creates a ClientContext instance from username and password.
Params:
site_url: The URL of the SharePoint site.
username: The username for authentication.
password: The password for authentication.
Returns:
ClientContext: An instance of the ClientContext.
"""
return ClientContext(site_url).with_user_credentials(username, password)
@classmethod
def get_client_context_from_app(
cls, site_url: str, client_id: str, client_secret: str
) -> ClientContext:
"""Creates a ClientContext instance from client ID and client secret.
Params:
site_url: The URL of the SharePoint site.
client_id: The client ID for authentication.
client_secret: The client secret for authentication.
Returns:
ClientContext: An instance of the ClientContext.
"""
return ClientContext(site_url).with_client_credentials(
client_id=client_id, client_secret=client_secret
)