Coverage for src/mcp_atlassian/confluence/config.py: 100%
22 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-10 03:26 +0900
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-10 03:26 +0900
1"""Configuration module for the Confluence client."""
3import os
4from dataclasses import dataclass
7@dataclass
8class ConfluenceConfig:
9 """Confluence API configuration."""
11 url: str # Base URL for Confluence
12 username: str # Email or username
13 api_token: str # API token used as password
15 @property
16 def is_cloud(self) -> bool:
17 """Check if this is a cloud instance."""
18 return "atlassian.net" in self.url
20 @classmethod
21 def from_env(cls) -> "ConfluenceConfig":
22 """Create configuration from environment variables.
24 Returns:
25 ConfluenceConfig with values from environment variables
27 Raises:
28 ValueError: If any required environment variable is missing
29 """
30 url = os.getenv("CONFLUENCE_URL")
31 username = os.getenv("CONFLUENCE_USERNAME")
32 token = os.getenv("CONFLUENCE_API_TOKEN")
34 if not all([url, username, token]):
35 error_msg = "Missing required Confluence environment variables"
36 raise ValueError(error_msg)
38 # These variables are guaranteed to be non-None after the check above
39 url = url if url is not None else ""
40 username = username if username is not None else ""
41 token = token if token is not None else ""
43 return cls(url=url, username=username, api_token=token)