Skip to content

Commit

Permalink
chg: [website] Harmonization of the documentation with interoperabili…
Browse files Browse the repository at this point in the history
…ty with former endpoints.
  • Loading branch information
cedricbonhomme committed Nov 25, 2024
1 parent 6f38ccf commit 7cf074a
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 89 deletions.
2 changes: 1 addition & 1 deletion website/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def exec_cmd(command: str) -> str:
return result.strip()


def exec_cmd_no_wait(command: str, cwd: str="") -> None:
def exec_cmd_no_wait(command: str, cwd: str = "") -> None:
"""Execute a command in a sub process."""
args = shlex.split(command)
if cwd == "":
Expand Down
18 changes: 10 additions & 8 deletions website/web/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


apiv1_blueprint = Blueprint(
"apiv1", __name__, url_prefix="/"
"apiv1", __name__, url_prefix=""
) # should we put the version in the URL ?
csrf.exempt(apiv1_blueprint)

Expand All @@ -27,12 +27,13 @@ def setup_api(application: Any) -> Api:

api = Api(
apiv1_blueprint,
title="Vulnerability Lookup API",
title="Vulnerability-Lookup API",
version=version("vulnerabilitylookup"),
description="<a href='https://www.circl.lu' rel='noreferrer' target='_blank'>"
"<img src='https://www.circl.lu/assets/images/circl-logo.png' /></a><br />"
"API to query <a href='https://github.com/cve-search/vulnerability-lookup' rel='noreferrer' target='_blank'>Vulnerability Lookup</a>."
"<br /><br />Back to the <a href='/'>main page</a>.",
"<img src='https://vulnerability.circl.lu/static/img/VL-hori-coul.png' width='500px' /></a><br />"
"API to query <a href='https://github.com/cve-search/vulnerability-lookup' rel='noreferrer' target='_blank'>Vulnerability Lookup</a>"
"<br /><br />Back to the <a href='/'>main page</a>"
"<br /><br /><a href='https://vulnerability.circl.lu/documentation' target='_blank'>Official documentation</a>",
license="GNU Affero General Public License version 3",
license_url="https://www.gnu.org/licenses/agpl-3.0.html",
doc="/doc",
Expand All @@ -53,15 +54,16 @@ def custom_ui() -> str:
),
)

from website.web.api.v1 import base
from website.web.api.v1 import system
from website.web.api.v1 import vulnerability
from website.web.api.v1 import comment
from website.web.api.v1 import user
from website.web.api.v1 import bundle
from website.web.api.v1 import epss
from website.web.api.v1 import sighting

api.add_namespace(base.default_ns, path="/")
api.add_namespace(base.api_ns, path="/api")
api.add_namespace(system.system_ns, path="/api")
api.add_namespace(vulnerability.vulnerability_ns, path="/api")
if get_config("generic", "user_accounts"):
api.add_namespace(comment.comment_ns, path="/api")
api.add_namespace(user.user_ns, path="/api")
Expand Down
2 changes: 1 addition & 1 deletion website/web/api/v1/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

logger = logging.getLogger(__name__)

bundle_ns = Namespace("bundle", description="bundle related operations")
bundle_ns = Namespace("bundle", description="Bundle related operations.")

local_instance_uuid = get_config("generic", "local_instance_uuid").lower()

Expand Down
2 changes: 1 addition & 1 deletion website/web/api/v1/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

logger = logging.getLogger(__name__)

comment_ns = Namespace("comment", description="comment related operations")
comment_ns = Namespace("comment", description="Comment related operations.")

local_instance_uuid = get_config("generic", "local_instance_uuid").lower()

Expand Down
2 changes: 1 addition & 1 deletion website/web/api/v1/epss.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

logger = logging.getLogger(__name__)

epss_ns = Namespace("epss", description="EPSS related operations")
epss_ns = Namespace("epss", description="EPSS related operations.")


@epss_ns.route("/epss/<string:vulnerability_id>")
Expand Down
2 changes: 1 addition & 1 deletion website/web/api/v1/sighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

logger = logging.getLogger(__name__)

sighting_ns = Namespace("sighting", description="sighting related operations")
sighting_ns = Namespace("sighting", description="Sighting related operations.")

local_instance_uuid = get_config("generic", "local_instance_uuid").lower()

Expand Down
56 changes: 56 additions & 0 deletions website/web/api/v1/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typing import Any

import logging
from flask_restx import Namespace # type: ignore[import-untyped]
from flask_restx import Resource

from vulnerabilitylookup import __version__
from vulnerabilitylookup.default import get_config
from website.web.bootstrap import application
from website.web.bootstrap import vulnerabilitylookup


logger = logging.getLogger(__name__)

local_instance_name = get_config("generic", "local_instance_name").lower()
local_instance_vulnid_pattern = get_config("generic", "local_instance_vulnid_pattern")

system_ns = Namespace("system", description="Get the status of the system.")


@system_ns.route("/system/redis_up")
@system_ns.doc(description="Check if redis is up and running")
class RedisUp(Resource): # type: ignore[misc]
def get(self) -> bool:
return vulnerabilitylookup.check_redis_up()


@system_ns.route("/system/dbInfo")
@system_ns.route(
"/dbInfo",
doc={
"description": "Alias for /api/sytem/dbInfo",
"deprecated": True,
},
)
@system_ns.doc(
description="Get more information about the current databases in use and when it was updated"
)
class Info(Resource): # type: ignore[misc]
def get(self) -> dict[str, Any]:
return vulnerabilitylookup.get_info()


@system_ns.route("/system/configInfo")
@system_ns.doc(
description="Get non-sensitive information about the configuration of the system."
)
class ConfigInfo(Resource): # type: ignore[misc]
def get(self) -> dict[str, Any]:
return {
"user_accounts": get_config("generic", "user_accounts"),
"local_instance_uuid": get_config("generic", "local_instance_uuid"),
"registration": application.config["SELF_REGISTRATION"],
"moderation": application.config["COMMENTS_MODERATION"],
"software_version": __version__,
}
2 changes: 1 addition & 1 deletion website/web/api/v1/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

logger = logging.getLogger(__name__)

user_ns = Namespace("user", description="user related operations")
user_ns = Namespace("user", description="User related operations.")


# Argument Parsing
Expand Down
Loading

0 comments on commit 7cf074a

Please sign in to comment.