dev: instance licenses

This commit is contained in:
pablohashescobar 2023-10-30 17:38:18 +05:30
parent b3868423f6
commit 088615f9d6
2 changed files with 76 additions and 40 deletions

View File

@ -37,6 +37,10 @@ class InstanceEndpoint(BaseAPIView):
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
instance = Instance.objects.first()
if instance is None:
# Register the instance
user = User.objects.filter(email=email).first() user = User.objects.filter(email=email).first()
if user is None: if user is None:
user = User.objects.create( user = User.objects.create(
@ -58,7 +62,11 @@ class InstanceEndpoint(BaseAPIView):
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}
payload = {"email": email, "version": data.get("version", 0.1)} payload = {
"email": email,
"version": data.get("version", 0.1),
"domain": str(request.headers.get("Host")),
}
response = requests.post( response = requests.post(
f"{LICENSE_ENGINE_BASE_URL}/api/instances", f"{LICENSE_ENGINE_BASE_URL}/api/instances",
@ -89,6 +97,14 @@ class InstanceEndpoint(BaseAPIView):
{"error": "Unable to create instance"}, status=response.status_code {"error": "Unable to create instance"}, status=response.status_code
) )
return Response(
{
"message": "Instance is already registered",
"instance_id": str(instance.id),
},
status=status.HTTP_200_OK,
)
def get(self, request): def get(self, request):
instance = Instance.objects.first() instance = Instance.objects.first()

View File

@ -0,0 +1,20 @@
# Generated by Django 4.2.3 on 2023-10-30 11:42
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('license', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='instance',
name='last_checked_at',
field=models.DateTimeField(default=datetime.datetime(2023, 10, 30, 11, 42, 52, 273809, tzinfo=datetime.timezone.utc)),
preserve_default=False,
),
]