feat(backend): PRWLR-4022 Basic Django and DRF setup and dev tools (#4)

* chore: PRWLR-4022 add django-cors-headers

* chore: PRWLR-4022 configure basic CORS

* feat: PRWLR-4022 add drf-spectacular and spec/docs endpoints

* build: PRWLR-4022 add basic docker development deployment

* chore: PRWLR-4022 update schema generation

* chore: PRWLR-4022 bump required Python version to 3.12
This commit is contained in:
Víctor Fernández Poyatos authored and GitHub committed 2024-07-03 09:34:29 -04:00
1 parent b440be717c
commit 7ff6d860ce
24 files changed
+463 -24

No files matched your search

View File
Whitespace-only changes.
View File
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.
View File
Whitespace-only changes.
+66
View File
@@ -0,0 +1,66 @@
openapi: 3.0.3
info:
title: Prowler RESTful API
version: 1.0.0
description: |-
Prowler RESTful API specification.
This file is auto-generated.
paths:
/api/v1/schema:
get:
operationId: schema_retrieve
description: |-
OpenApi3 schema for this API. Format can be selected via content negotiation.
- YAML: application/vnd.oai.openapi
- JSON: application/vnd.oai.openapi+json
parameters:
- in: query
name: format
schema:
type: string
enum:
- json
- yaml
- in: query
name: lang
schema:
type: string
enum:
- en
tags:
- schema
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'200':
content:
application/vnd.oai.openapi:
schema:
type: object
additionalProperties: {}
application/yaml:
schema:
type: object
additionalProperties: {}
application/vnd.oai.openapi+json:
schema:
type: object
additionalProperties: {}
application/json:
schema:
type: object
additionalProperties: {}
description: ''
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
cookieAuth:
type: apiKey
in: cookie
name: sessionid
View File
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+7
View File
@@ -0,0 +1,7 @@
from django.urls import path
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView
urlpatterns = [
path("schema", SpectacularAPIView.as_view(), name="schema"),
path("docs", SpectacularRedocView.as_view(url_name="schema"), name="docs")
]
View File
Whitespace-only changes.
Whitespace-only changes.
View File
Whitespace-only changes.
+26
View File
@@ -37,11 +37,18 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
'rest_framework',
'corsheaders',
'drf_spectacular'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -49,6 +56,11 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ALLOWED_ORIGINS = [
'http://localhost',
'http://127.0.0.1'
]
ROOT_URLCONF = 'backend.urls'
TEMPLATES = [
@@ -67,6 +79,17 @@ TEMPLATES = [
},
]
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}
SPECTACULAR_SETTINGS = {
'TITLE': 'Prowler RESTful API',
'DESCRIPTION': 'Prowler RESTful API specification.\n\nThis file is auto-generated.',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': True,
}
WSGI_APPLICATION = 'backend.wsgi.application'
@@ -104,6 +127,9 @@ AUTH_PASSWORD_VALIDATORS = [
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGES = [
('en', 'English'),
]
TIME_ZONE = 'UTC'
+3 -17
View File
@@ -1,22 +1,8 @@
"""
URL configuration for backend project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/v1/', include('api.urls.v1.urls'))
]