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 8435160
Show file tree
Hide file tree
Showing 8 changed files with 258 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()
class index(api.index):
"""deprecated osim index API endpoint"""


@extend_schema()
class healthy(api.healthy):
"""deprecated osim unauthenticated health check API endpoint"""


@extend_schema()
class adjust(api.adjust):
"""deprecated osim adjustion API endpoint"""


@extend_schema()
class promote(api.promote):
"""deprecated osim promote API endpoint"""


@extend_schema()
class reject(api.reject):
"""deprecated osim reject API endpoint"""


@extend_schema()
class classification(api.classification):
"""deprecated osim classification API endpoint"""


@extend_schema()
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
159 changes: 159 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7395,6 +7395,165 @@ paths:
version:
type: string
description: ''
/workflows/:
get:
operationId: workflows_retrieve
description: index API endpoint listing available API endpoints
tags:
- workflows
security:
- OsidbTokenAuthentication: []
responses:
'200':
content:
application/json:
schema:
type: object
properties:
dt:
type: string
format: date-time
env:
type: string
revision:
type: string
version:
type: string
description: ''
/workflows/api/v1:
get:
operationId: workflows_api_v1_retrieve
description: workflow info API endpoint
tags:
- workflows
security:
- OsidbTokenAuthentication: []
responses:
'200':
content:
application/json:
schema:
type: object
properties:
dt:
type: string
format: date-time
env:
type: string
revision:
type: string
version:
type: string
description: ''
/workflows/api/v1/{id}:
get:
operationId: workflows_api_v1_retrieve_2
description: |-
workflow classification API endpoint
for flaw identified by UUID or CVE returns its workflow:state classification
params:
verbose - return also workflows with flaw classification
which represents the reasoning of the result
parameters:
- in: path
name: id
schema:
type: string
required: true
- in: query
name: verbose
schema:
type: boolean
description: Return also workflows with flaw classification which represents
the reasoning of the result.
tags:
- workflows
security:
- OsidbTokenAuthentication: []
responses:
'200':
content:
application/json:
schema:
type: object
properties:
dt:
type: string
format: date-time
env:
type: string
revision:
type: string
version:
type: string
description: ''
/workflows/api/v1/{id}/adjust:
post:
operationId: workflows_api_v1_adjust_create
description: |-
workflow adjustion API endpoint
adjust workflow classification of flaw identified by UUID or CVE
and return its workflow:state classification (new if changed and old otherwise)
adjust operation is idempotent so when the classification
is already adjusted running it results in no operation
parameters:
- in: path
name: id
schema:
type: string
required: true
tags:
- workflows
security:
- OsidbTokenAuthentication: []
responses:
'200':
content:
application/json:
schema:
type: object
properties:
dt:
type: string
format: date-time
env:
type: string
revision:
type: string
version:
type: string
description: ''
/workflows/healthy:
get:
operationId: workflows_healthy_retrieve
description: unauthenticated health check API endpoint
tags:
- workflows
security:
- OsidbTokenAuthentication: []
- {}
responses:
'200':
content:
application/json:
schema:
type: object
properties:
dt:
type: string
format: date-time
env:
type: string
revision:
type: string
version:
type: string
description: ''
components:
schemas:
Affect:
Expand Down
Loading

0 comments on commit 8435160

Please sign in to comment.