Beispiel #1
0
    def test_delete_record(self):
        server = RemoteSettings('foo', 'baa')
        server._setup_done = True
        assert not server._changes
        url = (settings.REMOTE_SETTINGS_WRITER_URL +
               'buckets/foo/collections/baa/records/an-id')
        responses.add(responses.DELETE, url, content_type='application/json')

        server.delete_record('an-id')
        assert server._changes
Beispiel #2
0
def legacy_delete_blocks(blocks):
    bucket = settings.REMOTE_SETTINGS_WRITER_BUCKET
    server = RemoteSettings(bucket, REMOTE_SETTINGS_COLLECTION_LEGACY)
    for block in blocks:
        if block.legacy_id:
            if block.is_imported_from_legacy_regex:
                log.info(
                    f'Block [{block.guid}] was imported from a regex guid so '
                    "can't be safely deleted.  Skipping.")
            else:
                server.delete_record(block.legacy_id)
            block.update(legacy_id='')
    server.complete_session()
Beispiel #3
0
def legacy_publish_blocks(blocks):
    bucket = settings.REMOTE_SETTINGS_WRITER_BUCKET
    server = RemoteSettings(bucket, REMOTE_SETTINGS_COLLECTION_LEGACY)
    for block in blocks:
        needs_updating = block.include_in_legacy and block.legacy_id
        needs_creating = block.include_in_legacy and not block.legacy_id
        needs_deleting = block.legacy_id and not block.include_in_legacy

        if needs_updating or needs_creating:
            if block.is_imported_from_legacy_regex:
                log.info(
                    f'Block [{block.guid}] was imported from a regex guid so '
                    'can\'t be safely updated.  Skipping.')
                continue
            data = {
                'guid':
                block.guid,
                'details': {
                    'bug': block.url,
                    'why': block.reason,
                    'name': str(block.reason).partition('.')[0],  # required
                },
                'enabled':
                True,
                'versionRange': [{
                    'severity': 3,  # Always high severity now.
                    'minVersion': block.min_version,
                    'maxVersion': block.max_version,
                }],
            }
            if needs_creating:
                record = server.publish_record(data)
                block.update(legacy_id=record.get('id', ''))
            else:
                server.publish_record(data, block.legacy_id)
        elif needs_deleting:
            if block.is_imported_from_legacy_regex:
                log.info(
                    f'Block [{block.guid}] was imported from a regex guid so '
                    'can\'t be safely deleted.  Skipping.')
            else:
                server.delete_record(block.legacy_id)
            block.update(legacy_id='')
        # else no existing legacy record and it shouldn't be in legacy so skip
    server.complete_session()