Skip to content

Commit

Permalink
Rename pop_backend to pob_backend
Browse files Browse the repository at this point in the history
Signed-off-by: George J Padayatti <[email protected]>
  • Loading branch information
georgepadayatti committed Nov 1, 2022
1 parent 961a20e commit 9c6accc
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 108 deletions.
156 changes: 82 additions & 74 deletions certificate/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from django.shortcuts import render
from rest_framework.decorators import api_view, permission_classes
from rest_framework import permissions
from pop_backend.settings import COMPANY_AGENT_URL, ISSUER_AGENT_URL
from pob_backend.settings import COMPANY_AGENT_URL, ISSUER_AGENT_URL
from igrant_user.models import IGrantUser
from rest_framework.response import Response
from rest_framework import status
from .models import Certificates
from certificate.models import Certificates
import requests

authorization = "ApiKey eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2MjRjMDFlNzdlZmY2ZjAwMDE2NGJiOTIiLCJvcmdpZCI6IiIsImV4cCI6MTY4MDI1Mjk0Mn0.g6gCu7Mr1DompSXK8kQYhBUqRJ1PsOtahhxmB-klV10"


@permission_classes([permissions.IsAuthenticated])
@api_view(['GET'])
@api_view(["GET"])
def get_certificates(request):
"""
certificates = Certificates.objects.filter(user=request.user).values('credential_exchange_id').all()
Expand All @@ -21,12 +22,18 @@ def get_certificates(request):
"""
organisation_id = "6343ecbb6de5d70001ac038e"
url = f"https://cloudagent.igrant.io/v1/{organisation_id}/admin/credentials?count=1000"
response = requests.get(url,
headers={'Authorization': authorization, 'content-type': 'application/json;charset=UTF-8'})
response = requests.get(
url,
headers={
"Authorization": authorization,
"content-type": "application/json;charset=UTF-8",
},
)
return Response(response.json(), status=response.status_code)


@permission_classes([permissions.IsAuthenticated])
@api_view(['GET'])
@api_view(["GET"])
def request_certificates(request):
url = "https://cloudagent.igrant.io/v1/624c025d7eff6f000164bb94/admin/issue-credential/send-offer"
payload = {
Expand All @@ -39,102 +46,103 @@ def request_certificates(request):
"credential_preview": {
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview",
"attributes": [
{
"name": "name",
"value": "Bygg AB"
},
{
"name": "legalForm",
"value": "Aktiebolag"
},
{
"name": "activity",
"value": "Construction Industry"
},
{
"name": "registrationDate",
"value": "2005-10-08"
},
{
"name": "legalStatus",
"value": "ACTIVE"
},
{"name": "name", "value": "Bygg AB"},
{"name": "legalForm", "value": "Aktiebolag"},
{"name": "activity", "value": "Construction Industry"},
{"name": "registrationDate", "value": "2005-10-08"},
{"name": "legalStatus", "value": "ACTIVE"},
{
"name": "registeredAddress.fullAddress",
"value": "Sveavägen 48, 111 34 Stockholm, Sweden"
},
{
"name": "registeredAddress.thoroughFare",
"value": "Sveavägen"
"value": "Sveavägen 48, 111 34 Stockholm, Sweden",
},
{
"name": "registeredAddress.locatorDesignator",
"value": "48"
},
{
"name": "registeredAddress.postCode",
"value": "111 34"
},
{
"name": "registeredAddress.postName",
"value": "Stockholm"
},
{
"name": "registeredAddress.adminUnitLevel1",
"value": "SE"
}
]
{"name": "registeredAddress.thoroughFare", "value": "Sveavägen"},
{"name": "registeredAddress.locatorDesignator", "value": "48"},
{"name": "registeredAddress.postCode", "value": "111 34"},
{"name": "registeredAddress.postName", "value": "Stockholm"},
{"name": "registeredAddress.adminUnitLevel1", "value": "SE"},
],
},
"auto_issue": True
"auto_issue": True,
}
response = requests.post(url,
headers={'Authorization': authorization, 'content-type': 'application/json;charset=UTF-8'},
json=payload)
response = requests.post(
url,
headers={
"Authorization": authorization,
"content-type": "application/json;charset=UTF-8",
},
json=payload,
)
if response.status_code == 200:
instance = Certificates.objects.create(user=request.user,
credential_exchange_id=response.json().get('credential_exchange_id'))
instance = Certificates.objects.create(
user=request.user,
credential_exchange_id=response.json().get("credential_exchange_id"),
)
instance.save()
return Response(response.json(), status=response.status_code)
else:
return Response(response.text, status=response.status_code)


