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
3 changes: 1 addition & 2 deletions conf/reposcan.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ SYNC_REPO_LIST_SOURCE=manual
# (optional) - disable some particular data sync
SYNC_REPOS=yes
SYNC_CVE_MAP=yes
SYNC_CPE=yes
SYNC_CSAF=yes
SYNC_CSAF=yes # CPE sync is included in CSAF sync
SYNC_RELEASES=yes
SYNC_RELEASE_GRAPH=yes

Expand Down
59 changes: 16 additions & 43 deletions vmaas/reposcan/reposcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ class RepoListSource(StrEnum):
# Allow to optionally disable some parts of sync (e.g. to speed up testing)
SYNC_REPOS = strtobool(os.getenv("SYNC_REPOS", "yes"))
SYNC_CVE_MAP = strtobool(os.getenv("SYNC_CVE_MAP", "yes"))
SYNC_CPE = strtobool(os.getenv("SYNC_CPE", "yes"))
SYNC_CSAF = strtobool(os.getenv("SYNC_CSAF", "yes"))
SYNC_CSAF = strtobool(os.getenv("SYNC_CSAF", "yes")) # CPE sync is included in CSAF sync
SYNC_RELEASES = strtobool(os.getenv("SYNC_RELEASES", "yes"))
SYNC_RELEASE_GRAPH = strtobool(os.getenv("SYNC_RELEASE_GRAPH", "yes"))
REPO_SYNC_QUEUE_INTERVAL_MINUTES = int(os.getenv("REPO_SYNC_QUEUE_INTERVAL_MINUTES", "5"))
Expand Down Expand Up @@ -881,69 +880,44 @@ def run_task(*args, **kwargs):
return "OK"


class CpeSyncHandler(SyncHandler):
"""Handler for Cpe sync API."""

task_type = "Sync CPE metadata"

@classmethod
def put(cls, **kwargs):
"""Sync CPE metadata."""

status_code, status_msg = cls.start_task()
return status_msg, status_code

@staticmethod
def run_task(*args, **kwargs):
"""Function to start syncing all CVEs."""
try:
init_logging()
init_db()
controller = CpeController()
controller.store()
except Exception as err: # pylint: disable=broad-except
msg = "Internal server error <%s>" % hash(err)
LOGGER.exception(msg)
FAILED_IMPORT_CPE.inc()
DatabaseHandler.rollback()
if isinstance(err, DatabaseError):
return "DB_ERROR"
return "ERROR"
finally:
DatabaseHandler.close_connection()
return "OK"


def metrics():
"""Generate Prometheus metrics."""
return generate_latest(REGISTRY), 200, {'Content-Type': 'text/plain; charset=utf-8'}


class CsafSyncHandler(SyncHandler):
"""Handler for CSAF sync API."""
"""Handler for CPE + CSAF sync API."""

task_type = "Sync CSAF metadata"
task_type = "Sync CPE + CSAF metadata"

@classmethod
def put(cls, sync_all=False, **kwargs):
"""Sync CSAF metadata."""
"""Sync CPE + CSAF metadata."""

status_code, status_msg = cls.start_task(sync_all=sync_all)
return status_msg, status_code

@staticmethod
def run_task(*args, **kwargs):
"""Function to start syncing CSAFs."""
"""Function to start syncing CPEs and CSAFs."""
stage = "init"
try:
sync_all = kwargs.get("sync_all", False)
init_logging()
init_db()
stage = "CPE"
cpe_controller = CpeController()
cpe_controller.store()
stage = "CSAF"
controller = CsafController()
controller.store(sync_all=sync_all)
except Exception as err: # pylint: disable=broad-except
Comment thread
jdobes marked this conversation as resolved.
msg = "Internal server error <%s>" % hash(err)
msg = "Internal server error (%s) <%s>" % (stage, hash(err))
LOGGER.exception(msg)
CSAF_FAILED_IMPORT.inc()
if stage == "CPE":
FAILED_IMPORT_CPE.inc()
else:
CSAF_FAILED_IMPORT.inc()
DatabaseHandler.rollback()
if isinstance(err, DatabaseError):
return "DB_ERROR"
Expand Down Expand Up @@ -1046,8 +1020,7 @@ def all_sync_handlers() -> list:
handlers.extend([KatelloRepoListHandler] if SYNC_REPO_LIST_SOURCE == RepoListSource.KATELLO else []) # type: ignore[list-item]
handlers.extend([RepoSyncHandler] if SYNC_REPOS else []) # type: ignore[list-item]
handlers.extend([CvemapSyncHandler] if SYNC_CVE_MAP else []) # type: ignore[list-item]
handlers.extend([CpeSyncHandler] if SYNC_CPE else []) # type: ignore[list-item]
handlers.extend([CsafSyncHandler] if SYNC_CSAF else []) # type: ignore[list-item]
handlers.extend([CsafSyncHandler] if SYNC_CSAF else []) # type: ignore[list-item] # CPE is included in CSAF sync
handlers.extend([ReleaseSyncHandler] if SYNC_RELEASES else []) # type: ignore[list-item]
handlers.extend([ReleaseGraphSyncHandler] if SYNC_RELEASE_GRAPH else []) # type: ignore[list-item]
return handlers
Expand Down
12 changes: 1 addition & 11 deletions vmaas/reposcan/reposcan.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,9 @@ paths:
tags:
- Sync

/sync/cpe:
put:
summary: Sync CPE metadata
operationId: vmaas.reposcan.reposcan.CpeSyncHandler.put
<<: *secured
responses:
<<: *sync_responses
tags:
- Sync

/sync/csaf:
put:
summary: Sync CSAF metadata
summary: Sync CPE + CSAF metadata
operationId: vmaas.reposcan.reposcan.CsafSyncHandler.put
<<: *secured
parameters:
Expand Down
Loading