mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-11-08 12:24:45 +00:00
feat(poc): Add in current PoC to the repo that will be used by Vercel
This commit is contained in:
commit
5583714c7a
65 files changed
+2083
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,6 @@
|
||||
from django.contrib import admin
|
||||
from .models import Account, CloudAccount, Audit
|
||||
|
||||
admin.site.register(Account)
|
||||
admin.site.register(CloudAccount)
|
||||
admin.site.register(Audit)
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'api'
|
||||
@@ -0,0 +1,193 @@
|
||||
[
|
||||
{
|
||||
"model": "api.account",
|
||||
"pk": "c0bbdcd2-c69e-4bdf-bea7-8db6524fd205",
|
||||
"fields": {
|
||||
"name": "prod",
|
||||
"inserted_at": "2024-06-25T09:03:20.273Z",
|
||||
"updated_at": "2024-06-25T09:03:20.273Z",
|
||||
"aws_account_id": "1234567890",
|
||||
"scan_window_start_at": "2024-06-29T09:03:17Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.account",
|
||||
"pk": "cf51b7a0-687e-4a2a-bf3d-14f98dcb4c3f",
|
||||
"fields": {
|
||||
"name": "platform",
|
||||
"inserted_at": "2024-06-25T09:03:08.847Z",
|
||||
"updated_at": "2024-06-25T09:03:08.847Z",
|
||||
"aws_account_id": "1234567890",
|
||||
"scan_window_start_at": "2024-06-28T09:03:08Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.account",
|
||||
"pk": "cf9d2400-9a10-4c7b-a3be-6215c41b619e",
|
||||
"fields": {
|
||||
"name": "dev",
|
||||
"inserted_at": "2024-06-25T09:02:34.188Z",
|
||||
"updated_at": "2024-06-25T09:02:34.188Z",
|
||||
"aws_account_id": "12345467890",
|
||||
"scan_window_start_at": "2024-06-29T09:02:27Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.account",
|
||||
"pk": "dbc452bd-b51c-4199-8b42-c1bc8164d45d",
|
||||
"fields": {
|
||||
"name": "marketplace",
|
||||
"inserted_at": "2024-06-25T09:02:58.412Z",
|
||||
"updated_at": "2024-06-25T09:02:58.412Z",
|
||||
"aws_account_id": "1234567890",
|
||||
"scan_window_start_at": "2024-06-27T09:02:57Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.account",
|
||||
"pk": "fabc5b58-901b-4ba6-9901-4b2349acf492",
|
||||
"fields": {
|
||||
"name": "management",
|
||||
"inserted_at": "2024-06-25T09:02:46.950Z",
|
||||
"updated_at": "2024-06-25T09:02:46.950Z",
|
||||
"aws_account_id": "1234567890",
|
||||
"scan_window_start_at": "2024-06-27T09:02:46Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.cloudaccount",
|
||||
"pk": "1f1dd221-6d49-4413-a8b7-e10ca4b0660a",
|
||||
"fields": {
|
||||
"account_id": "cf9d2400-9a10-4c7b-a3be-6215c41b619e",
|
||||
"type": "test",
|
||||
"groups": [
|
||||
"Operation"
|
||||
],
|
||||
"resources": 644,
|
||||
"enable": true,
|
||||
"provider_id": "aws",
|
||||
"inserted_at": "2024-06-25T09:03:57.233Z",
|
||||
"updated_at": "2024-06-25T09:03:57.233Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.cloudaccount",
|
||||
"pk": "4997b2eb-a9f9-4d12-800b-1a6394728510",
|
||||
"fields": {
|
||||
"account_id": "c0bbdcd2-c69e-4bdf-bea7-8db6524fd205",
|
||||
"type": "test",
|
||||
"groups": [
|
||||
"Production"
|
||||
],
|
||||
"resources": 564,
|
||||
"enable": true,
|
||||
"provider_id": "aws",
|
||||
"inserted_at": "2024-06-25T09:04:56.941Z",
|
||||
"updated_at": "2024-06-25T09:04:56.941Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.cloudaccount",
|
||||
"pk": "668bb77d-cfb4-4f4a-8c51-45beb16af4e9",
|
||||
"fields": {
|
||||
"account_id": "dbc452bd-b51c-4199-8b42-c1bc8164d45d",
|
||||
"type": "test",
|
||||
"groups": [
|
||||
"Production"
|
||||
],
|
||||
"resources": 148,
|
||||
"enable": true,
|
||||
"provider_id": "aws",
|
||||
"inserted_at": "2024-06-25T09:04:31.753Z",
|
||||
"updated_at": "2024-06-25T09:04:31.753Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.cloudaccount",
|
||||
"pk": "a50d3d9d-ac2d-47d1-ac6c-29c8d304072e",
|
||||
"fields": {
|
||||
"account_id": "fabc5b58-901b-4ba6-9901-4b2349acf492",
|
||||
"type": "test",
|
||||
"groups": [
|
||||
"Production",
|
||||
"Operation"
|
||||
],
|
||||
"resources": 356,
|
||||
"enable": true,
|
||||
"provider_id": "aws",
|
||||
"inserted_at": "2024-06-25T09:04:14.567Z",
|
||||
"updated_at": "2024-06-25T09:04:14.567Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.cloudaccount",
|
||||
"pk": "d71c8ac6-074d-45a3-a7a7-0595ab5440bc",
|
||||
"fields": {
|
||||
"account_id": "cf51b7a0-687e-4a2a-bf3d-14f98dcb4c3f",
|
||||
"type": "test",
|
||||
"groups": [
|
||||
"Production"
|
||||
],
|
||||
"resources": 112,
|
||||
"enable": true,
|
||||
"provider_id": "aws",
|
||||
"inserted_at": "2024-06-25T09:04:44.431Z",
|
||||
"updated_at": "2024-06-25T09:04:44.431Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.audit",
|
||||
"pk": "0f712e8e-b419-40b4-9d85-65ef723fc1b9",
|
||||
"fields": {
|
||||
"aws_account_id": "fabc5b58-901b-4ba6-9901-4b2349acf492",
|
||||
"audit_complete": true,
|
||||
"inserted_at": "2024-06-25T09:05:37.352Z",
|
||||
"updated_at": "2024-06-25T09:05:37.352Z",
|
||||
"audit_duration": "00:06:30"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.audit",
|
||||
"pk": "1bf18315-34e6-4912-8e8e-3e4650e4653e",
|
||||
"fields": {
|
||||
"aws_account_id": "dbc452bd-b51c-4199-8b42-c1bc8164d45d",
|
||||
"audit_complete": true,
|
||||
"inserted_at": "2024-06-25T09:05:43.601Z",
|
||||
"updated_at": "2024-06-25T09:05:43.601Z",
|
||||
"audit_duration": "00:08:00"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.audit",
|
||||
"pk": "48605239-58ee-4dbf-8a46-3ef42b270a19",
|
||||
"fields": {
|
||||
"aws_account_id": "cf9d2400-9a10-4c7b-a3be-6215c41b619e",
|
||||
"audit_complete": true,
|
||||
"inserted_at": "2024-06-25T09:05:29.533Z",
|
||||
"updated_at": "2024-06-25T09:05:29.533Z",
|
||||
"audit_duration": "00:06:12"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.audit",
|
||||
"pk": "955c1a4f-496a-4df5-96c8-578280b7a914",
|
||||
"fields": {
|
||||
"aws_account_id": "cf51b7a0-687e-4a2a-bf3d-14f98dcb4c3f",
|
||||
"audit_complete": true,
|
||||
"inserted_at": "2024-06-25T09:05:49.405Z",
|
||||
"updated_at": "2024-06-25T09:05:49.405Z",
|
||||
"audit_duration": "00:06:40"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "api.audit",
|
||||
"pk": "ccbedd87-d64e-42dd-86d0-15ac60ade56d",
|
||||
"fields": {
|
||||
"aws_account_id": "c0bbdcd2-c69e-4bdf-bea7-8db6524fd205",
|
||||
"audit_complete": true,
|
||||
"inserted_at": "2024-06-25T09:06:00.463Z",
|
||||
"updated_at": "2024-06-25T09:06:00.463Z",
|
||||
"audit_duration": "00:07:12"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,65 @@
|
||||
# Generated by Django 5.0.6 on 2024-06-24 10:11
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Account',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('token', models.CharField(max_length=255)),
|
||||
('inserted_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('card_brand', models.CharField(max_length=255)),
|
||||
('card_exp_month', models.IntegerField()),
|
||||
('card_exp_year', models.IntegerField()),
|
||||
('card_last4', models.CharField(max_length=4)),
|
||||
('onboarding_required', models.BooleanField()),
|
||||
('onboarding_step', models.CharField(max_length=255)),
|
||||
('onboarding_completed_at', models.DateTimeField()),
|
||||
('aws_account_id', models.CharField(max_length=255)),
|
||||
('off_boarded', models.BooleanField()),
|
||||
('billing_type', models.CharField(max_length=255)),
|
||||
('billing_cancel_at', models.DateTimeField()),
|
||||
('billing_current_period_end_at', models.DateTimeField()),
|
||||
('billing_free_resource_count', models.IntegerField()),
|
||||
('grafana_org_name', models.CharField(max_length=255)),
|
||||
('billing_email', models.CharField(max_length=255)),
|
||||
('scan_window_start_at', models.DateTimeField()),
|
||||
('company_name', models.CharField(max_length=255)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'accounts',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CloudAccount',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('type', models.CharField(max_length=255)),
|
||||
('enable', models.BooleanField()),
|
||||
('provider_id', models.CharField(max_length=255)),
|
||||
('provider_data', models.JSONField()),
|
||||
('inserted_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('connected', models.BooleanField()),
|
||||
('last_checked_at', models.DateTimeField()),
|
||||
('alias', models.CharField(max_length=255)),
|
||||
('scanner_configuration', models.JSONField()),
|
||||
('account_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.account')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'cloud_accounts',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,54 @@
|
||||
# Generated by Django 5.0.6 on 2024-06-25 08:56
|
||||
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='cloudaccount',
|
||||
name='groups',
|
||||
field=models.JSONField(default=list),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='cloudaccount',
|
||||
name='resources',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='account',
|
||||
name='id',
|
||||
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='cloudaccount',
|
||||
name='account_id',
|
||||
field=models.ForeignKey(db_column='account_id', on_delete=django.db.models.deletion.CASCADE, to='api.account', unique=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='cloudaccount',
|
||||
name='id',
|
||||
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Audit',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('audit_complete', models.BooleanField(default=True)),
|
||||
('inserted_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('audit_duration', models.DurationField()),
|
||||
('aws_account_id', models.ForeignKey(db_column='aws_account_id', on_delete=django.db.models.deletion.CASCADE, to='api.cloudaccount', to_field='account_id', unique=True)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'audits',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.0.6 on 2024-06-25 08:57
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0002_cloudaccount_groups_cloudaccount_resources_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='audit',
|
||||
name='aws_account_id',
|
||||
field=models.OneToOneField(db_column='aws_account_id', on_delete=django.db.models.deletion.CASCADE, to='api.cloudaccount', to_field='account_id'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='cloudaccount',
|
||||
name='account_id',
|
||||
field=models.OneToOneField(db_column='account_id', on_delete=django.db.models.deletion.CASCADE, to='api.account'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,97 @@
|
||||
# Generated by Django 5.0.6 on 2024-06-25 09:01
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0003_alter_audit_aws_account_id_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='billing_cancel_at',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='billing_current_period_end_at',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='billing_email',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='billing_free_resource_count',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='billing_type',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='card_brand',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='card_exp_month',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='card_exp_year',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='card_last4',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='company_name',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='grafana_org_name',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='off_boarded',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='onboarding_completed_at',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='onboarding_required',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='onboarding_step',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='account',
|
||||
name='token',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='cloudaccount',
|
||||
name='alias',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='cloudaccount',
|
||||
name='connected',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='cloudaccount',
|
||||
name='last_checked_at',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='cloudaccount',
|
||||
name='provider_data',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='cloudaccount',
|
||||
name='scanner_configuration',
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,55 @@
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Account(models.Model):
|
||||
class Meta:
|
||||
db_table = "accounts"
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=255)
|
||||
inserted_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
aws_account_id = models.CharField(max_length=255)
|
||||
scan_window_start_at = models.DateTimeField()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} - {self.id}"
|
||||
|
||||
|
||||
class CloudAccount(models.Model):
|
||||
class Meta:
|
||||
db_table = "cloud_accounts"
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
account_id = models.OneToOneField(
|
||||
Account, on_delete=models.CASCADE, db_column="account_id", to_field="id"
|
||||
)
|
||||
type = models.CharField(max_length=255)
|
||||
groups = models.JSONField(default=list)
|
||||
resources = models.IntegerField(default=0)
|
||||
enable = models.BooleanField()
|
||||
provider_id = models.CharField(max_length=255)
|
||||
inserted_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.id} ({self.provider_id})"
|
||||
|
||||
|
||||
class Audit(models.Model):
|
||||
class Meta:
|
||||
db_table = "audits"
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
aws_account_id = models.OneToOneField(
|
||||
CloudAccount, on_delete=models.CASCADE, db_column="aws_account_id", to_field="account_id"
|
||||
)
|
||||
audit_complete = models.BooleanField(default=True)
|
||||
inserted_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
audit_duration = models.DurationField()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.id} - {self.aws_account_id}"
|
||||
@@ -0,0 +1,25 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Account, CloudAccount, Audit
|
||||
|
||||
|
||||
class AccountSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Account
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class CloudAccountSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = CloudAccount
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class AuditSerializer(serializers.ModelSerializer):
|
||||
account_id = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Audit
|
||||
fields = ['id', 'audit_complete', 'inserted_at', 'updated_at', 'audit_duration', 'account_id']
|
||||
|
||||
def get_account_id(self, obj):
|
||||
return obj.aws_account_id.account_id.id
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
|
||||
from .views import AuditListView, CloudAccountListView
|
||||
|
||||
urlpatterns = [
|
||||
path('providers/<str:provider_id>/accounts', CloudAccountListView.as_view(), name='cloud-account-list'),
|
||||
path('providers/aws/audits', AuditListView.as_view(), name='aws-audit-list'),
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
from rest_framework import generics
|
||||
from .models import Account, CloudAccount, Audit
|
||||
from .serializers import AccountSerializer, CloudAccountSerializer, AuditSerializer
|
||||
|
||||
|
||||
class AccountListView(generics.ListAPIView):
|
||||
queryset = Account.objects.all()
|
||||
serializer_class = AccountSerializer
|
||||
|
||||
|
||||
class CloudAccountListView(generics.ListAPIView):
|
||||
serializer_class = CloudAccountSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
provider_id = self.kwargs.get('provider_id')
|
||||
return CloudAccount.objects.filter(provider_id=provider_id)
|
||||
|
||||
|
||||
class AuditListView(generics.ListAPIView):
|
||||
serializer_class = AuditSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Audit.objects.all()
|
||||
account_id = self.request.query_params.get('account_id')
|
||||
if account_id:
|
||||
queryset = queryset.filter(aws_account_id__account_id=account_id)
|
||||
return queryset
|
||||
Reference in new issue
Block a user