示例#1
0
def main():
    parser = argumentParser()
    args = parser.parse_args()
    igorVar.VERBOSE = args.verbose
    query = {}
    for qstr in args.arguments:
        qname, qvalue = qstr.split('=')
        query[qname] = qvalue
    if not args.noSystemRootCertificates and not os.environ.get(
            'REQUESTS_CA_BUNDLE', None):
        # The requests package uses its own set of certificates, ignoring the ones the user has added to the system
        # set. By default, override that behaviour.
        for cf in [
                "/etc/ssl/certs/ca-certificates.crt",
                "/etc/ssl/certs/ca-certificates.crt"
        ]:
            if os.path.exists(cf):
                os.putenv('REQUESTS_CA_BUNDLE', cf)
                os.environ['REQUESTS_CA_BUNDLE'] = cf
                break
    server = igorVar.IgorServer(args.url,
                                bearer_token=args.bearer,
                                access_token=args.access,
                                credentials=args.credentials,
                                noverify=args.noverify,
                                certificate=args.certificate)
    try:
        result = server.get("/internal/%s" % args.action, query=query)
    except igorVar.IgorError as e:
        print("%s: %s" % (sys.argv[0], e.args[0]), file=sys.stderr)
        sys.exit(1)
    sys.stdout.write(result)
示例#2
0
def main():
    parser = argumentParser()
    args = parser.parse_args()
    igorServer = None
    if args.remote:
        if not args.noSystemRootCertificates and not os.environ.get(
                'REQUESTS_CA_BUNDLE', None):
            # The requests package uses its own set of certificates, ignoring the ones the user has added to the system
            # set. By default, override that behaviour.
            for cf in [
                    "/etc/ssl/certs/ca-certificates.crt",
                    "/etc/ssl/certs/ca-certificates.crt"
            ]:
                if os.path.exists(cf):
                    os.putenv('REQUESTS_CA_BUNDLE', cf)
                    os.environ['REQUESTS_CA_BUNDLE'] = cf
                    break
        igorServer = igorVar.IgorServer(args.url,
                                        bearer_token=args.bearer,
                                        access_token=args.access,
                                        credentials=args.credentials,
                                        noverify=args.noverify,
                                        certificate=args.certificate)
    m = IgorCA(sys.argv[0],
               igorServer,
               keysize=args.keysize,
               database=args.database)
    if not args.action:
        return m.main('help', [])
    return m.main(args.action, args.arguments)
示例#3
0
 def tearDownIgor(cls):
     if os.environ.get('IGOR_TEST_WAIT'):
         print('igorTest: tests finished.')
         print('igorTest: Waiting with teardown because environment variable IGOR_TEST_WAIT is set.')
         print('igorTest: Type return to continue - ', end=' ')
         sys.stdin.readline()
     # Stop servlet
     if DEBUG_TEST: print('IgorTest: Stop servlet')
     cls.servlet.stop()
     # Gracefully stop server
     if DEBUG_TEST: print('IgorTest: Request server to stop')
     try:
         p = igorVar.IgorServer(cls.igorUrl, credentials='admin:', **cls.igorVarArgs)
         result = p.get('/internal/stop')
     except:
         if DEBUG_TEST: traceback.print_exc()
         print('IgorTest: Ignoring exception during stop request')        
     time.sleep(2)
     
     sts = cls.igorProcess.poll()
     if sts is None:
         print('IgorTest: Terminate server')
         cls.igorProcess.terminate()
         time.sleep(2)
     sts = cls.igorProcess.wait()
     assert sts != None
示例#4
0
def main():
    parser = argparse.ArgumentParser(
        description="Control Igor home automation service")
    parser.add_argument(
        "-u",
        "--url",
        help="Base URL of the server (default: %s, environment IGORSERVER_URL)"
        % igorVar.DEFAULT_URL,
        default=igorVar.DEFAULT_URL)
    parser.add_argument("--verbose",
                        action="store_true",
                        help="Print what is happening")
    parser.add_argument("--bearer",
                        metavar="TOKEN",
                        help="Add Authorization: Bearer TOKEN header line")
    parser.add_argument("--access",
                        metavar="TOKEN",
                        help="Add access_token=TOKEN query argument")
    parser.add_argument(
        "action",
        help="Action to perform: help, save, stop, restart, command, ...")

    args = parser.parse_args()
    igorVar.VERBOSE = args.verbose
    server = igorVar.IgorServer(args.url,
                                bearer_token=args.bearer,
                                access_token=args.access)
    try:
        result = server.get("/internal/%s" % args.action)
    except httplib2.HttpLib2Error as e:
        print >> sys.stderr, "%s: %s" % (sys.argv[0],
                                         traceback.format_exception_only(
                                             type(e), e.message)[0].strip())
        sys.exit(1)
    sys.stdout.write(result)
示例#5
0
 def __init__(self, parent, igorServer):
     self.parent = parent
     # igorServer can either be a URL or an igorServer instance
     if isinstance(igorServer, str):
         igorServer = igorVar.IgorServer(igorServer)
     self.igor = igorServer
示例#6
0
 def _igorVar(self, server=None, **kwargs):
     kwargs = dict(kwargs)
     kwargs.update(self.igorVarArgs)
     if server is None:
         server = self.igorUrl
     return igorVar.IgorServer(server, **kwargs)