def send_email_notification(user): msg_template = ''' Hello, This is an automated message coming from App-Interface. The App SRE team adheres to the OpenShift GitHub policy: https://mojo.redhat.com/docs/DOC-1200784 Your GitHub profile does not comply with the following requirements: - Company field should contain "Red Hat". For any questions, please ping @app-sre-ic on #sd-app-sre in CoreOS Slack, or mail us at [email protected]. App-Interface repository: https://gitlab.cee.redhat.com/service/app-interface ''' to = user['username'] subject = 'App-Interface compliance - GitHub profile' body = msg_template smtp_client.send_mail(to, subject, body)
def run(dry_run): settings = queries.get_app_interface_settings() accounts = queries.get_aws_accounts() state = State( integration=QONTRACT_INTEGRATION, accounts=accounts, settings=settings ) emails = queries.get_app_interface_emails() # validate no 2 emails have the same name email_names = set([e['name'] for e in emails]) if len(emails) != len(email_names): logging.error('email names must be unique.') sys.exit(1) emails_to_send = [e for e in emails if not state.exists(e['name'])] for email in emails_to_send: logging.info(['send_email', email['name'], email['subject']]) if not dry_run: names = collect_to(email['to']) subject = email['subject'] body = email['body'] smtp_client.send_mail(names, subject, body, settings=settings) state.add(email['name'])
def run(dry_run=False): settings = queries.get_app_interface_settings() accounts = queries.get_aws_accounts() state = State( integration=QONTRACT_INTEGRATION, accounts=accounts, settings=settings ) credentials_requests = queries.get_credentials_requests() # validate no 2 requests have the same name credentials_requests_names = \ set([r['name'] for r in credentials_requests]) if len(credentials_requests) != len(credentials_requests_names): logging.error('request names must be unique.') sys.exit(1) error = False credentials_requests_to_send = \ [r for r in credentials_requests if not state.exists(r['name'])] for credentials_request_to_send in credentials_requests_to_send: user = credentials_request_to_send['user'] org_username = user['org_username'] public_gpg_key = user.get('public_gpg_key') credentials_name = credentials_request_to_send['credentials'] if not public_gpg_key: error = True logging.error( f"user {org_username} does not have a public gpg key") continue logging.info(['send_credentials', org_username, credentials_name]) if not dry_run: request_name = credentials_request_to_send['name'] names = [org_username] subject = request_name ecrypted_credentials = \ get_ecrypted_credentials(credentials_name, user, settings) if not ecrypted_credentials: error = True logging.error( f"could not get encrypted credentials {credentials_name}") continue body = MESSAGE_TEMPLATE.format( request_name, credentials_name, ecrypted_credentials) smtp_client.send_mail(names, subject, body, settings=settings) state.add(request_name) if error: sys.exit(1)