Example #1
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request('get', sync_host,
                    '/key/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception('Failed to sync conf', 'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info('Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning('Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200 and response.content:
                self.update_profile(response.content)
                return

        if status_code is not None and status_code != 200:
            logger.error('Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )
Example #2
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request('get', sync_host,
                    '/key/sync/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception('Failed to sync conf', 'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info('Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning('Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200:
                data = response.json()
                if not data.get('signature') or not data.get('conf'):
                    return

                conf_signature = base64.b64encode(hmac.new(
                    self.sync_secret.encode(), data.get('conf'),
                    hashlib.sha512).digest())

                if conf_signature != data.get('signature'):
                    return

                self.update_profile(data.get('conf'))
                return

        if status_code is not None and status_code != 200:
            logger.error('Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )
Example #3
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request(
                    'get',
                    sync_host,
                    '/key/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception(
                        'Failed to sync conf',
                        'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info(
                    'Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning(
                    'Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200 and response.content:
                self.update_profile(response.content)
                return

        if status_code is not None and status_code != 200:
            logger.error(
                'Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )
Example #4
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request('get', sync_host,
                    '/key/sync/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception('Failed to sync conf', 'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info('Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning('Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200:
                data = response.json()
                if not data.get('signature') or not data.get('conf'):
                    return

                conf_signature = base64.b64encode(hmac.new(
                    self.sync_secret.encode(), data.get('conf'),
                    hashlib.sha512).digest())

                if conf_signature != data.get('signature'):
                    return

                self.update_profile(data.get('conf'))
                return

        if status_code is not None and status_code != 200:
            logger.error('Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )