Skip to content

Commit

Permalink
rename osim api to workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Conrado Costa <[email protected]>
  • Loading branch information
costaconrado committed Nov 30, 2023
1 parent 0cb076d commit ef5f9c7
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 21 deletions.
46 changes: 46 additions & 0 deletions apps/workflows/api_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Former OSIM API endpoints marked as deprecated
"""

import logging

from drf_spectacular.utils import extend_schema

from apps.workflows import api

logger = logging.getLogger(__name__)


@extend_schema(deprecated=True, extensions={"x-sunset": "2024-07-01"})
class index(api.index):
"""deprecated osim index API endpoint"""


@extend_schema(deprecated=True, extensions={"x-sunset": "2024-07-01"})
class healthy(api.healthy):
"""deprecated osim unauthenticated health check API endpoint"""


@extend_schema(deprecated=True, extensions={"x-sunset": "2024-07-01"})
class adjust(api.adjust):
"""deprecated osim adjustion API endpoint"""


@extend_schema(deprecated=True, extensions={"x-sunset": "2024-07-01"})
class promote(api.promote):
"""deprecated osim promote API endpoint"""


@extend_schema(deprecated=True, extensions={"x-sunset": "2024-07-01"})
class reject(api.reject):
"""deprecated osim reject API endpoint"""


@extend_schema(deprecated=True, extensions={"x-sunset": "2024-07-01"})
class classification(api.classification):
"""deprecated osim classification API endpoint"""


@extend_schema(deprecated=True, extensions={"x-sunset": "2024-07-01"})
class workflows(api.workflows):
"""deprecated osim info API endpoint"""
32 changes: 16 additions & 16 deletions apps/workflows/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class TestEndpoints(object):
# osim/
# workflows/
def test_index_auth(self, auth_client, test_scheme_host):
"""test authenticated index API endpoint"""
response = auth_client.get(f"{test_scheme_host}/")
Expand All @@ -25,41 +25,41 @@ def test_index_no_auth(self, client, test_scheme_host):
response = client.get(f"{test_scheme_host}/")
assert response.status_code == 401

# osim/healthy
# workflows/healthy
def test_health(self, client, test_scheme_host):
"""test health API endpoint"""
response = client.get(f"{test_scheme_host}/healthy")
assert response.status_code == 200

# osim/workflows
# workflows
def test_workflows_auth(self, auth_client, test_api_uri):
"""test authenticated workflows API endpoint"""
response = auth_client.get(f"{test_api_uri}/workflows")
response = auth_client.get(f"{test_api_uri}")
assert response.status_code == 200
body = response.json()
workflows = WorkflowSerializer(WorkflowFramework().workflows, many=True).data
assert body["workflows"] == workflows

def test_workflows_no_auth(self, client, test_api_uri):
"""test authenticated workflows API endpoint without authenticating"""
response = client.get(f"{test_api_uri}/workflows")
response = client.get(f"{test_api_uri}")
assert response.status_code == 401

def test_workflows_cve(self, auth_client, test_api_uri):
"""test authenticated workflow classification API endpoint"""
flaw = FlawFactory()
response = auth_client.get(f"{test_api_uri}/workflows/{flaw.cve_id}")
response = auth_client.get(f"{test_api_uri}/{flaw.cve_id}")
assert response.status_code == 200
body = response.json()
assert body["flaw"] == str(flaw.uuid)
assert "classification" in body
assert "workflows" not in body

# osim/workflows/{flaw}
# workflows/{flaw}
def test_workflows_uuid(self, auth_client, test_api_uri):
"""test authenticated workflow classification API endpoint"""
flaw = FlawFactory()
response = auth_client.get(f"{test_api_uri}/workflows/{flaw.uuid}")
response = auth_client.get(f"{test_api_uri}/{flaw.uuid}")
assert response.status_code == 200
body = response.json()
assert body["flaw"] == str(flaw.uuid)
Expand All @@ -69,7 +69,7 @@ def test_workflows_uuid(self, auth_client, test_api_uri):
def test_workflows_uuid_verbose(self, auth_client, test_api_uri):
"""test authenticated workflow classification API endpoint with verbose parameter"""
flaw = FlawFactory()
response = auth_client.get(f"{test_api_uri}/workflows/{flaw.uuid}?verbose=true")
response = auth_client.get(f"{test_api_uri}/{flaw.uuid}?verbose=true")
assert response.status_code == 200
body = response.json()
assert body["flaw"] == str(flaw.uuid)
Expand All @@ -79,17 +79,17 @@ def test_workflows_uuid_verbose(self, auth_client, test_api_uri):
def test_workflows_uuid_non_existing(self, auth_client, test_api_uri):
"""test authenticated workflow classification API endpoint with non-exising flaw"""
response = auth_client.get(
f"{test_api_uri}/workflows/35d1ad45-0dba-41a3-bad6-5dd36d624ead"
f"{test_api_uri}/35d1ad45-0dba-41a3-bad6-5dd36d624ead"
)
assert response.status_code == 404

def test_workflows_uuid_no_auth(self, client, test_api_uri):
"""test authenticated workflow classification API endpoint without authenticating"""
flaw = FlawFactory()
response = client.get(f"{test_api_uri}/workflows/{flaw.uuid}")
response = client.get(f"{test_api_uri}/{flaw.uuid}")
assert response.status_code == 401

# osim/workflows/{flaw}/adjust
# workflows/{flaw}/adjust
def test_workflows_uuid_adjusting(self, auth_client, test_api_uri):
"""test flaw classification adjustion after metadata change"""
workflow_framework = WorkflowFramework()
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_workflows_uuid_adjusting(self, auth_client, test_api_uri):
flaw.major_incident_state = Flaw.FlawMajorIncident.NOVALUE
flaw.save()

response = auth_client.post(f"{test_api_uri}/workflows/{flaw.uuid}/adjust")
response = auth_client.post(f"{test_api_uri}/{flaw.uuid}/adjust")
assert response.status_code == 200
body = response.json()
assert body["flaw"] == str(flaw.uuid)
Expand All @@ -177,7 +177,7 @@ def test_workflows_uuid_adjusting_no_modification(self, auth_client, test_api_ur
test authenticated workflow classification adjusting API endpoint with no flaw modification
"""
flaw = FlawFactory()
response = auth_client.post(f"{test_api_uri}/workflows/{flaw.uuid}/adjust")
response = auth_client.post(f"{test_api_uri}/{flaw.uuid}/adjust")
assert response.status_code == 200
body = response.json()
assert body["flaw"] == str(flaw.uuid)
Expand All @@ -189,7 +189,7 @@ def test_workflows_uuid_adjust_non_existing(self, auth_client, test_api_uri):
test authenticated workflow classification adjusting API endpoint with non-exising flaw
"""
response = auth_client.post(
f"{test_api_uri}/workflows/35d1ad45-0dba-41a3-bad6-5dd36d624ead/adjust"
f"{test_api_uri}/35d1ad45-0dba-41a3-bad6-5dd36d624ead/adjust"
)
assert response.status_code == 404

Expand All @@ -198,7 +198,7 @@ def test_workflows_uuid_adjust_no_auth(self, client, test_api_uri):
test authenticated workflow classification adjusting API endpoint without authenticating
"""
flaw = FlawFactory()
response = client.post(f"{test_api_uri}/workflows/{flaw.uuid}/adjust")
response = client.post(f"{test_api_uri}/{flaw.uuid}/adjust")
assert response.status_code == 401

