Establishes the initial structure for the SuperOffice connector. Implements the complete, iterative authentication process, culminating in a successful refresh token exchange. Documents the process and the final blocker (API authorization) in the integration plan, awaiting IT action to change the application type to 'Server to server'.
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
import os
|
|
import logging
|
|
from dotenv import load_dotenv
|
|
|
|
# Import the new classes
|
|
from .auth_handler import AuthHandler
|
|
from .superoffice_client import SuperOfficeClient
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
handlers=[
|
|
logging.StreamHandler()
|
|
]
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def main():
|
|
"""
|
|
Main function to initialize and run the SuperOffice connector.
|
|
"""
|
|
logger.info("Starting SuperOffice Connector Proof of Concept...")
|
|
|
|
# Load environment variables from the root .env file
|
|
dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env')
|
|
logger.info(f"Attempting to load .env file from: {dotenv_path}")
|
|
|
|
if os.path.exists(dotenv_path):
|
|
load_dotenv(dotenv_path=dotenv_path)
|
|
logger.info(".env file loaded successfully.")
|
|
else:
|
|
logger.error(f".env file not found at the expected location: {dotenv_path}")
|
|
logger.error("Please ensure the .env file exists in the project root directory.")
|
|
return
|
|
|
|
try:
|
|
# 1. Initialize AuthHandler
|
|
auth_handler = AuthHandler()
|
|
|
|
# Define the tenant ID
|
|
TENANT_ID = "Cust26720" # As provided in the initial task description
|
|
|
|
# 2. Get a fresh access token (this will also update the refresh token if needed)
|
|
full_access_token = auth_handler.get_access_token()
|
|
logger.info(f"Full Access Token for curl: {full_access_token}")
|
|
|
|
# 3. Initialize SuperOfficeClient with the tenant ID
|
|
so_client = SuperOfficeClient(auth_handler, TENANT_ID)
|
|
|
|
# 3. Perform test connection
|
|
logger.info("--- Performing Connection Test ---")
|
|
connection_result = so_client.test_connection()
|
|
logger.info("--- Connection Test Finished ---")
|
|
|
|
if connection_result:
|
|
logger.info("POC Succeeded: Connection to SuperOffice API was successful.")
|
|
else:
|
|
logger.error("POC Failed: Could not establish a connection to SuperOffice API.")
|
|
|
|
except ValueError as ve:
|
|
logger.error(f"Configuration Error: {ve}")
|
|
logger.error("POC Failed due to missing configuration.")
|
|
except Exception as e:
|
|
logger.error(f"An unexpected error occurred during the POC execution: {e}", exc_info=True)
|
|
logger.error("POC Failed due to an unexpected error.")
|
|
|
|
|
|
logger.info("SuperOffice Connector POC finished.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |