nsone.config

This object is used to configure the SDK and REST client. It handles multiple API keys via a simple selection mechanism (keyID).

Sample:

{
   "default_key": "account2",
   "verbosity": 5,
   "keys": {
        "account1": {
            "key": "qACMD09OJXBxT7XOuRs8",
            "desc": "account number 1",
            "writeLock": true
        },
        "account2": {
            "key": "qACMD09OJXBxT7XOwv9v",
            "desc": "account number 2",
            "writeLock": false
        }
   },
   "cli": {
       "output_format": "text"
   }
}
class nsone.config.Config(path=None)

A simple object for accessing and manipulating config files. These contains options and credentials for accessing the NSONE REST API. Config files are simple JSON text files. To set or retrieve vales, use the object like a dict.

Parameters:path (str) – optional path. if given, try to load the given config file
API_VERSION = 'v1'
DEFAULT_CONFIG_FILE = '~/.nsone'
ENDPOINT = 'api.nsone.net'
PORT = 443
createFromAPIKey(apikey, maybeWriteDefault=False)

Create a basic config from a single API key

Parameters:
  • apikey (str) – NSONE API Key, as created in the NSONE portal
  • maybeWriteDefault (bool) – If True and DEFAULT_CONFIG_FILE doesn’t exist write out the resulting config there.
get(item, default=None)

Retrieve a value from the config object.

Parameters:
  • item (str) – Key to lookup
  • default – Default value to return if the requested item doesn’t exist
Returns:

Requested value, or default if it didn’t exist

getAPIKey(keyID=None)

Retrieve the NSONE API Key for the given keyID

Parameters:keyID (str) – optional keyID to retrieve, or current if not passed
Returns:API Key for the given keyID
getCurrentKeyID()

Retrieve the current keyID in use.

Returns:current keyID in use
getEndpoint()

Retrieve the NSONE API Endpoint URL that will be used for requests.

Returns:URL of the NSONE API that will be used for requests
getKeyConfig(keyID=None)

Get key configuration specified by keyID, or current keyID.

Parameters:keyID (str) – optional keyID to retrieve, or current if not passed
Returns:a dict of the request (or current) key config
isKeyWriteLocked(keyID=None)

Determine if a key config is write locked.

Parameters:keyID (str) – optional keyID to retrieve, or current if not passed
Returns:True if the given (or current) keyID is writeLocked
loadFromDict(d)

Load config data from the given dictionary

Parameters:d (dict) – Python dictionary containing configuration items
loadFromFile(path)

Load JSON config file from disk at the given path

Parameters:path (str) – path to config file
loadFromString(body)

Load config data (i.e. JSON text) from the given string

Parameters:body (str) – config data in JSON format
useKeyID(keyID)

Use the given API key config specified by keyID during subsequent API calls

Parameters:keyID (str) – an index into the ‘keys’ maintained in this config
write(path=None)
Write config data to disk. If this config object already has a path, it will write to it. If it doesn’t, one must be passed during this call.
Parameters:path (str) – path to config file
exception nsone.config.ConfigException

Bases: exceptions.Exception