
                         f   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ej(                   ej*                  ej,                  j.                  ej,                  j0                         G d dej2                                      Zddie_        y)z4Command for creating organization security policies.    )absolute_import)division)unicode_literalsN)base_classes)client)base)
exceptions)flags)security_policies_utils)filesc                   0    e Zd ZdZdZed        Zd Zd Zy)CreatezCreate a Compute Engine organization security policy.

  *{command}* is used to create organization security policies. An organization
  security policy is a set of rules that controls access to various resources.
  Nc                     t        j                  |       |j                  j                  t         j                         y )N)r
   AddArgSpCreationdisplay_infoAddCacheUpdaterOrgSecurityPoliciesCompleter)clsparsers     3lib/surface/compute/org_security_policies/create.pyArgszCreate.Args,   s*    	6"
''(J(JK    c                    t        j                  | j                               }t        j                  |j                  |j
                  t        j                  | j                               j                               }|j                  d      rd|j                  z   }n |j                  d      rd|j                  z   }|j                  d      r'| j                  ||j                  j                        }n|j                  d      r~|j                  dk(  ro|j                  j                  j                  |j                   |j"                  |j                  j                  j                  j$                  j&                  	      }nn|j                  j                  j                  |j                   |j(                  |j                  j                  j                  j$                  j*                  
      }|j-                  |d      S )N)compute_client	resourcesversionorganizationzorganizations/folderzfolders/	file_nametypeCLOUD_ARMOR)description	shortNamer    )r"   displayNamer    F)security_policy	parent_idonly_generate_request)r   ComputeApiHolderReleaseTrackr   OrgSecurityPolicyr   six	text_typelowerIsSpecifiedr   r   _GetTemplateFromFilemessagesr    SecurityPolicyr"   
short_nameTypeValueValuesEnumr!   display_nameFIREWALLr   )selfargsholderorg_security_policyr&   r%   s         r   Runz
Create.Run1   s   **4+<+<+>?F 22}}""d//1288:<
 '"T%6%66i			(	#t{{*i$11$8N8NOo			&	!dii=&@ --00??((oo&&55IIUU	 @ 
 !--00??(())&&55IIRR	 @ 
 %%'# & % %r   c                    t         j                  j                  |j                        s.t	        j
                  dj                  |j                              t         j                  j                  |j                        r.t	        j
                  dj                  |j                              	 t        j                  |j                        5 }|j                  dk(  r t        j                  ||d      cd d d        S t        j                  ||d      cd d d        S # 1 sw Y   y xY w# t        $ rV}t        |dt        j                   |            }dj                  |j                  |      }t	        j
                  |      d }~ww xY w)NzNo such file [{0}]z[{0}] is a directoryjsonyamlmessagezMUnable to read security policy config from specified file [{0}] because [{1}])ospathexistsr   r	   BadFileExceptionformatisdirr   
FileReaderfile_formatr   SecurityPolicyFromFile	Exceptiongetattrr+   r,   )r6   r7   r0   import_fileexpexp_msgmsgs          r   r/   zCreate._GetTemplateFromFileV   s2   77>>$..)''

%
%dnn
5  
ww}}T^^$''
 
'
'
7 -DNN+{v%(??8V ,+
 '==6
 ,++  -Yc(:;g  &t~~w ? 
 '',,-sC   0D+ &D5	D+ ?D	D+ D($D+ (D+ +	F
4AFF
)	__name__
__module____qualname____doc__ORG_SECURITY_POLICY_ARGclassmethodr   r:   r/    r   r   r   r   !   s.     !L L#%J-r   r   EXAMPLESaG      To create an organization security policy under folder with ID ``123456789'',
    run:

      $ {command} --short-name=my-policy --folder=123456789

    To create an organization security under organization with ID ``12345'' from
    an input file, run:

      $ {command} --file-name=my-file-name --organization=12345
    )rQ   
__future__r   r   r   r?   googlecloudsdk.api_lib.computer   4googlecloudsdk.api_lib.compute.org_security_policiesr   googlecloudsdk.callioper   r	   8googlecloudsdk.command_lib.compute.org_security_policiesr
   4googlecloudsdk.command_lib.compute.security_policiesr   googlecloudsdk.core.utilr   r+   UniverseCompatibleReleaseTracksr)   ALPHABETACreateCommandr   detailed_helprT   r   r   <module>rc      s    ; &  ' 	 7 G ( . J X * 
 D%%++T->->-C-CDK-T K- E K-^  
 r   