
    `8                         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rS r   SS jr " S S\5      rg
)z8API library for VPC Service Controls Service Perimeters.    )absolute_import)division)unicode_literals)
list_pager)util)waiter)log)	resourcesNc                 F    Ub  [        X U5        UR                  U 5        gg)a  Sets specified field to the provided value and adds it to update mask.

Args:
  field_name: The name of the field to set the value of.
  field_value: The value to set the field to. If it is None, the field will
    NOT be set.
  obj: The object on which the value is to be set.
  update_mask: The update mask to add this field to.

Returns:
  True if the field was set and False otherwise.
TF)setattrappend)
field_namefield_valueobjupdate_masks       8lib/googlecloudsdk/api_lib/accesscontextmanager/zones.py_SetIfNotNoner      s(     C[)z"	    c                    U R                  5       n/ n[        SX+U5        [        SX;U5        [        SXU5        [        SXU5        Ubr  UR                  S5        / nU HY  n[        U[        R
                  5      (       a  UR                  U5        OUR                  UR                  5       5        Xl        M[     U(       a  UR                  S5        Xl        O^Uc  UbX  U R                  5       n/ n[        SX_U5        [        S	UUU5        Xl        UR                  U Vs/ s H  nS
U-   PM
     sn5        U(       d  S/ 4$ X Vs/ s H  nSR                  UU5      PM     sn4$ s  snf s  snf )z5Returns a ServicePerimeterConfig and its update mask.r
   restrictedServicesingressPoliciesegressPoliciesNaccessLevelsvpcAccessibleServicesallowedServicesenableRestrictionzvpcAccessibleServices.z{}.{})ServicePerimeterConfigr   r   
isinstancesixstring_typesRelativeNamer   r   VpcAccessibleServicesextendformat)messagesmask_prefixr
   restricted_serviceslevelsvpc_allowed_servicesenable_vpc_accessible_servicesvpc_yaml_flag_usedvpc_accessible_services_configingress_policiesegress_policiesconfigmasklevel_nameslservice_filterservice_filter_maskmitems                      r   _CreateServicePerimeterConfigr7   2   so    **,&	$Y5$&94H!#3TB /4@KKK	As''	(	(1 	1>>+,'  KK'(#A $0		)335N#%9%'%'E "57#1 KK7JK7J!)A-7JKL	8O	E'..d3E	EE L
 Fs   #E(E-c                       \ rS rSrSrSS jrS rSS jrS rS r	             SS	 jr
             SS
 jrS rS rSrg)Clienth   zBHigh-level API client for VPC Service Controls Service Perimeters.Nc                     U=(       d    [         R                  " US9U l        U=(       d    U R                  R                  U l        g )N)version)r   	GetClientclientMESSAGES_MODULEr%   )selfr>   r%   r<   s       r   __init__Client.__init__k   s-    ;DNN7;DK; ; ;DMr   c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ )N)name)r>    accessPolicies_servicePerimetersGetr%   =AccesscontextmanagerAccessPoliciesServicePerimetersGetRequestr!   )r@   zone_refs     r   rF   
Client.Geto   sC    ;;77;;	F	F&&( 
G 
*+ +r   c           	          U R                   R                  UR                  5       S9n[        R                  " U R
                  R                  UUSS SS9$ )N)parentpageSizeservicePerimeters)limitbatch_size_attribute
batch_sizefield)r%   >AccesscontextmanagerAccessPoliciesServicePerimetersListRequestr!   r   YieldFromListr>   rE   )r@   
policy_refrN   reqs       r   ListClient.Listu   sW    
--
V
V&&( W *C##44'!# #r   c                    U R                   R                  US9nU R                   R                  UR                  5       US9nU R                  R
                  R                  U5      n[        R                  " U R                  R                  5      n[        R                  R                  UR                  SS9n[        R                  " XgSR                  UR!                  5       5      5      $ )N)etag)rK   commitServicePerimetersRequestaccesscontextmanager.operations
collectionz!Waiting for COMMIT operation [{}])r%   CommitServicePerimetersRequest@AccesscontextmanagerAccessPoliciesServicePerimetersCommitRequestr!   r>   rE   Commitr   CloudOperationPollerNoResources
operationscore_resourcesREGISTRYParserD   WaitForr$   Name)r@   rT   rY   
commit_reqrU   	operationpolleroperation_refs           r   r`   Client.Commit   s    ==4=HJ
--
X
X&&('1 Y 3C <<CCCHI33DKK4J4JKF"++11#D 2 FM>>+22=3E3E3GHJ Jr   c                    U R                   n[        U5      nUR                  nU" UUR                  5       SR	                  U5      S9nU R
                  R                  R                  U5      n[        R                  " U R
                  R                  U R
                  R                  U5      n[        R                  R                  UR                  SS9n	[        R                   " XSR#                  U	R%                  5       5      5      $ )z2Applies a PATCH to the provided Service Perimeter.,)servicePerimeterrD   
updateMaskr[   r\   z Waiting for PATCH operation [{}])r%   sorted?AccesscontextmanagerAccessPoliciesServicePerimetersPatchRequestr!   joinr>   rE   Patchr   OperationPollerrb   rc   rd   re   rD   r   rf   r$   rg   )
r@   perimeter_ref	perimeterr   r5   request_typerequestri   rj   rk   s
             r   _ApplyPatchClient._ApplyPatch   s    A%K	II "'')88K(G
 <<BB7KI!!$++"N"N"&++"8"8-IF"++11#D 2 FM>>*11-2D2D2FGI Ir   c                 n   U R                   nUR                  5       n/ n[        SUUU5        [        SUUU5        [        SUUU5        [        SUUU5        [        USUUUUU	U
UUUS9u  nnUUl        UR                  U5        U(       d  [        R                  " S5        U$ U R                  UUU5      $ )a  Patch a service perimeter.

Args:
  perimeter_ref: resources.Resource, reference to the perimeter to patch
  description: str, description of the zone or None if not updating
  title: str, title of the zone or None if not updating
  perimeter_type: PerimeterTypeValueValuesEnum type enum value for the level
    or None if not updating
  resources: list of str, the names of resources (for now, just
    'projects/...') in the zone or None if not updating.
  restricted_services: list of str, the names of services
    ('example.googleapis.com') that *are* restricted by the access zone or
    None if not updating.
  levels: list of Resource, the access levels (in the same policy) that must
    be satisfied for calls into this zone or None if not updating.
  vpc_allowed_services: list of str, the names of services
    ('example.googleapis.com') that *are* allowed to be made within the
    access zone, or None if not updating.
  enable_vpc_accessible_services: bool, whether to restrict the set of APIs
    callable within the access zone, or None if not updating.
  vpc_yaml_flag_used: bool, whether the vpc yaml flag was used.
  vpc_accessible_services_config: VpcAccessibleServices, or None if not
    updating.
  ingress_policies: list of IngressPolicy, or None if not updating.
  egress_policies: list of EgressPolicy, or None if not updating.
  etag: str, the optional etag for the version of the Perimeter that
    this operation is to be performed on.

Returns:
  ServicePerimeter, the updated Service Perimeter.
titledescriptionperimeterTyperY   statusr%   r&   r
   r'   r(   r)   r*   r+   r,   r-   r.   zHThe update specified results in an identical resource. Skipping request.)	r%   ServicePerimeterr   r7   r   r#   r	   warningrz   r@   rv   r~   r}   perimeter_typer
   r'   r(   r)   r*   r+   r,   r-   r.   rY   r5   rw   r   r/   config_mask_additionss                       r   rt   Client.Patch   s    ` 	A""$IK'5)[9-iE/>9kJ&$	;7$A/1'E-'E)'%)!F! I,- 	kk
T M9kBBr   c                    U R                   nUR                  5       n/ n[        SUUU5      (       a&  UR                  5       Ul        UR                  S5        [        SUUU5        [        SUUU5        [        SUUU5        [        USUUUUU	U
UUUS9u  nnUUl        UR                  U5        SUl	        UR                  S	5        U R                  UUU5      $ )
a  Patch the dry-run config (spec) for a Service Perimeter.

Args:
  perimeter_ref: resources.Resource, reference to the perimeter to patch
  description: str, description of the zone or None if not updating
  title: str, title of the zone or None if not updating
  perimeter_type: PerimeterTypeValueValuesEnum type enum value for the level
    or None if not updating
  resources: list of str, the names of resources (for now, just
    'projects/...') in the zone or None if not updating.
  restricted_services: list of str, the names of services
    ('example.googleapis.com') that *are* restricted by the access zone or
    None if not updating.
  levels: list of Resource, the access levels (in the same policy) that must
    be satisfied for calls into this zone or None if not updating.
  vpc_allowed_services: list of str, the names of services
    ('example.googleapis.com') that *are* allowed to be made within the
    access zone, or None if not updating.
  enable_vpc_accessible_services: bool, whether to restrict the set of APIs
    callable within the access zone, or None if not updating.
  vpc_yaml_flag_used: bool, whether the vpc yaml flag was used.
  vpc_accessible_services_config: VpcAccessibleServices, or None if not
    updating.
  ingress_policies: list of IngressPolicy, or None if not updating.
  egress_policies: list of EgressPolicy, or None if not updating.
  etag: str, the optional etag for the version of the Perimeter that
    this operation is to be performed on.

Returns:
  ServicePerimeter, the updated Service Perimeter.
r}   rD   r~   r   rY   specr   TuseExplicitDryRunSpec)r%   r   r   r!   rD   r   r7   r   r#   r   rz   r   s                       r   PatchDryRunConfigClient.PatchDryRunConfig   s    ` 	A""$IKWeY<<$113in -iE/>9kJ&$	;7$A/1'E-'E)'%)!F! IN,-&*I#./M9kBBr   c                     U R                  U5      nU R                  nUR                  5       n/ SQnUR                  Ul        SUl        SUl        U R                  XU5      $ )zPromotes a Service Perimeter's dry-run config to enforcement config.

Args:
  perimeter_ref: resources.Resource, reference to the perimeter to patch

Returns:
  ServicePerimeter, the updated Service Perimeter.
)r   r   r   NF)rF   r%   r   r   r   r   rz   )r@   rv   original_perimeterr5   rw   r   s         r   EnforceDryRunConfigClient.EnforceDryRunConfig@  s_     -0A""$I=K)..IIN&+I#MkBBr   c                 |    U R                   R                  5       nX#l        SUl        SS/nU R	                  XU5      $ )a  Unsets the spec for a Service Perimeter.

Args:
  perimeter_ref: resources.Resource, reference to the perimeter to patch.
  use_explicit_dry_run_spec: The value to use for the perimeter field of the
    same name.

Returns:
  ServicePerimeter, the updated Service Perimeter.
Nr   r   )r%   r   r   r   rz   )r@   rv   use_explicit_dry_run_specrw   r   s        r   	UnsetSpecClient.UnsetSpecR  sA     ..0I&?#IN23KMkBBr   )r>   r%   )NNv1)N)NNNNNNNNFNNNN)__name__
__module____qualname____firstlineno____doc__rA   rF   rV   r`   rz   rt   r   r   r   __static_attributes__ r   r   r9   r9   h   s    J<+	#JI. %)%)OCh %)%)LC\C$Cr   r9   )NNN)r   
__future__r   r   r   apitools.base.pyr   +googlecloudsdk.api_lib.accesscontextmanagerr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer	   r
   rc   r   r   r7   objectr9   r   r   r   <module>r      sP    ? &  ' ( < . # ; 
8 BF37263FlyCV yCr   