From 86c2d35f8fa673cc0f5ce3d5930b42c95d17f06f Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Wed, 22 Apr 2015 19:30:04 +0200 Subject: [PATCH] rest: add/remove pis to/from authority --- myslice/urls.py | 1 + rest/authority.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 rest/authority.py diff --git a/myslice/urls.py b/myslice/urls.py index e2b85cce..236e5ca5 100644 --- a/myslice/urls.py +++ b/myslice/urls.py @@ -88,6 +88,7 @@ urls = [ (r'^credentials/(?P[^/]+)/?$', 'rest.credentials.dispatch'), (r'^cache/(?P[^/]+)/?$', 'rest.cache.dispatch'), (r'^initscript/(?P[^/]+)/?$', 'rest.initscript.dispatch'), + (r'^authority/(?P[^/]+)/?$', 'rest.authority.dispatch'), # # REST monitoring (r'^monitor/services/?$', 'rest.monitor.servicesStatus'), diff --git a/rest/authority.py b/rest/authority.py new file mode 100644 index 00000000..8f3c31d8 --- /dev/null +++ b/rest/authority.py @@ -0,0 +1,29 @@ +from django.http import HttpResponse +from portal.actions import authority_add_pis, authority_remove_pis +import json + +def dispatch(request, action): + + try: + if request.method == 'POST': + req_items = request.POST + elif request.method == 'GET': + req_items = request.GET + + if 'user_hrn' in req_items: + user_hrn = str(req_items['user_hrn']) + if 'authority_hrn' in req_items: + authority_hrn = str(req_items['authority_hrn']) + + if (action == 'add') : + new_pis = authority_add_pis(request, authority_hrn, user_hrn) + result = {'ret':1} + elif (action == 'remove'): + new_pis = authority_remove_pis(request, authority_hrn, user_hrn) + result = {'ret':1} + else: + raise Exception, "action not supported" + except Exception as e: + result = {'ret': -1, 'msg':'error: %s' % e} + return HttpResponse(json.dumps(result), content_type="application/json") + -- 2.43.0