Skip to content

Commit

Permalink
Merge pull request #36 from jpower432/feat/create-cd
Browse files Browse the repository at this point in the history
feat: adds Action to created basic component definition JSON
  • Loading branch information
Alex Flom authored Jul 20, 2023
2 parents 58a05a0 + 8154037 commit f55db1b
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/create-new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Component Definitions Create
on:
workflow_dispatch:
inputs:
import_name:
required: true
description: Name of profile in trestle workspace to be imported
output:
required: true
description: Name of the component definition to create
component_name:
required: true
description: Name of the component in the generated component definition
component_description:
required: true
description: Description of the component in the generated component definition



jobs:
create-component:
name: Create component definition
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:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
run: make trestlebot-install
- name: Create new component definition with imports
run: |
python3 scripts/set_default_comp.py --profile_name "${IMPORT_NAME}" \
--compdef_name "${OUTPUT}" --comp_title "${COMP_NAME}" --comp_description "${COMP_DESCRIPTION}" --trestle_root .
env:
OUTPUT: ${{ github.event.inputs.output }}
IMPORT_NAME: ${{ github.event.inputs.import_name }}
COMP_NAME: ${{ github.event.inputs.component_name }}
COMP_DESCRIPTION: ${{ github.event.inputs.component_description }}
- name: Generate and PR new component definition
id: generate-cd
uses: RedHatProductSecurity/trestle-bot@main
with:
markdown_path: "markdown/components"
oscal_model: "compdef"
branch: "component-create-${{ github.run_id }}"
target_branch: "main"
file_pattern: "*.json,markdown/*"
skip_assemble: true
commit_user_name: "trestle-bot[bot]"
commit_user_email: "136850459+trestle-bot[bot]@users.noreply.github.com"
github_token: ${{ steps.get_installation_token.outputs.token }}
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ update-cds:
.PHONY: update-cd

check-csv:
@bash scripts/csv_sanity_check.sh
@bash scripts/csv_sanity_check.sh

trestlebot-install:
@python3 -m pip install --upgrade pip setuptools && python3 -m pip install -r requirements.txt
.PHONY: trestlebot-install
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trestlebot @ git+https://github.com/RedHatProductSecurity/trestle-bot@main
193 changes: 193 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile requirements.in
#
anyio==3.7.1
# via httpcore
argcomplete==3.1.1
# via datamodel-code-generator
attrs==23.1.0
# via
# compliance-trestle
# jsonschema
bcrypt==4.0.1
# via paramiko
black==23.7.0
# via datamodel-code-generator
certifi==2023.5.7
# via
# httpcore
# httpx
# requests
cffi==1.15.1
# via
# cmarkgfm
# cryptography
# pynacl
chardet==5.1.0
# via prance
charset-normalizer==3.2.0
# via requests
click==8.1.6
# via black
cmarkgfm==0.6.0
# via compliance-trestle
compliance-trestle==2.2.1
# via trestlebot
cryptography==41.0.2
# via
# compliance-trestle
# paramiko
# pyjwt
datamodel-code-generator[http]==0.21.1
# via compliance-trestle
defusedxml==0.7.1
# via compliance-trestle
dnspython==2.4.0
# via email-validator
email-validator==2.0.0.post2
# via pydantic
et-xmlfile==1.1.0
# via openpyxl
exceptiongroup==1.1.2
# via anyio
furl==2.1.3
# via compliance-trestle
genson==1.2.2
# via datamodel-code-generator
gitdb==4.0.10
# via gitpython
github3-py==4.0.1
# via trestlebot
gitpython==3.1.32
# via trestlebot
h11==0.14.0
# via httpcore
httpcore==0.17.3
# via
# dnspython
# httpx
httpx==0.24.1
# via datamodel-code-generator
idna==3.4
# via
# anyio
# email-validator
# httpx
# requests
ilcli==0.3.2
# via compliance-trestle
inflect==5.6.2
# via datamodel-code-generator
isort==5.12.0
# via datamodel-code-generator
jinja2==3.1.2
# via
# compliance-trestle
# datamodel-code-generator
jsonschema==4.17.3
# via
# jsonschema-spec
# openapi-schema-validator
# openapi-spec-validator
jsonschema-spec==0.1.6
# via openapi-spec-validator
lazy-object-proxy==1.9.0
# via openapi-spec-validator
markupsafe==2.1.3
# via jinja2
mypy-extensions==1.0.0
# via black
openapi-schema-validator==0.4.4
# via openapi-spec-validator
openapi-spec-validator==0.5.2
# via datamodel-code-generator
openpyxl==3.1.2
# via compliance-trestle
orderedmultidict==1.0.1
# via furl
orjson==3.9.2
# via compliance-trestle
packaging==23.1
# via
# black
# datamodel-code-generator
# prance
paramiko==3.2.0
# via compliance-trestle
pathable==0.4.3
# via jsonschema-spec
pathspec==0.11.1
# via black
platformdirs==3.9.1
# via black
prance==23.6.21.0
# via datamodel-code-generator
pycparser==2.21
# via cffi
pydantic[email]==1.10.11
# via
# compliance-trestle
# datamodel-code-generator
pyjwt[crypto]==2.8.0
# via github3-py
pynacl==1.5.0
# via paramiko
pyrsistent==0.19.3
# via jsonschema
pysnooper==1.2.0
# via datamodel-code-generator
python-dateutil==2.8.2
# via github3-py
python-dotenv==1.0.0
# via compliance-trestle
python-frontmatter==1.0.0
# via compliance-trestle
pyyaml==6.0.1
# via
# jsonschema-spec
# python-frontmatter
requests==2.31.0
# via
# github3-py
# jsonschema-spec
# prance
rfc3339-validator==0.1.4
# via openapi-schema-validator
ruamel-yaml==0.17.32
# via
# compliance-trestle
# prance
ruamel-yaml-clib==0.2.7
# via ruamel-yaml
six==1.16.0
# via
# furl
# orderedmultidict
# prance
# python-dateutil
# rfc3339-validator
smmap==5.0.0
# via gitdb
sniffio==1.3.0
# via
# anyio
# dnspython
# httpcore
# httpx
toml==0.10.2
# via datamodel-code-generator
tomli==2.0.1
# via black
trestlebot @ git+https://github.com/RedHatProductSecurity/trestle-bot@main
# via -r requirements.in
typing-extensions==4.7.1
# via
# black
# pydantic
uritemplate==4.1.1
# via github3-py
urllib3==2.0.4
# via requests
50 changes: 50 additions & 0 deletions scripts/set_default_comp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
# set_default_comp.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 component definitions and set default fields
Author: Jenn Power <[email protected]>
"""

import argparse

from trestlebot.tasks.authored.compdef import AuthoredComponentsDefinition


def main():
p = argparse.ArgumentParser(description="Set default component fields")
p.add_argument("--profile_name", required=True)
p.add_argument("--compdef_name", required=True)
p.add_argument("--comp_title", required=True)
p.add_argument("--comp_description", required=True)
p.add_argument("--trestle_root", required=True)
args = p.parse_args()

authored_comp = AuthoredComponentsDefinition(args.trestle_root)

authored_comp.create_new_default(
args.profile_name,
args.compdef_name,
args.comp_title,
args.comp_description,
"service",
)


if __name__ == "__main__":
main()

0 comments on commit f55db1b

Please sign in to comment.