Skip to content

Commit

Permalink
chore(deps): bump trestle to version v3.3.0 (#269)
Browse files Browse the repository at this point in the history
* chore(deps): bump trestle to version v3.3.0

Signed-off-by: Jennifer Power <[email protected]>

* fix: fixes inconsistent quote usage in pyproject.toml

Signed-off-by: Jennifer Power <[email protected]>

* feat: updates TrestleRule and tests for breaking changes

Applys changes neccessary to upgrade to
compliance-trestle v3 and pydantic v2

Signed-off-by: Jennifer Power <[email protected]>

---------

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jul 22, 2024
1 parent 9fc1da4 commit a2a2db6
Show file tree
Hide file tree
Showing 7 changed files with 523 additions and 404 deletions.
874 changes: 494 additions & 380 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ trestlebot-create-ssp = "trestlebot.entrypoints.create_ssp:main"
[tool.poetry.dependencies]
python = '^3.8.1'
gitpython = "^3.1.41"
compliance-trestle = "^2.6.0"
compliance-trestle = "^3.3.0"
github3-py = "^4.0.1"
python-gitlab = "^4.2.0"
ruamel-yaml = "^0.18.5"
pydantic = "1.10.15"
pydantic = "^2.0.0"

[tool.poetry.group.dev.dependencies]
flake8 = "^7.0.0"
Expand Down
6 changes: 3 additions & 3 deletions tests/trestlebot/tasks/authored/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from trestle.common.model_utils import ModelUtils
from trestle.core.models.file_content_type import FileContentType
from trestle.oscal.profile import Method, Profile
from trestle.oscal.profile import CombinationMethodValidValues, Profile

from tests import testutils
from trestlebot.tasks.authored.profile import AuthoredProfile
Expand Down Expand Up @@ -37,7 +37,7 @@ def test_create_new_default(tmp_trestle_dir: str) -> None:

assert prof.merge is not None
assert prof.merge.combine is not None
assert prof.merge.combine.method is Method.merge
assert prof.merge.combine.method is CombinationMethodValidValues.merge

assert prof.imports is not None
assert prof.imports[0].include_all is not None
Expand All @@ -62,7 +62,7 @@ def test_create_new_default_existing(tmp_trestle_dir: str) -> None:

assert prof.merge is not None
assert prof.merge.combine is not None
assert prof.merge.combine.method is Method.merge
assert prof.merge.combine.method is CombinationMethodValidValues.merge

assert prof.imports is not None
assert prof.imports[0].include_all is not None
Expand Down
2 changes: 1 addition & 1 deletion tests/trestlebot/tasks/test_assemble_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from trestle.common.model_utils import ModelUtils
from trestle.core.commands.author.catalog import CatalogGenerate
from trestle.core.commands.author.component import ComponentGenerate
from trestle.core.commands.author.profile import ProfileGenerate
from trestle.core.commands.author.prof import ProfileGenerate
from trestle.core.commands.author.ssp import SSPGenerate
from trestle.core.models.file_content_type import FileContentType
from trestle.oscal import catalog as oscal_cat
Expand Down
8 changes: 4 additions & 4 deletions tests/trestlebot/transformers/test_yaml_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_rules_transform_with_invalid_rule() -> None:
transformer = ToRulesYAMLTransformer()

with pytest.raises(
RulesTransformerException, match=".*value is not a valid dict.*"
RulesTransformerException, match=".*Input should be a valid dictionary.*"
):
transformer.transform(rule_file_info)

Expand Down Expand Up @@ -106,9 +106,9 @@ def test_rules_transform_with_additional_validation() -> None:
transformer = ToRulesYAMLTransformer()

expected_error = """2 error(s) found:
Location: description, Type: value_error.missing, Message: field required
Location: default-value, Type: value_error, Message: Default value 5% must be in the alternative \
values dict_values(['10%', '10%', '20%'])"""
Location: description, Type: missing, Message: Field required
Location: default-value, Type: value_error, Message: Value error, Default value 5% must be in the \
alternative values dict_values(['10%', '10%', '20%'])"""

with pytest.raises(
RulesTransformerException,
Expand Down
2 changes: 1 addition & 1 deletion trestlebot/tasks/authored/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def create_new_default(self, import_path: str, profile_name: str) -> None:
# Set up default values for merge settings.
merge_object: prof.Merge = gens.generate_sample_model(prof.Merge)
combine_object: prof.Combine = gens.generate_sample_model(prof.Combine)
combine_object.method = prof.Method.merge
combine_object.method = prof.CombinationMethodValidValues.merge
merge_object.combine = combine_object
merge_object.as_is = True

Expand Down
31 changes: 18 additions & 13 deletions trestlebot/transformers/trestle_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
"""


from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union

from pydantic import BaseModel, Field, ValidationError, validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
ValidationError,
ValidationInfo,
field_validator,
)

from trestlebot import const

Expand All @@ -25,13 +32,13 @@ class Parameter(BaseModel):
alternative_values: Dict[str, str] = Field(..., alias="alternative-values")
default_value: str = Field(..., alias="default-value")

class Config:
allow_population_by_field_name = True
model_config = ConfigDict(populate_by_name=True)

@validator("default_value", pre=False)
def check_default_value(cls, value: str, values: Dict[str, Any]) -> str:
@field_validator("default_value", mode="after")
@classmethod
def check_default_value(cls, value: str, info: ValidationInfo) -> str:
"""Check if default value is in the alternative values."""
alternative_values: Dict[str, str] = values.get("alternative_values", {})
alternative_values: Dict[str, str] = info.data.get("alternative_values", {})
if not alternative_values:
raise ValueError("Alternative values must be provided")

Expand Down Expand Up @@ -72,8 +79,7 @@ class Profile(BaseModel):
href: str
include_controls: List[Control] = Field(..., alias="include-controls")

class Config:
allow_population_by_field_name = True
model_config = ConfigDict(populate_by_name=True)


class ComponentInfo(BaseModel):
Expand All @@ -90,8 +96,7 @@ class Check(BaseModel):
name: str
description: str

class Config:
allow_population_by_field_name = True
model_config = ConfigDict(populate_by_name=True)


class TrestleRule(BaseModel):
Expand All @@ -101,8 +106,8 @@ class TrestleRule(BaseModel):
description: str
component: ComponentInfo
profile: Profile
check: Optional[Check]
parameter: Optional[Parameter]
check: Optional[Check] = Field(default=None)
parameter: Optional[Parameter] = Field(default=None)


def get_default_rule() -> TrestleRule:
Expand Down

0 comments on commit a2a2db6

Please sign in to comment.