Tristan Bilot
Tristan Bilot

Reputation: 479

Create users using Cloud Composer API: error 405

I'm trying to create an Airflow user on Cloud Composer based on the Airflow API and the Composer API example. The example given in the previous link works perfectly (so the auth to the API is a success) but when using the endpoint for user creation/update it returns the following error: 405 Client Error: Method Not Allowed for url: https://...

I use Airflow 2 on Cloud Composer so rbac UI is enabled by default.

Code:

import google.auth
from google.auth.transport.requests import AuthorizedSession

AUTH_SCOPE = "https://www.googleapis.com/auth/cloud-platform"
CREDENTIALS, _ = google.auth.default(scopes=[AUTH_SCOPE])


def make_composer2_web_server_request(url: str, method: str = "GET", **kwargs: Any) -> google.auth.transport.Response:
    authed_session = AuthorizedSession(CREDENTIALS)
    if "timeout" not in kwargs:
        kwargs["timeout"] = 90

    return authed_session.request(method, url, **kwargs)

def create_user(web_server_url: str) -> str:
    endpoint = f"api/v1/users"
    request_url = f"{web_server_url}/{endpoint}"
    json_data = {
        "first_name": "hello",
        "last_name": "hello",
        "username": "hello",
        "email": "[email protected]",
        "roles": [
            {
            "name": "Op"
            }
        ],
        "password": "password1"
    }

    response = make_composer2_web_server_request(
        request_url, method="POST", json=json_data
    )
    return response.text

Any idea?

Upvotes: 1

Views: 543

Answers (1)

Raul Saucedo
Raul Saucedo

Reputation: 1780

This type or error is about permissions with the user you are using.

For Cloud Composer you can use these roles to view, create, update, upgrade, and delete environments, manage objects (such as DAG files) in the environment buckets, and access the Airflow web interface:

  • Environment and Storage Object Administrator
  • Service Account User

To view environments, access the Airflow web interface, and manage objects in the environment buckets (to upload new DAG files):

  • Environment User and Storage Object Viewer
  • Storage Object Admin

You can see more documentation about Cloud Composer permissions.

You can use more granular permissions. Here are some examples:

  • Environments.create
  • Operations.get

You can see more granular permissions in this documentation.

If you want to manage the permission of the DAGs, you can see this documentation.

Upvotes: 1

Related Questions