paradrop.backend.pdfcd package

Submodules

paradrop.backend.pdfcd.apichute module

class ChuteAPI(rest)[source]

The Chute API submodule. This class handles all API calls related to actionable items that directly effect chutes.

POST_createChute(theSelf, request, *args, **kwargs)
POST_deleteChute(theSelf, request, *args, **kwargs)
POST_startChute(theSelf, request, *args, **kwargs)
POST_stopChute(theSelf, request, *args, **kwargs)

paradrop.backend.pdfcd.apiinternal module

class Base(module, **kwargs)[source]

Bases: twisted.web.xmlrpc.XMLRPC

lookupProcedure(procedurePath)[source]
class ServerPerspective(name, realm)[source]

Bases: pdtools.lib.riffle.RifflePerspective

destroy()[source]
initialize()[source]
perspective_subscribeLogs(*args, **kwargs)[source]

Fetch all logs since the target time. Stream all new logs to the server as they come in.

class ToolsPerspective(name, realm)[source]

Bases: pdtools.lib.riffle.RifflePerspective

apiWrapper(target)[source]

Add a final line of error and success callbacks before going onto the wire

api_provision(*args, **kwargs)[source]

Provision this router with an id and a set of keys.

This is a temporary call until the provisioning process is finalized.

castFailure(failure)[source]

Converts an exception (or general failure) into an xmlrpc fault for transmission.

castSuccess(res)[source]
checkStartRiffle()[source]

Temporary function. Do not start serving or connecting over riffle until we have our keys (which occurs during currently optional provisioning)

pollServer(host)[source]

Poll the server for a connection.

paradrop.backend.pdfcd.apiutils module

backend.pdfcd.apiutils. Contains helper functions specific to the backend API code.

addressInNetwork(ipaddr, netTuple)[source]

This function allows you to check if on IP belongs to a Network. Arguments:

unpacked IP address (use unpackIPAddr()) tuple of unpacked (addr, netmask) (use unpackIPAddrWithSlash())
Returns:
True if in network False otherwise
calcDottedNetmask(mask)[source]

Returns quad dot format of IP address.

getIP(req)[source]

Returns the str IP addr from the request. NOTE: This is required because when we use nginx servers it is used as a proxy, so the REAL IP addr is stored in a HTTP header called ‘X-Real-IP’, so we need to check for this first, otherwise the request.getClientIP() is always going to return ‘localhost’ to us.

unpackIPAddr(ip)[source]

Unpacks the ‘IP’ str. Returns a binary form of the ipaddr such that (ipaddr & netmask) will work.

unpackIPAddrWithSlash(net)[source]

Unpacks the ‘IP/bitmask’ str. Returns a tuple of binary forms of both the ipaddr and netmask such that (ipaddr & netmask) will work.

paradrop.backend.pdfcd.server module

pdfcd.server. Contains the classes required to establish a RESTful API server using Twisted.

class ParadropAPIServer(*args, **kwargs)[source]

Bases: paradrop.lib.api.pdrest.APIResource

The main API server module.

This sets up all of the submodules which should contain different types of RESTful API calls.

GET_test(request)[source]

A Simple test method to ping if the API server is working properly.

complete(update)[source]

Kicks off the properly threaded call to complete the API call that was passed to PDConfigurer. Since the PDConfigurer module has its own thread that runs outside of the main event loop, we have to call back into the event system properly in order to keep any issues of concurrency at bay.

default(request)[source]

A dummy catch for all API calls that are not caught by any other module.

failprocess(ip, request, logFailure, errorStmt, logUsage, errType)[source]

If logFailure is not None, Update the failureDict when the request does something wrong If logUsage is not None, log the usage track info.

Arguments:

ip : IP of client request : the request we received logFailure : If none, we do not log this failure to failure dict. Otherwise it is a tuple of

key : the key to use in the failureDict failureDict : the dict record the failure attempt history
errorStmt : A string to return to the user, looks like ‘Malformed Body: %s’
so that we can add things like “Number of attempts remaining: 2” to the response

logUsage : A tuple of (tictoc and devid) used for usage tracker errorResponse: The error code to set response code

Returns:
String to respond to the client
postprocess(request, key, failureDict, logUsage)[source]

If the client is successful in their request, we should: * reset their failure attempts if failureDict is not none. * set success response code * If usage is not none, add usage track info of the api call

preprocess(request, checkThresh, tictoc)[source]

Check if failure attempts for the user name has met the threshold. Arguments:

request : checkThresh : If None, no checking. Tuple of arguments for checking thresholds

ip: IP of client in string format token: sessionToken if found, or None username: username if signin, or None failureDict: the dict for failure history

ticktoc: If none, do not track the usage. The start time of the API call

Return:
str: if threshold is met None: if ok
initializeSystem()[source]

Perform some initialization steps such as writing important configuration.

setup(args=None)[source]

This is the main setup function to establish the TCP listening logic for the API server. This code also takes into account development or unit test mode.

Module contents