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

HTTP checks: add an option to prevent Cabot from following redirections #671

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions cabot/cabotapp/migrations/0008_statuscheck_follow_redirects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2019-06-11 10:26
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('cabotapp', '0007_statuscheckresult_consecutive_failures'),
]

operations = [
migrations.AddField(
model_name='statuscheck',
name='follow_redirects',
field=models.BooleanField(default=True, help_text=b'Uncheck to prevent Cabot from following HTTP redirections (default True)'),
),
]
5 changes: 5 additions & 0 deletions cabot/cabotapp/models/base.py
Original file line number Diff line number Diff line change
@@ -502,6 +502,10 @@ class StatusCheck(PolymorphicModel):
default=True,
help_text='Set to false to allow not try to verify ssl certificates (default True)',
)
follow_redirects = models.BooleanField(
default=True,
help_text='Uncheck to prevent Cabot from following HTTP redirections (default True)',
)

# Jenkins checks
max_queued_build_time = models.IntegerField(
@@ -769,6 +773,7 @@ def _run(self):
timeout=self.timeout,
verify=self.verify_ssl_certificate,
auth=auth,
allow_redirects=self.follow_redirects,
headers={
"User-Agent": settings.HTTP_USER_AGENT,
},
6 changes: 1 addition & 5 deletions cabot/cabotapp/tasks.py
Original file line number Diff line number Diff line change
@@ -99,11 +99,7 @@ def clean_db(days_to_retain=7, batch_size=10000):
InstanceStatusSnapshot.objects.filter(id__in=instance_snapshot_ids).delete()

# If we reached the batch size on either we need to re-queue to continue cleaning up.
if (
result_count == batch_size or
service_snapshot_count == batch_size or
instance_snapshot_count == batch_size
):
if result_count == batch_size or service_snapshot_count == batch_size or instance_snapshot_count == batch_size:
clean_db.apply_async(kwargs={
'days_to_retain': days_to_retain,
'batch_size': batch_size},
2 changes: 2 additions & 0 deletions cabot/cabotapp/tests/tests_basic.py
Original file line number Diff line number Diff line change
@@ -788,6 +788,7 @@ def setUp(self):
'name': u'HTTP Check',
'active': True,
'importance': u'CRITICAL',
'follow_redirects': True,
'frequency': 5,
'debounce': 0,
'endpoint': u'http://arachnys.com',
@@ -875,6 +876,7 @@ def setUp(self):
'name': u'posted http check',
'active': True,
'importance': u'ERROR',
'follow_redirects': True,
'frequency': 5,
'debounce': 0,
'endpoint': u'http://arachnys.com/post_tests',
3 changes: 2 additions & 1 deletion cabot/cabotapp/views.py
Original file line number Diff line number Diff line change
@@ -241,6 +241,7 @@ class Meta:
'password',
'text_match',
'status_code',
'follow_redirects',
'timeout',
'verify_ssl_certificate',
'frequency',
@@ -264,7 +265,7 @@ class Meta:
}),
'text_match': forms.TextInput(attrs={
'style': 'width: 100%',
'placeholder': '[Aa]rachnys\s+[Rr]ules',
'placeholder': r'[Aa]rachnys\s+[Rr]ules',
}),
'status_code': forms.TextInput(attrs={
'style': 'width: 20%',
3 changes: 2 additions & 1 deletion cabot/rest_urls.py
Original file line number Diff line number Diff line change
@@ -103,8 +103,9 @@ class ViewSet(viewset_class):
'password',
'text_match',
'status_code',
'follow_redirects',
'timeout',
'verify_ssl_certificate',
'verify_ssl_certificate'
),
))

2 changes: 1 addition & 1 deletion cabot/settings.py
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@
COMPRESS_PRECOMPILERS = (
('text/coffeescript', 'coffee --compile --stdio'),
('text/eco',
'eco -i TEMPLATES {infile} && cat "$(echo "{infile}" | sed -e "s/\.eco$/.js/g")"'),
r'eco -i TEMPLATES {infile} && cat "$(echo "{infile}" | sed -e "s/\.eco$/.js/g")"'),
('text/less', 'lessc {infile} > {outfile}'),
)

5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,10 @@
from os import environ as env
import subprocess

from pip.req import parse_requirements
try: # for pip >= 10
from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements

requirements = [str(req.req) for req in parse_requirements('requirements.txt', session=False)]
requirements_plugins = [str(req.req) for req in parse_requirements('requirements-plugins.txt', session=False)]