def post(self, request, client_name, format=None): """ Add subscriptions to the client provided. apiNme -- (REQUIRED) The name of the API to subscribe to; Send api_name=* to subscribe to all APIs. apiVersion -- Version of the API to be added. apiProvider -- Provider of the API to be added. tier -- tier level for subscriptions, default is unlimited. """ # We want these endpoints to work even when the backend userstore is not our LDAP. Therefore, # we cannot use the LdapUserSerializer class. parms = ['apiName'] try: parm_values = get_parms_from_request(request.DATA, parms) if parm_values['apiName'] == '*': add_apis(request.wso2_cookies, client_name, tier=request.DATA.get('tier', settings.DEFAULT_TIER)) else: add_api(request.wso2_cookies, client_name, parm_values['apiName'], request.DATA.get('apiVersion'), request.DATA.get('apiProvider'), request.DATA.get('tier', settings.DEFAULT_TIER)) except Error as e: return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) except Exception as e: logger.error("Unhandled exception in ClientSubscription: " + str(e)) return Response( error_dict(msg="Unable to subscribe client to Agave APIs."), status.HTTP_400_BAD_REQUEST) if parm_values['apiName'] == '*': return Response( success_dict(msg="Client " + client_name + " has been subscribed to Agave APIs.")) else: return Response( success_dict(msg="Client " + client_name + " has been subscribed to " + parm_values['apiName'] + "."))
def delete(self, request, client_name, format=None): """ Remove subscriptions from the client provided. api_name -- (REQUIRED) The name of the API to remove; Send api_name=* to remove all APIs. api_version -- Version of the API to be added. api_provider -- Provider of the API to be added. """ parms = ['apiName'] try: parm_values = get_parms_from_request(request.DATA, parms) if parm_values['apiName'] == '*': remove_apis(request.wso2_cookies, client_name) else: remove_api(request.wso2_cookies, client_name, parm_values['apiName'], request.DATA.get('apiVersion'), request.DATA.get('apiProvider')) except Error as e: return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) except Exception as e: logger.error("Unhandled exception in ClientSubscription: " + str(e)) return Response( error_dict(msg="Unable to remove API from client."), status.HTTP_400_BAD_REQUEST) if parm_values['apiName'] == '*': return Response( success_dict( msg="All APIs have been removed from the client " + client_name + ".")) else: return Response( success_dict(msg=parm_values['apiName'] + " has been removed from the client " + client_name + "."))
def delete(self, request, client_name, format=None): """ Remove a client. """ try: delete_client(request.wso2_cookies, client_name) except Error as e: return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) except Exception as e: logger.error("Uncaught exception trying to remove client: " + str(e)) return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) return Response(success_dict(msg="Client removed successfully."))
def get(self, request, client_name, format=None): """ Retrieve subscriptions for a client. """ try: subscriptions = get_subscriptions(request.wso2_cookies, client_name) except Error as e: return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) except Exception as e: logger.error("Unhandled exception in ClientSubscription: " + str(e)) return Response( error_dict(msg="Unable to retrieve subscriptions."), status.HTTP_400_BAD_REQUEST) return Response( success_dict(msg="Client subscriptions retrieved successfully.", result=subscriptions))
def get(self, request, client_name, format=None): """ Retrieve details for a client. """ try: app = get_application(request.wso2_cookies, request.wso2_username, client_name) except Error as e: return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) except Exception as e: logger.error( "Uncaught exception trying to retrieve client details: " + str(e)) return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) return Response( success_dict(msg="Client details retrieved successfully.", result=app))
def get(self, request, format=None): """ List all client applications for a user. username -- (REQUIRED) password -- (REQUIRED) """ try: applications = get_applications( request.wso2_cookies, request.wso2_username, ) except Error as e: return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) except Exception as e: logger.error("Uncaught exception trying to retrieve clients: " + str(e)) return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) return Response( success_dict(msg="Clients retrieved successfully.", result=applications))
def post(self, request, format=None): """ Create a new client that is subscribed to the Agave APIs. client_name -- (REQUIRED) The name of the application to create tier -- subscription tier description -- Description of the application callbackUrl -- Callback URL for OAuth authorization grant flow. """ parms = ['clientName'] try: parm_values = get_parms_from_request(request.DATA, parms) application = create_client_application( request.wso2_cookies, request.wso2_username, parm_values['clientName'], tier=request.DATA.get('tier', settings.DEFAULT_TIER), description=request.DATA.get('description', ''), callbackUrl=request.DATA.get('callbackUrl', '')) logger.info("Application created, id:" + str(application.get('application_id'))) # add_apis(request.wso2_cookies, application.get('id')) except Error as e: return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) except Exception as e: logger.error("Uncaught exception trying to create a new client: " + str(e)) return Response(error_dict(msg=e.message), status.HTTP_400_BAD_REQUEST) # we need to sanitize the application, but sanitize will remove the consumerSecret, which in # this one case we actually want to send back to the user: secret = application.pop("consumerSecret", None) sanitize_app(application) application['consumerSecret'] = secret return Response(success_dict(msg="Client created successfully.", result=application), status=status.HTTP_201_CREATED)