Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPLYTM-224 OSCAL Profiles organized by level task and command (WIP) #410

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3529537
docs: including emojis in contributing guide
hbraswelrh Dec 23, 2024
e4a9215
docs: including emojis in contributing guide
hbraswelrh Dec 23, 2024
2cab354
fix: spacing fix for image in contributing guide
hbraswelrh Dec 23, 2024
a742c8a
fix: spacing fix for image in contributing guide
hbraswelrh Dec 23, 2024
0ba61f4
fix: spacing fix for image in contributing guide
hbraswelrh Dec 23, 2024
07acf9c
docs: emoji updates
hbraswelrh Dec 23, 2024
f6bfd8b
docs: emoji updates
hbraswelrh Dec 23, 2024
0d3a3e9
docs: emoji updates
hbraswelrh Dec 23, 2024
97880bb
docs: emoji updates
hbraswelrh Dec 23, 2024
208400d
docs: update README.md emoji placement
hbraswelrh Jan 2, 2025
0daee86
Update README.md
hbraswelrh Jan 2, 2025
e8bb573
docs: update CONTRIBUTING.md
hbraswelrh Jan 2, 2025
ee1d7af
Merge pull request #3 from hbraswelrh/hbraswelrh-readme-updates
hbraswelrh Jan 2, 2025
2c1e781
docs: update CONTRIBUTING.md emoji placement
hbraswelrh Jan 2, 2025
2af5f37
Merge branch 'complytime:main' into main
hbraswelrh Jan 10, 2025
edb3076
feat: initial setup of syncing cac content for oscal profile authoring
hbraswelrh Jan 12, 2025
f0b2407
fix: comments labeled for next steps of interaction with task
hbraswelrh Jan 12, 2025
06ab49a
fix: comments typo
hbraswelrh Jan 12, 2025
2edf018
feat: inital setup of syncing cac content profile task for interactio…
hbraswelrh Jan 12, 2025
cdc3079
feat: inital setup of syncing cac content profile task for interactio…
hbraswelrh Jan 12, 2025
d0e8e4f
feat: updating sync cac content profile task logic
hbraswelrh Jan 13, 2025
df9e9c5
feat: updating CLI options for oscal_profile_cmd
hbraswelrh Jan 13, 2025
9c593f4
fix: sync profile task execution update
hbraswelrh Jan 13, 2025
e4459b8
feat: adding unit test for sync_cac_content_profile subcommand
hbraswelrh Jan 13, 2025
622d250
fix: updates for function call in execute method
hbraswelrh Jan 13, 2025
f8b4885
feat: initial setup for subcommand interaction with task
hbraswelrh Jan 13, 2025
7d61ba6
feat: updating unit tests for sync_cac_profile
hbraswelrh Jan 14, 2025
024f851
fix: updating the parameter names to match cli
hbraswelrh Jan 14, 2025
40c95fb
fix: updating the click cli options for input
hbraswelrh Jan 14, 2025
f90941b
feat: updating subcommand variable names
hbraswelrh Jan 15, 2025
9efb5da
feat: adding unit tests for oscal-profile subcommand
hbraswelrh Jan 15, 2025
757b8ba
docs: updating docstrings for SyncCacContentProfileTask
hbraswelrh Jan 15, 2025
03eb4e0
docs: updating docstrings for SyncCacContentProfileTask
hbraswelrh Jan 15, 2025
d09637a
docs: updating docstrings for SyncCacContentProfileTask
hbraswelrh Jan 15, 2025
f6ee50d
Merge remote-tracking branch 'origin/CPLYTM-224' into CPLYTM-224
hbraswelrh Jan 15, 2025
8f645ba
feat: inital setup of syncing cac content profile task for interactio…
hbraswelrh Jan 12, 2025
129fd5f
feat: adding unit test for sync_cac_content_profile subcommand
hbraswelrh Jan 13, 2025
ca940d0
docs: updating docstrings for SyncCacContentProfileTask
hbraswelrh Jan 15, 2025
d5ef267
feat: adding unit tests for oscal-profile sub-command and updating
hbraswelrh Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Contributing to trestlebot


