
                         .   S r SSKrSSKJr  SSKJr  SSKJr  SSKrSr	Sr
\R                  " S/ S	Q5      r " S
 S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      rS rS rS rS rg)z:Utility functions for WebSocket tunnelling with Cloud IAP.    N)parse)
exceptions)http_proxy_typeszingress.cloudproxy.appi  SecurityGatewayTarget)projectregionsecurity_gatewayhostporturl_override
proxy_infouse_dest_groupc                       \ rS rSrSrg)MissingSecurityGatewayParameter#    N__name__
__module____qualname____firstlineno____static_attributes__r       5lib/googlecloudsdk/api_lib/compute/sg_tunnel_utils.pyr   r   #       r   r   c                       \ rS rSrSrg)UnsupportedProxyType'   r   Nr   r   r   r   r   r   '   r   r   r   c                       \ rS rSrSrg)PythonVersionUnsupported+   r   Nr   r   r   r   r    r    +   r   r   r    c                       \ rS rSrSrg)PythonVersionMissingSNI/   r   Nr   r   r   r   r#   r#   /   r   r   r#   c                 &    SR                  XU5      $ )Nz,projects/{}/locations/{}/securityGateways/{}format)r   locationsg_ids      r   #GenerateSecurityGatewayResourcePathr*   3   s    4;;
Ur   c                 &    SR                  XU5      $ )Nz1projects/{}/iap_tunnel/locations/{}/destGroups/{}r&   )r   r(   dg_ids      r   GenerateDestGroupResourcePathr-   ;   s    9@@
Ur   c                    / nU R                  5       R                  5        HI  u  p#U(       d  US;   a  UR                  U5        U(       d  M,  SR                  U5      n[	        SU-   5      e   U R
                  (       aR  U R
                  R                  nU(       a4  U[        R                  :w  a  [        S[        R                  U   -   5      eggg)z?Validate the necessary Security Gateway parameters are present.)r   r
   r   r   r	   ,zMissing required arguments: zUnsupported proxy type: N)_asdictitemsappendjoinr   r   
proxy_typesocksPROXY_TYPE_HTTPr   r   REVERSE_PROXY_TYPE_MAP)target_infomissing_parameters
field_namefield_valuestr_parametersr4   s         r   ValidateParametersr=   C   s     !,!4!4!6!<!<!>j: *  
+xx 23n+
(>
9  "?  ''22JjE$9$99 
$33J?@  :z r   c                     [         n[        nU (       aV  [        R                  " U 5      nUR                  nUR
                  nU(       a  U(       d  [        SR                  U 5      5      eX4$ )Nz{} is an invalid url)SECURITY_GATEWAY_PROXY_HOSTSECURITY_GATEWAY_PROXY_PORTr   urlparsehostnamer   
ValueErrorr'   )url
proxy_host
proxy_portinfos       r   GetProxyHostPortrH   `   sT    ****>>#DJJZ-44S9::
	!!r   )__doc__collectionsurllibr   googlecloudsdk.corer   googlecloudsdk.core.utilr   r5   r?   r@   
namedtupleSecurityGatewayTargetInfoErrorr   r   r    r#   r*   r-   r=   rH   r   r   r   <module>rQ      s     A   * 5 6 ! '22%& j&6&6 :++ z// j.. :	"r   