def get_policy()

in terraform-modules/cloud-functions/src/provide-secrets-permissions/main.py [0:0]


def get_policy(project_id):
  """Function to fetch the policy of the project.
  Args:
      project_id (string); project id whose policy is to be fetched.

  Returns:
      policy (dict);  returns IAM policy.
  """
  import os
  from google.oauth2 import service_account
  import googleapiclient.discovery
  service = googleapiclient.discovery.build(
      "cloudresourcemanager", "v1"
  )
  policy = (
      service.projects()
      .getIamPolicy(
          resource=project_id,
          body={"options": {"requestedPolicyVersion": 1}},
      )
      .execute()
  )
  return(policy)