-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: 295 monorepo directory structure design proposal #389
Merged
gvauter
merged 137 commits into
main
from
295-monorepo-directory-structure-design-proposal
Dec 18, 2024
Merged
Changes from 48 commits
Commits
Show all changes
137 commits
Select commit
Hold shift + click to select a range
01fea64
initial directory structure organization
hbraswelrh ec67718
feat: initial work on config and common options
gvauter a1984a5
chore: add openssf scorecard workflow (#359)
jpower432 cc569d5
build(deps): bump compliance-trestle from 3.4.0 to 3.5.0 (#380)
dependabot[bot] c5b9418
feat: adds logic to load yaml config into click context to set defaut…
gvauter c6a2569
feat: adds debug logging statements
gvauter 78fd113
feat: add markdown directory creation and call to compliance trestle …
gvauter 6be37e8
feat: simplify directory creation and better error handling for inval…
gvauter 45fc4b8
feat: initial work on autosync
qduanmu a239482
Initial create command for click cli
hbraswelrh 5931b5c
Initial create command for click cli
hbraswelrh 1ba1010
adding unit test for config module
gvauter 7645fbe
adding unit test for config module
gvauter 268c558
Update autosync command
qduanmu 823e5bc
Update autosync command
qduanmu 000e26e
feat: add ssp index option
gvauter 5aeb27d
feat: add ssp index option
gvauter 362faf1
add unit tests for init command
gvauter 75fd0c1
add unit tests for init command
gvauter 59da2c8
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter 7f266f0
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter 1382cdc
feat: root call create and logging replacement
hbraswelrh 3292aa5
feat: root call create and logging replacement
hbraswelrh 0a12ef9
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh 89de0ce
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh d41e017
feat: add upstream commands, fix common options decorators, expand co…
gvauter b172bcf
feat: add upstream commands, fix common options decorators, expand co…
gvauter 0a1c0cd
Update autosync options and add tests
qduanmu c4a90a8
Update autosync options and add tests
qduanmu 05cb60a
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh d3b7215
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh 3725e7e
docs: adr-001 cli implementation (#347)
gvauter ed11e85
feat: add logic to make_config for nested upstream model and update r…
gvauter 8f34874
feat: add logic to make_config for nested upstream model and update r…
gvauter 2a3845d
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter f50c39d
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter b3ba8de
feat: create command logic for compdef and ssp
hbraswelrh ffae2e8
feat: create command logic for compdef and ssp
hbraswelrh 3b63750
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh b97d7fa
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh 9284ad8
feat: create command updates to prompts and logger messages
hbraswelrh 92092a7
feat: create command updates to prompts and logger messages
hbraswelrh 3c13ad6
feat: add default git info to init prompts and config
gvauter 3a9a7c3
feat: add default git info to init prompts and config
gvauter a4dbaa6
fix hidden keep file creation
gvauter 7d3b9e3
fix hidden keep file creation
gvauter 1206a16
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter 1b5566e
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter 8fe0747
Add rule-transform command and unit test
qduanmu 4484a56
Add rule-transform command and unit test
qduanmu 74dd43d
feat: create command logic and adding unit tests
hbraswelrh 17d524a
feat: create command logic and adding unit tests
hbraswelrh c628013
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh cf044da
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh d21f5f6
Fix AttributeError, some misc updates
qduanmu df0e5d2
Fix AttributeError, some misc updates
qduanmu aef085f
feat: unit tests added for create command
hbraswelrh dbf9fa2
feat: unit tests added for create command
hbraswelrh 7bca6cd
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter 40d6009
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter 486ad1e
Fix AttributeError, some misc updates
qduanmu fb36a11
Fix AttributeError, some misc updates
qduanmu 742cef9
feat: unit tests added for create command
hbraswelrh 026657c
feat: unit tests added for create command
hbraswelrh f9a2bca
fix: docstrings added for create command unit tests
hbraswelrh ee0feec
fix: docstrings added for create command unit tests
hbraswelrh 8f68749
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter 39ebbab
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter ec2d3f6
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter f439a6e
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter 9164f41
fix: docstrings added for create unit tests
hbraswelrh fc49a30
fix: docstrings added for create unit tests
hbraswelrh ef31702
add file pattern filter
gvauter 39ded49
add file pattern filter
gvauter f352487
fix: updated headers with license and copyright
hbraswelrh 3c094d2
fix: updated headers with license and copyright
hbraswelrh 9fd8c3b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh d31e2c0
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh 170cfbc
fix: updated logger statements
hbraswelrh afa3f8e
fix: updated logger statements
hbraswelrh fa13754
fix: logger statements shortened
hbraswelrh a11615f
fix: logger statements shortened
hbraswelrh 0ca9439
fix: yaml default deletion
hbraswelrh 799b0ec
fix: yaml default deletion
hbraswelrh 99915e4
docs: updates to reference the CLI commands in the README.md
hbraswelrh a44aa80
docs: updates to reference the CLI commands in the README.md
hbraswelrh f9feb88
feat: update for required ssp name
hbraswelrh 8dbe4e3
feat: update for required ssp name
hbraswelrh 91d115c
Update trestlebot/cli/commands/init.py
gvauter d6356c0
Update trestlebot/cli/commands/init.py
gvauter c6b5560
Update trestlebot/cli/commands/init.py
gvauter cba3776
Update trestlebot/cli/commands/init.py
gvauter 5f456a8
fix typo in error msg
gvauter f72483d
fix typo in error msg
gvauter 7bac602
fix help text for sync upstreams
gvauter f8c12b7
fix help text for sync upstreams
gvauter fa1466c
fix: update for help text and testing location errors
hbraswelrh 8133f73
fix: update for help text and testing location errors
hbraswelrh d1cbc0b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh 2df503b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh be89e66
fix: update for clarity on profile name for trestle workspace
hbraswelrh 4c5a7e2
fix: update for clarity on profile name for trestle workspace
hbraswelrh f6fcf2d
Fix AssertionError, add missing register
qduanmu 1669ea8
Fix AssertionError, add missing register
qduanmu e09b455
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh 562da56
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh 80cd9cc
fix: profile name prompting update
hbraswelrh 4226a86
fix: profile name prompting update
hbraswelrh 877ac9a
feat: updating compdef list to required
hbraswelrh 66f55c7
feat: updating compdef list to required
hbraswelrh db34e53
docs: change of verbiage for readability
hbraswelrh dfc0aba
docs: change of verbiage for readability
hbraswelrh 5c5a17a
docs: change to indicate trestle-bot as a cli tool
hbraswelrh 230568d
docs: change to indicate trestle-bot as a cli tool
hbraswelrh 0e31aa8
feat: change to help description of create command
hbraswelrh 143b92a
feat: change to help description of create command
hbraswelrh 88da512
docs: added high level folder structure for cli
hbraswelrh 553ad1d
docs: added high level folder structure for cli
hbraswelrh 7711aec
fix: default value returned if no key in dictionary
hbraswelrh b3b8ebd
fix: default value returned if no key in dictionary
hbraswelrh 826a8f5
feat: align skip-item option to skip-items
qduanmu 5144e10
feat: align skip-item option to skip-items
qduanmu 84c38ba
fix: add missing git options in create command
qduanmu 06e574b
fix: add missing git options in create command
qduanmu ddff735
fix: refactor testt and remove prompts
gvauter 6e28c41
fix: refactor testt and remove prompts
gvauter e47dca5
fix: formatting issues and typos
gvauter f125d5f
fix: formatting issues and typos
gvauter fd2f738
chore: merge latest from main and fix conflicts
gvauter 3b95d76
chore: merge latest from main and fix conflicts
gvauter 954d38a
chore: update poetry lock with latest dependencies
gvauter 586bfca
chore: update poetry lock with latest dependencies
gvauter 1f6f6c6
fix: do not overwrite config path if set
gvauter ceb084c
fix: do not overwrite config path if set
gvauter 769d0df
fix: do not overwrite config path if set
gvauter 18eaf09
fix: do not overwrite config path if set
gvauter 32a4132
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,90 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
|
||
|
||
"""Testing module for trestlebot autosync command""" | ||
import pathlib | ||
from typing import Tuple | ||
|
||
from click.testing import CliRunner | ||
from git import Repo | ||
|
||
from trestlebot.cli.commands.autosync import autosync_cmd | ||
from trestlebot.cli.config import TrestleBotConfig, write_to_file | ||
|
||
|
||
def test_invalid_oscal_model(tmp_repo: Tuple[str, Repo]) -> None: | ||
"""Test invalid OSCAl model option.""" | ||
|
||
repo_path, _ = tmp_repo | ||
runner = CliRunner() | ||
result = runner.invoke( | ||
autosync_cmd, | ||
[ | ||
"--oscal-model", | ||
"invalid", | ||
"--repo-path", | ||
repo_path, | ||
"--markdown-dir", | ||
"markdown", | ||
"--branch", | ||
"main", | ||
"--committer-name", | ||
"Test User", | ||
"--committer-email", | ||
"[email protected]", | ||
], | ||
) | ||
assert "Invalid value for '--oscal-model'" in result.output | ||
assert result.exit_code == 2 | ||
|
||
|
||
def test_missing_ssp_index_file_option(tmp_repo: Tuple[str, Repo]) -> None: | ||
"""Test missing ssp_index_file option for autosync ssp.""" | ||
repo_path, _ = tmp_repo | ||
runner = CliRunner() | ||
cmd_options = [ | ||
"--oscal-model", | ||
"ssp", | ||
"--repo-path", | ||
repo_path, | ||
"--markdown-dir", | ||
"markdown", | ||
"--branch", | ||
"main", | ||
"--committer-name", | ||
"Test User", | ||
"--committer-email", | ||
"[email protected]", | ||
] | ||
result = runner.invoke(autosync_cmd, cmd_options) | ||
assert result.exit_code == 1 | ||
assert "Missing option '--ssp-index-file'" in result.output | ||
|
||
|
||
def test_missing_markdown_dir_option(tmp_repo: Tuple[str, Repo]) -> None: | ||
repo_path, _ = tmp_repo | ||
runner = CliRunner() | ||
cmd_options = [ | ||
"--oscal-model", | ||
"compdef", | ||
"--repo-path", | ||
repo_path, | ||
"--branch", | ||
"main", | ||
"--committer-name", | ||
"Test User", | ||
"--committer-email", | ||
"[email protected]", | ||
] | ||
result = runner.invoke(autosync_cmd, cmd_options) | ||
assert result.exit_code == 2 | ||
assert "Error: Missing option '--markdown-dir'" in result.output | ||
|
||
# With 'markdown_dir' setting in config.yml | ||
config_obj = TrestleBotConfig(markdown_dir="markdown") | ||
filepath = pathlib.Path(repo_path).joinpath("config.yml") | ||
write_to_file(config_obj, filepath) | ||
cmd_options += ["--config", str(filepath)] | ||
result = runner.invoke(autosync_cmd, cmd_options) | ||
assert result.exit_code == 0 |
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,80 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
|
||
|
||
"""Unit tests for CLI config module""" | ||
import pathlib | ||
|
||
import pytest | ||
import yaml | ||
|
||
from trestlebot.cli.config import ( | ||
TrestleBotConfig, | ||
TrestleBotConfigError, | ||
UpstreamsConfig, | ||
load_from_file, | ||
make_config, | ||
write_to_file, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def config_obj() -> TrestleBotConfig: | ||
return TrestleBotConfig( | ||
repo_path="/tmp", | ||
markdown_dir="markdown", | ||
upstreams=UpstreamsConfig(sources=["repo@main"]), | ||
) | ||
|
||
|
||
def test_invalid_config_raises_errors() -> None: | ||
"""Test create config with invalid directory to raise error.""" | ||
|
||
with pytest.raises(TrestleBotConfigError) as ex: | ||
_ = make_config(dict(repo_path="0")) | ||
|
||
assert ( | ||
str(ex.value) | ||
== "Invalid config value for repo_path. Path does not point to a directory." | ||
) | ||
|
||
|
||
def test_make_config_raises_no_errors(tmp_init_dir: str) -> None: | ||
"""Test create a valid config object.""" | ||
values = { | ||
"repo_path": tmp_init_dir, | ||
"markdown_dir": "markdown", | ||
"committer_name": "committer-name", | ||
"committer_email": "committer-email", | ||
"upstreams": {"sources": ["https://test@main"], "skip_validation": True}, | ||
} | ||
config = make_config(values) | ||
assert isinstance(config, TrestleBotConfig) | ||
assert config.upstreams is not None | ||
assert config.upstreams.sources == ["https://test@main"] | ||
assert config.upstreams.skip_validation is True | ||
assert config.repo_path == pathlib.Path(tmp_init_dir) | ||
assert config.markdown_dir == values["markdown_dir"] | ||
assert config.committer_name == values["committer_name"] | ||
assert config.committer_email == values["committer_email"] | ||
|
||
|
||
def test_config_write_to_file(config_obj: TrestleBotConfig, tmp_init_dir: str) -> None: | ||
"""Test config is written to yaml file.""" | ||
filepath = pathlib.Path(tmp_init_dir).joinpath("config.yml") | ||
write_to_file(config_obj, filepath) | ||
with open(filepath, "r") as f: | ||
yaml_data = yaml.safe_load(f) | ||
|
||
assert yaml_data == config_obj.to_yaml_dict() | ||
|
||
|
||
def test_config_load_from_file(config_obj: TrestleBotConfig, tmp_init_dir: str) -> None: | ||
"""Test config is read from yaml file into config object.""" | ||
filepath = pathlib.Path(tmp_init_dir).joinpath("config.yml") | ||
with filepath.open("w") as config_file: | ||
yaml.dump(config_obj.to_yaml_dict(), config_file) | ||
|
||
config = load_from_file(filepath) | ||
assert isinstance(config, TrestleBotConfig) | ||
assert config == config_obj |
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,134 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
|
||
""" Unit test for create commands ssp and cd""" | ||
|
||
from click.testing import CliRunner | ||
|
||
from trestlebot.cli.commands.create import create_cmd | ||
|
||
|
||
def test_invalid_create_cmd() -> None: | ||
"""Tests that create command fails if given invalid oscal model subcommand.""" | ||
runner = CliRunner() | ||
result = runner.invoke(create_cmd, ["invalid"]) | ||
|
||
assert "Error: No such command 'invalid'" in result.output | ||
assert result.exit_code == 2 | ||
|
||
|
||
def test_create_ssp_cmd(tmp_init_dir: str) -> None: | ||
"""Tests successful create ssp command.""" | ||
SSP_INDEX_FILE = "tester-ssp-index.json" | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
create_cmd, | ||
[ | ||
"ssp", | ||
"--profile-name", | ||
"oscal-profile-name", | ||
"--markdown-dir", | ||
"markdown", | ||
"--ssp-name", | ||
"test-name", | ||
"--repo-path", | ||
tmp_init_dir, | ||
"--ssp-index-file", | ||
SSP_INDEX_FILE, | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
|
||
def test_create_compdef_cmd(tmp_init_dir: str) -> None: | ||
"""Tests successful create compdef command.""" | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
create_cmd, | ||
[ | ||
"compdef", | ||
"--profile-name", | ||
"oscal-profile-name", | ||
"--compdef-name", | ||
"test-name", | ||
"--component-title", | ||
"title-test", | ||
"--component-description", | ||
"description-test", | ||
"--component-definition-type", | ||
"type-test", | ||
"repo-path", | ||
tmp_init_dir, | ||
], | ||
) | ||
assert result.exit_code == 2 | ||
|
||
|
||
def test_default_ssp_index_file_cmd(tmp_init_dir: str) -> None: | ||
"""Tests successful default ssp_index.json file creation.""" | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
create_cmd, | ||
[ | ||
"ssp", | ||
"--profile-name", | ||
"oscal-profile-name", | ||
"--markdown-dir", | ||
"markdown", | ||
"--ssp-name", | ||
"test-name", | ||
"--repo-path", | ||
tmp_init_dir, | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
|
||
def test_markdown_files_not_created(tmp_init_dir: str) -> None: | ||
"""Tests failure of markdown file creation when not supplied with directory name.""" | ||
SSP_INDEX_TESTER = "ssp-tester.index.json" | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
create_cmd, | ||
[ | ||
"ssp", | ||
"--profile-name", | ||
"oscal-profile-name", | ||
"--ssp-name", | ||
"test-name", | ||
"repo-path", | ||
tmp_init_dir, | ||
"--ssp-index-file", | ||
SSP_INDEX_TESTER, | ||
], | ||
) | ||
assert result.exit_code == 2 | ||
|
||
|
||
def test_markdown_files_created(tmp_init_dir: str) -> None: | ||
"""Tests successful creation of markdown files.""" | ||
SSP_INDEX_TESTER = "ssp-tester.index.json" | ||
markdown_file_tester = "/markdown/system-security-plan.md" | ||
hbraswelrh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
create_cmd, | ||
[ | ||
"ssp", | ||
"--profile-name", | ||
"oscal-profile-name", | ||
"--markdown-dir", | ||
markdown_file_tester, | ||
"--ssp-name", | ||
"test-name", | ||
"--repo-path", | ||
tmp_init_dir, | ||
"--ssp-index-file", | ||
SSP_INDEX_TESTER, | ||
], | ||
) | ||
assert result.exit_code == 0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected exit_code is 2? Is there any context I missed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the arguments,
'--committer-email'
,'--committer-name'
and'--branch'
could be added;repo-path
could be updated to--repo-path
;the
assert result.exit_code == 2could be
result.exit_code == 0 `.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@huiwangredhat yes, you are correct, this should have a successful exit code since test expects it work correctly.