Coverage for /usr/local/lib/python3.10/site-packages/opal_common-0.0.0-py3.10.egg/opal_common/schemas/policy_source.py: 94%

32 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 11:54 +0000

1from typing import List, Optional, Union 

2 

3try: 

4 from typing import Literal 

5except ImportError: 

6 # Py<3.8 

7 from typing_extensions import Literal 

8 

9from opal_common.schemas.policy import BaseSchema 

10from pydantic import Field 

11 

12 

13class NoAuthData(BaseSchema): 

14 auth_type: Literal["none"] = "none" 

15 

16 

17class SSHAuthData(BaseSchema): 

18 auth_type: Literal["ssh"] = "ssh" 

19 username: str = Field(..., description="SSH username") 

20 public_key: Optional[str] = Field(None, description="SSH public key") 

21 private_key: str = Field(..., description="SSH private key") 

22 

23 

24class GitHubTokenAuthData(BaseSchema): 

25 auth_type: Literal["github_token"] = "github_token" 

26 token: str = Field(..., description="Github Personal Access Token (PAI)") 

27 

28 

29class UserPassAuthData(BaseSchema): 

30 auth_type: Literal["userpass"] = "userpass" 

31 username: str = Field(..., description="Username") 

32 password: str = Field(..., description="Password") 

33 

34 

35class BasePolicyScopeSource(BaseSchema): 

36 source_type: str 

37 url: str 

38 auth: Union[NoAuthData, SSHAuthData, GitHubTokenAuthData, UserPassAuthData] = Field( 

39 ..., discriminator="auth_type" 

40 ) 

41 directories: List[str] = Field(["."], description="Directories to include") 

42 extensions: List[str] = Field( 

43 [".rego", ".json"], description="File extensions to use" 

44 ) 

45 bundle_ignore: Optional[List[str]] = Field( 

46 None, description="glob paths to omit from bundle" 

47 ) 

48 manifest: str = Field(".manifest", description="path to manifest file") 

49 poll_updates: bool = Field( 

50 False, description="Whether OPAL should check for updates periodically" 

51 ) 

52 

53 

54class GitPolicyScopeSource(BasePolicyScopeSource): 

55 branch: str = Field("main", description="Git branch to track")