|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import TYPE_CHECKING |
| 3 | +from datetime import datetime |
| 4 | +from enum import Enum |
| 5 | +from typing import TYPE_CHECKING, Any |
4 | 6 |
|
5 | 7 | from pydantic import BaseModel, ConfigDict, Field |
6 | 8 |
|
7 | 9 | if TYPE_CHECKING: |
8 | 10 | from .run import Run |
9 | 11 |
|
10 | 12 |
|
11 | | -# PolicyCheck represents a Terraform Enterprise policy check.. |
| 13 | +class PolicyScope(str, Enum): |
| 14 | + """The scope of the policy check.""" |
| 15 | + |
| 16 | + POLICY_SCOPE_ORGANIZATION = "organization" |
| 17 | + POLICY_SCOPE_WORKSPACE = "workspace" |
| 18 | + |
| 19 | + |
| 20 | +class PolicyStatus(str, Enum): |
| 21 | + """The status of the policy check.""" |
| 22 | + |
| 23 | + POLICY_CANCELED = "canceled" |
| 24 | + POLICY_ERRORED = "errored" |
| 25 | + POLICY_HARD_FAILED = "hard_failed" |
| 26 | + POLICY_OVERRIDDEN = "overridden" |
| 27 | + POLICY_PASSES = "passed" |
| 28 | + POLICY_PENDING = "pending" |
| 29 | + POLICY_QUEUED = "queued" |
| 30 | + POLICY_SOFT_FAILED = "soft_failed" |
| 31 | + POLICY_UNREACHABLE = "unreachable" |
| 32 | + |
| 33 | + |
| 34 | +class PolicyCheckIncludeOpt(str, Enum): |
| 35 | + """A list of relations to include""" |
| 36 | + |
| 37 | + POLICY_CHECK_RUN_WORKSPACE = "run.workspace" |
| 38 | + POLICY_CHECK_RUN = "run" |
| 39 | + |
| 40 | + |
12 | 41 | class PolicyCheck(BaseModel): |
| 42 | + """PolicyCheck represents a Terraform Enterprise policy check.""" |
| 43 | + |
13 | 44 | model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
14 | 45 |
|
15 | 46 | id: str |
16 | | - # actions: PolicyActions = Field(..., alias="actions") |
17 | | - # permissions: PolicyPermissions = Field(..., alias="permissions") |
18 | | - # result: PolicyResult = Field(..., alias="result") |
19 | | - # scope: PolicyScope = Field(..., alias="scope") |
20 | | - # status: PolicyStatus = Field(..., alias="status") |
21 | | - # status_timestamps: PolicyStatusTimestamps = Field(..., alias="status-timestamps") |
| 47 | + actions: PolicyActions | None = Field(None, alias="actions") |
| 48 | + permissions: PolicyPermissions | None = Field(None, alias="permissions") |
| 49 | + result: PolicyResult | None = Field(None, alias="result") |
| 50 | + scope: PolicyScope | None = Field(None, alias="scope") |
| 51 | + status: PolicyStatus | None = Field(None, alias="status") |
| 52 | + status_timestamps: PolicyStatusTimestamps | None = Field( |
| 53 | + None, alias="status-timestamps" |
| 54 | + ) |
22 | 55 |
|
23 | 56 | # Relations |
24 | | - run: Run = Field(..., alias="run") |
| 57 | + run: Run | None = Field(None, alias="run") |
| 58 | + |
| 59 | + |
| 60 | +class PolicyActions(BaseModel): |
| 61 | + """PolicyActions represents the policy check actions.""" |
| 62 | + |
| 63 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 64 | + |
| 65 | + is_overridable: bool | None = Field(None, alias="is-overridable") |
| 66 | + |
| 67 | + |
| 68 | +class PolicyPermissions(BaseModel): |
| 69 | + """PolicyPermissions represents the policy check permissions.""" |
| 70 | + |
| 71 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 72 | + |
| 73 | + can_override: bool | None = Field(None, alias="can-override") |
| 74 | + |
| 75 | + |
| 76 | +class PolicyResult(BaseModel): |
| 77 | + """PolicyResult represents the complete policy check result""" |
| 78 | + |
| 79 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 80 | + |
| 81 | + advisory_failed: int | None = Field(None, alias="advisory-failed") |
| 82 | + duration: int | None = Field(None, alias="duration") |
| 83 | + hard_failed: int | None = Field(None, alias="hard-failed") |
| 84 | + soft_failed: int | None = Field(None, alias="soft-failed") |
| 85 | + total_failed: int | None = Field(None, alias="total-failed") |
| 86 | + passed: int | None = Field(None, alias="passed") |
| 87 | + result: bool | None = Field(None, alias="result") |
| 88 | + sentinel: Any | None = Field(None, alias="sentinel") |
| 89 | + |
| 90 | + |
| 91 | +class PolicyStatusTimestamps(BaseModel): |
| 92 | + """PolicyStatusTimestamps holds the timestamps for individual policy check statuses.""" |
| 93 | + |
| 94 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 95 | + |
| 96 | + errored_at: datetime | None = Field(None, alias="errored-at") |
| 97 | + hard_failed_at: datetime | None = Field(None, alias="hard-failed-at") |
| 98 | + passed_at: datetime | None = Field(None, alias="passed-at") |
| 99 | + queued_at: datetime | None = Field(None, alias="queued-at") |
| 100 | + soft_failed_at: datetime | None = Field(None, alias="soft-failed-at") |
| 101 | + |
| 102 | + |
| 103 | +class PolicyCheckListOptions(BaseModel): |
| 104 | + """PolicyCheckListOptions represents the options for listing policy checks.""" |
| 105 | + |
| 106 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 107 | + |
| 108 | + include: list[PolicyCheckIncludeOpt] | None = Field(None, alias="include") |
| 109 | + page_number: int | None = Field(None, alias="page[number]") |
| 110 | + page_size: int | None = Field(None, alias="page[size]") |
| 111 | + |
| 112 | + |
| 113 | +class PolicyCheckList(BaseModel): |
| 114 | + """PolicyCheckList represents a list of policy checks.""" |
| 115 | + |
| 116 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 117 | + |
| 118 | + items: list[PolicyCheck] = Field(default_factory=list, alias="items") |
| 119 | + current_page: int | None = Field(None, alias="current_page") |
| 120 | + total_pages: int | None = Field(None, alias="total_pages") |
| 121 | + prev_page: int | None = Field(None, alias="prev_page") |
| 122 | + next_page: int | None = Field(None, alias="next_page") |
| 123 | + total_count: int | None = Field(None, alias="total_count") |
0 commit comments