Skip to content

Commit

Permalink
feat: adds AssembleTask and bot pre-tasks
Browse files Browse the repository at this point in the history
Adds an extendable TaskBase type
Adds Authored types for assembly
Adds AssembleTask execution and implementation in CLI
Adds unit tests for SSP AuthorType and AssembleTask

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jun 24, 2023
1 parent 71c0b2a commit 360e4e6
Show file tree
Hide file tree
Showing 26 changed files with 8,135 additions and 95 deletions.
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ author: "Red Hat Product Security"
description: "A workflow automation manager for OSCAL formatted compliance content"

inputs:
markdown_path:
description: Path relative to the repository path where the Trestle markdown files are located. See project README.md for more information.
required: true
assemble_model:
description: OSCAL Model type to assemble. Values can be catalog, profile, compdef, or ssp.
required: true
ssp_index_path:
description: Path relative to the repository path where the ssp index is located. See project README.md for information about the ssp index.
required: false
default: "ssp-index.txt"
commit_message:
description: Commit message
required: false
Expand Down
1,460 changes: 1,425 additions & 35 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trestle-bot = "trestlebot.cli:run"
[tool.poetry.dependencies]
python = '^3.8.1'
gitpython = "^3.1.31"
compliance-trestle = "^2.1.1"

[tool.poetry.group.dev.dependencies]
flake8 = "^6.0.0"
Expand Down
76 changes: 76 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/python

# Copyright 2023 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""Test fixtures"""

import argparse
import os
import pathlib
from tempfile import TemporaryDirectory
from typing import Generator, Tuple, TypeVar

import pytest
from git.repo import Repo
from trestle.common.err import TrestleError
from trestle.core.commands.init import InitCmd


T = TypeVar("T")

YieldFixture = Generator[T, None, None]

_TEST_CONTENTS = """
test file
"""

_TEST_FILENAME = "test.txt"


@pytest.fixture
def tmp_repo() -> YieldFixture[Tuple[str, Repo]]:
"""Create a temporary git repository"""
with TemporaryDirectory(prefix="trestlebot_tests") as tmpdir:
with open(os.path.join(tmpdir, _TEST_FILENAME), "x", encoding="utf8") as file:
file.write(_TEST_CONTENTS)
repo = Repo.init(tmpdir)
with repo.config_writer() as config:
config.set_value("user", "email", "[email protected]")
config.set_value("user", "name", "Test User")
repo.git.add(all=True)
repo.index.commit("Initial commit")
yield tmpdir, repo


@pytest.fixture
def tmp_trestle_dir() -> YieldFixture[str]:
"""Create an initialized temporary trestle directory"""
with TemporaryDirectory(prefix="trestlebot_tests") as tmpdir:
tmp_path = pathlib.Path(tmpdir)
try:
args = argparse.Namespace(
verbose=0,
trestle_root=tmp_path,
full=True,
local=False,
govdocs=False,
)
init = InitCmd()
init._run(args)
except Exception as e:
raise TrestleError(
f"Initialization failed for temporary trestle directory: {e}."
)
yield tmpdir
Loading

0 comments on commit 360e4e6

Please sign in to comment.