
    A                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJr   " S S\R                  5      r	 " S	 S
\	5      r
S rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rg)z*Utilities for `gcloud network-management`.    )absolute_import)division)unicode_literalsN)
exceptionsc                       \ rS rSrSrSrg)NetworkManagementError   z6Top-level exception for all Network Management errors. N__name__
__module____qualname____firstlineno____doc____static_attributes__r
       9lib/googlecloudsdk/command_lib/network_management/util.pyr   r      s    >r   r   c                       \ rS rSrSrSrg)InvalidInputError   zException for invalid input.r
   Nr   r
   r   r   r   r      s    $r   r   c                    S/n[        U 5      S:  a  UR                  S5        [        U 5       H  u  p4UR                  SR                  XS95        US:X  a"  [        U 5      S:X  a  UR                  S5        MK  U[        U 5      S-
  :X  a  UR                  S	5        Mp  U[        U 5      S-
  :  d  M  UR                  S
5        M     UR                  S5        SR	                  U5      $ )zOCreates a message to specify at least one endpoint, separated by commas and or.zInvalid Connectivity Test.    zAt least one of z--{endpoint_type}-{endpoint})endpoint_typeendpointr      z or z, or z, z must be specified. )lenappend	enumerateformatjoin)	endpointsr   	error_msgindexr   s        r   "GetClearSingleEndpointAttrErrorMsgr%   !   s    ,-)^a'("9-oe&--' 	. 	

 zc)n)v	#i.1$	$w	Y!#	#t . ()		r   c                 0    U=R                   S-  sl         U$ )zXAdd locations/global to parent path, since it isn't automatically populated by apitools./locations/global)parent
