Skip to content

Instantly share code, notes, and snippets.

@ozgurgul
Forked from nehiljain/setup_airflow_auth.py
Created June 10, 2020 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozgurgul/148bca37dcf8955f0ed409b88285d88c to your computer and use it in GitHub Desktop.
Save ozgurgul/148bca37dcf8955f0ed409b88285d88c to your computer and use it in GitHub Desktop.
A script to automatically setup a admin user for airflow which can be run at infrastructure setup time.
import os
import airflow
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
def create_admin_user(uname, pwd, email):
user = PasswordUser(models.User())
user.username = uname
user.email = email
user.password = pwd
session = settings.Session()
session.add(user)
session.commit()
session.close()
if __name__ == '__main__':
# you can generate username password dynamically or parse it using argparser
create_admin_user(some_username, some_password, some_email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment