Exemple #1
0
    def _add_client(self, source_config):
        logger.debug('Instanciating a new confd client for %s',
                     source_config['uuid'])
        auth_config = dict(source_config['auth'])
        if auth_config.get('key_file'):
            # File must be readable by wazo-dird
            key_file = parse_config_file(auth_config.pop('key_file'))
            if not key_file:
                logger.info('failed to load key file for source %s',
                            source_config['name'])
                return
            auth_config['username'] = key_file['service_id']
            auth_config['password'] = key_file['service_key']
        auth_client = AuthClient(**auth_config)
        token_renewer = TokenRenewer(auth_client)

        confd_config = source_config['confd']
        logger.debug('confd config %s', confd_config)
        client = ConfdClient(**confd_config)
        client.set_tenant(source_config['tenant_uuid'])

        token_renewer.subscribe_to_token_change(client.set_token)
        token_renewer.start()

        self._clients[source_config['uuid']] = RegisteredClient(
            client, token_renewer)
Exemple #2
0
class TokenRenewerService(Service):
    def __init__(self, prov_service, config):
        self._config = config
        self._prov_service = prov_service

    def startService(self):
        app = self._prov_service.app
        auth_client = auth.get_auth_client(**self._config['auth'])
        amid_client = provd.synchronize.get_AMID_client(**self._config['amid'])
        self._token_renewer = TokenRenewer(auth_client)
        self._token_renewer.subscribe_to_token_change(app.set_token)
        self._token_renewer.subscribe_to_token_change(auth_client.set_token)
        self._token_renewer.subscribe_to_token_change(amid_client.set_token)
        self._token_renewer.start()
        Service.startService(self)

    def stopService(self):
        self._token_renewer.stop()
        Service.stopService(self)