defaults = {
    'apt': {
        'packages': {
            'gunicorn': {},
            'python3-flask': {},
            'python3-psycopg2': {},
        },
    },
}


@metadata_reactor.provides(
    'icinga2-statuspage',
)
def import_db_settings_from_icinga(metadata):
    return {
        'icinga2-statuspage': {
            'DB_USER': 'icinga2',
            'DB_PASS': metadata.get('postgresql/roles/icinga2/password'),
            'DB_NAME': 'icinga2',
        },
    }


@metadata_reactor.provides(
    'nginx/vhosts/icinga2-statuspage',
)
def nginx(metadata):
    if not node.has_bundle('nginx'):
        raise DoNotRunAgain

    return {
        'nginx': {
            'vhosts': {
                'icinga2-statuspage': {
                    'domain': metadata.get('icinga2-statuspage/DOMAIN'),
                    'locations': {
                        '/': {
                            'target': 'http://127.0.0.1:22110',
                        },
                    },
                    'website_check_path': '/',
                    'website_check_string': 'status page',
                },
            },
        },
    }