diff --git a/apps/workflows/api_deprecated.py b/apps/workflows/api_deprecated.py new file mode 100644 index 000000000..60ef0f4b7 --- /dev/null +++ b/apps/workflows/api_deprecated.py @@ -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""" diff --git a/apps/workflows/tests/test_endpoints.py b/apps/workflows/tests/test_endpoints.py index b6964eed3..45264d310 100644 --- a/apps/workflows/tests/test_endpoints.py +++ b/apps/workflows/tests/test_endpoints.py @@ -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}/") @@ -25,16 +25,16 @@ 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 @@ -42,24 +42,24 @@ def test_workflows_auth(self, auth_client, test_api_uri): 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) @@ -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) @@ -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() @@ -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) @@ -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) @@ -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 @@ -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): diff --git a/apps/workflows/urls.py b/apps/workflows/urls.py index 0713f75dd..66fc65cf8 100644 --- a/apps/workflows/urls.py +++ b/apps/workflows/urls.py @@ -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/", classification.as_view()), - path(f"api/{WORKFLOWS_API_VERSION}/workflows//adjust", adjust.as_view()), + path(f"api/{WORKFLOWS_API_VERSION}", workflows.as_view()), + path(f"api/{WORKFLOWS_API_VERSION}/", classification.as_view()), + path(f"api/{WORKFLOWS_API_VERSION}//adjust", adjust.as_view()), path(f"api/{WORKFLOWS_API_VERSION}/graph/workflows", graph_workflows.as_view()), path( f"api/{WORKFLOWS_API_VERSION}/graph/workflows/", diff --git a/apps/workflows/urls_deprecated.py b/apps/workflows/urls_deprecated.py new file mode 100644 index 000000000..5eb054c38 --- /dev/null +++ b/apps/workflows/urls_deprecated.py @@ -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/", classification.as_view()), + path(f"api/{WORKFLOWS_API_VERSION}/workflows//adjust", adjust.as_view()), + path(f"api/{WORKFLOWS_API_VERSION}/graph/workflows", graph_workflows.as_view()), + path( + f"api/{WORKFLOWS_API_VERSION}/graph/workflows/", + graph_classification.as_view(), + ), +] diff --git a/config/urls.py b/config/urls.py index 505067b3c..4ab175649 100644 --- a/config/urls.py +++ b/config/urls.py @@ -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 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f260bff62..1e3c97574 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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) diff --git a/openapi.yml b/openapi.yml index a07cc3557..d5e003f45 100644 --- a/openapi.yml +++ b/openapi.yml @@ -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: diff --git a/osidb/templates/index.html b/osidb/templates/index.html index b13a3f337..fa31af1b9 100644 --- a/osidb/templates/index.html +++ b/osidb/templates/index.html @@ -20,7 +20,7 @@

OSIDB: API | health | status

-

Workflows: API | health

+

Workflows: API | health

Taskman: health


Docs: OSIDB REST API tutorial |