def main(reactor):
    args = getArgs()
    data = loadZoneData(args.filename)

    config = Config()
    config.createFromAPIKey(args.api_key)
    config['transport'] = 'twisted'

    nsoneObj = NSONE(config=config)

    if args.delete:
        return deleteZoneData(data, nsoneObj)

    else:
        return importZoneData(data, nsoneObj)
Ejemplo n.º 2
0
# to specify an apikey here instead, use:
nsone = NSONE(apiKey='qACMD09OJXBxT7XOuRs8')

# to load an alternate configuration file:
nsone = NSONE(configFile='/etc/nsone/api.json')

# to load a specific keyID inside of your config file (see config format
# in docs), use this. this only makes sense for config file loads, not
# apiKey loads:
nsone = NSONE(keyID='all-access')

# if you have special needs, build your own Config object and pass it to
# NSONE:
config = Config()
config.createFromAPIKey('qACMD09OJXBxT7XOwv9v')
config['verbosity'] = 5
config['transport'] = 'twisted'
nsone = NSONE(config=config)

#  you can get the current config object NSONE is using via
config = nsone.config

# change config variables
config['verbosity'] = 5

# write out new config files
config.write('/tmp/newconfig.json')

# the config file format supports different apiKeys (see docs) using keyID
Ejemplo n.º 3
0
 def _build_nsone(self):
     config = Config()
     config[self._transport_key] = self._transport
     config.createFromAPIKey(self._api_key)
     self._nsone = NSONE(config=config)
     return self._nsone
Ejemplo n.º 4
0
#
# Copyright (c) 2014 NSONE, Inc.
#
# License under The MIT License (MIT). See LICENSE in project root.
#

import logging
from nsone import NSONE, Config

# to enable verbose logging, set 'verbosity' in the config and use
# the standard python logging system

config = Config()
config.createFromAPIKey('qACMD09OJXBxT7XOwv9v')
config['verbosity'] = 5
logging.basicConfig(level=logging.DEBUG)
print(config)
nsone = NSONE(config=config)

# now all requests will show up in the logging system

# exception handling:
# the follow exceptions may be thrown
# from nsone.rest.errors import ResourceException, \
#     RateLimitException, AuthException

# ResourceException is the base exception (Auth and RateLimit extend it)
# it (and therefore they) have the properties message, response, body

# AuthException is raised when apikey is incorrect or the key doesn't
# have permission to the requested resource
from argparse import ArgumentParser
from nsone import NSONE, Config
from file_parser import parseCSV
from twisted.internet import defer, reactor

# Get configuration settings from command line for added flexibility.
parser = ArgumentParser(description='Asychronously create DNS records from file.')
parser.add_argument('-f', dest='filename', required=True, type=str, nargs='?', help='relative path to file')
parser.add_argument('-k', dest='apikey', required=True, type=str, nargs='?', help='NS1 API key')
args = parser.parse_args()

# Set configuration with API key and asynchronous Twisted transport setting.
config = Config()
config.createFromAPIKey(args.apikey)
config['transport'] = 'twisted'
nsone = NSONE(config=config)

def getData(filename):
    # Return Deferred.
    # Parse file into dict containing zones with record data.
    # Currently only parses CSV files.
    # Could add other file type parsing and select based on filename.
    data = parseCSV(filename)
    return defer.succeed(data)

def handleData(data):
    # Return DeferredList.
    # Register success when record additions for all zones have completed.
    zones = []
    for domain, records in data.iteritems():
        zone = loadZone(domain)
Ejemplo n.º 6
0
# to specify an apikey here instead, use:
nsone = NSONE(apiKey="qACMD09OJXBxT7XOuRs8")

# to load an alternate configuration file:
nsone = NSONE(configFile="/etc/nsone/api.json")

# to load a specific keyID inside of your config file (see config format
# in docs), use this. this only makes sense for config file loads, not
# apiKey loads:
nsone = NSONE(keyID="all-access")

# if you have special needs, build your own Config object and pass it to
# NSONE:
config = Config()
config.createFromAPIKey("qACMD09OJXBxT7XOwv9v")
config["verbosity"] = 5
config["transport"] = "twisted"
nsone = NSONE(config=config)

#  you can get the current config object NSONE is using via
config = nsone.config

# change config variables
config["verbosity"] = 5

# write out new config files
config.write("/tmp/newconfig.json")

# the config file format supports different apiKeys (see docs) using keyID