0

I'm trying to access the IAM permissions for the artifact registry of one of my projects through artifactregistry_v1 python API fro GCP.

name_val = "projects/" + REGISTRY_NAME
    artifact_registry_client = artifactregistry_v1.ArtifactRegistryClient(
    credentials=credentials
)
    req = iam_policy_pb2.GetIamPolicyRequest(resource=name_val)
    policy = artifact_registry_client.get_iam_policy(request=req)
    print(policy)

When I try this code, I get an error: 400 requests contain an invalid argument for the line request=req.

But if I just pass the resource into the get_iam_policy function, I get an error saying it got an unexpected keyword argument 'resource'.

  • Have you checked [this](https://cloud.google.com/python/docs/reference/artifactregistry/latest/google.cloud.artifactregistry_v1.services.artifact_registry.ArtifactRegistryClient#google_cloud_artifactregistry_v1_services_artifact_registry_ArtifactRegistryClient_get_iam_policy) documentation? – Chanpols Aug 24 '23 at 17:03

1 Answers1

-1

Based on this documentation on get_iam_policy, when you make the request, the variable for the request argument(s) should be the same when you make the request.

In your sample code, it should look like this:

name_val = "projects/" + REGISTRY_NAME
    artifact_registry_client = artifactregistry_v1.ArtifactRegistryClient(
    credentials=credentials
)
    req = iam_policy_pb2.GetIamPolicyRequest(resource=name_val)
    policy = artifact_registry_client.get_iam_policy(req=req) # the code should look like this
    print(policy)

Let me know if this works.

Robert G
  • 1,583
  • 3
  • 13
  • @Anushka, I would like to know the reason why my answer was not acceptable. It would be better to add a comment first. – Robert G Aug 30 '23 at 13:34