
                         r    S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr   " S	 S
\5      rg)z3API library for cloudresourcemanager organizations.    )absolute_import)division)unicode_literals)
exceptions)
list_pager)projects_util)iam_utilc                   H    \ rS rSrSrSS jrSS jrSS jrS rS r	S	 r
S
rg)Client   z8Client class for cloudresourcemanager organizations API.Nc                     U=(       d    [         R                  " 5       U l        U=(       d    U R                  R                  U l        g N)r   	GetClientclientMESSAGES_MODULEmessages)selfr   r   s      @lib/googlecloudsdk/api_lib/cloudresourcemanager/organizations.py__init__Client.__init__   s-    5M335DK; ; ;DM    c           
          U R                   R                  US9n[        R                  " U R                  R
                  USUSUSS9$ )N)filterSearchpageSizeorganizations)methodlimitbatch_size_attribute
batch_sizefield)r   SearchOrganizationsRequestr   YieldFromListr   r   )r   filter_r   	page_sizereqs        r   ListClient.List#   sJ    
--
2
2'
2
BC##!!3' r   c                     U R                   R                  R                  U R                   R                  R	                  US95      $ )zReturns an Organization resource identified by the specified organization id.

Args:
  organization_id: organization id

Returns:
  An instance of Organization
)organizationsId)r   r   Getr   +CloudresourcemanagerOrganizationsGetRequest)r   organization_ids     r   r+   
Client.Get-   sB     ;;$$((##OO+ 	P 	-. .r   c                     SR                  U5      n [        U R                  US95      n[        U5      S:X  a  US   $ g! [        R                   a     gf = f)av  Returns an Organization resource identified by the domain name.

If no organization is returned, or if more than one organization is
returned, this method will return None.

Args:
  domain: A string representing an organizations associated domain.
          e.g. 'example.com'

Returns:
  An instance of Organization or None if a unique organization cannot be
  determined.
z
domain:{0})r$   N   r   )formatlistr'   r   HttpBadRequestErrorlen)r   domaindomain_filter	orgs_lists       r   GetByDomainClient.GetByDomain:   sc     !''/Mtyyy78i 9~q\ )) s   A   AAc                     U R                   R                  U R                   R                  U R                   R                  [        R
                  S9S9US9nU R                  R                  R                  U5      $ )zhReturns IAM policy for a organization.

Args:
  organization_id: organization id

Returns:
  IAM policy
)requestedPolicyVersion)options)getIamPolicyRequestr*   )	r   4CloudresourcemanagerOrganizationsGetIamPolicyRequestGetIamPolicyRequestGetPolicyOptionsr	   !MAX_LIBRARY_IAM_SUPPORTED_VERSIONr   r   GetIamPolicy)r   r-   requests      r   rB   Client.GetIamPolicyR   sw     mmPP MM==MM22'/22 3 4 > 5 ( Q )G ;;$$11'::r   c                    [         R                  " X R                  R                  5      u  p4[         R                  Ul        SU;  a  US-  nSU;  a  US-  nU R                  R                  UUS9nU R                  R                  UUS9nU R                  R                  R                  U5      n[         R                  " US5        U$ )zSets the IAM policy for an organization.

Args:
  organization_id: organization id.
  policy_file: A JSON or YAML file containing the IAM policy.

Returns:
  The output from the SetIamPolicy API call.
bindingsz	,bindingsetagz,etag)policy
updateMask)r*   setIamPolicyRequestorganization)r	   ParsePolicyFileWithUpdateMaskr   PolicyrA   versionSetIamPolicyRequest4CloudresourcemanagerOrganizationsSetIamPolicyRequestr   r   SetIamPolicyLogSetIamPolicy)r   r-   policy_filerH   update_maskset_iam_policy_requestpolicy_requestresults           r   rQ   Client.SetIamPolicyd   s     #@@]]))+F??FN $[ k[ Wk!]]>> ?  
 	JJ+ 6 	K 	8  [[&&33NCF_n=Mr   )r   r   )NN)NNNr   )__name__
__module____qualname____firstlineno____doc__r   r'   r+   r8   rB   rQ   __static_attributes__ r   r   r   r      s#    @<.0;$ r   r   N)r]   
__future__r   r   r   apitools.base.pyr   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   googlecloudsdk.command_lib.iamr	   objectr   r_   r   r   <module>re      s-    : &  ' ' ' E 3hV hr   