airflow-cli
Cli to interact with you airflow instance using the REST API when you can't ssh into the airflow server.
The code as been greatly inspired by glab and jira-cli.
Quickstart
Create a new profile
Using the CLI
Create a profile using :
airflow-cli profile create
you can choose between two kind of authentication :
In case of a jwt auth you can choose to use a shell command to retrieve the jwt token instead of directly providing it.
Editing the config file
The config file is stored in ~/.config/.airflow/.config
.
You can edit it directly.
; classic airflow authentication
[default]
user = airflow
password = airflow
url = http://0.0.0.0:8080/api/v1/
; auth across a proxy via jwt
[token]
token = secrettoken
url = https://some.server:8080/path/to/proxy
; you can retrieve the token via any shell command
[shell]
isShell = true
token = cat file_with_token
url = https://some.server:8080/path/to/proxy
Commands
Dag
The dag
command allow you to access dags and dag runs resources. They are by default sorted by -date_start
.
# list dags
airflow-cli dag list
# list dag run (prompt will ask for which dag_id)
airflow-cli dag list-run
# list dag run for dag_id
airflow-cli dag list-run -d dag_id
# trigger a dag run for dag_id
airflow-cli dag trigger -d dag_id
# get status of dag runs, tasks associated and log of a task instance
airflow-cli dag trigger -d dag_id
Dag graph
To get a graphviz representation of the graph.
airflow-cli dag graph
You can use graph-easy
to plot an asci art in your terminal. Installation instruction here.
airflow-cli dag graph -d tutorial_dag | graph-easy --from=graphviz --as=boxart
tutorial_dag
╭─────────╮ ╭───────────╮ ╭──────╮
│ extract │ ──▶ │ transform │ ──▶ │ load │
╰─────────╯ ╰───────────╯ ╰──────╯
Dag run grid
Get a grid view similar to airflow UI.
go run airflow-cli/main.go dag grid -d example_bash_operator
example_bash_operator v v v v v v
------------------------------------
also_run_this v v v v v v
runme_0 v v v v v v
runme_1 v v v v v v
runme_2 v v v v v v
run_after_loop v v v v v v
this_will_skip - - - - - -
run_this_last - - - - - -
|
2023-06-24
00:00:00
Task
# list tasks of a dag (prompt will ask to choose a dag)
airflow-cli task list
# list tasks instance of a dag run
airflow-cli task list
# list tasks instance of a dag run with no prompt
airflow-cli task list -d dag_id -r dag_run_id
# get logs from a task instance
airflow-cli task logs -d dag_id -r dag_run_id
Contribute
To run linting, install golang-lint.
make lint
Test
Use test makefile to spin up any airflow version.
make up VERSION=2.5.3
Todo
- Choose a name
- Reoganise required module
- Wrap error and sys exit [x]
- Correct Select descriptions servey [x]
- Correctly escape with crtl+d [x]
- Write quickstart README [x]
- Output DAG with diagon and natural C biding