Skip to content

Commit

Permalink
Merge branch 'develop' into topic/chriscummings/enable-build-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorescu authored Nov 18, 2024
2 parents 683eb71 + 55e0cc9 commit 67e89d6
Showing 67 changed files with 417 additions and 99 deletions.
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ name: Build sphinx docs
on:
push:
branches:
- '**'
- 'main'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
4 changes: 2 additions & 2 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ jobs:

- name: Install dependencies
run: |
pip install flake8
pip install flake8 flake8-docstrings
- name: Run flake8
run: |
flake8
flake8 scram translator
6 changes: 5 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Run pytest

on:
@@ -72,7 +73,10 @@ jobs:
POSTGRES_DB: test_scram
run: make coverage.xml

- name: Upload Coverage Report
- name: Upload Coverage to Coveralls
uses: coverallsapp/github-action@v2

- name: Upload Coverage to GitHub
uses: actions/upload-artifact@v4
with:
name: coverage-report
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -85,6 +85,11 @@ down: compose.override.yml
exec: compose.override.yml
@docker compose exec $(CONTAINER) $(COMMAND)

## gobgp-neighbor: shows the gobgp neighbor information (append neighbor IP for specific information)
.Phony: gobgp-neighbor
gobgp-neighbor: compose.override.yml
@docker compose exec gobgp gobgp neighbor $(NEIGHBOR)

# This automatically builds the help target based on commands prepended with a double hashbang
## help: print this help output
.Phony: help
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -3,14 +3,16 @@ SCRAM

Security Catch and Release Automation Manager

.. image:: https://coveralls.io/repos/github/esnet-security/SCRAM/badge.svg
:target: https://coveralls.io/github/esnet-security/SCRAM
:alt: Coveralls Code Coverage Stats
.. image:: https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg?logo=cookiecutter
:target: https://github.com/pydanny/cookiecutter-django/
:alt: Built with Cookiecutter Django
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:alt: Black code style


:License: BSD

====
2 changes: 1 addition & 1 deletion compose/local/django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim-buster
FROM python:3.12-slim-bookworm

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
2 changes: 1 addition & 1 deletion compose/production/django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM python:3.8-slim-buster
FROM python:3.12-slim-bookwork

ENV PYTHONUNBUFFERED 1

12 changes: 6 additions & 6 deletions config/asgi.py
Original file line number Diff line number Diff line change
@@ -19,18 +19,18 @@
from django.core.asgi import get_asgi_application

# Here we setup a debugger if this is desired. This obviously should not be run in production.
debug_mode = os.environ.get("DEBUG")
if debug_mode:
logging.info(f"Django is set to use a debugger. Provided debug mode: {debug_mode}")
if debug_mode == "pycharm-pydevd":
debug = os.environ.get("DEBUG")
if debug:
logging.info(f"Django is set to use a debugger. Provided debug mode: {debug}")
if debug == "pycharm-pydevd":
logging.info("Entering debug mode for pycharm, make sure the debug server is running in PyCharm!")

import pydevd_pycharm

pydevd_pycharm.settrace("host.docker.internal", port=56783, stdoutToServer=True, stderrToServer=True)

logging.info("Debugger started.")
elif debug_mode == "debugpy":
elif debug == "debugpy":
logging.info("Entering debug mode for debugpy (VSCode)")

import debugpy
@@ -39,7 +39,7 @@

logging.info("Debugger listening on port 56780.")
else:
logging.warning(f"Invalid debug mode given: {debug_mode}. Debugger not started")
logging.warning(f"Invalid debug mode given: {debug}. Debugger not started")

# This allows easy placement of apps within the interior
# scram directory.
4 changes: 4 additions & 0 deletions config/settings/local.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,10 @@
# http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development
INSTALLED_APPS = ["whitenoise.runserver_nostatic"] + INSTALLED_APPS # noqa F405

# django-coverage-plugin
# ------------------------------------------------------------------------------
# https://github.com/nedbat/django_coverage_plugin?tab=readme-ov-file#django-template-coveragepy-plugin
TEMPLATES[0]["OPTIONS"]['debug'] = True # noqa F405