@permission_classes([permissions.IsAuthenticated])
@api_view(['GET'])
@api_view(["GET"])
def check_certificate(request):
credential_exchange_id = request.GET['credential_exchange_id']
credential_exchange_id = request.GET["credential_exchange_id"]
url = f"https://cloudagent.igrant.io/v1/624c025d7eff6f000164bb94/admin/issue-credential/records/{credential_exchange_id}"
response = requests.get(url,
headers={'Authorization': authorization, 'content-type': 'application/json;charset=UTF-8'})
response = requests.get(
url,
headers={
"Authorization": authorization,
"content-type": "application/json;charset=UTF-8",
},
)
return Response(response.json(), status=response.status_code)


@permission_classes([permissions.IsAuthenticated])
@api_view(['GET'])
@api_view(["GET"])
def get_certificate_schemas(request):
organisation_id = request.GET['organisation_id']
organisation_id = request.GET["organisation_id"]
url = f"https://cloudagent.igrant.io/v1/{organisation_id}/admin/v1/data-agreements?method_of_use=data-source&publish_flag=true&page=1&page_size=1000000"
response = requests.get(url,
headers={'Authorization': authorization, 'content-type': 'application/json;charset=UTF-8'})
response = requests.get(
url,
headers={
"Authorization": authorization,
"content-type": "application/json;charset=UTF-8",
},
)
return Response(response.json(), status=response.status_code)


@permission_classes([permissions.IsAuthenticated])
@api_view(['GET'])
@api_view(["GET"])
def get_certificate_schema_attributes(request):
organisation_id = request.GET['organisation_id']
schema_id = request.GET['schema_id']
organisation_id = request.GET["organisation_id"]
schema_id = request.GET["schema_id"]
url = f"https://cloudagent.igrant.io/v1/{organisation_id}/admin/schemas/{schema_id}"
print(url)
response = requests.get(url,
headers={'Authorization': authorization, 'content-type': 'application/json;charset=UTF-8'})
response = requests.get(
url,
headers={
"Authorization": authorization,
"content-type": "application/json;charset=UTF-8",
},
)
return Response(response.json(), status=response.status_code)


@permission_classes([permissions.IsAuthenticated])
@api_view(['DELETE'])
@api_view(["DELETE"])
def delete_certificate(request):
organisation_id = request.GET['organisation_id']
referent = request.GET['referent']
url = f"https://cloudagent.igrant.io/v1/{organisation_id}/admin/credential/{referent}"
response = requests.delete(url,
headers={'Authorization': authorization, 'content-type': 'application/json;charset=UTF-8'})
return Response(status=response.status_code)
organisation_id = request.GET["organisation_id"]
referent = request.GET["referent"]
url = (
f"https://cloudagent.igrant.io/v1/{organisation_id}/admin/credential/{referent}"
)
response = requests.delete(
url,
headers={
"Authorization": authorization,
"content-type": "application/json;charset=UTF-8",
},
)
return Response(status=response.status_code)
48 changes: 30 additions & 18 deletions connections/views.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
from django.shortcuts import render
from rest_framework.decorators import api_view, permission_classes
from rest_framework import permissions
from pop_backend.settings import COMPANY_AGENT_URL, ISSUER_AGENT_URL
from pob_backend.settings import COMPANY_AGENT_URL, ISSUER_AGENT_URL
from igrant_user.models import IGrantUser
from rest_framework.response import Response
from rest_framework import status
from .models import Invitations
from connections.models import Invitations
import json
import base64

import requests

@api_view(['GET'])

@api_view(["GET"])
def get_default_wallet(request):
organisation_id = "624c025d7eff6f000164bb94"
authorization = "ApiKey eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2MzQzZWM0ZjZkZTVkNzAwMDFhYzAzOGQiLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTY5NjUwMDAxOH0.8hSeQhWhU0xg8mbJbqNhx8OHHDF_PkJdNiRrAvgkjEs"
url = f"https://staging-api.igrant.io/v1/organizations/{organisation_id}/aries-cloudagent"
response = requests.get(url,
headers={'Authorization': authorization, 'content-type': 'application/json;charset=UTF-8'})
response = requests.get(
url,
headers={
"Authorization": authorization,
"content-type": "application/json;charset=UTF-8",
},
)
return Response(response.json(), status=response.status_code)


