paradrop.lib.api package

Submodules

paradrop.lib.api.pdapi module

exception PDAPIError(etype, msg)[source]

Bases: exceptions.Exception

Exception class related to ParaDrop API calls.

getErrorToken()[source]

Generates a random string which is used to match client issues with log output.

getResponse(code, *args)[source]

Designed to be called to provide the arguments for the Request.setResponseCode()

isPDError(code)[source]

Checks all Paradrop API error codes, if the HTTP code is in our set it is assumed a PDAPI error.

paradrop.lib.api.pdrest module

ALL(regex)
APIDecorator(admin=False, permission=None, requiredArgs=[], optionalArgs=[])[source]

The decorator for the API functions to make the API functions focus on their job. This decorator do the following things:

  • Set HTTP header
  • Get some common values like ip, tictoc
  • Do the preprocess
  • Extract arguments from HTTP body and put them into APIPackage
  • Get devid if token is shown and put devid into APIPackage
  • Check admin authorization if devid is shown and admin argument is set to be true
  • Do the failprocess if fails. Do the postProcess if success

This decorator will pass an APIPackage to an API function and the API function is supposed to put return value into the API package Arguments:

  • admin: if the function needs admin authority to call
  • requiredArgs: the required arguments for this API, this wrapper will parse the required args from HTTP body and check if they exist in the body.
  • optionalArgs: the optional arguments for this API, the args will be parsed from HTTP body
  • permission: choose from None, “AP Owner”, “Chute Owner”
TODO:
1.Permission
  • multiple permission/multiple level of permission??
  • More permissions: such as Vnet Owner, Group Owner
class APIPackage(request)[source]

This is a class that wrap up the input and return value of API The input arguments will be in the inputArgs as a dict Result is True means the API return success Result is False means the API return failure Result is None means the API return NOT_YET_DONE

setFailure(errType, errMsg=None, countFailure=True)[source]
setNotDoneYet()[source]
setSuccess(returnVal)[source]
class APIResource(*args, **kwargs)[source]

Bases: twisted.web.resource.Resource

getChild(name, request)[source]
register(method, regex, callback)[source]
unregister(method=None, regex=None, callback=None)[source]
DELETE(regex)
GET(regex)
POST(regex)
PUT(regex)
maybeResource(f)[source]
method_factory_factory(method)[source]

Module contents