
    )                        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 d Zd Zd Zd Ze
j(                   e
j*                  e
j,                  j.                  e
j,                  j0                         G d de
j2                                      Z e
j*                  e
j,                  j6                         G d de             ZddddZee_        ee_        y)zB`gcloud access-context-manager perimeters dry-run update` command.    )absolute_import)division)unicode_literals)util)zones)base)
perimeters)policies)repeatedc                 J    | j                   r| j                  S | j                  S )z8Returns the base config to use for the update operation.)useExplicitDryRunSpecspecstatus)	perimeters    ?lib/surface/access_context_manager/perimeters/dry_run/update.py_GetBaseConfigr      s!    $$>>			    c                 H    t        j                  | |fd      }|s|s}|S )zAReturns the repeated field value to use for the update operation.c                       xs g S N )base_config_values   r   <lambda>z(_GetRepeatedFieldValue.<locals>.<lambda>'   s    7H7NB7Nr   )r   ParsePrimitiveArgs)args
field_namer   has_specrepeated_fields     `  r   _GetRepeatedFieldValuer   $   s-    ..tZ/NP. 
.&N	r   c                 b    g d}|D cg c]  }|| z   	 }}t        fd|D              S c c}w )N)remove_add_clear_c              3   @   K   | ]  }j                  |        y wr   )IsSpecified).0argr   s     r   	<genexpr>z$_IsFieldSpecified.<locals>.<genexpr>8   s     8isTc"is   )any)r   r   list_command_prefixescommand	list_argss    `   r   _IsFieldSpecifiedr-   4   s;    73HI3Hw#3H)I	8i8	88 Js   ,c                 >    t        j                  | |      }|s||}|S )zGReturns the ingress/egress field value to use for the update operation.)r	   "ParseUpdateDirectionalPoliciesArgs)r   r   r   r   ingress_egress_fields        r   _GetIngressEgressFieldValuer1   ;   s1    #FF
J
 
*2, 
r   c                   <    e Zd ZdZdZed        Zedd       Zd Zy)UpdatePerimeterDryRun?Updates the dry-run mode configuration for a Service Perimeter.v1c                 2    t         j                  | d       y )Nr5   versionr3   ArgsVersionedparsers    r   ArgszUpdatePerimeterDryRun.ArgsR   s    '''=r   c                     t        j                  | d       t        j                  | |       t        j                  |        t	        j
                  | dddd       t	        j
                  | dddd       t	        j
                  | dd	d
d       |dk7  r@| j                  d      }|j                  ddd       t	        j
                  |dddd       nt        j                  | |       | j                  ddd       y )Nz	to updatezService Perimeter	resources	ResourcesF)include_setzrestricted-serviceszRestricted Serviceszaccess-levelszAccess Levelv1alphaz>Arguments for configuring VPC accessible service restrictions.z --enable-vpc-accessible-services
store_truezWhen specified restrict API calls within the Service Perimeter to the
          set of vpc allowed services. To disable use
          '--no-enable-vpc-accessible-services'.)actionhelpvpc-allowed-serviceszVPC Allowed Servicesz--asyncz^Return immediately, without waiting for the operation in
                progress to complete.)	r	   AddResourceArg%AddUpdateDirectionalPoliciesGroupArgs
AddEtagArgr   AddPrimitiveArgsadd_argument_groupadd_argument'AddUpdateVpcAccessibleServicesGroupArgs)r<   r8   	vpc_groups      r   r:   z#UpdatePerimeterDryRun.ArgsVersionedV   s   fk244VWE&!   )++
JLi
,4  5 


 
  88
' )  *r   c                    t        j                  | j                        }t        j                  | j                        }|j
                  j                  j                         }t        j                  ||       |j                  |      }t        |      }t        d|      r#t        |d|j                  |j                        }n|j                  }t        d|      r#t        |d|j                   |j                        }n|j                   }t        d|      r#t        |d|j"                  |j                        }	n|j"                  }	|j$                  }
|
|j'                         }
t        d|      r#t        |d|
j(                  |j                        }n|j$                  |
j(                  }nd }|j+                  d      r|j,                  }n|j$                  |
j.                  }nd }d }d}| j                  d	k(  rt1        j2                  |d
      \  }}|d }n|sg }t5        |d|j6                  |j                        }t5        |d|j8                  |j                        }|j;                  |||	||||||||j<                        S )Nr7   r?   restricted_servicesaccess_levelsvpc_allowed_servicesrF   enable_vpc_accessible_servicesFrB   zvpc-accessible-serviceszingress-policieszegress-policies)
r?   levelsrP   rR   rS   vpc_yaml_flag_usedvpc_accessible_services_configingress_policiesegress_policiesetag)	zones_apiClient_API_VERSIONr   GetMessagesCONCEPTSr   Parser
   ValidateAccessPolicyArgGetr   r-   r   r?   r   restrictedServicesaccessLevelsvpcAccessibleServicesVpcAccessibleServicesallowedServicesr%   rS   enableRestrictionr	   $ParseUpdateVpcAccessibleServicesArgsr1   ingressPoliciesegressPoliciesPatchDryRunConfigrY   )selfr   clientmessagesperimeter_reforiginal_perimeterbase_configupdated_resourcesupdated_restricted_servicesupdated_access_levelsbase_vpc_configupdated_vpc_servicesupdated_vpc_enabledrV   rU   updated_ingressupdated_egresss                    r   RunzUpdatePerimeterDryRun.Run   s   d&7&78F(9(9:HMM++113M$$]D9M2 !34Kd+0
[22

2
24 &//.5$:
%{'E'E

2
2%4! %0$B$B!$/4
!9!9

2
24 *66!77O 668o/63
&(G(G

2
24 
	*	*	6,<<!89 ??		*	*	6+== %)"I%

9
9- 9$&8 "! 1##00	O 1""00	N ###$71':-'E(&YY $  r   N)r5   )	__name__
__module____qualname____doc__r\   staticmethodr=   r:   rz   r   r   r   r3   r3   L   s:     H,> > -* -*^Sr   r3   c                   $    e Zd ZdZdZed        Zy)UpdatePerimeterDryRunAlphar4   rB   c                 2    t         j                  | d       y )NrB   r7   r9   r;   s    r   r=   zUpdatePerimeterDryRunAlpha.Args   s    ''	'Br   N)r{   r|   r}   r~   r\   r   r=   r   r   r   r   r      s    G,C Cr   r   z>Update the dry-run mode configuration for a Service Perimeter.a`  This command updates the dry-run mode configuration (`spec`) for a Service Perimeter.

For Service Perimeters with an explicitly defined dry-run mode configuration (i.e. an explicit `spec`), this operation updates that configuration directly, ignoring enforcement mode configuration.

Service Perimeters that do not have explict dry-run mode configuration will inherit the enforcement mode configuration in the dry-run mode. Therefore, this command effectively clones the enforcement mode configuration, then applies the update on that configuration, and uses that as the explicit dry-run mode configuration.a;  To update the dry-run mode configuration for a Service Perimeter:

  $ {command} my-perimeter --add-resources="projects/123,projects/456" --remove-restricted-services="storage.googleapis.com" --add-access-levels="accessPolicies/123/accessLevels/a_level" --enable-vpc-accessible-services --clear-vpc-allowed-services)briefDESCRIPTIONEXAMPLESN)r~   
__future__r   r   r   +googlecloudsdk.api_lib.accesscontextmanagerr   r   rZ   googlecloudsdk.callioper   /googlecloudsdk.command_lib.accesscontextmanagerr	   r
   $googlecloudsdk.command_lib.util.argsr   r   r   r-   r1   UniverseCompatibleReleaseTracksReleaseTrackBETAGAUpdateCommandr3   ALPHAr   detailed_helpr   r   r   <module>r      s    I &  ' < J ( F D 9 9" D%%**D,=,=,@,@AKD.. K B K\ D%%++,C!6 C -C 	I	
'
(0 ,9  (&3  #r   