Archelon Daemon API

For convenient reference in development, here are the Archelon Daemon API docs.

Abstract Base Class for Data Storage

Abstract base class for data stores

class archelond.data.abstract.HistoryData(config)[source]

Bases: object

Abstract Data storage for command history

Abstract class implementation of a database for use with command history. Generally a command data item needs just two things, an ID and the command itself. It also needs order. See the archelond.data.MemoryData class as the simplest structure using an collections.OrderedDict.

An ID can be any string, and the concrete implementation of HistoryData is responsible for type casting it if needed.

It is also required implicitly that there is only one entry per command. Thus add ing the same command multiple times should result in the return of just one command when filtered by a term equal to that command.

add(command, username, host, **kwargs)[source]

Add or update a command

Save (update or create) a command to the data store.

Parameters:
  • command (str) – The command to store
  • username (str) – The username of the person adding it
  • host (str) – The IP address of API caller
Returns:

Command ID – The id of the command stored

Return type:

str

all(order, username, host, **kwargs)[source]

Unfiltered but ordered command history

Return the full data set as a list of dict structures in the specified order.

Parameters:
  • order (str) – An ordering from ORDER_TYPES
  • username (str) – The username of the person adding it
  • host (str) – The IP address of API caller
Returns:

A list of dictionaries where each dictionary must

have at least a command key and an id key.

Return type:

list

delete(command_id, username, host, **kwargs)[source]

Delete a command

Remove a command from the data store, raise a KeyError if it is not available to be deleted.

Parameters:
  • command_id (str) – Unique command identifier
  • username (str) – The username of the person adding it
  • host (str) – The IP address of API caller
filter(term, order, username, host, **kwargs)[source]

Get a filtered by term and ordered command history

Parameters:
  • term (str) – The term being searched for/filtered by.
  • order (str) – An ordering from ORDER_TYPES
  • username (str) – The username of the person adding it
  • host (str) – The IP address of API caller
Returns:

A list of dictionaries where each dictionary must

have at least a command key and an id key.

Return type:

list

get(command_id, username, host, **kwargs)[source]

Get a single command

Retrieve a single command by username and id. Raise a KeyError if the command does not exist.

Parameters:
  • command_id (str) – Unique command identifier
  • username (str) – The username of the person adding it
  • host (str) – The IP address of API caller
Returns:

Command

Dictionary with at least the keys id

and command

Return type:

dict

In Memory Data Storage

In memory data store implementation for development and testing

class archelond.data.memory.MemoryData(config)[source]

Bases: archelond.data.abstract.HistoryData

A quick in memory deduplicated structure for standalone testing and development.

INITIAL_DATA = [u'cd', u'pwd', u'echo hi', u'cat /proc/cpuinfo']
add(command, username, host, **kwargs)[source]

Append item to data list

all(order, username, host, page=0, **kwargs)[source]

Simply rewrap the data structure, order, and return

delete(command_id, username, host, **kwargs)[source]

Remove key from internal dictionary

filter(term, order, username, host, page=0, **kwargs)[source]

Return filtered and reversed OrderedDict.

get(command_id, username, host, **kwargs)[source]

Pull the specified command out of the data store.

Elastic Search Data Storage

ElasticSearch implementation of the data store. Currently the recommended default data store.

class archelond.data.elastic.ElasticData(config)[source]

Bases: archelond.data.abstract.HistoryData

An ElasticSearch implementation of HistoryData. This is what should be used in production

DOC_TYPE = u'history'
NUM_RESULTS = 50
add(command, username, host, **kwargs)[source]

Add the command to the index with a time stamp and id by hash of the command and append username to doc type for user separation of data.

all(order, username, host, page=0, **kwargs)[source]

Just build a body with match all and return filter

delete(command_id, username, host, **kwargs)[source]

Remove item from elasticsearch

filter(term, order, username, host, body=None, page=0, **kwargs)[source]

Return filtered search that is ordered

get(command_id, username, host, **kwargs)[source]

Pull one command out of elasticsearch

Configuration Module

Configure the flask application

Log Module

Configure logging

archelond.log.configure_logging(app)[source]

Set the log level for the application

Utility Module

Classic utility module for removing repetitive tasks and such

archelond.util.jsonify_code(src_object, status_code)[source]

Wrap jsonify with a status code option for jsonifying non-200 responses.

Parameters:
  • src_object (serializable object) – data structure to jsonify
  • status_code (int) – Status code to send
Returns:

werkzug response object with json MIME-type

Web Module

Main entry point for flask application

archelond.web.history()[source]

POST=Add entry GET=Get entries with query

archelond.web.history_item(cmd_id)[source]

Actions for individual command history items.

Updates, gets, or deletes a command from the active data store.

PUT: Takes a payload in either form or JSON request, and runs the add routine by passing the dictinoary minus command, username, and host as kwargs to the data stores add routine.

archelond.web.index()[source]

Simple index view for documentation and navigation.

archelond.web.run_server()[source]

If started from command line, rebuild object in debug mode and run directly

archelond.web.token()[source]

Return the user token for API auth that is based off the flask secret and user password

archelond.web.wsgi_app()[source]

Start flask application runtime