'Removing the labels from a google cloud project using python

I'm trying to use the python client API to remove labels from a GCP project. I have been able to use this method to add labels, but the documentation is not clear on how to remove them. I have assumed that I would need to provide a project object that has the labels removed, and then call the update.

The documentation here for update_project suggests that I need to provide a field mask. as a result, I have ended up with this:

from google.protobuf import field_mask_pb2
from google.oauth2 import service_account
from google.cloud import resourcemanager_v3
import sys

if len(sys.argv) < 2:
    print('You must provide a credentials .json file that has the correct permissions')
    quit()

credentials = service_account.Credentials.from_service_account_file(sys.argv[1])

client = resourcemanager_v3.ProjectsClient(credentials=credentials)

#request = resourcemanager3.GetProjectRequest(name="projects/968048482008")

fm =field_mask_pb2.FieldMask(paths=["labels"])

request = resourcemanager_v3.UpdateProjectRequest()
request.project.name="projects/968048482008"
request.project.labels={}
request.update_mask=fm

operation = client.update_project(request=request)

response = operation.result()

# Handle the response
print("after: ",response)

But it's not working. Any experts out there... Advice would be much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source