Thank you for your interest in the trestlebot project.

Before you start contributing, please take a moment to read through the guide below.
Expand Down Expand Up @@ -31,7 +32,7 @@ Before you start contributing, please take a moment to read through the guide be
- [Release Process](#release-process)


## How To Contribute
## :heavy_plus_sign: How To Contribute

Some initial contributions could be:

Expand All @@ -40,27 +41,27 @@ Some initial contributions could be:
- Try out issues that have the label `good first issue`
- Opening an issue for bugs or feature requests

## Opening a Pull Request
## :incoming_envelope: Opening a Pull Request

When submitting a pull request, please follow these guidelines:

1. Ensure that you have an issue submitted first and reference it in your pull request.
2. Ensure that your code passes all CI tests.
3. Please keep the pull request focused on a single issue or feature, if possible.

## Developer Guide
## :bookmark_tabs: :flashlight: Developer Guide

### Prerequisites
### :closed_lock_with_key: Prerequisites

- [Python](https://www.python.org/downloads/) - v3.8+
- [Poetry](https://python-poetry.org/)
- [Podman](https://podman.io/docs/installation) (Optional) - For testing locally and end-to-end tests

### Development Environment
### :computer: Development Environment

For a reproducible development environment, we use Dev Containers. See [devcontainer.json](./.devcontainer/devcontainer.json) for more information. Note that this does not include the `podman` installation to avoid the requirement for containers with elevated privileges.

### How It Works
### :grey_question: How It Works

For workflow diagrams, see the [diagrams](./docs/workflows/) under the `docs` folder.

Expand All @@ -82,9 +83,9 @@ For workflow diagrams, see the [diagrams](./docs/workflows/) under the `docs` fo
- `transformers` - This contains data transformation logic; specifically for rules.


### Documentation
### :open_file_folder: Documentation

#### Architecture Decisions
#### :brain: Architecture Decisions

We document decisions using [Architectural Decision Records](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions). The team will decide when an ADR will be put in place, but this is generally done to document impactful architectural decisions.

Expand All @@ -100,7 +101,7 @@ Each `README.md` under the `actions` directory have an Actions Inputs and Action
make update-action-readmes
```

#### Authoring CI Workflows
#### :pencil2: Authoring CI Workflows

The CI workflows for trestle-bot leverage third party actions pinned to a hash value which is updated by `dependabot.yml`. The purpose of pinning actions to a full length commit SHA is to ensure that the action's code and behavior remain consistent. Actions that are pinned to full length commit SHAs act as immutable releases which allow for distinction between versions and an accurate history log. When selecting a commit SHA to include, the SHA value that is associated with the version of the action should be chosen from the associated action's repository. Dependabot checks for the action's reference against the latest version ensuring a secure and consistent approach to managing dependencies and version updating.

Expand All @@ -111,17 +112,17 @@ To generate a pin for a third party action, there should be a full length commit

This approach is used for authoring CI workflows that utilize versioned actions to produce frequent updates from dependabot for python and GitHub Actions.

### License Text in Files
### :ticket: License Text in Files

Please use the SPDX license identifier in all source files.

```
# SPDX-License-Identifier: Apache-2.0
```

### Tools
### :wrench: :hammer: :nut_and_bolt: Tools

#### Format and Styling
#### :zap: Format and Styling

This project uses `black` and `isort` for formatting and `flake8` for linting. You can run these commands to format and lint your code.
Linting checks can be run as a pre-commit hook and are verified in CI.
Expand All @@ -142,7 +143,7 @@ We encourage the use of type hints in Python code to enhance readability, mainta
- [SonarCloud](https://sonarcloud.io/dashboard?id=rh-psce_trestle-bot) - We use SonarCloud to analyze code quality, coverage, and security. To not break GitHub security model, this will not run on a forked repository.
- [Semgrep](https://semgrep.dev/docs/extensions/overview/#pre-commit) - Identify issues in the local development environment before committing code. These checks are also run in CI.

### Running tests
### :running: Running tests

Run all tests with `make test` or `make test-slow` to run all tests including end-to-end.
For information on end-to-end tests, see [README.md](./tests/e2e/README.md).
Expand All @@ -167,7 +168,7 @@ poetry run trestlebot sync-upstreams
poetry run trestlebot create ssp
```

#### Local testing
#### :computer: :shell: Local testing

For this guide, we will be using `podman` to test trestlebot in a running container.

Expand Down Expand Up @@ -219,7 +220,7 @@ cat my-token.txt | podman secret create repo-secret -
podman run --entrypoint /entrypoint.sh --secret repo-secret,type=env,target=TRESTLEBOT_REPO_ACCESS_TOKEN --env-file=envfile -v my-trestle-space:/data -w /data localhost:5000/trestlebot:latest
```

### Release Process
### :outbox_tray: :file_folder: Release Process

Once work on a release has been completed:

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(https://as2.ftcdn.net/v2/jpg/06/18/11/81/1000_F_618118160_UGnTNfImuDiU3p6ejshQxIenyqSB70ce.jpg)
# trestle-bot

[![Pre commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
Expand All @@ -13,7 +14,7 @@ trestle-bot is a CLI tool that assists users in leveraging [Compliance-Trestle](

## Getting Started

### Available Commands
### :memo: :octocat: Available Commands

The `autosync` command will sync trestle-generated Markdown files to OSCAL JSON files in a trestle workspace. All content under the provided markdown directory will be transformed when the action is run. This action supports all top-level models [supported by compliance-trestle for authoring](https://oscal-compass.github.io/compliance-trestle/tutorials/ssp_profile_catalog_authoring/ssp_profile_catalog_authoring/).

Expand All @@ -37,15 +38,15 @@ Below is a table of the available commands and their current availability as a G

For detailed documentation on how to use each action, see the README.md in each folder under [actions](./actions/).

### Supported Git Providers
### :octocat: Supported Git Providers

> Note: Only applicable if using `trestle-bot` to create pull requests. Automatically detecting the git
provider information is supported for GitHub Actions (GitHub) and GitLab CI (GitLab).

- GitHub
- GitLab

### Run as a Container
### :fireworks: Run as a Container

> Note: When running the commands in a container, all are prefixed with `trestlebot` (e.g. `trestlebot autosync`). The default entrypoint for the container is the autosync command.

Expand All @@ -62,14 +63,14 @@ Container images are available in `quay.io`:
podman run -v $(pwd):/data -w /data quay.io/continuouscompliance/trestle-bot:<tag>
```

## Contributing
## :outbox_tray: :chart_with_upwards_trend: Contributing

For information about contributing to trestle-bot, see the [CONTRIBUTING.md](./CONTRIBUTING.md) file.

## License
## :page_facing_up: License

This project is licensed under the Apache 2.0 License - see the [LICENSE.md](LICENSE) file for details.

## Troubleshooting
## :warning: Troubleshooting

See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) for troubleshooting tips.
150 changes: 149 additions & 1 deletion tests/trestlebot/cli/test_sync_cac_content_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from git import Repo

from tests.testutils import setup_for_catalog, setup_for_profile
from trestlebot.cli.commands.sync_cac_content import sync_cac_content_cmd
from trestlebot.cli.commands.sync_cac_content import (
sync_cac_content_cmd,
sync_cac_content_profile_cmd,
)


test_product = "ocp4"
Expand Down Expand Up @@ -84,3 +87,148 @@ def test_sync_product_name(tmp_repo: Tuple[str, Repo]) -> None:
with open(component_definition, "r", encoding="utf-8") as file:
content = file.read()
assert '"title": "ocp4"' in content

# Working
def test_missing_required_profile_option(tmp_repo: Tuple[str, Repo]) -> None:
"""Tests missing required options in sync-cac-content-profile subcommand."""

repo_dir, _ = tmp_repo
repo_path = pathlib.Path(repo_dir)
policy_id_test = "RHEL-9"

runner = CliRunner()
result = runner.invoke(
sync_cac_content_cmd,
[
"oscal-profile",
"--policy-id",
policy_id_test,
"--oscal-catalog",
"catalog_tester",
"--repo-path",
str(repo_path.resolve()),
"--committer-email",
"[email protected]",
"--committer-name",
"test name",
"--branch",
"test",
],
)
assert result.exit_code == 2
# Working
def test_invalid_subcommand() -> None:
"""Tests missing required options in sync-cac-content-profile subcommand."""

runner = CliRunner()
result = runner.invoke(sync_cac_content_cmd,["Invalid"])
assert result.exit_code == 2
# Need additional data
def test_created_oscal_profile(tmp_repo: Tuple[str, Repo]) -> None:
"""Tests creation of OSCAL profile and change of .json title."""

repo_dir, _ = tmp_repo
repo_path = pathlib.Path(repo_dir)
policy_id_test = "OCP-4"
test_profile = "simplified_nist_profile"
setup_for_catalog(repo_path, test_cat, "catalog")
setup_for_profile(repo_path, test_prof, "profile")

runner = CliRunner()
result = runner.invoke(
sync_cac_content_cmd,
[
"oscal-profile",
"--cac-content-root",
cac_content_test_data,
"--product",
test_product,
"--oscal-catalog",
test_cat,
"--policy-id",
policy_id_test,
"--filter-by-level",
"high",
"--repo-path",
str(repo_path.resolve()),
"--committer-email",
"[email protected]",
"--committer-name",
"test name",
"--branch",
"test",
],
)
assert result.exit_code == 0

def test_sync_profile_product_name(tmp_repo: Tuple[str, Repo]) -> None:
"""Tests sync Cac content product name to OSCAL component title ."""
repo_dir, _ = tmp_repo
repo_path = pathlib.Path(repo_dir)

setup_for_catalog(repo_path, test_cat, "catalog")
setup_for_profile(repo_path, test_prof, "profile")

runner = CliRunner()
result = runner.invoke(
sync_cac_content_cmd,
[
"oscal-profile",
"--cac-content-root",
cac_content_test_data,
"product",
test_product,
"--oscal-catalog",
test_prof,
"--policy-id",
"ac",
"--filter-by-level",
"high",
"--repo-path",
str(repo_path.resolve()),
"--committer-email",
"[email protected]",
"--committer-name",
"test name",
"--branch",
"test",
"--dry-run",
],
)
# Check the CLI sync-cac-content is successful
assert result.exit_code == 0
# Check if the component definition is created
profile = repo_path.joinpath(test_prof_path)
assert profile.exists()

def test_oscal_json_created(tmp_repo: Tuple[str, Repo]) -> None:
"""Tests creation of OSCAL JSON file."""
repo_dir, _ = tmp_repo
repo_path = pathlib.Path(repo_dir)
catalog_tester = "simplified_nist_catalog.json"
setup_for_catalog(repo_path, test_cat, "catalog")

runner = CliRunner()
result = runner.invoke(
sync_cac_content_cmd,
[
"oscal-profile",
"--cac-content-root",
cac_content_test_data,
"json",
"--product",
test_product,
"--oscal-catalog",
catalog_tester,
"--repo-path",
str(repo_path.resolve()),
"--committer-email",
"[email protected]",
"--committer-name",
"test name",
"--branch",
"test",
"--dry-run",
]
)
assert result.exit_code == 0
Loading