Ejemplo n.º 1
0
    def __init__(self, URI, retrymax=None, timeout=None, **kwargs):

        scheme, host, port, name, urlparams = c_cobra.chopCobraUri(URI)
        logger.debug('Host: %s, Port: %s, Obj: %s', host, port, name)
        self._cobra_uri = URI
        self._cobra_scheme = scheme
        self._cobra_host = host
        self._cobra_port = port
        self._cobra_slookup = (host, port)
        self._cobra_name = name
        self._cobra_timeout = timeout
        self._cobra_kwargs = kwargs
        self._cobra_gothello = False
        self._cobra_sessid = None

        if kwargs.get('sslkey') and not os.path.isfile(kwargs.get('sslkey')):
            raise Exception('CobraProxy: sslkey must be a file!')

        if kwargs.get('sslcrt') and not os.path.isfile(kwargs.get('sslcrt')):
            raise Exception('CobraProxy: sslcrt must be a file!')

        if kwargs.get('sslca') and not os.path.isfile(kwargs.get('sslca')):
            raise Exception('CobraProxy: sslca must be a file!')

        csock = self._cobra_http_getsock()

        data = CobraHttpMethod(self, '__cobra_hello')()

        self._cobra_gothello = True
        self._cobra_methods = data
Ejemplo n.º 2
0
    def __init__(self, URI, retrymax=None, timeout=None, **kwargs):

        scheme, host, port, name, urlparams = c_cobra.chopCobraUri( URI )
        if verbose: print "HOST",host,"PORT",port,"OBJ",name

        self._cobra_uri = URI
        self._cobra_scheme = scheme
        self._cobra_host = host
        self._cobra_port = port
        self._cobra_slookup = (host,port)
        self._cobra_name = name
        self._cobra_timeout = timeout
        self._cobra_kwargs = kwargs
        self._cobra_gothello = False
        self._cobra_sessid = None
        

        if kwargs.get('sslkey') and not os.path.isfile(kwargs.get('sslkey')):
            raise Exception('CobraProxy: sslkey must be a file!')

        if kwargs.get('sslcrt') and not os.path.isfile(kwargs.get('sslcrt')):
            raise Exception('CobraProxy: sslcrt must be a file!')

        if kwargs.get('sslca') and not os.path.isfile(kwargs.get('sslca')):
            raise Exception('CobraProxy: sslca must be a file!')

        csock = self._cobra_http_getsock()

        data = CobraHttpMethod(self, '__cobra_hello')()
        
        self._cobra_gothello = True
        self._cobra_methods = data
Ejemplo n.º 3
0
def main(uri, cacrt=None, sslcert=None, sslkey=None):
    if any([cacrt, sslcert, sslkey]):
        scheme, host, port, name, urlparams = cobra.chopCobraUri(uri)
        builder = cobra.initSocketBuilder(host, port)

        tempdir = tempfile.mkdtemp()
        if cacrt:
            cafile = dumpfile(cacrt, os.path.join(tempdir, 'ca.crt'))
            builder.setSslCa(cafile)

        if sslkey:
            keyfile = dumpfile(sslkey, os.path.join(tempdir, 'client.key'))
            certfile = dumpfile(sslcert, os.path.join(tempdir, 'client.crt'))
            builder.setSslClientCert(certfile, keyfile)

    try:
        c_remoteapp.getAndRunApp(uri)
    except Exception as e:
        logger.warning('error: %s', e)
Ejemplo n.º 4
0
def main(uri,cacrt=None,sslcert=None,sslkey=None):
    if any([cacrt,sslcert,sslkey]):
        scheme, host, port, name, urlparams = cobra.chopCobraUri( uri )
        builder = cobra.initSocketBuilder(host,port)

        tempdir = tempfile.mkdtemp()
        if cacrt:
            cafile = dumpfile(cacrt, os.path.join(tempdir,'ca.crt'))
            builder.setSslCa(cafile)

        if sslkey:
            keyfile = dumpfile(sslkey, os.path.join(tempdir,'client.key'))
            certfile = dumpfile(sslcert, os.path.join(tempdir,'client.crt'))
            builder.setSslClientCert(certfile,keyfile)

    try:
        c_remoteapp.getAndRunApp(uri)
    except Exception, e:
        print('error: %s' % e)
def _getAndRunApp(uri):
    # We dont want our *local* code, we want the remote code.
    cwd = os.getcwd()
    if cwd in sys.path:
        sys.path.remove(cwd)
    if '' in sys.path:
        sys.path.remove('')

    duri = cobra.swapCobraObject(uri, 'DcodeServer')
    cobra.dcode.addDcodeUri(duri)

    server = cobra.CobraProxy(uri)
    scheme, host, port, name, urlparams = cobra.chopCobraUri(uri)

    module = importlib.import_module(name)

    if hasattr(module, 'remotemain'):
        module.remotemain(server)
    else:
        module.main()
Ejemplo n.º 6
0
def _getAndRunApp(uri):
    # We dont want our *local* code, we want the remote code.
    cwd = os.getcwd()
    if cwd in sys.path:
        sys.path.remove(cwd)
    if '' in sys.path:
        sys.path.remove('')

    duri = cobra.swapCobraObject(uri, 'DcodeServer')
    cobra.dcode.addDcodeUri(duri)

    server = cobra.CobraProxy(uri)
    scheme, host, port, name, urlparams = cobra.chopCobraUri( uri )

    module = importlib.import_module(name)

    if hasattr(module, 'remotemain'):
        module.remotemain(server)
    else:
        module.main()