-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dagster-airlift] tutorial auth (#24199)
Add a section on custom auth to the tutorial. This could be genericized for sure since there are other potential uses for a subclass of the proxy, but to keep it use-case driven.
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...l/dagster-airlift/examples/tutorial-example/tutorial_example/airflow_dags/custom_proxy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import requests | ||
from airflow.utils.context import Context | ||
from dagster_airlift.in_airflow import BaseProxyToDagsterOperator, mark_as_dagster_migrating | ||
|
||
|
||
class CustomProxyToDagsterOperator(BaseProxyToDagsterOperator): | ||
def get_dagster_session(self, context: Context) -> requests.Session: | ||
if "var" not in context: | ||
raise ValueError("No variables found in context") | ||
api_key = context["var"]["value"].get("my_api_key") | ||
session = requests.Session() | ||
session.headers.update({"Authorization": f"Bearer {api_key}"}) | ||
return session | ||
|
||
def get_dagster_url(self, context: Context) -> str: | ||
return "https://dagster.example.com/" | ||
|
||
|
||
... | ||
|
||
# At the end of your dag file | ||
mark_as_dagster_migrating( | ||
global_vars=globals(), migration_state=..., dagster_operator_klass=CustomProxyToDagsterOperator | ||
) |