-
Notifications
You must be signed in to change notification settings - Fork 67
📝 Improve Getting Started Section #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -178,14 +178,6 @@ For details on enabling/configuring CORS, see | |
| To be able to meet the requirements of many organizations, Airflow supports many authentication methods, | ||
| and it is even possible to add your own method. | ||
|
|
||
| If you want to check which auth backend is currently set, you can use | ||
| `airflow config get-value api auth_backends` command as in the example below. | ||
|
|
||
| ```bash | ||
| $ airflow config get-value api auth_backends | ||
| airflow.providers.fab.auth_manager.api.auth.backend.basic_auth | ||
| ``` | ||
|
|
||
| The default is to deny all requests. | ||
|
|
||
| For details on configuring the authentication, see | ||
|
|
@@ -279,24 +271,62 @@ import airflow_client.client | |
|
|
||
| ## Getting Started | ||
|
|
||
| Before attempting the following examples ensure you have an account with API access. | ||
| As an example you can create an account for usage with the API as follows using the Airflow CLI. | ||
|
|
||
| ```bash | ||
| airflow users create -u admin-api -e [email protected] -f admin-api -l admin-api -p $PASSWORD -r Admin | ||
| ``` | ||
|
|
||
| Please follow the [installation procedure](#installation--usage) and then run the following: | ||
|
|
||
| ```python | ||
| import airflow_client.client | ||
| import requests | ||
| from airflow_client.client.rest import ApiException | ||
| from pprint import pprint | ||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| # What we expect back from auth/token | ||
| class AirflowAccessTokenResponse(BaseModel): | ||
pierrejeambrun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| access_token: str | ||
|
|
||
|
|
||
| # An optional helper function to retrieve an access token | ||
| def get_airflow_client_access_token( | ||
| host: str, | ||
| username: str, | ||
| password: str, | ||
| ) -> str: | ||
| url = f"{host}/auth/token" | ||
| payload = { | ||
| "username": username, | ||
| "password": password, | ||
| } | ||
| headers = {"Content-Type": "application/json"} | ||
| response = requests.post(url, json=payload, headers=headers) | ||
| if response.status_code != 201: | ||
| raise RuntimeError(f"Failed to get access token: {response.status_code} {response.text}") | ||
| response_success = AirflowAccessTokenResponse(**response.json()) | ||
| return response_success.access_token | ||
|
|
||
|
|
||
| # Defining the host is optional and defaults to http://localhost | ||
| # See configuration.py for a list of all supported configuration parameters. | ||
| configuration = airflow_client.client.Configuration(host="http://localhost") | ||
| host = "http://localhost" | ||
| configuration = airflow_client.client.Configuration(host=host) | ||
|
|
||
| # The client must configure the authentication and authorization parameters | ||
| # in accordance with the API server security policy. | ||
| # Examples for each auth method are provided below, use the example that | ||
| # satisfies your auth use case. | ||
|
|
||
| configuration.access_token = os.environ["ACCESS_TOKEN"] | ||
|
|
||
| configuration.access_token = get_airflow_client_access_token( | ||
| host=host, | ||
| username="admin-api", | ||
| password=os.environ["PASSWORD"], | ||
| ) | ||
|
|
||
| # Enter a context with an instance of the API client | ||
| with airflow_client.client.ApiClient(configuration) as api_client: | ||
|
|
@@ -599,7 +629,7 @@ You can also set it by env variable: `export AIRFLOW__CORE__LOAD_EXAMPLES=True` | |
|
|
||
| * optionally expose configuration (NOTE! that this is dangerous setting). The script will happily run with | ||
| the default setting, but if you want to see the configuration, you need to expose it. | ||
| In the `[webserver]` section of your `airflow.cfg` set: | ||
| In the `[api]` section of your `airflow.cfg` set: | ||
|
|
||
| ```ini | ||
| [api] | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.