unused_refunused_argsrequests      r   AppendLocationsGlobalToParentr-   8   s    	..''.	.r   c                 0    U=R                   S-  sl         U$ )Nr'   )namer)   s      r   "UpdateOperationRequestNameVariabler0   >   s    	,,%%,	.r   c                 `    UR                   nU(       d  Xl         U$ X;  a  US-   U -   Ul         U$ )z"Adds name of field to update mask.,)
updateMask)fieldpatch_requestupdate_masks      r   AddFieldToUpdateMaskr7   C   s>    ((+	$ 
 *S058M	r   c                 H    1 SknX;   a  [        XS 5        g [        XS5        g )N>   cloudFunctionappEngineVersioncloudRunRevisionr   )setattr)r   endpoint_nameproto_endpoint_fieldss      r   ClearEndpointValuer?   M   s(    
 +HT* HR(r   c                    U R                   n[        X15      n1 SknSnU H  n[        XGS5      (       d  M  US-  nM     US:  d  [        XBS5      (       d/  [        XB5        [        X1U5        X0l         [	        US-   U-   U 5      $ / SQnUS:X  a  UR                  / SQ5        US	:X  a  UR                  / S
Q5        [        [        X5      5      ezNChecks if given endpoint can be removed from Connectivity Test and removes it.>
   instance	ipAddressredisClusterr9   redisInstanceforwardingRuler:   r;   cloudSqlInstancegkeMasterClusterr   Nr   .)rB   z
ip-addresszgke-master-clusterzcloud-sql-instancesource)zcloud-functionzapp-engine-versionzcloud-run-revisiondestination)zforwarding-rulezredis-instancezredis-clusterconnectivityTestgetattrr?   r<   r7   extendr   r%   	r5   r   r=   testr   endpoint_fieldsnon_empty_endpoint_fieldsr4   r"   s	            r   ClearSingleEndpointAttrrT   [       		'	'$T)(/  ex%%1$  "'t+ + x/D*%)"m+] I    	
 %  	
 *9D r   c                 p    / SQnU H+  u  pEnUR                  U5      (       d  M  [        UUU5      nM-     U$ z5Handles clear_source_* and clear_destination_* flags.))clear_source_instancerJ   rB   )clear_source_ip_addressrJ   rC   )clear_source_gke_master_clusterrJ   rH   )clear_source_cloud_sql_instancerJ   rG   )clear_source_cloud_functionrJ   r9   )clear_source_app_engine_versionrJ   r:   )clear_source_cloud_run_revisionrJ   r;   )clear_destination_instancerK   rB   )clear_destination_ip_addressrK   rC   )$clear_destination_gke_master_clusterrK   rH   )$clear_destination_cloud_sql_instancerK   rG   )!clear_destination_forwarding_rulerK   rF   ) clear_destination_redis_instancerK   rE   )clear_destination_redis_clusterrK   rD   )IsSpecifiedrT   r*   argsr5   flags_and_endpointsflagr   r=   s          r   ClearEndpointAttrsrk      sI    2 -@(d=-


m -@ 
r   c                    U R                   n[        X15      n1 SknSnU H  n[        XGS5      (       d  M  US-  nM     US:  d  [        XBS5      (       d/  [        XB5        [        X1U5        X0l         [	        US-   U-   U 5      $ / SQnUS:X  a  UR                  / SQ5        US	:X  a  UR                  / S
Q5        [        [        X5      5      erA   rL   rP   s	            r   ClearSingleEndpointAttrBetarm      rU   r   c                 p    / SQnU H+  u  pEnUR                  U5      (       d  M  [        UUU5      nM-     U$ rW   )rf   rm   rg   s          r   ClearEndpointAttrsBetaro      sI    2 -@(d=1


m -@ 
r   c                     SS/n[         R                  " S5      nU HV  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        SR                  XV5      5      e   U$ )z5Checks if all provided instances are in valid format.source_instancedestination_instancezEprojects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/zones/[-\w]+/instances/[-\w]+zInvalid value for flag {}: {}
Expected instance in the following format:
  projects/my-project/zones/zone/instances/my-instancerecompilerf   rN   matchr   r    r*   rh   r,   flagsinstance_patternrj   rB   s          r   ValidateInstanceNamesrz     s     % ZZN d$h##H--EEKVF
 	
	  
.r   c                     SS/n[         R                  " S5      nU HV  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        SR                  XV5      5      e   U$ )z4Checks if all provided networks are in valid format.source_networkdestination_networkz>projects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/global/networks/[-\w]+zxInvalid value for flag {}: {}
Expected network in the following format:
  projects/my-project/global/networks/my-networkrs   )r*   rh   r,   rx   network_patternrj   networks          r   ValidateNetworkURIsr   )  s     % JJG/ d#g""7++??Ev@
 	
	  
.r   c                     SS/n[         R                  " S5      nU HV  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        SR                  XV5      5      e   U$ )zFChecks if all provided GKE Master Clusters URIs are in correct format.source_gke_master_clusterdestination_gke_master_clusterzPprojects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/(zones|locations)/[-\w]+/clusters/[-\w]+zInvalid value for flag {}: {}
Expected Google Kubernetes Engine master cluster in the following format:
  projects/my-project/location/location/clusters/my-clusterrs   )r*   rh   r,   rx   ry   rj   clusters          r   ValidateGKEMasterClustersURIsr   A  s     "&% ZZY d#g##G,,IIOJ
 	
	  
.r   c                     SS/n[         R                  " S5      nU HV  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        SR                  XV5      5      e   U$ )zFChecks if all provided Cloud SQL Instances URIs are in correct format.source_cloud_sql_instancedestination_cloud_sql_instancez8projects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/instances/[-\w]+z~Invalid value for flag {}: {}
Expected Cloud SQL instance in the following format:
  projects/my-project/instances/my-instancers   rw   s          r   ValidateCloudSQLInstancesURIsr   X  s     "&% ZZA d$h##H--::@&:P
 	
	  
.r   c                     S/n[         R                  " S5      nU HV  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        SR                  XV5      5      e   U$ )zBChecks if all provided Cloud Functions URIs are in correct format.source_cloud_functionzIprojects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/locations/[-\w]+/functions/[-\w]+zInvalid value for flag {}: {}
Expected Cloud Function in the following format:
  projects/my-project/locations/location/functions/my-functionrs   )r*   rh   r,   rx   function_patternrj   functions          r   ValidateCloudFunctionsURIsr   m  s     % ZZR dD!!t"H!!(++K 6$!	   
.r   c                     S/n[         R                  " S5      nU HV  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        SR                  XV5      5      e   U$ )zEChecks if all provided App Engine version URIs are in correct format.source_app_engine_versionzCapps/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/services/[-\w]+/versions/[-\w]+zInvalid value for flag {}: {}
Expected App Engine version in the following format:
  apps/my-project/services/my-service/versions/my-versionrs   )r*   rh   r,   rx   version_patternrj   versions          r   ValidateAppEngineVersionsURIsr     s     "% JJL/ dD!!d!G  ))FFLfG   
.r   c                     S/n[         R                  " S5      nU HV  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        SR                  XV5      5      e   U$ )zFChecks if all provided Cloud Run revisions URIs are in correct format.source_cloud_run_revisionzIprojects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/locations/[-\w]+/revisions/[-\w]+zInvalid value for flag {}: {}
Expected Cloud Run revision in the following format:
  projects/my-project/locations/location/revisions/my-revisionrs   )r*   rh   r,   rx   revision_patternrj   revisions          r   ValidateCloudRunRevisionsURIsr     s     "% ZZR dD!!t"H!!(++K 6$!	   
.r   c                     S/n[         R                  " S5      nU HG  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        S5      e   U$ )zCChecks if all provided forwarding rules URIs are in correct format.destination_forwarding_rulezVprojects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/(global|regions/[-\w]+)/forwardingRules/[-\w]+zInvalid value for flag {flag}: {forwarding_rule}
Expected forwarding rule in one of the following formats:
  projects/my-project/global/forwardingRules/my-forwarding-rule
  projects/my-project/regions/us-central1/forwardingRules/my-forwarding-rulert   ru   rf   rN   rv   r   )r*   rh   r,   rx   forwarding_rule_patternrj   forwarding_rules          r   ValidateForwardingRulesURIsr     sw     $% JJ_ dD!!d)O"((99[   
.r   c                     S/n[         R                  " S5      nU HG  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        S5      e   U$ )zAChecks if all provided Redis Instance URIs are in correct format.destination_redis_instancezIprojects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/locations/[-\w]+/instances/[-\w]+zInvalid value for flag {flag}: {redis_instance}
Expected Redis Instance in the following format:
  projects/my-project/locations/location/instances/my-redis-instance
r   )r*   rh   r,   rx   redis_instance_patternrj   redis_instances          r   ValidateRedisInstancesURIsr     sq    '
(%::R dD!!T(N!''77U   
.r   c                     S/n[         R                  " S5      nU HG  nUR                  U5      (       d  M  [        X5      nUR	                  U5      (       a  M>  [        S5      e   U$ )z@Checks if all provided Redis Cluster URIs are in correct format.destination_redis_clusterzHprojects/(?:[a-z][a-z0-9-\.:]*[a-z0-9])/locations/[-\w]+/clusters/[-\w]+zInvalid value for flag {flag}: {redis_cluster}
Expected Redis Cluster in the following format:
  projects/my-project/locations/location/clusters/my-redis-cluster
r   )r*   rh   r,   rx   redis_cluster_patternrj   redis_clusters          r   ValidateRedisClustersURIsr     sq    &
'%**Q dD!!D'M &&}55S   
.r   c                 t    UR                  S5      (       a!  UR                  S5      (       d  [        S5      eU$ )zZChecks if destination-gke-master-cluster was specified when destination-fqdn is specified.destination_fqdnr   zXdestination-fqdn can only be specified when destination-gke-master-cluster is specified
)rf   r   )r*   rh   r,   s      r   ValidateFqdnr     sD    	())$2B2B&3 3 	9  
.r   )r   
__future__r   r   r   rt   googlecloudsdk.corer   Errorr   r   r%   r-   r0   r7   r?   rT   rk   rm   ro   rz   r   r   r   r   r   r   r   r   r   r   r
   r   r   <module>r      s    1 &  ' 	 *?Z-- ?%. %.
)2j#L2j#L00.*.0..((	r   