Coverage for src/mcp_atlassian/confluence/config.py: 100%

1"""Configuration module for the Confluence client."""

2

3 import os

4 from dataclasses import dataclass

5

6

7@dataclass

8 class ConfluenceConfig:

9 """Confluence API configuration."""

10

11 url: str # Base URL for Confluence

12 username: str # Email or username

13 api_token: str # API token used as password

14

15 @property

16 def is_cloud(self) -> bool:

17 """Check if this is a cloud instance."""

18 return "atlassian.net" in self.url

19

20 @classmethod

21 def from_env(cls) -> "ConfluenceConfig":

22 """Create configuration from environment variables.

23

24 Returns:

25 ConfluenceConfig with values from environment variables

26

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")

33

34 if not all([url, username, token]):

35 error_msg = "Missing required Confluence environment variables"

36 raise ValueError(error_msg)

37

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 ""

42

43 return cls(url=url, username=username, api_token=token)