Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions openapi.public.json
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,17 @@
"string",
"null"
]
},
"terraform": {
"anyOf": [
{
"$ref": "#/components/schemas/TerraformRootsView"
},
{
"type": "null"
}
],
"description": "The Terraform addresses the reach also started from, or why it took\n none. Absent when the assessment read reach only from the deployed\n revision."
}
},
"required": [
Expand Down Expand Up @@ -5826,6 +5837,48 @@
],
"type": "object"
},
"TerraformPlanView": {
"enum": [
"TAKEN",
"NOT_DECLARED",
"NOT_PINNED",
"HEAD_DIFFERS",
"ADDRESSES_UNREPORTED"
],
"type": "string"
},
"TerraformRootsView": {
"description": "The Terraform roots of one declared reach read.",
"properties": {
"addresses": {
"description": "The changed resource instance addresses taken as roots.",
"items": {
"type": "string"
},
"type": "array"
},
"omitted": {
"description": "Changed addresses left out at World's limit of 100 roots per read.",
"format": "uint",
"minimum": 0,
"type": "integer"
},
"plan": {
"allOf": [
{
"$ref": "#/components/schemas/TerraformPlanView"
}
],
"description": "`TAKEN` when the plan pinned for the reviewed commit named the roots,\n `NOT_DECLARED` when the environment captures no Terraform plan for this\n review, `NOT_PINNED` when it declares one and none was pinned,\n `HEAD_DIFFERS` when the pinned plan is for another commit, and\n `ADDRESSES_UNREPORTED` when the pinned plan records no changed\n addresses because it was pinned before World reported them."
}
},
"required": [
"plan",
"addresses",
"omitted"
],
"type": "object"
},
"ThreadObservationFreshness": {
"enum": [
"FRESH",
Expand Down
4 changes: 4 additions & 0 deletions proofline/_generated/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
from .stop_response import StopResponse
from .subject_authorization import SubjectAuthorization
from .subject_view import SubjectView
from .terraform_plan_view import TerraformPlanView
from .terraform_roots_view import TerraformRootsView
from .thread_observation_freshness import ThreadObservationFreshness
from .thread_observation_view import ThreadObservationView
from .thread_provider_state import ThreadProviderState
Expand Down Expand Up @@ -321,6 +323,8 @@
"StopResponse",
"SubjectAuthorization",
"SubjectView",
"TerraformPlanView",
"TerraformRootsView",
"ThreadObservationFreshness",
"ThreadObservationView",
"ThreadProviderState",
Expand Down
37 changes: 37 additions & 0 deletions proofline/_generated/models/declared_reach_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
if TYPE_CHECKING:
from ..models.reach_gap_view import ReachGapView
from ..models.reached_entity_view import ReachedEntityView
from ..models.terraform_roots_view import TerraformRootsView


T = TypeVar("T", bound="DeclaredReachView")
Expand All @@ -32,6 +33,10 @@ class DeclaredReachView:
outcome (DeclaredReachOutcome):
receipt_digest (None | str | Unset): World's digest of its full answer. Null unless `READ`.
snapshot_id (None | Unset | UUID): The World snapshot the reach was read at. Null unless `READ`.
terraform (None | TerraformRootsView | Unset): The Terraform addresses the reach also started from, or why it
took
none. Absent when the assessment read reach only from the deployed
revision.
"""

complete: bool
Expand All @@ -40,9 +45,12 @@ class DeclaredReachView:
outcome: DeclaredReachOutcome
receipt_digest: None | str | Unset = UNSET
snapshot_id: None | Unset | UUID = UNSET
terraform: None | TerraformRootsView | Unset = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> dict[str, Any]:
from ..models.terraform_roots_view import TerraformRootsView # noqa: PLC0415

complete = self.complete

entities = []
Expand Down Expand Up @@ -71,6 +79,14 @@ def to_dict(self) -> dict[str, Any]:
else:
snapshot_id = self.snapshot_id

terraform: dict[str, Any] | None | Unset
if isinstance(self.terraform, Unset):
terraform = UNSET
elif isinstance(self.terraform, TerraformRootsView):
terraform = self.terraform.to_dict()
else:
terraform = self.terraform

field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
Expand All @@ -85,13 +101,16 @@ def to_dict(self) -> dict[str, Any]:
field_dict["receipt_digest"] = receipt_digest
if snapshot_id is not UNSET:
field_dict["snapshot_id"] = snapshot_id
if terraform is not UNSET:
field_dict["terraform"] = terraform

return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.reach_gap_view import ReachGapView # noqa: PLC0415
from ..models.reached_entity_view import ReachedEntityView # noqa: PLC0415
from ..models.terraform_roots_view import TerraformRootsView # noqa: PLC0415

d = dict(src_dict)
complete = d.pop("complete")
Expand Down Expand Up @@ -138,13 +157,31 @@ def _parse_snapshot_id(data: object) -> None | Unset | UUID:

snapshot_id = _parse_snapshot_id(d.pop("snapshot_id", UNSET))

def _parse_terraform(data: object) -> None | TerraformRootsView | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
terraform_type_0 = TerraformRootsView.from_dict(data)

return terraform_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(None | TerraformRootsView | Unset, data)

terraform = _parse_terraform(d.pop("terraform", UNSET))

declared_reach_view = cls(
complete=complete,
entities=entities,
gaps=gaps,
outcome=outcome,
receipt_digest=receipt_digest,
snapshot_id=snapshot_id,
terraform=terraform,
)

declared_reach_view.additional_properties = d
Expand Down
12 changes: 12 additions & 0 deletions proofline/_generated/models/terraform_plan_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from enum import StrEnum


class TerraformPlanView(StrEnum):
ADDRESSES_UNREPORTED = "ADDRESSES_UNREPORTED"
HEAD_DIFFERS = "HEAD_DIFFERS"
NOT_DECLARED = "NOT_DECLARED"
NOT_PINNED = "NOT_PINNED"
TAKEN = "TAKEN"

def __str__(self) -> str:
return str(self.value)
80 changes: 80 additions & 0 deletions proofline/_generated/models/terraform_roots_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.terraform_plan_view import TerraformPlanView

T = TypeVar("T", bound="TerraformRootsView")


@_attrs_define
class TerraformRootsView:
"""The Terraform roots of one declared reach read.

Attributes:
addresses (list[str]): The changed resource instance addresses taken as roots.
omitted (int): Changed addresses left out at World's limit of 100 roots per read.
plan (TerraformPlanView):
"""

addresses: list[str]
omitted: int
plan: TerraformPlanView
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> dict[str, Any]:
addresses = self.addresses

omitted = self.omitted

plan = self.plan.value

field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"addresses": addresses,
"omitted": omitted,
"plan": plan,
}
)

return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
addresses = cast(list[str], d.pop("addresses"))

omitted = d.pop("omitted")

plan = TerraformPlanView(d.pop("plan"))

terraform_roots_view = cls(
addresses=addresses,
omitted=omitted,
plan=plan,
)

terraform_roots_view.additional_properties = d
return terraform_roots_view

@property
def additional_keys(self) -> list[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
35 changes: 34 additions & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
StopResponse,
_sync_http,
_transport,
models,
)
from proofline import client as client_module
from proofline._generated.models.finding_fix_prompt_type_0 import FindingFixPromptType0
Expand Down Expand Up @@ -113,7 +114,13 @@ async def async_sleep(self, delay: float) -> None:


@MODES
async def test_all_public_operations_use_generated_models_and_scoped_paths(mode: str) -> None:
@pytest.mark.parametrize(
"terraform",
[UNSET, None, {"plan": "TAKEN", "addresses": ["aws_s3_bucket.synthetic"], "omitted": 1}],
)
async def test_all_public_operations_use_generated_models_and_scoped_paths(
mode: str, terraform: Any
) -> None:
prefix = f"/api/v1/organizations/{ORG}"
paths = [
("GET", f"{prefix}/reviews", page(), ReviewPage),
Expand Down Expand Up @@ -192,6 +199,19 @@ async def test_all_public_operations_use_generated_models_and_scoped_paths(mode:
),
]

for _, _, body, response_model in paths:
if response_model is CustomerReviewDetail:
assessments = body["assessments"]
elif response_model is CustomerAssessmentDetail:
assessments = [body]
else:
continue
for entry in assessments:
reach = {"complete": True, "entities": [], "gaps": [], "outcome": "READ"}
if terraform is not UNSET:
reach["terraform"] = terraform
entry["declared_reach"] = reach

def respond(request: Request, index: int) -> Reply:
method, path, body, _ = paths[index]
assert request.method == method
Expand Down Expand Up @@ -223,6 +243,19 @@ def respond(request: Request, index: int) -> Reply:
for index, (name, args, kwargs) in enumerate(calls):
result = await call(client, name, *args, **kwargs)
assert isinstance(result, paths[index][3])
if isinstance(result, (CustomerReviewDetail, CustomerAssessmentDetail)):
entries = (
result.assessments if isinstance(result, CustomerReviewDetail) else [result]
)
for entry in entries:
roots = entry.declared_reach.terraform
if isinstance(terraform, dict):
assert isinstance(roots, models.TerraformRootsView)
assert roots.plan is models.TerraformPlanView.TAKEN
assert roots.addresses == ["aws_s3_bucket.synthetic"]
assert roots.omitted == 1
else:
assert roots is terraform
if isinstance(result, CustomerFinding):
assert result.rule_refs[0].key == "no-sync-io-in-handlers"
revision = result.rule_refs[0].revisions[0]
Expand Down
Loading