Skip to content

Commit

Permalink
add docstrings, lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
rndmh3ro committed Aug 25, 2023
1 parent 38764c9 commit 6a73225
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@

import settings

# we cannot use annotations-based diffbase_storage
# because kopf creates a annotation that contains the last applied
# state. this anootation will be too large too handle for k8s and cannot
# be added to the object.

@kopf.on.startup()
def configure(settings: kopf.OperatorSettings, **_):
"""
This function tells kopf to use the StatusDiffBaseStorage instead
of the annotations-based storage, because the annotation will get too large
for k8s to handle. see: https://github.com/kubernetes-sigs/kubebuilder/issues/2556
"""
settings.persistence.diffbase_storage = kopf.MultiDiffBaseStorage(
[
kopf.StatusDiffBaseStorage(field="status.diff-base"),
]
)


labels: dict = {}
if settings.LABEL and settings.LABEL_VALUE:
labels={settings.LABEL: settings.LABEL_VALUE}
labels = {settings.LABEL: settings.LABEL_VALUE}
else:
labels={}
labels = {}

@kopf.on.create(
"vulnerabilityreports.aquasecurity.github.io",
labels=labels
)

@kopf.on.create("vulnerabilityreports.aquasecurity.github.io", labels=labels)
def send_to_dojo(body, meta, logger, **_):
"""
The main function that creates a report-file from the trivy-operator vulnerabilityreport
and sends it to the defectdojo instance.
"""

logger.info(f"Working on {meta['name']}")

Expand Down Expand Up @@ -75,7 +81,9 @@ def send_to_dojo(body, meta, logger, **_):
)
response.raise_for_status()
except HTTPError as http_err:
raise kopf.PermanentError(f"HTTP error occurred: {http_err} - {response.content}")
raise kopf.PermanentError(
f"HTTP error occurred: {http_err} - {response.content}"
)
except Exception as err:
raise kopf.PermanentError(f"Other error occurred: {err}")
else:
Expand Down

0 comments on commit 6a73225

Please sign in to comment.