def api_operation_pcu_register(request): print "PCU-Register" o = api_util.init_request(request, "POST") profile = api_util.get_profile(request) if profile == None: return HttpResponse(status = 401) if isinstance(o, HttpResponse): return o else: json = o if not api_util.check_keys(json, [ "url", "pcuIdentifier" ]): return HttpResponse(status = 422) url = json["url"] ident = json["pcuIdentifier"] # Get 'active' status activeStatus = None try: activeStatus = PCUStatus.objects.get(code = "ACTIVE") except Exception, e: print "Error retrieving ACTIVE status: %s" % e return HttpResponse(status = 500)
def api_operation_pcu_delete(request, pcu_pub_key): print "PCU-Delete" o = api_util.init_request(request, "DELETE") if isinstance(o, HttpResponse): return o profile = api_util.get_profile(request) if profile == None: return HttpResponse(status = 401) try : pcu = PCU.objects.get(publicKey = pcu_pub_key) except Exception, e: print "Error obtaining PCU [%d]: %s" % pcu_pub_key % e return HttpResponse(status = 401) # Mask the fact that the PCU does not exist.
def api_operation_pcu_get(request, pcu_pub_key): print "PCU-Get" o = api_util.init_request(request, "GET") if isinstance(o, HttpResponse): return o profile = api_util.get_profile(request) if profile == None: return HttpResponse(status = 400) try : pcu = PCU.objects.get(publicKey = pcu_pub_key, profile = profile) except Exception, e: print "Error retrieving PCU for public key [%s]: %s" % (pcu_pub_key, e) return HttpResponse(status = 401)
def api_operation_render_overlay(request, pcu_pub_key): print "Render-Overlay" o = api_util.init_request(request, "POST") if isinstance(o, HttpResponse): return o else : json = o userProfile = api_util.get_profile(request) if userProfile == None: return HttpResponse(status = 401) try: pcu = PCU.objects.get(publicKey = pcu_pub_key, profile = userProfile) except Exception, e: print "Error retrieving PCU for public key [%s] belonging to profile [%s]: %s" % (pcu_pub_key, userProfile.privateKey, e)
def api_operation_pcu_list(request): print "PCU-List" o = api_util.init_request(request, "GET") if isinstance(o, HttpResponse): return o userProfile = api_util.get_profile(request) if userProfile == None: return HttpResponse(status = 401) output = [] profileUnits = PCU.objects.filter(profile = userProfile) for pcu in profileUnits: output.append({ "url": pcu.url, "pcuIdentifier": pcu.pcuIdentifier, "publicKey": pcu.publicKey, "created": pcu.created }) return api_util.generate_response(output, 200)