Abhishek Singh
Abhishek Singh

Reputation: 61

Trying to access Cloud composer APIs

I am using below code to modify Airflow dag status.

statusObject = {"state": "failed"}
AUTH_SCOPE = "https://www.googleapis.com/auth/cloud-platform"
CREDENTIALS, _ = google.auth.default(scopes=[AUTH_SCOPE])
authed_session = AuthorizedSession(CREDENTIALS)
headers = {'content-type': 'application/json', 'accept': 'application/json'}

url = "https://{composer-name}.composer.googleusercontent.com/api/v1/dags/" + dag_run.conf["dag_id"] + "/dagRuns/" + dag_run.conf["cancel_dag_id"]

response= authed_session.request("PATCH", url, json=statusObject,headers=headers)

I am getting 401 unauthorised because the service account I am using has access_type = 'online'.

How can I make this API request or set access_type='offline' programmatically?

Upvotes: 0

Views: 183

Answers (1)

Shipra Sarkar
Shipra Sarkar

Reputation: 1475

@Abhishek Singh, As you have mentioned in the comment, issue can be resolved by limiting the character size of service account ID.

The ID must be between 6 and 30 characters, and can contain lowercase alphanumeric characters and dashes. After you create a service account, you cannot change its name. The service account's name appears in the email address that is provisioned during creation, in the format SA_NAME @ PROJECT_ID.

For more information this document can be referred.

Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future.

Feel free to edit this answer for additional information.

Upvotes: 1

Related Questions