def __init__( self, host_base, broker_name=None, broker_passphase=None, 
                  result_path=None):
        SCConnection.__init__(self, host_base, broker_name, broker_passphase)

        # pseudo sample path
        self.result_path = result_path
        
        if os.path.isdir(self.result_path) == False:
            os.makedirs(self.result_path)
    def make_request(self,
                     action='',
                     params=None,
                     headers=None,
                     data='',
                     method='GET'):

        fake = None
        resfile = reqfile = action.replace('/', '.')
        reqfile = os.path.join(self.result_path,
                               '[Request]-%s %s.xml' % (method, reqfile))
        resfile = os.path.join(self.result_path,
                               '[Response]-%s %s.xml' % (method, resfile))

        # serialize Request data
        sclib.log.debug("---------- RESTFul Request ---------- ")
        sclib.log.debug('%s %s' % (method, action))
        rf = io.open(reqfile, 'w')
        if data:
            # Format request data
            formated = self.nice_format(data)
            rf.write(formated)

            # Debug - request data
            sclib.log.debug('\n%s' % (formated))
        rf.close()

        # make request to securecloud
        response = SCConnection.make_request(self, action, params, headers,
                                             data, method)
        if response:
            sclib.log.debug("---------- RESTFul Response (%s) ---------- " %
                            (response.code))
            body = response.read()

            # serialize Response data
            f = io.open(resfile, 'w')
            if body:
                # Format response data
                formated = self.nice_format(body)
                f.write(formated)

                # Debug - response data
                if formated: sclib.log.debug('\n%s' % (formated))
            f.close()

            #make fake response
            resfp = StringIO.StringIO(body)
            fake = urllib.addinfourl(resfp, response.info(), response.geturl(),
                                     response.getcode())

        sclib.log.debug("------------------------------------------\n")
        return fake
Ejemplo n.º 3
0
def connect_sc(sc_host_url, sc_broker, sc_broker_key):
    """
    :type sc_host_url: string
    :param sc_host_url: Your SecureCloud broker url. Ex. https://ms.securecloud.com:7443/broker/API.svc/v3.5

    :type sc_broker: string
    :param sc_broker: Your broker name

    :type sc_broker_key: string
    :param sc_broker_key: Your broker access key

    :rtype: :class:`sclib.sc.connection.SCConnection`
    :return: A connection to SecureCloud
    """
    from sclib.sc.connection import SCConnection
    return SCConnection(sc_host_url, sc_broker, sc_broker_key)
    def make_request(self, action='', params=None, headers=None, data='', method='GET'):

        fake = None
        resfile = reqfile = action.replace('/', '.')
        reqfile = os.path.join(self.result_path, '[Request]-%s %s.xml' % (method, reqfile ) )
        resfile = os.path.join(self.result_path, '[Response]-%s %s.xml' % (method, resfile) )


        # serialize Request data
        sclib.log.debug("---------- RESTFul Request ---------- " )
        sclib.log.debug('%s %s' % (method, action))
        rf = io.open(reqfile, 'wb')
        if data:
            # Format request data
            formated = self.nice_format(data)
            rf.write(formated)

            # Debug - request data
            sclib.log.debug('\n%s' % (formated))
        rf.close()

        # make request to securecloud
        response = SCConnection.make_request(self, action, params, headers, data, method)
        if response:
            sclib.log.debug("---------- RESTFul Response (%s) ---------- " % (response.code) )
            body = response.read()
            
            # serialize Response data
            f = io.open(resfile, 'wb')
            if body:
                # Format response data
                formated = self.nice_format(body)
                f.write(formated)

                # Debug - response data
                if formated: sclib.log.debug('\n%s' % (formated))
            f.close()

            #make fake response
            resfp = StringIO.StringIO(body)
            fake = urllib.addinfourl(resfp, response.info(), response.geturl(), response.getcode())
            

        sclib.log.debug("------------------------------------------\n")
        return fake