-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initialize command for cac to oscal transformation
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
|
||
""" Unit test for sync-cac-content command""" | ||
import pathlib | ||
from typing import Tuple | ||
|
||
from click.testing import CliRunner | ||
from git import Repo | ||
|
||
from trestlebot.cli.commands.sync_cac_content import sync_cac_content_cmd | ||
|
||
|
||
test_product = "ocp4" | ||
|
||
|
||
def test_missing_required_option(tmp_repo: Tuple[str, Repo]) -> None: | ||
"""Tests missing required options in sync-cac-content command.""" | ||
|
||
repo_dir, _ = tmp_repo | ||
repo_path = pathlib.Path(repo_dir) | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
sync_cac_content_cmd, | ||
[ | ||
"--product", | ||
test_product, | ||
"--repo-path", | ||
str(repo_path.resolve()), | ||
"--committer-email", | ||
"test@email.com", | ||
"--committer-name", | ||
"test name", | ||
"--branch", | ||
"test", | ||
], | ||
) | ||
assert result.exit_code == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
|
||
"""Module for sync cac content command""" | ||
import logging | ||
from typing import Any | ||
|
||
import click | ||
|
||
from trestlebot.cli.options.common import common_options, git_options, handle_exceptions | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@click.command( | ||
name="sync-cac-content", | ||
help="Transform CaC content to component definition in OSCAL.", | ||
) | ||
@click.pass_context | ||
@common_options | ||
@git_options | ||
@click.option( | ||
"--cac-content-root", | ||
help="Root of the CaC content project.", | ||
required=True, | ||
) | ||
@click.option( | ||
"--product", | ||
type=str, | ||
help="Product to build OSCAL component definition with", | ||
required=True, | ||
) | ||
@click.option( | ||
"--cac-profile", | ||
type=str, | ||
help="CaC profile used to collect product data for transformation", | ||
required=True, | ||
) | ||
@click.option( | ||
"--oscal-profile", | ||
type=str, | ||
help="Main profile href, or name of the profile in trestle workspace", | ||
required=True, | ||
) | ||
@click.option( | ||
"--component-definition-type", | ||
type=click.Choice(["service", "validation"]), | ||
help="Type of component definition. Default: service", | ||
required=False, | ||
default="service", | ||
) | ||
@handle_exceptions | ||
def sync_cac_content_cmd(ctx: click.Context, **kwargs: Any) -> None: | ||
"""Transform CaC content to OSCAL component definition.""" | ||
|
||
# Steps: | ||
# 1. Check options, logger errors if any and exit. | ||
# 2. Create a new task to run the data transformation. | ||
# 3. Initialize a Trestlebot object and run the task(s). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters