Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ If a monitoring list with the same name already exists, it gets overwritten with
vilocify monitoringlist import --name "My Project v1.2.3" --from-cyclonedx my_project_v1.2.3.sbom.json
```

### Example: Tenant with group feature enabled
If the example above gave you the error `Organization group must exist`, you must specify the `--group` parameter on import.
Valid values for `--group` can be listed with `vilocify groups`.
```bash
vilocify monitoringlist import --name "My Project v1.2.3" --group "ABC" --from-cyclonedx my_project_v1.2.3.sbom.json
```

## SDK usage
The SDK is built on Vilocify's API.
We recommend you also take a quick look at the raw API docs at https://portal.vilocify.com/documentation.
Expand Down
20 changes: 16 additions & 4 deletions vilocify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from vilocify.models import (
Component,
ComponentRequest,
Group,
MonitoringList,
Notification,
Vulnerability,
Expand Down Expand Up @@ -132,11 +133,11 @@ def _load_bom(file: io.FileIO) -> Bom:
return bom


def _load_ml(name: str, comment: str) -> MonitoringList:
def _load_ml(name: str, comment: str, group: str | None) -> MonitoringList:
ml = MonitoringList.where("name", "eq", name).where("comment", "eq", comment).first()
if ml is None:
logger.info("No monitoring list with given name and comment found. Creating new list.")
ml = MonitoringList(name=name, comment=comment)
ml = MonitoringList(name=name, comment=comment, group=group)
ml.create()

logger.info("Using monitoring list %s", ml.id)
Expand Down Expand Up @@ -190,9 +191,10 @@ def monitoringlist_show(monitoring_list_id: str, export_format: str):
@monitoringlist.command("import")
@click.option("--name", required=True, help="The monitoring list name.")
@click.option("--comment", default="", help="The comment set for the monitoring list.")
@click.option("--group", help="The group of the monitoring list, in case a new list is created.")
@click.option("--yes", is_flag=True, help="Skip interactive questions. Assumes 'yes' for all answers.")
@click.option("--from-cyclonedx", type=click.File("rt"), required=True, help="The CycloneDX file to import.")
def monitoringlist_import(name: str, comment: str, yes: bool, from_cyclonedx: io.FileIO):
def monitoringlist_import(name: str, comment: str, group: str | None, yes: bool, from_cyclonedx: io.FileIO):
"""Creates or updates a monitoring list from a CycloneDX JSON or XML file.

The monitoring list is identified by the given name and comment. Changing the name or comment between runs will
Expand All @@ -205,7 +207,7 @@ def monitoringlist_import(name: str, comment: str, yes: bool, from_cyclonedx: io

component_requests = []
bom = _load_bom(from_cyclonedx)
ml = _load_ml(name, comment)
ml = _load_ml(name, comment, group)
components_cache = {(c.name, c.version): c for c in ml.components}
components, unidentified_components = _match_bom(components_cache, bom)

Expand Down Expand Up @@ -261,6 +263,16 @@ def component_request(state: tuple[str]):
print()


@cli.command()
def groups():
"""List groups available on the current tenant.

This lists the names of groups that are visible to the current membership.
"""
for group in Group.asc("name"):
print(group.name)


def main():
try:
exit_code = cli.main(standalone_mode=False)
Expand Down
6 changes: 6 additions & 0 deletions vilocify/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ class Subscription(Model):

membership = RelationshipToOne(Membership)
monitoring_list = RelationshipToOne(MonitoringList)


class Group(Model):
name = Attribute[str]("name")
created_at = Attribute[str]("createdAt")
updated_at = Attribute[str]("updatedAt")
Loading