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

Make docs RTD compatible #527

Merged
merged 2 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI Documentation

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-20.04

strategy:
max-parallel: 4
matrix:
python-version: [3.7]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Give permission to run scripts
run: chmod +x ./docs/scripts/doc8_style_check.sh

- name: Install Dependencies
working-directory: ./docs
run: pip install -r requirements.txt

- name: Check Sphinx Documentation build minimally
working-directory: ./docs
run: sphinx-build -E source build

- name: Check for documentation style errors
working-directory: ./docs
run: ./scripts/doc8_style_check.sh
16 changes: 16 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Where the Sphinx conf.py file is located
sphinx:
configuration: docs/source/conf.py

# Setting the doc build requirements
python:
version: "3.7"
install:
- requirements: docs/requirements.txt
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Sphinx>=3.3.1
sphinx-rtd-theme>=0.5.0
doc8>=0.8.1
5 changes: 5 additions & 0 deletions docs/scripts/doc8_style_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# halt script on error
set -e
# Check for Style Code Violations
doc8 --max-line-length 100 source --ignore D000 --quiet
5 changes: 5 additions & 0 deletions docs/scripts/sphinx_build_link_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# halt script on error
set -e
# Build locally, and then check links
sphinx-build -E -W -b linkcheck source build
Binary file added docs/source/README.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = "vulnerablecode"
copyright = "nexb Inc. and others"
author = "nexb Inc. and others"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []

master_doc = "index"
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Run your image as a container
At this point, the VulnerableCode app should be running at port ``8000`` on your Docker host.
Go to http://localhost:8000/ on a web browser to access the web UI.
Optionally, you can set ``NGINX_PORT`` environment variable in your shell or in the `.env` file to run on a different port than 8000.
Optionally, you can set ``NGINX_PORT`` environment variable in your shell or in the `.env` file
to run on a different port than 8000.

.. note::

Expand All @@ -58,17 +59,17 @@ Optionally, you can set ``NGINX_PORT`` environment variable in your shell or in
.. warning::

Serving VulnerableCode on a network could lead to security issues and there
are several steps that may be needed to secure such a deployment.
are several steps that may be needed to secure such a deployment.
Currently, this is not recommendend.


Invoke the importers
--------------------

Connect to the Docker container ``bash``.
From here you can access ``manage.py`` and run management commands
to import data as specified in the `Data import <../README.rst#data-import>`_ section and run commands
for the importers from there
Connect to the Docker container ``bash``.
From here you can access ``manage.py`` and run management commands
to import data as specified in the `Data import <../README.rst#data-import>`_ section and
run commands for the importers from there

For example:

Expand Down
4 changes: 4 additions & 0 deletions docs/source/getting-started/sources.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Vulneribility Sources
=====================

.. include:: ../../../SOURCES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ The Building Blocks A.K.A Prerequisites
reference_id: str = ""
url: str = ""
severities: List[VulnerabilitySeverity] = dataclasses.field(default_factory=list)
Steps to build an Importer
--------------------------

* **Register an Importer:**

To do this go to ``vulnerabilites/importer_yielder.py``, in the ``IMPORTER_REGISTRY``
list add a dictionary with following data
list add a dictionary with following data

.. code:: python
Expand All @@ -63,7 +63,7 @@ list add a dictionary with following data
'data_source_cfg': {},
}
**Don't forget to replace <your_importer_name> and <your_data_source_name> with
appropriate strings**

Expand All @@ -72,7 +72,7 @@ If you know the license of the data you are importing, assign the license field
equal to the license of the data in the ``add_<your_importer_name>_importer``
method of the migration script.

* **Create a data source** :
* **Create a data source** :

- Go to ``vulnerabilities/importers`` , create a python script, let's call it ``my_importer.py``

Expand All @@ -83,25 +83,25 @@ method of the migration script.
.. code:: python
from typing import Set
from packageurl import PackageURL
import requests
from vulnerabilities.data_source import Advisory
from vulnerabilities.data_source import DataSource
class ExampleDataSource(DataSource):
#This method must be implemented
def updated_advisories(self)-> Set[Advisory]:
raw_data = self.fetch()
advisories = self.to_advisories(raw_data)
return self.batch_advisories(advisories)
#Optional Method, but it is recommended to have fetching separated
#Optional Method, but it is recommended to have fetching separated
def fetch(self):
return requests.get("http://examplesecurity.org/api/json").json()
#Optional Method
#Optional Method
@staticmethod
def to_advisories(json_response:dict) -> Set[Advisory]:
advisories = []
Expand All @@ -113,18 +113,18 @@ method of the migration script.
cve_id = entry['cve_id']
safe_purls ={ PackageURL(name=pkg_name,
type=pkg_type,
version=version)
version=version)
for version in safe_pkg_versions}
vuln_purls= {PackageURL(name=pkg_name,
type=pkg_type,
version=version)
version=version)
for version in vuln_pkg_versions}
advisory = Advisory(vulnerability_id=cve_id,summary='',impacted_package_urls=vuln_purls,resolved_package_urls=safe_purls)
advisories.append(advisory)
return advisories
Finally register this ``ExampleDataSource`` in
``vulnerabilities/importers/__init__.py`` by adding the following line
Expand All @@ -138,4 +138,4 @@ Done, congrats on writing your new importer.Test it via
::

./manage.py migrate
./manage.py import my_importer
./manage.py import my_importer
24 changes: 24 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Welcome to nexb-skeleton's documentation!
=========================================

.. toctree::
:maxdepth: 2
:caption: Getting Started:

getting-started/docker_installation.rst
getting-started/sources.rst

.. toctree::
:maxdepth: 2
:caption: How-To Guides:

how-to-guides/add_new_importer.rst

.. include:: ../../README.rst

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`