enabled keys
diff --git a/plstackapi/planetstack/views/api_root.py b/plstackapi/planetstack/views/api_root.py
index 560d9eb..10ceae1 100644
--- a/plstackapi/planetstack/views/api_root.py
+++ b/plstackapi/planetstack/views/api_root.py
@@ -7,6 +7,7 @@
return Response({
'roles': reverse('role-list', request=request, format=format),
'users': reverse('user-list', request=request, format=format),
+ 'keys': reverse('key-list', request=request, format=format),
#'nodes': reverse('node-list', request=request, format=format),
'sites': reverse('site-list', request=request, format=format),
'deploymentNetworks': reverse('deploymentnetwork-list', request=request, format=format),
diff --git a/plstackapi/planetstack/views/keys.py b/plstackapi/planetstack/views/keys.py
new file mode 100644
index 0000000..fde6b40
--- /dev/null
+++ b/plstackapi/planetstack/views/keys.py
@@ -0,0 +1,66 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from plstackapi.planetstack.api.keys import add_key, delete_key, get_keys, update_key
+from plstackapi.planetstack.serializers import KeySerializer
+from plstackapi.util.request import parse_request
+
+
+class KeyListCreate(APIView):
+ """
+ List all users or create a new user.
+ """
+
+ def post(self, request, format = None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'key' in data:
+ key = add_user(data['auth'], data['key'])
+ serializer = UserSerializer(key)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ keys = get_keys(data['auth'])
+ serializer = UserSerializer(keys, many=True)
+ return Response(serializer.data)
+
+
+class KeyRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a user
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a key"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ keys = get_keys(data['auth'], {'id': pk})
+ if not keys:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = UserSerializer(keys[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a key"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'key' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ key = update_key(pk, data['key'])
+ serializer = UserSerializer(key)
+ return Response(serializer.data)
+
+ def delete(self, request, pk, format=None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ delete_key(data['auth'], {'id': pk})
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+