
                             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	\R                  5      rS
 rS rS rS rg)z%Base class for Organization commands.    )absolute_import)division)unicode_literals)organizations)
exceptions)	resourcesc                   ,   ^  \ rS rSrSU 4S jjrSrU =r$ )UnknownOrganizationError   c                 N   > SR                  U5      n[        [        U ]  X#5        g )NzjCannot determine Organization ID from [{0}]. Try `gcloud organizations list` to find your Organization ID.)formatsuperr
   __init__)selforg_argumentmetavarmessage	__class__s       9lib/googlecloudsdk/command_lib/organizations/org_utils.pyr   !UnknownOrganizationError.__init__   s*    O|$  

"D27D     )ORGANIZATION_ID)__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r
   r
      s    E Er   r
   c                 R    SnU R                  U5      (       a  U [        U5      S  $ U $ )Nzorganizations/)
startswithlen)org_idprefixs     r   StripOrgPrefixr%   $   s.    &v#f+,Mr   c                     [         R                  R                  5       nUR                  SS5        [	        U R
                  5      nUR                  SSU0SS9nUR                  5       $ )z0Get the Organization URI for the given resource.cloudresourcemanagerv1NorganizationsIdz"cloudresourcemanager.organizations)params
collection)r   REGISTRYCloneRegisterApiByNamer%   nameParseSelfLink)resourceregistryr#   org_refs       r   OrganizationsUriFuncr5   ,   sk    %%'(
3T:(--(&NN

V 6  7' 
			r   c                     [         R                  " 5       n[        U 5      nUR                  5       (       a  UR	                  U5      $ UR                  U5      $ )a  Get the Organization object for the provided Organization argument.

Returns the organization object for a given organization ID or will search
for and return the organization object associated with the given domain name.

Args:
  org_argument: The value of the organization argument.

Returns:
  An object representing an organization, or None if the organization could
  not be determined.
)r   Clientr%   isdigitGetGetByDomain)r   orgs_clientr#   s      r   GetOrganizationr<   :   sI     $$&+,'&^^??6""""6**r   c                     [         R                  " 5       n[        U 5      nUR                  5       (       a  U$ UR	                  U5      nU(       a  [        UR
                  5      $ g)a  Get the Organization ID for the provided Organization argument.

Numeric values will be returned, values like 'organizations/123456789' will
return '123456789' and a value like 'example.com' will search for the
organization ID associated with that domain.

Args:
  org_argument: The value of the organization argument.

Returns:
  A string containing the numeric organization ID, or None if the
  organization ID could not be determined.
N)r   r7   r%   r8   r:   r/   )r   r;   r#   
org_objects       r   GetOrganizationIdr?   P   sS     $$&+,'&^^M((0JJOO,,r   N)__doc__
__future__r   r   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   googlecloudsdk.callioper   googlecloudsdk.corer   BadArgumentExceptionr
   r%   r5   r<   r?   r   r   r   <module>rF      sD     , &  ' E . )Ez>> E+,r   