dev: enable api key authentication

This commit is contained in:
pablohashescobar 2023-10-27 14:02:03 +05:30
parent 7f521da889
commit 7a550dd2f7
3 changed files with 8 additions and 6 deletions

View File

@ -23,7 +23,7 @@ class CheckoutEndpoint(BaseAPIView):
license = License.objects.first()
if license is None:
return Response({"error": "Instance is not activated"}, status=status.HTTP_400_BAD_REQUEST)
return Response({"error": "Instance is not activated"}, status=status.HTTP_403_FORBIDDEN)
price_id = request.data.get("price_id", False)

View File

@ -68,7 +68,7 @@ class InstanceEndpoint(BaseAPIView):
license = License.objects.first()
if license is None:
return Response({"activated": False}, status=status.HTTP_200_OK)
return Response({"activated": False}, status=status.HTTP_403_FORBIDDEN)
data = {
"instance_id": license.instance_id,

View File

@ -20,17 +20,19 @@ class ProductEndpoint(BaseAPIView):
if license is None:
return Response(
{"error": "Instance is not activated"},
status=status.HTTP_400_BAD_REQUEST,
status=status.HTTP_403_FORBIDDEN,
)
# # Request the licensing engine
headers = {
"x-api-key": license.api_key,
}
response = requests.get(
f"{LICENSE_ENGINE_BASE_URL}/api/products",
headers={
"X-Api-Key": license.api_key,
},
headers=headers,
)
if response.status_code == 200:
return Response(response.json(), status=status.HTTP_200_OK)
return Response(