
    ;5                         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KJr  SS	KJr  SS
KJr  SSKJr  SS jrSS jrS rS r\R.                  \R0                  " \R2                  R4                  \R2                  R6                  5       " S S\R8                  5      5       5       r\R0                  " \R2                  R<                  5       " S S\5      5       rSSSS.r \ \l         \ \l         g)zB`gcloud access-context-manager perimeters dry-run create` command.    )absolute_import)division)unicode_literals)
exceptions)zones)arg_parsers)base)
perimeters)policies)repeatedc                     U R                  5       nUR                  SR                  U5      SS SS9  UR                  SR                  U5      S[        R                  " 5       S SS9  g )	Nz"--{}enable-vpc-accessible-services
store_truezmWhether to restrict API calls within the perimeter to those in the
              `vpc-allowed-services` list.)actiondefaulthelpz--{}vpc-allowed-servicesvpc_allowed_serviceszComma-separated list of APIs accessible from within the Service
              Perimeter. In order to include all restricted services, use
              reference "RESTRICTED-SERVICES". Requires vpc-accessible-services
              be enabled.metavartyper   r   )add_argument_groupadd_argumentformatr   ArgList)parserprefix	vpc_groups      ?lib/surface/access_context_manager/perimeters/dry_run/create.py,_AddLegacyVpcAccessibleServicesArgsForCreater      sv    ''))*11&9.	    ''/$   	    c                    U R                  SR                  U5      S[        R                  " 5       SSS9  U R                  SR                  U5      S[        R                  " 5       SSS9  U R                  S	R                  U5      S
[        R                  " 5       SSS9  US:w  a
  [	        XS9  ONU R                  5       nUR                  SR                  U5      S[        R                  " U5      SS9  [	        X1S9  U R                  SR                  U5      S[        R                  " U5      SSS9  U R                  SR                  U5      S[        R                  " U5      SSS9  g)zAdds arguments common to the two dry-run create modes.

Args:
  parser: The argparse parser to add the arguments to.
  prefix: Optional prefix, e.g. 'perimeter-' to use for the argument names.
  version: Api version. e.g. v1alpha, v1beta, v1.
z--{}resources	resourcesNzComma-separated list of resources (currently only projects, in the
              form `projects/<projectnumber>`) in this perimeter.r   z--{}restricted-servicesrestricted_serviceszComma-separated list of services to which the perimeter boundary
              *does* apply (for example, `storage.googleapis.com`).z--{}access-levelsaccess_levelszComma-separated list of IDs for access levels (in the same policy)
              that an intra-perimeter request must satisfy to be allowed.v1alpha)r   z--{}vpc-accessible-services!VPC_ACCESSIBLE_SERVICES_YAML_FILEz>Path to a YAML file containing a VpcAccessibleServices object.)r   r   r   z--{}ingress-policies	YAML_FILEa7  Path to a file containing a list of Ingress Policies.
              This file contains a list of YAML-compliant objects representing
              Ingress Policies described in the API reference.
              For more information about the alpha version, see:
              https://cloud.google.com/access-context-manager/docs/reference/rest/v1alpha/accessPolicies.servicePerimeters
              For more information about non-alpha versions, see:
              https://cloud.google.com/access-context-manager/docs/reference/rest/v1/accessPolicies.servicePerimetersz--{}egress-policiesa5  Path to a file containing a list of Egress Policies.
              This file contains a list of YAML-compliant objects representing
              Egress Policies described in the API reference.
              For more information about the alpha version, see:
              https://cloud.google.com/access-context-manager/docs/reference/rest/v1alpha/accessPolicies.servicePerimeters
              For more information about non-alpha versions, see:
              https://cloud.google.com/access-context-manager/docs/reference/rest/v1/accessPolicies.servicePerimeters)
r   r   r   r   r   add_mutually_exclusive_groupr
   ParseVpcAccessibleServicesParseIngressPoliciesParseEgressPolicies)r   r   versionvpc_config_groups       r   _AddCommonArgsForDryRunCreater-   4   s    	V$ E  F 	&&v.# G  H 	  ( M  N 	0G ::< !!%,,V43227;M	 "  1 	##F+**73y   	""6*))'2y  r   c                     SU-   nU R                  U5      (       a  [        XS5      $ U R                  U5      (       a  [        XS5      $ g)a  Returns the argument value for given short_name or None if not specified.

Args:
  args: The argument object obtained by parsing the command-line arguments
    using argparse.
  short_name: The regular name for the argument to be fetched, such as
    `access_levels`.

perimeter_N)IsSpecifiedgetattr)args
short_namealt_names      r   _ParseArgWithShortNamer5      sM     J&(	j!!4T**!!44((	r   c                 8    [        U S5      n[        U S5      nX4$ )Ningress_policiesegress_policies)r5   )r2   r7   r8   s      r   _ParseDirectionalPoliciesr9      s&    +D2DE*41BC/		**r   c                   F    \ rS rSrSrSr\S 5       r\S	S j5       rS r	Sr
g)
CreatePerimeterDryRun   ?Creates a dry-run spec for a new or existing Service Perimeter.v1c                 ,    [         R                  U SS9  g )Nr>   r+   r;   ArgsVersionedr   s    r   ArgsCreatePerimeterDryRun.Args   s    '''=r   c                 H   U R                  SSSS9  [        R                  " U S5        U R                  SS9nUR	                  S5      n[        X1S	9  UR	                  S
5      n[        USUS9  UR                  SSS SS9  UR                  SS SS9  UR                  SSS SS9  g )Nz--asyncr   z^Return immediately, without waiting for the operation in
                progress to complete.)r   r   z	to updateT)requiredzJArguments for creating dry-run spec for an **existing** Service Perimeter.r@   zBArguments for creating a dry-run spec for a new Service Perimeter.z
perimeter-)r   r+   z--perimeter-titlez5Short human-readable title for the Service Perimeter.)rG   r   r   z--perimeter-descriptionz+Long-form description of Service Perimeter.)r   r   z--perimeter-typea  Type of the perimeter.

            A *regular* perimeter allows resources within this service perimeter
            to import and export data amongst themselves. A project may belong
            to at most one regular service perimeter.

            A *bridge* perimeter allows resources in different regular service
            perimeters to import and export data between each other. A project
            may belong to multiple bridge service perimeters (only if it also
            belongs to a regular service perimeter). Both restricted and
            unrestricted service lists, as well as access level lists, must be
            empty.)r   r
   AddResourceArgr'   r   r-   )r   r+   top_level_groupexisting_perimeter_groupnew_perimeter_groups        r   rB   #CreatePerimeterDryRun.ArgsVersioned   s    
)  *
 fk29949HO.AA	  "":L)<<LN!L'C$$H	 % J
 $$!> % @ $$	 % r   c                     [         R                  " U R                  S9nUR                  R                  R                  5       n[        R                  " UR                  U R                  5      n[        US5      n[        US5      n[        R                  " XcR                  5      n[        US5      nS nU R                  S:X  a  [        US5      n[        US5      n	[        U5      u  pUR                  c  UR                  c  S nOUR                  =(       d    UR                  n[        R                   R#                  UR$                  U5      n UR%                  5         UR&                  c  Ub  [(        R*                  " SS	5      e [2        R4                  " X15        UR7                  UUR&                  UR8                  UUUUU	UUS LUU
US9$ ! [,        R.                   a*    UR&                  b  Uc  [(        R0                  " SS
5      e Nf = f)Nr@   r!   r#   r"   r$   vpc_accessible_servicesr   zperimeter-titlez|A Service Perimeter with the given name already exists. The title and the type fields cannot be updated in the dry-run mode.zaSince this Service Perimeter does not exist, perimeter-title and perimeter-type must be supplied.)titledescriptionperimeter_typer!   levelsr"   r   enable_vpc_accessible_servicesvpc_yaml_flag_usedvpc_accessible_services_configr7   r8   )	zones_apiClient_API_VERSIONCONCEPTS	perimeterParser
    GetPerimeterTypeEnumForShortNamerQ   r5   ExpandLevelNamesIfNecessaryaccessPoliciesIdr9   rS   (perimeter_enable_vpc_accessible_servicesr   CachedResultFromFuncGetperimeter_titler   InvalidArgumentExceptionapitools_exceptionsHttpNotFoundErrorRequiredArgumentExceptionr   ValidateAccessPolicyArgPatchDryRunConfigperimeter_description)selfr2   clientperimeter_refrQ   r!   rR   r"   rU   r   r7   r8   rS   results                 r   RunCreatePerimeterDryRun.Run   s    d&7&78FMM++113M@@T..0N 't[9I#D/:F33..0F07LM%)"I% (>
)($ 2$8NO(A$(G%++355='+$ 
-
- 8

7
7 % ""++FJJFFQjjl 
			)^-G112COQ 	Q .H $$]9##""..%/1'E9E'E)' $   00 6				%)?2246 	6 *@6s   G ;HH N)r>   )__name__
__module____qualname____firstlineno____doc__rX   staticmethodrD   rB   ro   __static_attributes__rq   r   r   r;   r;      s9     H,> > ( (T=r   r;   c                   ,    \ rS rSrSrSr\S 5       rSrg)CreatePerimeterDryRunAlphai  r=   r$   c                 ,    [         R                  U SS9  g )Nr$   r@   rA   rC   s    r   rD   CreatePerimeterDryRunAlpha.Args  s    ''	'Br   rq   N)	rr   rs   rt   ru   rv   rX   rw   rD   rx   rq   r   r   rz   rz     s    G,C Cr   rz   zTCreate a dry-run mode configuration for a new or existing Service
        Perimeter.a  When a Service Perimeter with the specified name does not exist, a new Service Perimeter will be created. In this case, the newly created Service Perimeter will not have any enforcement mode configuration, and, therefore, all policy violations will be logged.

When a perimeter with the specified name does exist, a dry-run mode configuration will be created for it. The behavior of the enforcement mode configuration, if present, will not be impacted in this case. Requests that violate the existing enforcement mode configuration of the Service Perimeter will continue being denied. Requests that only violate the policy in the dry-run mode configuration will be logged but will not be denied.aj  To create a dry-run configuration for an existing Service Perimeter:

  $ {command} my-perimeter --resources="projects/0123456789" --access-levels="accessPolicies/a_policy/accessLevels/a_level" --restricted-services="storage.googleapis.com"

To create a dry-run configuration for a new Service Perimeter:

  $ {command} my-perimeter --perimeter-title="My New Perimeter" --perimeter-description="Perimeter description" --perimeter-type="regular" --perimeter-resources="projects/0123456789" --perimeter-access-levels="accessPolicies/a_policy/accessLevels/a_level" --perimeter-restricted-services="storage.googleapis.com")briefDESCRIPTIONEXAMPLESN) )r   r>   )!rv   
__future__r   r   r   apitools.base.pyr   re   +googlecloudsdk.api_lib.accesscontextmanagerr   rV   googlecloudsdk.callioper   r	   /googlecloudsdk.command_lib.accesscontextmanagerr
   r   $googlecloudsdk.command_lib.util.argsr   r   r-   r5   r9   UniverseCompatibleReleaseTracksReleaseTrackBETAGAUpdateCommandr;   ALPHArz   detailed_helprq   r   r   <module>r      s    I &  ' > J / ( . F D 9*IX"+ D%%**D,=,=,@,@ApD.. p B pf D%%++,C!6 C -C	
	?	D#> ,9  (&3  #r   