from itertools import (
    chain,
)
import logging

from azul import (
    config,
    require,
)
from azul.logging import (
    configure_script_logging,
)
from azul.terra import (
    TDRClient,
    TDRSourceName,
)

log = logging.getLogger(__name__)


def main():
    configure_script_logging(log)
    tdr = TDRClient()
    tdr.register_with_sam()

    tdr_catalogs = (
        catalog.name
        for catalog in config.catalogs.values()
        if catalog.plugins['repository'] == 'tdr'
    )
    for source in set(chain(*map(config.tdr_sources, tdr_catalogs))):
        source = TDRSourceName.parse(source)
        api_project = tdr.lookup_source_project(source)
        require(api_project == source.project,
                'Actual Google project of TDR source differs from configured '
                'one',
                api_project, source)
        tdr.check_api_access(source)
        tdr.check_bigquery_access(source)


if __name__ == '__main__':
    main()

[((18, 6, 18, 33), 'logging.getLogger', 'logging.getLogger', ({(18, 24, 18, 32): '__name__'}, {}), '(__name__)', False, 'import logging\n'), ((22, 4, 22, 33), 'azul.logging.configure_script_logging', 'configure_script_logging', ({(22, 29, 22, 32): 'log'}, {}), '(log)', False, 'from azul.logging import configure_script_logging\n'), ((23, 10, 23, 21), 'azul.terra.TDRClient', 'TDRClient', ({}, {}), '()', False, 'from azul.terra import TDRClient, TDRSourceName\n'), ((32, 17, 32, 44), 'azul.terra.TDRSourceName.parse', 'TDRSourceName.parse', ({(32, 37, 32, 43): 'source'}, {}), '(source)', False, 'from azul.terra import TDRClient, TDRSourceName\n'), ((34, 8, 37, 36), 'azul.require', 'require', ({(34, 16, 34, 45): '(api_project == source.project)', (35, 16, 36, 21): '"""Actual Google project of TDR source differs from configured one"""', (37, 16, 37, 27): 'api_project', (37, 29, 37, 35): 'source'}, {}), "(api_project == source.project,\n    'Actual Google project of TDR source differs from configured one',\n    api_project, source)", False, 'from azul import config, require\n'), ((28, 23, 28, 47), 'azul.config.catalogs.values', 'config.catalogs.values', ({}, {}), '()', False, 'from azul import config, require\n')]