def test_promote_endpoint(self, auth_client, test_api_uri_osidb, user_token):
Expand Down
6 changes: 3 additions & 3 deletions apps/workflows/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
urlpatterns = [
path("", index.as_view()),
path("healthy", healthy.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/workflows", workflows.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/workflows/<str:pk>", classification.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/workflows/<str:pk>/adjust", adjust.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}", workflows.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/<str:pk>", classification.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/<str:pk>/adjust", adjust.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/graph/workflows", graph_workflows.as_view()),
path(
f"api/{WORKFLOWS_API_VERSION}/graph/workflows/<str:pk>",
Expand Down
27 changes: 27 additions & 0 deletions apps/workflows/urls_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Former OSIM URLs marked as deprecated
"""

import logging

from django.urls import path

from .api_deprecated import adjust, classification, healthy, index, workflows
from .constants import WORKFLOWS_API_VERSION
from .views import classification as graph_classification
from .views import workflows as graph_workflows

logger = logging.getLogger(__name__)

urlpatterns = [
path("", index.as_view()),
path("healthy", healthy.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/workflows", workflows.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/workflows/<str:pk>", classification.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/workflows/<str:pk>/adjust", adjust.as_view()),
path(f"api/{WORKFLOWS_API_VERSION}/graph/workflows", graph_workflows.as_view()),
path(
f"api/{WORKFLOWS_API_VERSION}/graph/workflows/<str:pk>",
graph_classification.as_view(),
),
]
4 changes: 3 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
path("", index.as_view(), name="index"),
# Exploits
path("exploits/", include("apps.exploits.urls")),
# Osim - deprecated
path("osim/", include("apps.workflows.urls_deprecated")),
# Workflows
path("osim/", include("apps.workflows.urls")),
path("workflows/", include("apps.workflows.urls")),
# Task Manager
path("taskman/", include("apps.taskman.urls")),
# collectors
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
/collectors/api/v1/status endpoint
- fix schema to reflect Erratum shipped_dt to be nullable

### Changed
- Renamed OSIM module to Workflows (OSIDB-1395)

### Removed
- Remove daily monitoring email for failed tasks / collectors (OSIDB-1215)

Expand Down
Loading

0 comments on commit ef5f9c7

Please sign in to comment.