class SudsSOAPWrapper(BaseHTTPSOAPWrapper): """ A thin wrapper around the suds SOAP library """ def __init__(self, config): super(SudsSOAPWrapper, self).__init__(config) self.set_auth() self.update_lock = RLock() self.config = config self.config['timeout'] = float(self.config['timeout']) self.config_no_sensitive = deepcopy(self.config) self.config_no_sensitive['password'] = '******' self.address = '{}{}'.format(self.config['address_host'], self.config['address_url_path']) self.conn_type = 'Suds SOAP' self.client = ConnectionQueue( self.config['pool_size'], self.config['queue_build_cap'], self.config['name'], self.conn_type, self.address, self.add_client) def set_auth(self): """ Configures the security for requests, if any is to be configured at all. """ self.suds_auth = {'username':self.config['username'], 'password':self.config['password']} def add_client(self): logger.info('About to add a client to `%s` (%s)', self.address, self.conn_type) # Lazily-imported here to make sure gevent monkey patches everything well in advance from suds.client import Client from suds.transport.https import HttpAuthenticated from suds.transport.https import WindowsHttpAuthenticated from suds.wsse import Security, UsernameToken sec_type = self.config['sec_type'] if sec_type == SEC_DEF_TYPE.BASIC_AUTH: transport = HttpAuthenticated(**self.suds_auth) elif sec_type == SEC_DEF_TYPE.NTLM: transport = WindowsHttpAuthenticated(**self.suds_auth) elif sec_type == SEC_DEF_TYPE.WSS: security = Security() token = UsernameToken(self.suds_auth['username'], self.suds_auth['password']) security.tokens.append(token) client = Client(self.address, autoblend=True, wsse=security) if sec_type in(SEC_DEF_TYPE.BASIC_AUTH, SEC_DEF_TYPE.NTLM): client = Client(self.address, autoblend=True, transport=transport) # Still could be either none at all or WSS if not sec_type: client = Client(self.address, autoblend=True, timeout=self.config['timeout']) self.client.put_client(client) def build_client_queue(self): with self.update_lock: self.client.build_queue()
class OdooWrapper(object): """ Wraps a queue of connections to Odoo. """ def __init__(self, config, server): self.config = config self.server = server # Decrypt the password if it is encrypted. It will be in clear text when the server is starting up # but otherwise for connections created in run-time, it will be decrypted. if self.config.password.startswith(SECRETS.PREFIX): self.config.password = self.server.decrypt(self.config.password) self.url = '{protocol}://{user}:******@{host}:{port}/{database}'.format(**self.config) self.client = ConnectionQueue( self.config.pool_size, self.config.queue_build_cap, self.config.name, 'Odoo', self.url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__) def build_queue(self): with self.update_lock: self.client.build_queue() def add_client(self): conn = client_lib.get_connection(hostname=self.config.host, protocol=self.config.protocol, port=self.config.port, database=self.config.database, login=self.config.user, password=self.config.password) try: ping_odoo(conn) except Exception: logger.warn('Could not ping Odoo (%s), e:`%s`', self.config.name, format_exc()) self.client.put_client(conn)
class SudsSOAPWrapper(BaseHTTPSOAPWrapper): """ A thin wrapper around the suds SOAP library """ def __init__(self, config): super(SudsSOAPWrapper, self).__init__(config) self.update_lock = RLock() self.config = config self.config['timeout'] = float(self.config['timeout']) self.config_no_sensitive = deepcopy(self.config) self.config_no_sensitive['password'] = '******' self.address = '{}{}'.format(self.config['address_host'], self.config['address_url_path']) self.conn_type = 'Suds SOAP' self.client = ConnectionQueue(self.config['pool_size'], self.config['queue_build_cap'], self.config['name'], self.conn_type, self.address, self.add_client) def add_client(self): logger.info('About to add a client to `%s` (%s)', self.address, self.conn_type) # Lazily-imported here to make sure gevent monkey patches everything well in advance from suds.client import Client from suds.transport.https import HttpAuthenticated from suds.transport.https import WindowsHttpAuthenticated from suds.wsse import Security, UsernameToken sec_type = self.config['sec_type'] if sec_type == SEC_DEF_TYPE.BASIC_AUTH: transport = HttpAuthenticated(**self.suds_auth) elif sec_type == SEC_DEF_TYPE.NTLM: transport = WindowsHttpAuthenticated(**self.suds_auth) elif sec_type == SEC_DEF_TYPE.WSS: security = Security() token = UsernameToken(self.suds_auth['username'], self.suds_auth['password']) security.tokens.append(token) client = Client(self.address, autoblend=True, wsse=security) if sec_type in (SEC_DEF_TYPE.BASIC_AUTH, SEC_DEF_TYPE.NTLM): client = Client(self.address, autoblend=True, transport=transport) # Still could be either none at all or WSS if not sec_type: client = Client(self.address, autoblend=True, timeout=self.config['timeout']) self.client.put_client(client) def build_client_queue(self): with self.update_lock: self.client.build_queue()
class SwiftWrapper(object): """ Wraps a queue of connections to OpenStack Swift. """ def __init__(self, config, server): self.config = config self.server = server self.client = ConnectionQueue( self.config.pool_size, self.config.queue_build_cap, self.config.name, 'OpenStack Swift', self.config.auth_url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__) def build_queue(self): with self.update_lock: self.client.build_queue() def add_client(self): conn = Connection(authurl=self.config.auth_url, user=self.config.user, key=self.config.key, retries=self.config.retries, snet=self.config.is_snet, starting_backoff=float(self.config.starting_backoff), max_backoff=float(self.config.max_backoff), tenant_name=self.config.tenant_name, os_options=parse_extra_into_dict(self.config.custom_options), auth_version=self.config.auth_version, cacert=self.config.cacert, insecure=not self.config.should_validate_cert, ssl_compression=self.config.needs_tls_compr, retry_on_ratelimit=self.config.should_retr_ratelimit) try: conn.head_account() except Exception: self.logger.warn('Could not HEAD an account (%s), e:`%s`', self.config.name, format_exc()) self.client.put_client(conn)
class OdooWrapper(object): """ Wraps a queue of connections to Odoo. """ def __init__(self, config): self.config = config self.url = '{protocol}://{user}:******@{host}:{port}/{database}'.format(**self.config) self.client = ConnectionQueue( self.config.pool_size, self.config.queue_build_cap, self.config.name, 'Odoo', self.url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__) def build_queue(self): with self.update_lock: self.client.build_queue() def add_client(self): conn = openerplib.get_connection(hostname=self.config.host, protocol=self.config.protocol, port=self.config.port, database=self.config.database, login=self.config.user, password=self.config.password) try: ping_odoo(conn) except Exception, e: logger.warn('Could not ping Odoo (%s), e:`%s`', self.config.name, format_exc(e)) self.client.put_client(conn)
class SwiftWrapper(object): """ Wraps a queue of connections to OpenStack Swift. """ def __init__(self, config): self.config = config self.client = ConnectionQueue( self.config.pool_size, self.config.queue_build_cap, self.config.name, 'OpenStack Swift', self.config.auth_url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__) def build_queue(self): with self.update_lock: self.client.build_queue() def add_client(self): conn = Connection(authurl=self.config.auth_url, user=self.config.user, key=self.config.key, retries=self.config.retries, snet=self.config.is_snet, starting_backoff=float(self.config.starting_backoff), max_backoff=float(self.config.max_backoff), tenant_name=self.config.tenant_name, os_options=parse_extra_into_dict(self.config.custom_options), auth_version=self.config.auth_version, cacert=self.config.cacert, insecure=not self.config.should_validate_cert, ssl_compression=self.config.needs_tls_compr, retry_on_ratelimit=self.config.should_retr_ratelimit) try: conn.head_account() except Exception, e: self.logger.warn('Could not HEAD an account (%s), e:`%s`', self.config.name, format_exc(e)) self.client.put_client(conn)
def __init__(self, config): self.config = config self.url = '{protocol}://{user}:******@{host}:{port}/{database}'.format(**self.config) self.client = ConnectionQueue( self.config.pool_size, self.config.queue_build_cap, self.config.name, 'Odoo', self.url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__)
def __init__(self, config): self.config = config self.client = ConnectionQueue(self.config.pool_size, self.config.queue_build_cap, self.config.name, 'OpenStack Swift', self.config.auth_url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__)
def __init__(self, config): super(SudsSOAPWrapper, self).__init__(config) self.update_lock = RLock() self.config = config self.config['timeout'] = float(self.config['timeout']) self.config_no_sensitive = deepcopy(self.config) self.config_no_sensitive['password'] = '******' self.address = '{}{}'.format(self.config['address_host'], self.config['address_url_path']) self.conn_type = 'Suds SOAP' self.client = ConnectionQueue( self.config['pool_size'], self.config['queue_build_cap'], self.config['name'], self.conn_type, self.address, self.add_client)
def __init__(self, config, server): self.config = config self.server = server # Decrypt the password if it is encrypted. It will be in clear text when the server is starting up # but otherwise for connections created in run-time, it will be decrypted. if self.config.password.startswith(SECRETS.PREFIX): self.config.password = self.server.decrypt(self.config.password) self.url = '{protocol}://{user}:******@{host}:{port}/{database}'.format(**self.config) self.client = ConnectionQueue( self.config.pool_size, self.config.queue_build_cap, self.config.name, 'Odoo', self.url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__)
def __init__(self, config, server): # Imported here because not everyone will be using SAP import pyrfc self.pyrfc = pyrfc self.config = config self.server = server self.url = 'rfc://{user}@{host}:{sysnr}/{client}'.format(**self.config) self.client = ConnectionQueue(self.config.pool_size, self.config.queue_build_cap, self.config.name, 'SAP', self.url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__)
def __init__(self, config): self.config = config self.client = ConnectionQueue( self.config.pool_size, self.config.queue_build_cap, self.config.name, 'OpenStack Swift', self.config.auth_url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__)
def __init__(self, config): super(SudsSOAPWrapper, self).__init__(config) self.update_lock = RLock() self.config = config self.config_no_sensitive = deepcopy(self.config) self.config_no_sensitive['password'] = '******' self.address = '{}{}'.format(self.config['address_host'], self.config['address_url_path']) self.conn_type = 'Suds SOAP' self.client = ConnectionQueue( self.config['pool_size'], self.config['queue_build_cap'], self.config['name'], self.conn_type, self.address, self.add_client)
class SAPWrapper(object): """ Wraps a queue of connections to SAP RFC. """ def __init__(self, config, server): # Imported here because not everyone will be using SAP import pyrfc self.pyrfc = pyrfc self.config = config self.server = server self.url = 'rfc://{user}@{host}:{sysnr}/{client}'.format(**self.config) self.client = ConnectionQueue(self.config.pool_size, self.config.queue_build_cap, self.config.name, 'SAP', self.url, self.add_client) self.update_lock = RLock() self.logger = getLogger(self.__class__.__name__) def build_queue(self): with self.update_lock: self.client.build_queue() def add_client(self): conn = self.pyrfc.Connection(user=self.config.user, passwd=self.config.password, ashost=self.config.host, sysnr=self.config.sysnr, client=self.config.client) try: ping_sap(conn) except Exception, e: self.logger.warn('Could not ping SAP (%s), e:`%s`', self.config.name, format_exc(e)) self.client.put_client(conn)