
    V                         d 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mZ dd
lmZ ej                   Z G d dej"                        Z G d de      Zd Zd Zd Zd Zd Zd Zy)z<Command line processing utilities for authorized orgs descs.    )absolute_import)division)unicode_literals)concepts)policies)repeated)concept_parsers)
exceptions)	resourcesc                        e Zd Z fdZ xZS )
ParseErrorc                 L    t         t        |   dj                  ||             y )NzIssue parsing file [{}]: {})superr   __init__format)selfpathreason	__class__s      Flib/googlecloudsdk/command_lib/accesscontextmanager/authorized_orgs.pyr   zParseError.__init__!   s#    	*
6==dFKL    __name__
__module____qualname__r   __classcell__r   s   @r   r   r      s    M Mr   r   c                        e Zd Z fdZ xZS )InvalidFormatErrorc           	          |j                         D cg c]  }|j                   }}t        t        |   |dj                  |dj                  |                   y c c}w )Na  Invalid format: {}

An authorized orgs desc file is a YAML-formatted list of authorized orgs descs, which are YAML objects with the fields [{}]. For example:

- name: my_authorized_orgs
  authorizationType: AUTHORIZATION_TYPE_TRUST.
  assetType: ASSET_TYPE_DEVICE.
  authorizationDirection: AUTHORIZATION_DIRECTION_TO.
  orgs:
  - organizations/123456789
  - organizations/234567890
, )
all_fieldsnamer   r   r   r   join)r   r   r   message_classfvalid_fieldsr   s         r   r   zInvalidFormatError.__init__(   s_    $1$<$<$>?$>qAFF$>L?	
d,T
	( *004		,0G*IJ @s   Ar   r   s   @r   r   r   &   s    J Jr   r   c                     t               }|D ]2  }|j                         s|j                  |j                                4 |r7t        | dj	                  dj                  |            t        |d               y )NzUnrecognized fields: [{}]r!   r   )setall_unrecognized_fieldsupdater   r   r$   type)r   
conditionsunrecognized_fields	conditions       r   _ValidateAllFieldsRecognizedr0   9   su    i((*  !B!B!DE  
#**4995H+IJZ]  r   c                  0    t        j                  dd      S )Nauthorized_orgs_descz#The ID of the authorized orgs desc.)r#   	help_text)r    ResourceParameterAttributeConfig r   r   _GetAttributeConfigr6   E   s    		2	2!5
7 7r   c                  h    t        j                  ddt        j                         t	                     S )Nz7accesscontextmanager.accessPolicies.authorizedOrgsDescsr2   )resource_nameaccessPoliciesIdauthorizedOrgsDescsId)r   ResourceSpecr   GetAttributeConfigr6   r5   r   r   _GetResourceSpecr=   K   s-    			?*224/1	
3 3r   c                     t         j                  j                  dt               dj	                  |      d      j                  |        y)zAdd a resource argument for an authorized orgs desc.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  r2   zThe authorized orgs desc {}.T)requiredN)r	   ConceptParserForResourcer=   r   AddToParser)parserverbs     r   AddResourceArgrE   S   sC     ++$++D1	 ,  ![(r   c                 8    t        j                  | dddd       y )Nr2   orgszNOrgs must be organizations, in the form `organizations/<organizationsnumber>`.)additional_help)r   AddPrimitiveArgs)rC   s    r   AddAuthorizedOrgsDescUpdateArgsrJ   c   s#    
@Br   c                 8    t        j                  | dfd      S )NrG   c                  8     j                         j                  S )N)GetrG   )authorized_orgs_desc_results   r   <lambda>zParseOrgs.<locals>.<lambda>o   s    7;;=BBr   )r   ParsePrimitiveArgs)argsrN   s    `r   	ParseOrgsrR   m   s     		$	$
FB
D Dr   N)__doc__
__future__r   r   r    googlecloudsdk.calliope.conceptsr   /googlecloudsdk.command_lib.accesscontextmanagerr   $googlecloudsdk.command_lib.util.argsr   (googlecloudsdk.command_lib.util.conceptsr	   googlecloudsdk.corer
   r   REGISTRYErrorr   r   r0   r6   r=   rE   rJ   rR   r5   r   r   <module>r\      ss    C &  ' 5 D 9 D * )M!! MJ J&	73) BDr   