
    7                     x    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rS r   SS	 jr " S
 S\5      rg)z8API library for VPC Service Controls Service Perimeters.    )
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   _CreateServicePerimeterConfigr4   /   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)Cliente   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"   r9   s       r   __init__Client.__init__h   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   rC   
Client.Getl   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;   rB   )r=   
policy_refrK   reqs       r   ListClient.Listr   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)rH   commitServicePerimetersRequestaccesscontextmanager.operations
collectionz!Waiting for COMMIT operation [{}])r"   CommitServicePerimetersRequest@AccesscontextmanagerAccessPoliciesServicePerimetersCommitRequestr   r;   rB   Commitr   CloudOperationPollerNoResources
operationscore_resourcesREGISTRYParserA   WaitForr!   Name)r=   rQ   rV   
commit_reqrR   	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.,)servicePerimeterrA   
updateMaskrX   rY   z Waiting for PATCH operation [{}])r"   sorted?AccesscontextmanagerAccessPoliciesServicePerimetersPatchRequestr   joinr;   rB   Patchr   OperationPollerr_   r`   ra   rb   rA   r   rc   r!   rd   )
r=   perimeter_ref	perimeterr   r2   request_typerequestrf   rg   rh   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perimeterTyperV   statusr"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   zHThe update specified results in an identical resource. Skipping request.)	r"   ServicePerimeterr   r4   r}   r    r   warningrw   r=   rs   r{   rz   perimeter_typer   r$   r%   r&   r'   r(   r)   r*   r+   rV   r2   rt   r   r,   config_mask_additionss                       r   rq   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.
rz   rA   r{   r|   rV   specr~   TuseExplicitDryRunSpec)r"   r   r   r   rA   r
   r4   r   r    r   rw   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)rC   r"   r   r   r}   r   rw   )r=   rs   original_perimeterr2   rt   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   rw   )r=   rs   use_explicit_dry_run_specrt   r   s        r   	UnsetSpecClient.UnsetSpecO  sA     ..0I&?#IN23KMkBBr   )r;   r"   )NNv1)N)NNNNNNNNFNNNN)__name__
__module____qualname____firstlineno____doc__r>   rC   rS   r]   rw   rq   r   r   r   __static_attributes__ r   r   r6   r6   e   s    J<+	#JI. %)%)OCh %)%)LC\C$Cr   r6   )NNN)r   apitools.base.pyr   +googlecloudsdk.api_lib.accesscontextmanagerr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r`   r   r   r4   objectr6   r   r   r   <module>r      sG    ? ( < . # ; 
8 BF37263FlyCV yCr   