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

[VIRTS-2887] Update Swagger Docs #2324

Merged
merged 13 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 12 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
9 changes: 6 additions & 3 deletions app/api/v2/handlers/ability_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,25 @@ async def get_ability_by_id(self, request: web.Request):
ability = await self.get_object(request)
return web.json_response(ability)

@aiohttp_apispec.docs(tags=['abilities'])
@aiohttp_apispec.docs(tags=['abilities'], summary='"name", "tactic", and "executors" are all required fields.')
@aiohttp_apispec.request_schema(AbilitySchema)
@aiohttp_apispec.response_schema(AbilitySchema)
async def create_ability(self, request: web.Request):
ability = await self.create_on_disk_object(request)
return web.json_response(ability.display)

@aiohttp_apispec.docs(tags=['abilities'])
@aiohttp_apispec.docs(tags=['abilities'], summary='"name", "tactic", and "executors" are all required fields.')
@aiohttp_apispec.request_schema(AbilitySchema(partial=True))
@aiohttp_apispec.response_schema(AbilitySchema)
async def create_or_update_ability(self, request: web.Request):
ability = await self.create_or_update_on_disk_object(request)
return web.json_response(ability.display)

@aiohttp_apispec.docs(tags=['abilities'])
@aiohttp_apispec.request_schema(AbilitySchema(partial=True))
@aiohttp_apispec.request_schema(AbilitySchema(partial=True, exclude=['ability_id',
'requirements',
'additional_info',
'access']))
@aiohttp_apispec.response_schema(AbilitySchema)
async def update_ability(self, request: web.Request):
ability = await self.update_on_disk_object(request)
Expand Down
2 changes: 1 addition & 1 deletion app/api/v2/handlers/adversary_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def create_adversary(self, request: web.Request):
return web.json_response(adversary.display)

@aiohttp_apispec.docs(tags=['adversaries'])
@aiohttp_apispec.request_schema(AdversarySchema(partial=True))
@aiohttp_apispec.request_schema(AdversarySchema(partial=True, exclude=['adversary_id']))
@aiohttp_apispec.response_schema(AdversarySchema)
async def update_adversary(self, request: web.Request):
adversary = await self.update_on_disk_object(request)
Expand Down
7 changes: 6 additions & 1 deletion app/api/v2/handlers/agent_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ async def create_agent(self, request: web.Request):
return web.json_response(agent.display)

@aiohttp_apispec.docs(tags=['agents'])
@aiohttp_apispec.request_schema(AgentSchema(partial=True))
@aiohttp_apispec.request_schema(AgentSchema(partial=True, only=['group',
'trusted',
'sleep_min',
'sleep_max',
'watchdog',
'pending_contact']))
@aiohttp_apispec.response_schema(AgentSchema)
async def update_agent(self, request: web.Request):
agent = await self.update_object(request)
Expand Down
3 changes: 2 additions & 1 deletion app/api/v2/handlers/fact_source_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ async def create_fact_source(self, request: web.Request):
source = await self.create_on_disk_object(request)
return web.json_response(source.display)

@aiohttp_apispec.docs(tags=['sources'])
@aiohttp_apispec.docs(tags=['sources'], summary='All fields can be updated excluding "id" '
'and "adjustments".')
@aiohttp_apispec.request_schema(SourceSchema(partial=True))
@aiohttp_apispec.response_schema(SourceSchema)
async def update_fact_source(self, request: web.Request):
Expand Down
2 changes: 1 addition & 1 deletion app/api/v2/handlers/objective_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def create_objective(self, request: web.Request):
return web.json_response(objective.display)

@aiohttp_apispec.docs(tags=['objectives'])
@aiohttp_apispec.request_schema(ObjectiveSchema(partial=True))
@aiohttp_apispec.request_schema(ObjectiveSchema(partial=True, exclude=['id', 'percentage']))
@aiohttp_apispec.response_schema(ObjectiveSchema)
async def update_objective(self, request: web.Request):
objective = await self.update_on_disk_object(request)
Expand Down
16 changes: 11 additions & 5 deletions app/api/v2/handlers/operation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ async def get_operation_by_id(self, request: web.Request):
operation = await self.get_object(request)
return web.json_response(operation)

@aiohttp_apispec.docs(tags=['operations'])
@aiohttp_apispec.request_schema(OperationSchema)
@aiohttp_apispec.docs(tags=['operations'],
summary='Required nested schema fields are as follows: "adversary.adversary_id", '
'"planner.planner_id", and "source.id".')
@aiohttp_apispec.request_schema(OperationSchema())
@aiohttp_apispec.response_schema(OperationSchema)
async def create_operation(self, request: web.Request):
operation = await self.create_object(request)
return web.json_response(operation.display)

@aiohttp_apispec.docs(tags=['operations'])
@aiohttp_apispec.request_schema(OperationSchema(partial=True))
@aiohttp_apispec.request_schema(OperationSchema(partial=True, only=['state',
'autonomous',
'obfuscator']))
@aiohttp_apispec.response_schema(OperationSchema(partial=True))
async def update_operation(self, request: web.Request):
operation = await self.update_object(request)
Expand Down Expand Up @@ -118,7 +122,7 @@ async def get_operation_link_result(self, request: web.Request):
return web.json_response(result)

@aiohttp_apispec.docs(tags=['operations'])
@aiohttp_apispec.request_schema(LinkSchema(partial=True))
@aiohttp_apispec.request_schema(LinkSchema(partial=True, only=['command', 'status']))
@aiohttp_apispec.response_schema(LinkSchema)
async def update_operation_link(self, request: web.Request):
operation_id = request.match_info.get('id')
Expand All @@ -128,7 +132,9 @@ async def update_operation_link(self, request: web.Request):
link = await self._api_manager.update_operation_link(operation_id, link_id, data, access)
return web.json_response(link)

@aiohttp_apispec.docs(tags=['operations'])
@aiohttp_apispec.docs(tags=['operations'], summary='The only required fields for this endpoint are "paw", '
'"executor.name", "executor.command", and "executor.platform". '
'"executor.command" is expected to be unencoded.')
@aiohttp_apispec.request_schema(LinkSchema)
@aiohttp_apispec.response_schema(LinkSchema)
async def create_potential_link(self, request: web.Request):
Expand Down
5 changes: 5 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import sys
import warnings

import aiohttp_apispec
from aiohttp_apispec import validation_middleware
Expand Down Expand Up @@ -77,6 +78,10 @@ def init_swagger_documentation(app):
"""Makes swagger documentation available at /api/docs for any endpoints
marked for aiohttp_apispec documentation.
"""
warnings.filterwarnings(
"ignore",
message="Multiple schemas resolved to the name"
)
aiohttp_apispec.setup_aiohttp_apispec(
app=app,
title='CALDERA',
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uuid
import yaml
import aiohttp_apispec
import warnings

from unittest import mock
from aiohttp_apispec import validation_middleware
Expand Down Expand Up @@ -315,6 +316,11 @@ def agent_config():
@pytest.fixture
def api_v2_client(loop, aiohttp_client, contact_svc):
def make_app(svcs):
warnings.filterwarnings(
"ignore",
message="Multiple schemas resolved to the name"
)

app = web.Application(
middlewares=[
authentication_required_middleware_factory(svcs['auth_svc']),
Expand Down