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

Feature - Add Route 53 support #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions ghostwriter/commandcenter/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
ReportConfiguration,
SlackConfiguration,
VirusTotalConfiguration,
Route53Configuration,
)

admin.site.register(CloudServicesConfiguration, SingletonModelAdmin)
admin.site.register(CompanyInformation, SingletonModelAdmin)
admin.site.register(NamecheapConfiguration, SingletonModelAdmin)
admin.site.register(SlackConfiguration, SingletonModelAdmin)
admin.site.register(VirusTotalConfiguration, SingletonModelAdmin)
admin.site.register(Route53Configuration, SingletonModelAdmin)


class ReportConfigurationAdmin(SingletonModelAdmin):
Expand Down
25 changes: 25 additions & 0 deletions ghostwriter/commandcenter/migrations/0006_route53configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.0.10 on 2021-01-08 03:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('commandcenter', '0005_auto_20201102_2207'),
]

operations = [
migrations.CreateModel(
name='Route53Configuration',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('enable', models.BooleanField(default=False)),
('access_key', models.CharField(default='Route53 Access Key', max_length=255)),
('secret_access_key', models.CharField(default='Route53 Secret Access Key', max_length=255)),
],
options={
'verbose_name': 'Route53 Configuration',
},
),
]
16 changes: 16 additions & 0 deletions ghostwriter/commandcenter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ def sanitized_api_key(self):
return sanitize(self.api_key)


class Route53Configuration(SingletonModel):
enable = models.BooleanField(default=False)
access_key = models.CharField(max_length=255, default="Route53 Access Key")
secret_access_key = models.CharField(max_length=255, default="Route53 Secret Access Key")

def __str__(self):
return "Route53 Configuration"

class Meta:
verbose_name = "Route53 Configuration"

@property
def sanitized_secret_access_key(self):
return sanitize(self.secret_access_key)


class ReportConfiguration(SingletonModel):
enable_borders = models.BooleanField(
default=False, help_text="Enable borders around images in Word documents"
Expand Down
21 changes: 21 additions & 0 deletions ghostwriter/home/templates/home/management.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{% get_solo "commandcenter.CompanyInformation" as company_config %}
{% get_solo "commandcenter.CloudServicesConfiguration" as cloud_config %}
{% get_solo "commandcenter.NamecheapConfiguration" as namecheap_config %}
{% get_solo "commandcenter.Route53Configuration" as route53_config %}
{% get_solo "commandcenter.ReportConfiguration" as report_config %}
{% get_solo "commandcenter.SlackConfiguration" as slack_config %}
{% get_solo "commandcenter.VirusTotalConfiguration" as vt_config %}
Expand Down Expand Up @@ -122,6 +123,25 @@ <h2>API & Notification Configurations</h2>
<td>Disabled</td>
</tr>
{% endif %}
{% if route53_config.enable %}
<tr>
<td><i class="fas fa-toggle-on"></i> Route53 API Enabled</td>
<td>{{ route53_config.enable }}</td>
</tr>
<tr>
<td><i class="fas fa-key"></i> Route53 Access Key</td>
<td>{{ route53_config.access_key }}</td>
</tr>
<tr>
<td><i class="fas fa-key"></i> Route53 Secret Access Key</td>
<td>{{ route53_config.sanitized_secret_access_key }}</td>
</tr>
{% else %}
<tr>
<td><i class="fas fa-toggle-off"></i> Route53 API Enabled</td>
<td>Disabled</td>
</tr>
{% endif %}

<!-- Spacer -->
<tr>
Expand Down Expand Up @@ -212,6 +232,7 @@ <h6>Test Configurations</h6>

<div class="btn-group mr-2" role="group" aria-label="API Tests">
<button class="js-queue-task btn btn-primary" queue-task-url="{% url 'home:ajax_test_namecheap' %}" queue-task-csrf-token="{{ csrf_token }}">Test Namecheap API</button>
<button class="js-queue-task btn btn-primary" queue-task-url="{% url 'home:ajax_test_route53' %}" queue-task-csrf-token="{{ csrf_token }}">Test Route53 API</button>
<button class="js-queue-task btn btn-primary" queue-task-url="{% url 'home:ajax_test_virustotal' %}" queue-task-csrf-token="{{ csrf_token }}">Test VirusTotal API</button>
</div>

Expand Down
5 changes: 5 additions & 0 deletions ghostwriter/home/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
views.TestNamecheapConnection.as_view(),
name="ajax_test_namecheap",
),
path(
"ajax/management/test/route53",
views.TestRoute53Connection.as_view(),
name="ajax_test_route53",
),
path(
"ajax/management/test/slack",
views.TestSlackConnection.as_view(),
Expand Down
35 changes: 35 additions & 0 deletions ghostwriter/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,41 @@ def post(self, request, *args, **kwargs):
return JsonResponse(data)


class TestRoute53Connection(LoginRequiredMixin, UserPassesTestMixin, View):
"""
Create an individual :model:`django_q.Task` under group ``Route53 Test`` with
:task:`shepherd.tasks.test_route53` to test the Route53 API configuration stored
in :model:`commandcenter.Route53Configuration`.
"""

def test_func(self):
return self.request.user.is_staff

def handle_no_permission(self):
messages.error(self.request, "You do not have permission to access that")
return redirect("home:dashboard")

def post(self, request, *args, **kwargs):
# Add an async task grouped as ``Route53 Test``
result = "success"
try:
task_id = async_task(
"ghostwriter.shepherd.tasks.test_route53",
self.request.user,
group="Route53 Test",
)
message = "Route53 API test has been successfully queued"
except Exception:
result = "error"
message = "Route53 API test could not be queued"

data = {
"result": result,
"message": message,
}
return JsonResponse(data)


class TestSlackConnection(LoginRequiredMixin, UserPassesTestMixin, View):
"""
Create an individual :model:`django_q.Task` under group ``Slack Test`` with
Expand Down
Loading