# django-debug-toolbar
# ------------------------------------------------------------------------------
14 changes: 12 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -12,8 +12,18 @@ python_files = [
include = ["scram/*", "config/*", "translator/*"]
omit = ["**/migrations/*", "scram/contrib/*", "*/tests/*"]
plugins = ["django_coverage_plugin"]


branch = true
data_file = "coverage.coverage"

[tool.coverage.report]
exclude_also = [
"if debug:",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
]

# ==== black ====
[tool.black]
32 changes: 13 additions & 19 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
pytz==2022.1 # https://github.com/stub42/pytz
django-netfields==1.2.2 # https://pypi.org/project/django-netfields/
python-slugify==6.1.2 # https://github.com/un33k/python-slugify
Pillow==9.1.1 # https://github.com/python-pillow/Pillow
argon2-cffi==21.3.0 # https://github.com/hynek/argon2_cffi
whitenoise==6.2.0 # https://github.com/evansd/whitenoise
celery==5.2.7 # pyup: < 6.0 # https://github.com/celery/celery
django-celery-beat==2.3.0 # https://github.com/celery/django-celery-beat
django-celery-beat # https://github.com/celery/django-celery-beat
django-netfields # https://pypi.org/project/django-netfields/
flower==1.0.0 # https://github.com/mher/flower
python-slugify==6.1.2 # https://github.com/un33k/python-slugify
uvicorn[standard]==0.17.6 # https://github.com/encode/uvicorn
asgiref~=3.5.0 # https://github.com/django/asgiref
whitenoise==6.2.0 # https://github.com/evansd/whitenoise

# Django
# ------------------------------------------------------------------------------
channels==3.0.4
channels_redis==3.4.0
django-redis==5.3.0
django==3.2.13 # pyup: < 4.0 # https://www.djangoproject.com/
django-grip==3.4.0
django-eventstream==4.5.1 # https://github.com/fanout/django-eventstream
crispy-bootstrap5==0.6 # https://github.com/django-crispy-forms/crispy-bootstrap5
django~=4.2 # https://www.djangoproject.com/

django-allauth==0.51.0 # https://github.com/pennersr/django-allauth
django-environ==0.9.0 # https://github.com/joke2k/django-environ
django-eventstream==4.5.1 # https://github.com/fanout/django-eventstream
django-model-utils==4.2.0 # https://github.com/jazzband/django-model-utils
django-allauth==0.51.0 # https://github.com/pennersr/django-allauth
django-crispy-forms==1.14.0 # https://github.com/django-crispy-forms/django-crispy-forms
crispy-bootstrap5==0.6 # https://github.com/django-crispy-forms/crispy-bootstrap5
django-redis==5.3.0
django-simple-history~=3.1.1

# Django REST Framework
djangorestframework==3.13.1 # https://github.com/encode/django-rest-framework
djangorestframework~=3.15 # https://github.com/encode/django-rest-framework
django-cors-headers==3.13.0 # https://github.com/adamchainz/django-cors-headers
# DRF-spectacular for api documentation
drf-spectacular==0.22.1 # https://github.com/tfranzel/drf-spectacular
drf-spectacular # https://github.com/tfranzel/drf-spectacular

# OIDC
# ------------------------------------------------------------------------------
mozilla_django_oidc==2.0.0 # https://github.com/mozilla/mozilla-django-oidc

websockets~=10.3
django-simple-history~=3.1.1
10 changes: 2 additions & 8 deletions requirements/local.txt
Original file line number Diff line number Diff line change
@@ -7,12 +7,9 @@ watchgod==0.8.2 # https://github.com/samuelcolvin/watchgod

# Testing
# ------------------------------------------------------------------------------
mypy==0.950 # https://github.com/python/mypy
django-stubs==1.11.0 # https://github.com/typeddjango/django-stubs
pytest==7.1.2 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.4 # https://github.com/Frozenball/pytest-sugar
behave-django==1.4.0 # https://github.com/behave/behave-django
django-debug-toolbar~=3.2 # https://github.com/jazzband/django-debug-toolbar

# Documentation
# ------------------------------------------------------------------------------
@@ -21,9 +18,8 @@ sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild

# Code quality
# ------------------------------------------------------------------------------
flake8==4.0.1 # https://github.com/PyCQA/flake8
flake8-docstrings==1.7.0 # https://github.com/pycqa/flake8-docstrings
flake8-isort==4.1.1 # https://github.com/gforcada/flake8-isort
coverage==6.4.1 # https://github.com/nedbat/coveragepy
black==22.3.0 # https://github.com/psf/black
pylint-django==2.5.3 # https://github.com/PyCQA/pylint-django
pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
@@ -35,10 +31,8 @@ factory-boy==3.2.1 # https://github.com/FactoryBoy/factory_boy

django-debug-toolbar==3.4.0 # https://github.com/jazzband/django-debug-toolbar
django-extensions==3.1.5 # https://github.com/django-extensions/django-extensions
django-coverage-plugin==2.0.3 # https://github.com/nedbat/django_coverage_plugin
django-coverage-plugin==3.1.0 # https://github.com/nedbat/django_coverage_plugin
pytest-django==4.5.2 # https://github.com/pytest-dev/pytest-django
pytest~=7.1.2
behave~=1.2.6 # https://behave.readthedocs.io/en/stable/

# Debugging
# ------------------------------------------------------------------------------
4 changes: 3 additions & 1 deletion scram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__version__ = "0.1.0"
"""The Django project for Security Catch and Release Automation Manager (SCRAM)."""

__version__ = "1.1.1"
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".")])
4 changes: 4 additions & 0 deletions scram/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Some simple tests for the User app."""

import pytest

from scram.users.models import User
@@ -6,9 +8,11 @@

@pytest.fixture(autouse=True)
def media_storage(settings, tmpdir):
"""Configure the test to use the temp directory."""
settings.MEDIA_ROOT = tmpdir.strpath


@pytest.fixture
def user() -> User:
"""Return the UserFactory."""
return UserFactory()
2 changes: 1 addition & 1 deletion scram/contrib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
To understand why this file is here, please read:
To understand why this file is here, please read the CookieCutter documentation.
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
"""
2 changes: 1 addition & 1 deletion scram/contrib/sites/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
To understand why this file is here, please read:
To understand why this file is here, please read the CookieCutter documentation.
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
"""
1 change: 1 addition & 0 deletions scram/route_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Route Manager is the core app, and it handles adding and removing routes that will be blocked."""
4 changes: 4 additions & 0 deletions scram/route_manager/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Register models in the Admin site."""

from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin

@@ -6,6 +8,8 @@

@admin.register(ActionType)
class ActionTypeAdmin(SimpleHistoryAdmin):
"""Configure the ActionType and how it shows up in the Admin site."""

list_filter = ("available",)
list_display = ("name", "available")

1 change: 1 addition & 0 deletions scram/route_manager/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The API, which leverages Django Request Framework."""
8 changes: 8 additions & 0 deletions scram/route_manager/api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""Custom exceptions for the API."""

from django.conf import settings
from rest_framework.exceptions import APIException


class PrefixTooLarge(APIException):
"""The CIDR prefix that was specified is larger than the prefix allowed in the settings."""

v4_min_prefix = getattr(settings, "V4_MINPREFIX", 0)
v6_min_prefix = getattr(settings, "V6_MINPREFIX", 0)
status_code = 400
@@ -11,12 +15,16 @@ class PrefixTooLarge(APIException):


class IgnoredRoute(APIException):
"""An operation attempted to add a route that overlaps with a route on the ignore list."""

status_code = 400
default_detail = "This CIDR is on the ignore list. You are not allowed to add it here."
default_code = "ignored_route"


class ActiontypeNotAllowed(APIException):
"""An operation attempted to perform an action on behalf of a client that is unauthorized to perform that type."""

status_code = 403
default_detail = "This client is not allowed to use this actiontype"
default_code = "actiontype_not_allowed"
Loading

0 comments on commit 67e89d6

Please sign in to comment.