-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds GitHub Action to create a new profile with inputs
Signed-off-by: Jennifer Power <[email protected]>
- Loading branch information
Showing
4 changed files
with
148 additions
and
5 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,21 @@ | ||
name: "setup-trestle" | ||
description: "Composite action to setup trestle." | ||
|
||
inputs: | ||
python-version: | ||
required: false | ||
description: "The python version to use" | ||
default: "3.11" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
|
||
- name: Install dependencies | ||
run: make trestle-install | ||
shell: bash |
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,64 @@ | ||
name: Profile Create | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
import_type: | ||
type: choice | ||
description: Import type | ||
options: | ||
- catalog | ||
- profile | ||
import_name: | ||
required: true | ||
description: Name of profile or catalog in trestle workspace to be imported | ||
output: | ||
required: true | ||
description: Name of the profile to create | ||
|
||
|
||
jobs: | ||
create-profile: | ||
name: Create profile | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Generate app token | ||
uses: tibdex/github-app-token@v1 | ||
id: get_installation_token | ||
with: | ||
app_id: ${{ secrets.APP_ID }} | ||
private_key: ${{ secrets.PRIVATE_KEY }} | ||
permissions: >- | ||
{"contents": "write", "pull_requests": "write"} | ||
- name: Clone | ||
uses: actions/checkout@v3 | ||
with: | ||
token: ${{ steps.get_installation_token.outputs.token }} | ||
- name: Setup trestle | ||
uses: ./.github/actions/setup-trestle | ||
with: | ||
python-version: "3.8" | ||
- name: Create new profile with imports | ||
run: | | ||
echo "Creating profile with name ${OUTPUT}" | ||
trestle create --type profile --output "${OUTPUT}" | ||
trestle href --name "${OUTPUT}" -hr "trestle://${IMPORT_TYPE}s/${IMPORT_NAME}/${IMPORT_TYPE}.json" | ||
echo "Normalizing profile fields" | ||
trestle create --type profile -e profile.imports.0.include-all -f "profiles/${OUTPUT}/profile.json" | ||
python3 scripts/set_default_profile.py --profile_name "${OUTPUT}" --trestle_root . | ||
env: | ||
OUTPUT: ${{ github.event.inputs.output }} | ||
IMPORT_NAME: ${{ github.event.inputs.import_name }} | ||
IMPORT_TYPE: ${{ github.event.inputs.import_type }} | ||
- name: Generate and PR new profile | ||
id: generate-profile | ||
uses: RedHatProductSecurity/trestle-bot@main | ||
with: | ||
markdown_path: "markdown/profiles" | ||
oscal_model: "profile" | ||
branch: "profile-create-${{ github.run_id }}" | ||
target_branch: "main" | ||
file_pattern: "*.json,markdown/*" | ||
skip_items: "fedramp_rev5_high" | ||
skip_assemble: true | ||
github_token: ${{ steps.get_installation_token.outputs.token }} |
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,60 @@ | ||
#!/usr/bin/env python3 | ||
# set_default_profile.py | ||
|
||
# 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. | ||
|
||
""" | ||
Read in a profile created by trestle and set up default profile fields | ||
Author: Jenn Power <[email protected]> | ||
""" | ||
|
||
import argparse | ||
import pathlib | ||
|
||
import trestle.core.generators as gens | ||
import trestle.oscal.profile as prof | ||
from trestle.common.load_validate import load_validate_model_name | ||
from trestle.common.model_utils import ModelUtils | ||
from trestle.core.models.file_content_type import FileContentType | ||
|
||
def main(): | ||
p = argparse.ArgumentParser(description="Set default profile fields") | ||
p.add_argument("--profile_name", required=True) | ||
p.add_argument("--trestle_root", required=True) | ||
args = p.parse_args() | ||
|
||
trestle_root: pathlib.Path = pathlib.Path(args.trestle_root) | ||
profile_data, _ = load_validate_model_name( | ||
trestle_root, args.profile_name, prof.Profile | ||
) | ||
|
||
# Set up default values for merge settings. | ||
merge_object: prof.Merge = gens.generate_sample_model(prof.Merge) | ||
combine_object: prof.Combine = gens.generate_sample_model(prof.Combine) | ||
combine_object.method = prof.Method.merge | ||
merge_object.combine = combine_object | ||
merge_object.as_is = True | ||
|
||
profile_data.merge = merge_object | ||
|
||
ModelUtils.update_last_modified(profile_data) | ||
ModelUtils.save_top_level_model( | ||
profile_data, trestle_root, args.profile_name, FileContentType.JSON | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |