Skip to content

Commit

Permalink
Merge pull request #217 from rackerlabs/minor-tuning-of-uwsgi-models-…
Browse files Browse the repository at this point in the history
…and-api-client

Minor tuning of uwsgi models and api client
  • Loading branch information
derpadoo authored Jun 22, 2020
2 parents ad542bd + be50382 commit 2943078
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ server {
location / {
uwsgi_pass scantron;
include uwsgi_params;
uwsgi_read_timeout 600;
}

# client_max_body_size must be the MB value of the max_length of any target type fields in
# master/django_scantron/models.py
# 4194304 bytes --> 4M, assuming each character takes up 1 byte.
client_max_body_size 4M;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pidfile = /tmp/scantron-master.pid
# Respawn processes taking more than 120 seconds
harakiri = 120

# Respawn processes after serving 5000 requests
max-requests = 5000
# Respawn processes after serving 50 requests
max-requests = 50

# Socket file
socket = /tmp/uwsgi.sock
Expand Down
2 changes: 1 addition & 1 deletion master/django_scantron/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.33"
__version__ = "1.34"
25 changes: 20 additions & 5 deletions master/django_scantron/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ class GloballyExcludedTarget(models.Model):
"""Model for globally excluded targets."""

id = models.AutoField(primary_key=True, verbose_name="Globally excluded target ID")
# See the client_max_body_size setting in
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
# is changed.
globally_excluded_targets = models.CharField(
unique=False,
max_length=1_048_576, # 2^20 = 1048576
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
validators=[
RegexValidator(
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
Expand Down Expand Up @@ -130,9 +133,12 @@ class Site(models.Model):
verbose_name="Site Name",
)
description = models.CharField(unique=False, max_length=255, blank=True, verbose_name="Description")
# See the client_max_body_size setting in
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
# is changed.
targets = models.CharField(
unique=False,
max_length=1_048_576, # 2^20 = 1048576
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
validators=[
RegexValidator(
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
Expand All @@ -141,10 +147,13 @@ class Site(models.Model):
],
verbose_name="Targets",
)
# See the client_max_body_size setting in
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
# is changed.
excluded_targets = models.CharField(
unique=False,
blank=True,
max_length=1_048_576, # 2^20 = 1048576
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
validators=[
RegexValidator(
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
Expand Down Expand Up @@ -273,9 +282,12 @@ class ScheduledScan(models.Model):
start_datetime = models.DateTimeField(verbose_name="Scheduled scan start date and time")
scan_binary = models.CharField(max_length=7, default="nmap", verbose_name="Scan binary")
scan_command = models.TextField(unique=False, verbose_name="Scan command")
# See the client_max_body_size setting in
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
# is changed.
targets = models.CharField(
unique=False,
max_length=1_048_576, # 2^20 = 1048576
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
validators=[
RegexValidator(
regex="^[a-zA-Z0-9/\.\: ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
Expand All @@ -284,10 +296,13 @@ class ScheduledScan(models.Model):
],
verbose_name="Targets",
)
# See the client_max_body_size setting in
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
# is changed.
excluded_targets = models.CharField(
unique=False,
blank=True,
max_length=1_048_576, # 2^20 = 1048576
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
validators=[
RegexValidator(
regex="^[a-zA-Z0-9/\.\: ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
Expand Down
8 changes: 4 additions & 4 deletions scantron_api_client/scantron_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import utility


__version__ = "1.34"
__version__ = "1.35"


class ScantronClient:
Expand All @@ -29,9 +29,9 @@ def __init__(self, secrets_file_location="./scantron_api_secrets.json", **kwargs

# Ensure key/values exist in secrets.json.
try:
self.host = SECRETS["host"]
self.port = SECRETS["port"]
self.token = SECRETS["token"]
self.host = SECRETS["scantron"]["host"]
self.port = SECRETS["scantron"]["port"]
self.token = SECRETS["scantron"]["token"]

except KeyError:
print(f"Error reading key-values in {secrets_file_location} file. Exiting...")
Expand Down
8 changes: 5 additions & 3 deletions scantron_api_client/scantron_api_secrets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"host": "",
"port": 443,
"token": ""
"scantron": {
"host": "",
"port": 443,
"token": ""
}
}

0 comments on commit 2943078

Please sign in to comment.