
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlZddZddZd Zd Zy)zUtilities for Policies API.    )absolute_import)division)unicode_literalsN)messages)encoding)apis)base)
exceptions)iam_util)yamlc                    | t         j                  j                  k(  rt        j                  dd|      S | t         j                  j
                  k(  rt        j                  dd|      S t        j                  dd|      S )Niamv2alpha)no_httpv2betav2)r	   ReleaseTrackALPHAr   GetClientInstanceBETA)release_trackr   s     *lib/googlecloudsdk/api_lib/iam/policies.pyr   r   !   si    d''---!!%GDD))...!!%7CC!!%w??    c                 8    |xs t        |       }|j                  S N)r   MESSAGES_MODULE)r   clients     r   GetMessagesModuler   *   s    5&}5&			r   c           	         t        j                  |       }	 t        j                  ||      }|S # t        t
        j                  f$ r=}t        j                  dj                  | t        j                  |                  d}~wt
        j                  t        j                  f$ r=}t        j                   dj                  | t        j                  |                  d}~ww xY w)a  Create an IAM V2 Policy protorpc.Message from YAML or JSON formatted file.

  Returns the parsed policy object.
  Args:
    policy_file_path: Path to the YAML or JSON IAM policy file.
    policy_message_type: Policy message type to convert YAML to.

  Returns:
    policy that is a protorpc.Message of type policy_message_type filled in
    from the JSON or YAML policy file
  Raises:
    BadFileException if the YAML or JSON file is malformed.
    IamEtagReadError if the etag is badly formatted.
  zKPolicy file [{0}] is not a properly formatted YAML or JSON policy file. {1}Nz<The etag of policy file [{0}] is not properly formatted. {1})r   	load_pathr   PyValueToMessageAttributeErrorapitools_messagesValidationErrorgcloud_exceptionsBadFileExceptionformatsix	text_typeDecodeErrorbinasciiErrorr   IamEtagReadError)policy_file_pathpolicy_message_typepolicy_to_parsepolicyes        r   ParseYamlOrJsonPolicyFiler3   /   s     NN#34/1&&':OLF 
- +;;	< G

,
,	!6"2CMM!4DEG G 
'
'	8 1

#
#FMMcmmA.	01 11s!   / C#8B  &C#&8CC#c                    t        |      }t        |      }g }|dv rdj                  ||       }|j                  j	                  |j                  |            j                  }|D ]H  }|j                  j                  |j                  |j                              }	|j                  |	       J |S t        j                  d|      )a\  Gets the IAM Deny policies for an organization.

  Args:
    resource_id: id for the resource
    resource_type: what type of a resource the id represents. Either
      organization, project, or folder
    release_track: ALPHA or BETA or GA

  Returns:
    The output from the ListPolicies API call for deny policies for the passed
    resource.
  )organizationfolderprojectzDpolicies/cloudresourcemanager.googleapis.com%2F{}s%2F{}/denypolicies)parent)nameresource_type)r   r   r'   policiesListPoliciesIamPoliciesListPoliciesRequestGetIamPoliciesGetRequestr9   appendr%   UnknownArgumentException)
resource_idr:   r   r   r   policies_to_returnattachment_pointpolicies_to_fetchpolicy_metadatar1   s
             r   ListDenyPoliciesrG   N   s     ]+&}-(;;]dd{$ 44//# 	0 	%&&.h  -""

(
(o.B.B
(
CEf' -
 22?3@	B Br   )Fr   )__doc__
__future__r   r   r   r+   apitools.base.protorpcliter   r#   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   r
   r%   googlecloudsdk.command_lib.iamr   googlecloudsdk.corer   r(   r   r   r3   rG    r   r   <module>rQ      sD    " &  '  D % , ( C 3 $ 
@ 
>#Br   