dev: license check

This commit is contained in:
pablohashescobar 2023-10-30 13:59:41 +05:30
parent cc82fae0e1
commit 08a81b0c5e
5 changed files with 78 additions and 26 deletions

View File

@ -40,32 +40,34 @@ class InstanceEndpoint(BaseAPIView):
payload = {"email": email, "version": data.get("version", 0.1)}
response = requests.post(
f"{LICENSE_ENGINE_BASE_URL}/api/instances",
headers=headers,
data=json.dumps(payload),
)
print(request.get_host())
if response.status_code == 201:
data = response.json()
license = License.objects.create(
instance_id=data.get("id"),
license_key=data.get("license_key"),
api_key=data.get("api_key"),
version=data.get("version"),
email=data.get("email"),
last_checked_at=timezone.now(),
)
return Response(
{
"id": str(license.instance_id),
"message": "Instance registered succesfully",
},
status=status.HTTP_200_OK,
)
# response = requests.post(
# f"{LICENSE_ENGINE_BASE_URL}/api/instances",
# headers=headers,
# data=json.dumps(payload),
# )
# if response.status_code == 201:
# data = response.json()
# license = License.objects.create(
# instance_id=data.get("id"),
# license_key=data.get("license_key"),
# api_key=data.get("api_key"),
# version=data.get("version"),
# email=data.get("email"),
# last_checked_at=timezone.now(),
# )
# return Response(
# {
# "id": str(license.instance_id),
# "message": "Instance registered succesfully",
# },
# status=status.HTTP_200_OK,
# )
return Response(
{"error": "Unable to create instance"}, status=response.status_code
{"error": "Unable to create instance"}, status=200
)
def get(self, request):

View File

@ -1,7 +1,19 @@
# Django imports
from django.utils import timezone
# Third party imports
from celery import shared_task
# Module imports
from plane.license.models import License
@shared_task
def license_check_task():
license = License.objects.first()
now = timezone.now()
if license.check_frequency == "daily" and (now - license.last_checked_at).total_seconds() > 86400:
pass
if license.check_frequency == "fortnite" and (now - license.last_checked_at).total_seconds():
pass

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.3 on 2023-10-27 11:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('license', '0004_alter_license_instance_id'),
]
operations = [
migrations.AddField(
model_name='license',
name='last_checked_at',
field=models.DateTimeField(null=True),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.3 on 2023-10-27 11:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('license', '0005_license_last_checked_at'),
]
operations = [
migrations.AddField(
model_name='license',
name='check_frequency',
field=models.CharField(null=True),
),
]

View File

@ -11,7 +11,9 @@ class License(BaseModel):
api_key = models.CharField(max_length=16)
version = models.CharField(max_length=10)
email = models.CharField(max_length=256)
# last_checked_at = models.DateTimeField(null=True)
last_checked_at = models.DateTimeField(null=True)
check_frequency = models.CharField(null=True)
class Meta:
verbose_name = "License"