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

Add basic autogenerated docs #65

Open
wants to merge 2 commits into
base: main
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
47 changes: 36 additions & 11 deletions proxylist/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from proxylist.base64_decoder import decode_base64
from proxylist.proxy import update_proxy_status, get_proxy_location
from shadowmere import settings


def validate_sip002(value):
Expand All @@ -31,7 +32,7 @@ def validate_not_existing(value):

def validate_proxy_can_connect(value):
location = get_proxy_location(get_sip002(value))
if location is None or location == 'unknown':
if location is None or location == "unknown":
raise ValidationError(
"Can't get the location for this address",
params={"value": value},
Expand All @@ -47,17 +48,41 @@ class Proxy(ExportModelOperationsMixin("proxy"), models.Model):
validate_not_existing,
validate_proxy_can_connect,
],
help_text="SIP002 compatible URL representing a key",
)
location = models.CharField(
max_length=100,
default="",
help_text="Where is this proxy located geographically",
)
location_country_code = models.CharField(
max_length=3, default="", help_text="2 letters country code (e.g.: DE)"
)
location_country = models.CharField(
max_length=50, default="", help_text="Country hosting this proxy"
)
ip_address = models.CharField(
max_length=100, default="", help_text="Proxy IP address"
)
port = models.IntegerField(default=0, help_text="Port used by this key")
is_active = models.BooleanField(
default=False,
help_text=f"Whether or not this key worked in the past {settings.CHECK_INTERVAL_MINUTES} minutes",
)
last_checked = models.DateTimeField(
auto_now=True, help_text="Last time this key was tested"
)
last_active = models.DateTimeField(
blank=True,
default=now,
help_text="Last time this key responded positively to a test",
)
times_checked = models.IntegerField(
default=0, help_text="How many times was this key tested so far"
)
times_check_succeeded = models.IntegerField(
default=0, help_text="How many times this key responded positively to a test"
)
location = models.CharField(max_length=100, default="")
location_country_code = models.CharField(max_length=3, default="")
location_country = models.CharField(max_length=50, default="")
ip_address = models.CharField(max_length=100, default="")
port = models.IntegerField(default=0)
is_active = models.BooleanField(default=False)
last_checked = models.DateTimeField(auto_now=True)
last_active = models.DateTimeField(blank=True, default=now)
times_checked = models.IntegerField(default=0)
times_check_succeeded = models.IntegerField(default=0)

def __str__(self):
return f"{self.location} ({self.url})"
Expand Down
1 change: 1 addition & 0 deletions proxylist/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Meta:
read_only_fields = [
"id",
"location",
"location_country",
"location_country_code",
"ip_address",
"is_active",
Expand Down
3 changes: 2 additions & 1 deletion proxylist/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django.views.decorators.cache import cache_page
from django_filters import rest_framework as filters
from rest_framework import viewsets
from rest_framework.decorators import api_view
from rest_framework.response import Response

from proxylist.base64_decoder import decode_base64
Expand Down Expand Up @@ -115,6 +114,7 @@ class CountryCodeViewSet(viewsets.ViewSet):
"""
List all country codes and countries with active proxies
"""

def list(self, request, format=None):
country_codes = [
{"code": code["location_country_code"], "name": code["location_country"]}
Expand All @@ -131,6 +131,7 @@ class PortViewSet(viewsets.ViewSet):
"""
List all available ports
"""

def list(self, request, format=None):
ports = [
port
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
botocore==1.28.3
celery==5.2.7
coreapi==2.3.3
Django==4.1.2
django-admin-rangefilter==0.9.0
django-filter==22.1
Expand Down
4 changes: 3 additions & 1 deletion shadowmere/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@

CELERY_BROKER_URL = "redis://redis:6379"
CELERY_RESULT_BACKEND = "redis://redis:6379"
CHECK_INTERVAL_MINUTES = 20

CELERY_BEAT_SCHEDULE = {
"update_status": {
"task": "proxylist.tasks.update_status",
"schedule": crontab(minute="*/20"),
"schedule": crontab(minute=f"*/{CHECK_INTERVAL_MINUTES}"),
},
}

Expand All @@ -240,6 +241,7 @@
PROMETHEUS_METRICS_EXPORT_PORT_RANGE = range(8002, 8008)

REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
"DEFAULT_PAGINATION_CLASS": "proxylist.pagination.ProxiesPagination",
"PAGE_SIZE": 10,
}
Expand Down
2 changes: 2 additions & 0 deletions shadowmere/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from rest_framework.documentation import include_docs_urls

import proxylist.views
from proxylist import views
Expand All @@ -19,4 +20,5 @@
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
path("api/", include(router.urls)),
path("", include("django_prometheus.urls")),
path('docs/', include_docs_urls(title='Shadowmere API docs'))
]