def run(dry_run,
        gitlab_project_id=None,
        thread_pool_size=10,
        enable_deletion=False,
        send_mails=False):
    settings = queries.get_app_interface_settings()
    users = queries.get_users()
    g = init_github()

    results = threaded.run(get_user_company, users, thread_pool_size, github=g)

    users_to_delete = get_users_to_delete(results)

    if not dry_run and enable_deletion:
        gw = prg.init(gitlab_project_id=gitlab_project_id)

    for user in users_to_delete:
        username = user['username']
        paths = user['paths']
        logging.info(['delete_user', username])

        if not dry_run:
            if send_mails:
                send_email_notification(user, settings)
            elif enable_deletion:
                gw.create_delete_user_mr(username, paths)
            else:
                msg = ('\'delete\' action is not enabled. '
                       'Please run the integration manually '
                       'with the \'--enable-deletion\' flag.')
                logging.warning(msg)
Пример #2
0
def main(configfile, dry_run, log_level, gitlab_project_id, reports_path):
    config.init_from_toml(configfile)
    init_log_level(log_level)
    config.init_from_toml(configfile)
    gql.init_from_config()

    now = datetime.now()
    apps = get_apps_data(now)

    reports = [Report(app, now).to_message() for app in apps]

    for report in reports:
        logging.info(['create_report', report['file_path']])

        if reports_path:
            report_file = os.path.join(reports_path, report['file_path'])

            try:
                os.makedirs(os.path.dirname(report_file))
            except FileExistsError:
                pass

            with open(report_file, 'w') as f:
                f.write(report['content'])

    if not dry_run:
        email_schema = '/app-interface/app-interface-email-1.yml'
        email_body = """\
            Hello,

            A new report by the App SRE team is now available at:
            https://visual-app-interface.devshift.net/reports

            You can use the Search bar to search by App.

            You can also view reports per service here:
            https://visual-app-interface.devshift.net/services


            Having problems? Ping us on #sd-app-sre on Slack!


            You are receiving this message because you are a member
            of app-interface or subscribed to a mailing list specified
            as owning a service being run by the App SRE team:
            https://gitlab.cee.redhat.com/service/app-interface
            """
        gw = prg.init(gitlab_project_id=gitlab_project_id,
                      override_pr_gateway_type='gitlab')
        mr = gw.create_app_interface_reporter_mr(reports, email_schema,
                                                 textwrap.dedent(email_body),
                                                 reports_path)
        logging.info(['created_mr', mr.web_url])
Пример #3
0
def act(dry_run, gitlab_project_id, accounts, keys_to_delete):
    if not dry_run and keys_to_delete:
        gw = prg.init(gitlab_project_id=gitlab_project_id)

    for k in keys_to_delete:
        account = k['account']
        key = k['key']
        logging.info(['delete_aws_access_key', account, key])
        if not dry_run:
            path = 'data' + \
                [a['path'] for a in accounts if a['name'] == account][0]
            gw.create_delete_aws_access_key_mr(account, path, key)