ns1.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": "<<CLEARTEXT API KEY>>",
"desc": "account number 1",
"writeLock": true
},
"account2": {
"key": "<<ANOTHER CLEARTEXT API KEY>>",
"desc": "account number 2",
"writeLock": false
}
},
"cli": {
"output_format": "text"
}
}
-
class
ns1.config.
Config
(path=None)¶ A simple object for accessing and manipulating config files. These contains options and credentials for accessing the NS1 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:
-
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 NS1 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 NS1 API Endpoint URL that will be used for requests.
Returns: URL of the NS1 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
-
getRateLimitingFunc
()¶ choose how to handle rate limiting
-
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
-
-
exception
ns1.config.
ConfigException
¶ Bases:
exceptions.Exception