|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from datetime import datetime |
| 4 | +from enum import Enum |
| 5 | + |
| 6 | +from pydantic import BaseModel, ConfigDict, Field |
| 7 | + |
| 8 | +from .policy_types import PolicyKind |
| 9 | + |
| 10 | + |
| 11 | +class PolicyEvaluationStatus(str, Enum): |
| 12 | + """PolicyEvaluationStatus is an enum that represents all possible statuses for a policy evaluation""" |
| 13 | + |
| 14 | + POLICYEVALUATIONPASSED = "passed" |
| 15 | + POLICYEVALUATIONFAILED = "failed" |
| 16 | + POLICYEVALUATIONPENDING = "pending" |
| 17 | + POLICYEVALUATIONRUNNING = "running" |
| 18 | + POLICYEVALUATIONCANCELED = "canceled" |
| 19 | + POLICYEVALUATIONERRORED = "errored" |
| 20 | + POLICYEVALUATIONUNREACHABLE = "unreachable" |
| 21 | + POLICYEVALUATIONOVERRIDDEN = "overridden" |
| 22 | + |
| 23 | + |
| 24 | +class PolicyEvaluation(BaseModel): |
| 25 | + """PolicyEvaluation represents the policy evaluations that are part of the task stage.""" |
| 26 | + |
| 27 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 28 | + |
| 29 | + id: str |
| 30 | + status: PolicyEvaluationStatus | None = Field(None, alias="status") |
| 31 | + policy_kind: PolicyKind | None = Field(None, alias="policy-kind") |
| 32 | + status_timestamp: PolicyEvaluationStatusTimestamps | None = Field( |
| 33 | + None, alias="status-timestamp" |
| 34 | + ) |
| 35 | + result_count: PolicyResultCount | None = Field(None, alias="result-count") |
| 36 | + created_at: datetime | None = Field(None, alias="created-at") |
| 37 | + updated_at: datetime | None = Field(None, alias="updated-at") |
| 38 | + |
| 39 | + # The task stage the policy evaluation belongs to |
| 40 | + task_stage: PolicyAttachable | None = Field(None, alias="policy-attachable") |
| 41 | + |
| 42 | + |
| 43 | +class PolicyEvaluationStatusTimestamps(BaseModel): |
| 44 | + """PolicyEvaluationStatusTimestamps represents the set of timestamps recorded for a policy evaluation""" |
| 45 | + |
| 46 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 47 | + |
| 48 | + passed_at: datetime | None = Field(None, alias="passed-at") |
| 49 | + failed_at: datetime | None = Field(None, alias="failed-at") |
| 50 | + running_at: datetime | None = Field(None, alias="running-at") |
| 51 | + canceled_at: datetime | None = Field(None, alias="canceled-at") |
| 52 | + errored_at: datetime | None = Field(None, alias="errored-at") |
| 53 | + |
| 54 | + |
| 55 | +class PolicyAttachable(BaseModel): |
| 56 | + """The task stage the policy evaluation belongs to""" |
| 57 | + |
| 58 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 59 | + |
| 60 | + id: str |
| 61 | + type: str | None = Field(None, alias="type") |
| 62 | + |
| 63 | + |
| 64 | +class PolicyResultCount(BaseModel): |
| 65 | + """PolicyResultCount represents the count of the policy results""" |
| 66 | + |
| 67 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 68 | + |
| 69 | + advisory_failed: int | None = Field(None, alias="advisory-failed") |
| 70 | + mandatory_failed: int | None = Field(None, alias="mandatory-failed") |
| 71 | + passed: int | None = Field(None, alias="passed") |
| 72 | + errored: int | None = Field(None, alias="errored") |
| 73 | + |
| 74 | + |
| 75 | +class PolicyEvaluationList(BaseModel): |
| 76 | + """PolicyEvaluationList represents a list of policy evaluations""" |
| 77 | + |
| 78 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 79 | + |
| 80 | + items: list[PolicyEvaluation] | None = Field(default_factory=list) |
| 81 | + current_page: int | None = None |
| 82 | + next_page: str | None = None |
| 83 | + prev_page: str | None = None |
| 84 | + total_count: int | None = None |
| 85 | + total_pages: int | None = None |
| 86 | + |
| 87 | + |
| 88 | +class PolicyEvaluationListOptions(BaseModel): |
| 89 | + """PolicyEvaluationListOptions represents the options for listing policy evaluations""" |
| 90 | + |
| 91 | + model_config = ConfigDict(populate_by_name=True, validate_by_name=True) |
| 92 | + |
| 93 | + page_number: int | None = Field(None, alias="page[number]") |
| 94 | + page_size: int | None = Field(None, alias="page[size]") |
0 commit comments