Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importer & Split task CLI in two command lines #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions fedcode/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def run(self):
if diff.a_path.startswith("."):
continue

yaml_data_a_blob = (
yaml_data_a_blob = dict(
saneyaml.load(diff.a_blob.data_stream.read()) if diff.a_blob else None
)
yaml_data_b_blob = (
yaml_data_b_blob = dict(
saneyaml.load(diff.b_blob.data_stream.read()) if diff.b_blob else None
)

Expand Down Expand Up @@ -113,7 +113,7 @@ def vul_handler(change_type, repo_obj, yaml_data_a_blob, yaml_data_b_blob, a_pat

def pkg_handler(change_type, default_service, yaml_data_a_blob, yaml_data_b_blob):
if change_type == "A":
package = yaml_data_b_blob.get("package")
package = yaml_data_b_blob.get("pacakge")

pkg, _ = Package.objects.get_or_create(purl=package, service=default_service)

Expand Down
35 changes: 35 additions & 0 deletions fedcode/management/commands/federate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# FederatedCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/federatedcode for support or download.
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
#
from django.core.management import BaseCommand

from fedcode.models import FederateRequest
from fedcode.signatures import FEDERATEDCODE_PRIVATE_KEY
from fedcode.signatures import HttpSignature


class Command(BaseCommand):
def handle(self, *args, **options):
"""
Federate Command is sending the http signed request to the target and save the status of the request
"""

for rq in FederateRequest.objects.all().order_by("created_at"):
if rq.done:
continue

try:
HttpSignature.signed_request(
rq.target, rq.body, FEDERATEDCODE_PRIVATE_KEY, rq.key_id
)
rq.done = True
rq.save()
except Exception as e:
rq.error_message = e
finally:
rq.save()
33 changes: 33 additions & 0 deletions fedcode/management/commands/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# FederatedCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/federatedcode for support or download.
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
#
from django.core.management import BaseCommand

from fedcode.importer import Importer
from fedcode.models import SyncRequest


class Command(BaseCommand):
def handle(self, *args, **options):
"""
The Sync Command is responsible for running the Importer and updating the status of pending sync requests.
"""
for sync_r in SyncRequest.objects.all().order_by("created_at"):
if sync_r.done:
continue

try:
repo = sync_r.repo
repo.git_repo_obj.remotes.origin.pull()
importer = Importer(repo, repo.admin)
importer.run()
sync_r.done = True
except Exception as e:
sync_r.error_message = e
finally:
sync_r.save()
63 changes: 0 additions & 63 deletions fedcode/management/commands/tasks.py

This file was deleted.

2 changes: 1 addition & 1 deletion federatedcode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
redirect_vulnerability,
name="vulnerability-page",
),
path("notes/<uuid:note_id>", NoteView.as_view(), name="note-page"),
path("notes/<uuid:uuid>", NoteView.as_view(), name="note-page"),
path("api/v0/users/@<str:username>", UserProfile.as_view(), name="user-ap-profile"),
path(
"api/v0/purls/@<path:purl_string>/",
Expand Down
Loading