woohoo_pdns.api package

Submodules

woohoo_pdns.api.api module

woohoo_pdns.api.api.count()[source]

The method supporting the count API endpoint. It just returns the number of records in the database.

Returns

The number of entries in the database (as string).

woohoo_pdns.api.api.most_recent()[source]

The method supporting the recent API endpoint. It returns the most recent entry from the database.

For example like this:

{
    "hitcount": 56,
    "time_first": 1559244767.913,
    "time_last": 1559245313.506,
    "rrtype": 1,
    "rrname": "prod-cc-asn-20190411-1321-nlb-19436c10e4427871.elb.us-east-1.amazonaws.com",
    "rdata": "3.208.62.22"
}
woohoo_pdns.api.api.query(q)[source]

The method supporting the query API endpoint.

Parameters

q (str) – The term to search for (use ‘*’ as wildcard).

Returns

A JSON structure compatible with the Passive DNS - Common Output Format.

An example:

[
    {
        "hitcount": 7,
        "time_first": 1559245077.432,
        "time_last": 1559245077.432,
        "rrtype": 5,
        "rrname": "www.icloud.com.edgekey.net",
        "rdata": "e4478.a.akamaiedge.net."
    }
]

woohoo_pdns.api.api.verify_password(username, password)[source]

Check if a valid API key was provided.

Called by flask_httpauth when authentication is required. As woohoo pDNS is ‘misusing’ flask_httpauth to avoid reinventing the wheel, username and password will always be empty (we do not use basic authentication).

The API key must be provided in a header called Authorization and have the following format:

"Authorization: <API key as configured in config file>"
Parameters
  • username (str) – Ignored (would be the username for basic authentication).

  • password (str) – Ignored (would be the password for basic authentication).

woohoo_pdns.api.config module

class woohoo_pdns.api.config.DefaultSettings[source]

Bases: object

The default configuration of the API just demonstrates the available options.

API_KEYS = ['IXsA7uRnxR4xek4JDEG5vk2oGjTYDSqaoKLRQLVjV2s3kw0bbv49qrgAT7Bk3g2K', 'jLHKK0AIk1l6r3W8SAJj4Lh0v2a27JGbSSd406mr0u5FNrJn6RLWQ5m6qPYXT0d5']

The complete list of available/valid API keys.

DATABASE = 'sqlite:///demo.db'

The connection string to be used by SQLAlchemy.

SECRET_KEY = 'snakeoil'

Flask uses a secret key to encrypt things that sould be tamper proof (for example the Session object).

__dict__ = mappingproxy({'__module__': 'woohoo_pdns.api.config', '__doc__': 'The default configuration of the API just demonstrates the available options.', 'SECRET_KEY': 'snakeoil', 'DATABASE': 'sqlite:///demo.db', 'API_KEYS': ['IXsA7uRnxR4xek4JDEG5vk2oGjTYDSqaoKLRQLVjV2s3kw0bbv49qrgAT7Bk3g2K', 'jLHKK0AIk1l6r3W8SAJj4Lh0v2a27JGbSSd406mr0u5FNrJn6RLWQ5m6qPYXT0d5'], '__dict__': <attribute '__dict__' of 'DefaultSettings' objects>, '__weakref__': <attribute '__weakref__' of 'DefaultSettings' objects>})
__module__ = 'woohoo_pdns.api.config'
__weakref__

list of weak references to the object (if defined)

woohoo_pdns.api.db module

woohoo_pdns.api.db.close_db(e=None)[source]

Close the woohoo_pdns.pdns.Database that is present in Flask’s global state.

woohoo_pdns.api.db.get_db()[source]

Provide access to a single woohoo_pdns.pdns.Database for all API endpoints.

woohoo_pdns.api.db.init_app(app)[source]

Called from the Flask app’s create_app() and used to register the teardown method (close_db()).

Module contents

woohoo_pdns.api.create_app(test_config=None)[source]

A Flask specific method that is called automagically.