def get_endpoint(request):
endpoint = ''
endpoint = ""
if request.user.user_type == IGrantUser.UserType.COMPANY:
endpoint = COMPANY_AGENT_URL
else:
endpoint = ISSUER_AGENT_URL
print(endpoint)
return endpoint


@permission_classes([permissions.IsAuthenticated])
@api_view(['GET'])
@api_view(["GET"])
def get_connections(request):
url = "https://staging-api.igrant.io/v1/organizations/624c025d7eff6f000164bb94/aries-cloudagent"
authorization_header = 'ApiKey eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2MzQzZWM0ZjZkZTVkNzAwMDFhYzAzOGQiLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTY5NjUwMDAxOH0.8hSeQhWhU0xg8mbJbqNhx8OHHDF_PkJdNiRrAvgkjEs'
response = requests.get(url, headers={'Authorization': authorization_header})
authorization_header = "ApiKey eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2MzQzZWM0ZjZkZTVkNzAwMDFhYzAzOGQiLCJvcmdpZCI6IiIsImVudiI6IiIsImV4cCI6MTY5NjUwMDAxOH0.8hSeQhWhU0xg8mbJbqNhx8OHHDF_PkJdNiRrAvgkjEs"
response = requests.get(url, headers={"Authorization": authorization_header})
return Response(response.json(), status=response.status_code)

return
Expand All @@ -52,25 +60,29 @@ def get_connections(request):
}, status=response.status_code)
"""


@permission_classes([permissions.IsAuthenticated])
@api_view(['POST'])
@api_view(["POST"])
def accept_invitation(request):
endpoint = get_endpoint(request)
body = request.data
print(body)
connection_url = body.get('connection_url', None)
connection_url = body.get("connection_url", None)
if connection_url is not None:
payload = {
"connection_url": connection_url
}
response = requests.post(endpoint + '/v2/connections/receive-invitation?auto_accept=true', json=payload)
payload = {"connection_url": connection_url}
response = requests.post(
endpoint + "/v2/connections/receive-invitation?auto_accept=true",
json=payload,
)
if response.status_code == status.HTTP_200_OK:
connection = response.json()
connection_id = connection.get('connection_id')
connection_data = connection_url.split('c_i=')[-1]
connection_id = connection.get("connection_id")
connection_data = connection_url.split("c_i=")[-1]
connection_data = str(base64.b64decode(connection_data))

invitation, created = Invitations.objects.get_or_create(user=request.user, connection_id=connection_id)
invitation, created = Invitations.objects.get_or_create(
user=request.user, connection_id=connection_id
)
invitation.invitation_data = connection_data
invitation.save()
return Response(response.json(), status=response.status_code)
Expand Down
4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pop_backend.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pob_backend.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -17,5 +17,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
File renamed without changes.
4 changes: 2 additions & 2 deletions pop_backend/asgi.py → pob_backend/asgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ASGI config for pop_backend project.
ASGI config for pob_backend project.
It exposes the ASGI callable as a module-level variable named ``application``.
Expand All @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pop_backend.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pob_backend.settings")

application = get_asgi_application()
6 changes: 3 additions & 3 deletions pop_backend/settings.py → pob_backend/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for pop_backend project.
Django settings for pob_backend project.
Generated by 'django-admin startproject' using Django 3.0.7.
Expand Down Expand Up @@ -59,7 +59,7 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "pop_backend.urls"
ROOT_URLCONF = "pob_backend.urls"

TEMPLATES = [
{
Expand All @@ -77,7 +77,7 @@
},
]

WSGI_APPLICATION = "pop_backend.wsgi.application"
WSGI_APPLICATION = "pob_backend.wsgi.application"


# Database
Expand Down
12 changes: 6 additions & 6 deletions pop_backend/urls.py → pob_backend/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""pop_backend URL Configuration
"""pob_backend URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Expand All @@ -17,9 +17,9 @@
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path(r'rest-auth/', include('rest_auth.urls')),
path(r'users', include('igrant_user.urls')),
path(r'connections', include('connections.urls')),
path(r'certificates', include('certificate.urls')),
path("admin/", admin.site.urls),
path(r"rest-auth/", include("rest_auth.urls")),
path(r"users", include("igrant_user.urls")),
path(r"connections", include("connections.urls")),
path(r"certificates", include("certificate.urls")),
]
Loading

0 comments on commit 9c6accc

Please sign in to comment.