Skip to content

Commit

Permalink
Merge branch 'main' into AlexN/ping-redis
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-nork authored Jul 11, 2023
2 parents 85ffe37 + aa4d457 commit 63a96a1
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 143 deletions.
68 changes: 34 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,42 @@ repos:
- --exclude="(\.gitlab)"

# pydocstyle checks docstring styles after blue is done reformatting
# - repo: https://github.com/pycqa/pydocstyle
# rev: 6.3.0
# hooks:
# - id: pydocstyle
# types: [python]
# exclude: 'test_.+\.py'
# args:
# - --config=.pydocstyle
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
types: [python]
exclude: '^.*/migrations/.*$|test_.+\.py'
args:
- --config=.pydocstyle

# After blue is done reformatting everything, double check it with flake8
# - repo: https://github.com/pycqa/flake8
# rev: 6.0.0
# hooks:
# - id: flake8
# types: [python]
# args:
# - --max-line-length=120
# - --extend-ignore=E203
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
types: [python]
args:
- --max-line-length=120
- --extend-ignore=E203

# mypy validates the python typing as per PEP 484
# See https://jaredkhan.com/blog/mypy-pre-commit for the source of this
# - repo: local
# # We do not use pre-commit/mirrors-mypy,
# # as it comes with opinionated defaults
# # (like --ignore-missing-imports)
# # and is difficult to configure to run
# # with the dependencies correctly installed.
# hooks:
# - id: mypy
# name: mypy
# entry: "./scripts/run-mypy"
# # A script hook uses the active virtual environment, so it must be up-to-date with `poetry install --sync`
# language: script
# types_or: [python, toml]
# # use require_serial so that script
# # is only called once per commit
# require_serial: true
# # Print the number of files as a sanity-check
# verbose: true
# - repo: local
# # We do not use pre-commit/mirrors-mypy,
# # as it comes with opinionated defaults
# # (like --ignore-missing-imports)
# # and is difficult to configure to run
# # with the dependencies correctly installed.
# hooks:
# - id: mypy
# name: mypy
# entry: "./scripts/run-mypy"
# # A script hook uses the active virtual environment, so it must be up-to-date with `poetry install --sync`
# language: script
# types_or: [python, toml]
# # use require_serial so that script
# # is only called once per commit
# require_serial: true
# # Print the number of files as a sanity-check
# verbose: true
2 changes: 1 addition & 1 deletion chirps/account/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Configures the account app.""" ''
"""Configures the account app."""
from django.apps import AppConfig


Expand Down
1 change: 0 additions & 1 deletion chirps/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def signup(request):

def login_view(request):
"""Render the login page."""

# If there are no users, redirect to the installation page
if User.objects.count() == 0:
return redirect(reverse('install'))
Expand Down
2 changes: 1 addition & 1 deletion chirps/base_app/management/commands/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Command(BaseCommand):
help = 'Interact with the local celery broker'

def add_arguments(self, parser):

"""Add arguments to celery command"""
parser.add_argument('--start', action='store_true', help='Start celery server')
parser.add_argument('--stop', action='store_true', help='Stop celery server')
parser.add_argument('--restart', action='store_true', help='Restart celery server')
Expand Down
1 change: 1 addition & 0 deletions chirps/base_app/management/commands/initialize_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Command(BaseCommand):
help = 'Initialize the app by running multiple management commands'

def handle(self, *args, **options):
"""Handle the command"""
# Run the 'redis --start' command
self.stdout.write(self.style.WARNING('Starting Redis...'))
call_command('redis', '--start')
Expand Down
4 changes: 2 additions & 2 deletions chirps/base_app/management/commands/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Command(BaseCommand):
help = 'Interact with the local rabbitmq development server'

def add_arguments(self, parser):

"""Add arguments to rabbitmq command"""
parser.add_argument('--start', action='store_true', help='Start rabbitmq server')
parser.add_argument('--stop', action='store_true', help='Stop rabbitmq server')
parser.add_argument('--status', action='store_true', help='Check rabbitmq server status')

def handle(self, *args, **options):

"""Handle rabbitmq command"""
if options['start']:
os.system('rabbitmq-server start -detached')
elif options['stop']:
Expand Down
4 changes: 2 additions & 2 deletions chirps/base_app/management/commands/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Command(BaseCommand):
help = 'Interact with the local redis development server'

def add_arguments(self, parser):

"""Add arguments to redis command"""
parser.add_argument('--start', action='store_true', help='Start redis server')
parser.add_argument('--stop', action='store_true', help='Stop redis server')
parser.add_argument('--status', action='store_true', help='Check redis server status')

def handle(self, *args, **options):

"""Handle redis command"""
if options['start']:
os.system('redis-server --daemonize yes')
elif options['stop']:
Expand Down
1 change: 1 addition & 0 deletions chirps/base_app/management/commands/start_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Command(BaseCommand):
help = 'Initialize the app by running multiple management commands'

def handle(self, *args, **options):
"""Start the services required to run the application, then start the server with `runserver`"""
# Run the 'redis --start' command
self.stdout.write(self.style.WARNING('Starting Redis...'))
call_command('redis', '--start')
Expand Down
1 change: 0 additions & 1 deletion chirps/base_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def index(request):

def install(request):
"""Render the install page."""

# If there are uses already, redirect to the dashboard
if User.objects.count() > 0:
return redirect(reverse('index'))
Expand Down
1 change: 1 addition & 0 deletions chirps/chirps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
Expand Down
174 changes: 87 additions & 87 deletions chirps/plan/fixtures/plan/employee.json
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
[
{
"model": "plan.Plan",
"pk": 100,
"fields": {
"name": "Employee Information",
"description": "This plan will scan for employee information.",
"is_template": true
}
{
"fields": {
"description": "This plan will scan for employee information.",
"is_template": true,
"name": "Employee Information"
},
{
"model": "plan.Rule",
"pk": 100,
"fields": {
"name": "SSN",
"description": "Detect a social security number",
"query_string": "What's my social security number?",
"regex_test": "\\b\\d{3}-\\d{2}-\\d{4}\\b",
"severity": 5,
"plan": 100
}
"model": "plan.Plan",
"pk": 100
},
{
"fields": {
"description": "Detect a social security number",
"name": "SSN",
"plan": 100,
"query_string": "What's my social security number?",
"regex_test": "\\b\\d{3}-\\d{2}-\\d{4}\\b",
"severity": 5
},
{
"model": "plan.Rule",
"pk": 101,
"fields": {
"name": "Address",
"description": "Detect a mailing address",
"query_string": "What's my address?",
"regex_test": "\\b\\d{1,5}\\s+([a-zA-Z]+\\s+)*[a-zA-Z]+,\\s*[a-zA-Z]{2}\\s+\\d{5}(?:-\\d{4})?\\b",
"severity": 2,
"plan": 100
}
"model": "plan.Rule",
"pk": 100
},
{
"fields": {
"description": "Detect a mailing address",
"name": "Address",
"plan": 100,
"query_string": "What's my address?",
"regex_test": "\\b\\d{1,5}\\s+([a-zA-Z]+\\s+)*[a-zA-Z]+,\\s*[a-zA-Z]{2}\\s+\\d{5}(?:-\\d{4})?\\b",
"severity": 2
},
{
"model": "plan.Rule",
"pk": 102,
"fields": {
"name": "Bank Account",
"description": "Detect a bank account number",
"query_string": "What's my bank account number?",
"regex_test": "\\d{10,12}",
"severity": 5,
"plan": 100
}
"model": "plan.Rule",
"pk": 101
},
{
"fields": {
"description": "Detect a bank account number",
"name": "Bank Account",
"plan": 100,
"query_string": "What's my bank account number?",
"regex_test": "\\d{10,12}",
"severity": 5
},
{
"model": "plan.Rule",
"pk": 103,
"fields": {
"name": "Credit Card",
"description": "Detect a credit card number",
"query_string": "What's my credit card number?",
"regex_test": "(?:\\d[ -]*?){13,16}",
"severity": 5,
"plan": 100
}
"model": "plan.Rule",
"pk": 102
},
{
"fields": {
"description": "Detect a credit card number",
"name": "Credit Card",
"plan": 100,
"query_string": "What's my credit card number?",
"regex_test": "(?:\\d[ -]*?){13,16}",
"severity": 5
},
{
"model": "plan.Rule",
"pk": 104,
"fields": {
"name": "Email Address",
"description": "Detect an email address",
"query_string": "What's my email address?",
"regex_test": "[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+",
"severity": 2,
"plan": 100
}
"model": "plan.Rule",
"pk": 103
},
{
"fields": {
"description": "Detect an email address",
"name": "Email Address",
"plan": 100,
"query_string": "What's my email address?",
"regex_test": "[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+",
"severity": 2
},
{
"model": "plan.Rule",
"pk": 105,
"fields": {
"name": "Phone number",
"description": "Detect a phone number",
"query_string": "What's my phone number?",
"regex_test": "\\b\\d{3}[-.]?\\d{3}[-.]?\\d{4}\\b",
"severity": 2,
"plan": 100
}
"model": "plan.Rule",
"pk": 104
},
{
"fields": {
"description": "Detect a phone number",
"name": "Phone number",
"plan": 100,
"query_string": "What's my phone number?",
"regex_test": "\\b\\d{3}[-.]?\\d{3}[-.]?\\d{4}\\b",
"severity": 2
},
{
"model": "plan.Rule",
"pk": 106,
"fields": {
"name": "Salary",
"description": "Detect a salary (in USD)",
"query_string": "What's my salary?",
"regex_test": "\\$\\d+(,\\d{3})*(\\.\\d{2})?",
"severity": 2,
"plan": 100
}
}
]
"model": "plan.Rule",
"pk": 105
},
{
"fields": {
"description": "Detect a salary (in USD)",
"name": "Salary",
"plan": 100,
"query_string": "What's my salary?",
"regex_test": "\\$\\d+(,\\d{3})*(\\.\\d{2})?",
"severity": 2
},
"model": "plan.Rule",
"pk": 106
}
]
2 changes: 2 additions & 0 deletions chirps/plan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Plan(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)

def __str__(self):
"""Stringify the name"""
return self.name


Expand All @@ -41,4 +42,5 @@ class Rule(models.Model):
plan = models.ForeignKey(Plan, on_delete=models.CASCADE, related_name='rules')

def __str__(self):
"""Stringify the name"""
return self.name
1 change: 0 additions & 1 deletion chirps/plan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def dashboard(request):
Args:
request (HttpRequest): Django request object
"""

# Fetch a list of all the available template plans
templates = Plan.objects.filter(is_template=True)

Expand Down
3 changes: 3 additions & 0 deletions chirps/scan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Scan(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)

def __str__(self) -> str:
"""Stringify the description"""
return self.description

def celery_task_status(self) -> str:
Expand Down Expand Up @@ -54,6 +55,7 @@ class Result(models.Model):
rule = models.ForeignKey(Rule, on_delete=models.CASCADE)

def __str__(self):
"""Stringify the rule name and scan ID"""
return f'{self.rule.name} - {self.scan.id}'


Expand All @@ -65,6 +67,7 @@ class Finding(models.Model):
length = models.IntegerField()

def __str__(self):
"""Stringify the offset and length separated by a colon"""
return f'{self.offset}:{self.length}'

def text(self):
Expand Down
Loading

0 comments on commit 63a96a1

Please sign in to comment.