def _CheckIamPermissions(project_id):
    'Check for needed IAM permissions and prompt to add if missing.\n\n  Args:\n    project_id: A string with the name of the project.\n  '
    project = projects_api.Get(project_id)
    expected_services = ['cloudbuild.googleapis.com', 'logging.googleapis.com']
    for service_name in expected_services:
        if (not services_api.IsServiceEnabled(project.projectId, service_name)):
            prompt_message = 'The "{0}" service is not enabled for this project. It is required for this operation.\n'.format(service_name)
            console_io.PromptContinue(prompt_message, 'Would you like to enable this service?', throw_if_unattended=True, cancel_on_no=True)
            services_api.EnableService(project.projectId, service_name)
    service_account = 'serviceAccount:example@example.com'.format(project.projectNumber)
    expected_permissions = {'roles/compute.admin': service_account}
    for role in SERVICE_ACCOUNT_ROLES:
        expected_permissions[role] = service_account
    permissions = projects_api.GetIamPolicy(project_id)
    for binding in permissions.bindings:
        if (expected_permissions.get(binding.role) in binding.members):
            del expected_permissions[binding.role]
    if expected_permissions:
        ep_table = ['{0} {1}'.format(role, account) for (role, account) in expected_permissions.items()]
        prompt_message = 'The following IAM permissions are needed for this operation:\n[{0}]\n'.format('\n'.join(ep_table))
        console_io.PromptContinue(message=prompt_message, prompt_string='Would you like to add the permissions', throw_if_unattended=True, cancel_on_no=True)
        for (role, account) in expected_permissions.items():
            log.info('Adding [{0}] to [{1}]'.format(account, role))
            projects_api.AddIamPolicyBinding(project_id, account, role)
Check for needed IAM permissions and prompt to add if missing.

Args:
  project_id: A string with the name of the project.
def _CheckIamPermissions(project_id):
    'Check for needed IAM permissions and prompt to add if missing.\n\n  Args:\n    project_id: A string with the name of the project.\n  '
    project = projects_api.Get(project_id)
    expected_services = ['cloudbuild.googleapis.com', 'logging.googleapis.com']
    for service_name in expected_services:
        if (not services_api.IsServiceEnabled(project.projectId, service_name)):
            prompt_message = 'The "{0}" service is not enabled for this project. It is required for this operation.\n'.format(service_name)
            console_io.PromptContinue(prompt_message, 'Would you like to enable this service?', throw_if_unattended=True, cancel_on_no=True)
            services_api.EnableService(project.projectId, service_name)
    service_account = 'serviceAccount:example@example.com'.format(project.projectNumber)
    expected_permissions = {'roles/compute.admin': service_account}
    for role in SERVICE_ACCOUNT_ROLES:
        expected_permissions[role] = service_account
    permissions = projects_api.GetIamPolicy(project_id)
    for binding in permissions.bindings:
        if (expected_permissions.get(binding.role) in binding.members):
            del expected_permissions[binding.role]
    if expected_permissions:
        ep_table = ['{0} {1}'.format(role, account) for (role, account) in expected_permissions.items()]
        prompt_message = 'The following IAM permissions are needed for this operation:\n[{0}]\n'.format('\n'.join(ep_table))
        console_io.PromptContinue(message=prompt_message, prompt_string='Would you like to add the permissions', throw_if_unattended=True, cancel_on_no=True)
        for (role, account) in expected_permissions.items():
            log.info('Adding [{0}] to [{1}]'.format(account, role))
            projects_api.AddIamPolicyBinding(project_id, account, role)