Skip to content

Commit

Permalink
Modernize model spec, use camel case to update attribute
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Daue <[email protected]>
  • Loading branch information
mdaue committed Mar 29, 2023
1 parent 93ca808 commit de2110c
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions iambic/output/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json

import pathlib
from typing import Any, Dict, List, Set
from typing import Any, Dict, List, Optional, Set

from dictdiffer import diff
from pydantic import BaseModel as PydanticBaseModel
Expand All @@ -15,11 +15,12 @@
ProposedChangeType,
TemplateChangeDetails,
)
from iambic.core.utils import camel_to_snake


class ProposedChangeDiff(ProposedChange):
diff: str = Field(default=None)
diff_resolved: str = Field(default=None)
diff: Optional[str]
diff_resolved: Optional[str]

field_map = {
"inline_policies": "InlinePolicies",
Expand All @@ -42,7 +43,10 @@ class ProposedChangeDiff(ProposedChange):

def __init__(self, proposed_change: ProposedChange) -> None:
super().__init__(**proposed_change.dict())
object_attribute = self.field_map.get(self.attribute, self.attribute)
try:
object_attribute = camel_to_snake(self.attribute)
except TypeError:
object_attribute = None
if self.current_value is None:
self.current_value = {}
if self.new_value is None:
Expand Down Expand Up @@ -79,12 +83,12 @@ def diff_plus_minus(self) -> List[str]:


class ApplicableChange(PydanticBaseModel):
account: str = Field(default=None)
change: ProposedChange = Field(default=None)
template_change: TemplateChangeDetails = Field(default=None)
template_name: str = Field(default=None)
resource_id: str = Field(default=None)
resource_type: str = Field(default=None)
account: Optional[str]
change: Optional[ProposedChange]
template_change: Optional[TemplateChangeDetails]
template_name: Optional[str]
resource_id: Optional[str]
resource_type: Optional[str]

def __hash__(self):
return hash((self.resource_id, self.resource_type))
Expand All @@ -102,10 +106,10 @@ def __init__(


class AccountSummary(PydanticBaseModel):
account: str = Field(default="NONE")
count: int = Field(default=0)
num_changes: int = Field(default=0)
changes: List[ProposedChange] = Field(default=[])
account: Optional[str] = Field(default="NONE")
count: Optional[int]
num_changes: Optional[int]
changes: Optional[List[ProposedChange]]

def __hash__(self):
return hash((self.account, self.num_changes))
Expand All @@ -123,11 +127,11 @@ def compile(


class TemplateSummary(PydanticBaseModel):
template_path: str = Field(default="")
template_name: str = Field(default="")
count: int = Field(default=0)
num_accounts: int = Field(default=0)
accounts: List[AccountSummary] = Field(default=[])
template_path: Optional[str]
template_name: Optional[str]
count: Optional[int]
num_accounts: Optional[int]
accounts: Optional[List[AccountSummary]]

def __hash__(self):
return hash(self.template_path)
Expand Down Expand Up @@ -207,10 +211,10 @@ def _get_annotated_change(


class ActionSummary(PydanticBaseModel):
action: str = Field(default="")
count: int = Field(default=0)
num_templates = Field(default=0)
templates: List[TemplateSummary] = Field(default=[])
action: Optional[str]
count: Optional[int]
num_templates: Optional[int]
templates: Optional[List[TemplateSummary]]

@classmethod
def compile_proposed_changes(
Expand Down Expand Up @@ -252,10 +256,10 @@ def compile_proposed_changes(


class ExceptionSummary(PydanticBaseModel):
action: str = Field(default="")
count: int = Field(default=0)
num_templates = Field(default=0)
templates: List[TemplateSummary] = Field(default=[])
action: Optional[str]
count: Optional[int]
num_templates: Optional[int]
templates: Optional[List[TemplateSummary]]

@classmethod
def compile_exceptions_seen(
Expand Down Expand Up @@ -295,12 +299,12 @@ def compile_exceptions_seen(


class ActionSummaries(PydanticBaseModel):
num_actions: int = Field(default=0)
num_templates: int = Field(default=0)
num_accounts: int = Field(default=0)
num_exceptions: int = Field(default=0)
action_summaries: List[ActionSummary] = Field(default=[])
exceptions: List[ExceptionSummary] = Field(default=[])
num_actions: Optional[int]
num_templates: Optional[int]
num_accounts: Optional[int]
num_exceptions: Optional[int]
action_summaries: Optional[List[ActionSummary]]
exceptions: Optional[List[ExceptionSummary]]

@classmethod
def compile(cls, changes: List[TemplateChangeDetails]):
Expand Down

0 comments on commit de2110c

Please sign in to comment.