Skip to content

Commit

Permalink
fix base 64 issue
Browse files Browse the repository at this point in the history
Signed-off-by: Lou DeGenaro <[email protected]>
  • Loading branch information
degenaro committed Apr 14, 2024
1 parent 14a8248 commit 369e8ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 0 additions & 2 deletions scripts/schema_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ def patch_poam_item(model_name: str, k3: str) -> None:
return
new_value = 'finding'
data['definitions'][k1][k2][k3][k4][k5] = data['definitions'][k1][k2][k3][k4][k5].replace(old_value, new_value)
x = data['definitions'][k1][k2][k3][k4][k5]
print(f'{x}')
logger.info(f'patch: {model_name} {k1}.{k2}.{k3}.{k4}.{k5} {old_value} -> {new_value}')
json_data_put(model_name, data)

Expand Down
18 changes: 13 additions & 5 deletions trestle/core/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@
from trestle.common.str_utils import AliasMode
from trestle.core.base_model import OscalBaseModel
from trestle.oscal import OSCAL_VERSION
from trestle.oscal.common import Base64, Methods
from trestle.oscal.common import Base64, Base64Datatype, Methods
from trestle.oscal.ssp import DateDatatype

logger = logging.getLogger(__name__)

TG = TypeVar('TG', bound=OscalBaseModel)

sample_base_64 = Base64(filename=const.REPLACE_ME, media_type=const.REPLACE_ME, value=0)
type_base64 = type(sample_base_64)
sample_base64_value = 0
sample_base64 = Base64(filename=const.REPLACE_ME, media_type=const.REPLACE_ME, value=sample_base64_value)
type_base64 = type(sample_base64)

sample_date_value = '2400-02-29'

sample_method = Methods.EXAMINE

Expand Down Expand Up @@ -74,7 +78,7 @@ def generate_sample_value_by_type(
if is_enum_method(type_):
return sample_method
if type_ is Base64:
return sample_base_64
return sample_base64
if type_ is datetime:
return datetime.now().astimezone()
if type_ is bool:
Expand Down Expand Up @@ -196,7 +200,11 @@ def generate_sample_model(
# Root models should ideally not exist, however, sometimes we are stuck with them.
# If that is the case we need sufficient information on the type in order to generate a model.
# E.g. we need the type of the container.
if field == '__root__' and hasattr(model, '__name__'):
if model_type in [Base64, Base64Datatype]:
model_dict[field] = sample_base64_value
elif model_type in [DateDatatype]:
model_dict[field] = sample_date_value
elif field == '__root__' and hasattr(model, '__name__'):
model_dict[field] = generate_sample_value_by_type(
outer_type, str_utils.classname_to_alias(model.__name__, AliasMode.FIELD)
)
Expand Down

0 comments on commit 369e8ad

Please sign in to comment.