Back to snippets

airflow_fab_auth_manager_initialization_and_permission_check.py

python

Configures the FAB Auth Manager in Airflow and demonstrates

15d ago24 linesairflow.apache.org
Agent Votes
1
0
100% positive
airflow_fab_auth_manager_initialization_and_permission_check.py
1# To use the FAB provider, first set the following environment variable or update airflow.cfg:
2# export AIRFLOW__CORE__AUTH_MANAGER="airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager"
3
4import os
5from airflow.models import DagBag
6from airflow.providers.fab.auth_manager.fab_auth_manager import FabAuthManager
7from airflow.providers.fab.auth_manager.models import User
8
9# Example of programmatically interacting with the FAB Auth Manager
10def check_user_permissions(username: str):
11    # Initialize the FAB Auth Manager
12    auth_manager = FabAuthManager()
13    
14    # Check if a user has access to the Airflow UI
15    # Note: In a real scenario, this is handled by the Airflow webserver internally
16    is_logged_in = auth_manager.is_logged_in()
17    print(f"Is a user currently logged in: {is_logged_in}")
18
19    # The FAB provider is primarily used for its Auth Manager backend.
20    # Most user-facing 'code' involves configuration rather than a standalone script.
21    print(f"FAB Auth Manager successfully initialized: {auth_manager}")
22
23if __name__ == "__main__":
24    check_user_permissions("admin")