
                          R   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ ddlZd	Zd
Z ej                  dg d      Z G d de	j"                        Z G d de	j"                        Z G d de	j"                        Z G d de	j"                        Zd Zd Zd Zd Zy)z:Utility functions for WebSocket tunnelling with Cloud IAP.    )absolute_import)division)unicode_literalsN)parse)
exceptions)http_proxy_typeszingress.cloudproxy.appi  SecurityGatewayTarget)projectregionsecurity_gatewayhostporturl_override
proxy_infouse_dest_groupc                       e Zd Zy)MissingSecurityGatewayParameterN__name__
__module____qualname__     5lib/googlecloudsdk/api_lib/compute/sg_tunnel_utils.pyr   r   &       r   r   c                       e Zd Zy)UnsupportedProxyTypeNr   r   r   r   r   r   *   r   r   r   c                       e Zd Zy)PythonVersionUnsupportedNr   r   r   r   r   r   .   r   r   r   c                       e Zd Zy)PythonVersionMissingSNINr   r   r   r   r!   r!   2   r   r   r!   c                 (    dj                  | ||      S )Nz,projects/{}/locations/{}/securityGateways/{}format)r
   locationsg_ids      r   #GenerateSecurityGatewayResourcePathr'   6   s    4;;
8Ur   c                 (    dj                  | ||      S )Nz1projects/{}/iap_tunnel/locations/{}/destGroups/{}r#   )r
   r%   dg_ids      r   GenerateDestGroupResourcePathr*   >   s    9@@
8Ur   c                 t   g }| j                         j                         D ]=  \  }}|s|dv r|j                  |       |s dj                  |      }t	        d|z          | j
                  rL| j
                  j                  }|r3|t        j                  k7  rt        dt        j                  |   z         yyy)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_parametersr1   s         r   ValidateParametersr:   F   s     !,!4!4!6!<!<!>j+: *  
+xx 23n+
(>
9  "?  ''22JjE$9$99 
$33J?@  :z r   c                     t         }t        }| rKt        j                  |       }|j                  }|j
                  }|r|st        dj                  |             ||fS )Nz{} is an invalid url)SECURITY_GATEWAY_PROXY_HOSTSECURITY_GATEWAY_PROXY_PORTr   urlparsehostnamer   
ValueErrorr$   )url
proxy_host
proxy_portinfos       r   GetProxyHostPortrE   c   sV    ****>>#DJJZ-44S9::
j	!!r   )__doc__
__future__r   r   r   collectionsurllibr   googlecloudsdk.corer   googlecloudsdk.core.utilr   r2   r<   r=   
namedtupleSecurityGatewayTargetInfoErrorr   r   r   r!   r'   r*   r:   rE   r   r   r   <module>rO      s     A &  '   * 5 6 ! 2K22%& j&6&6 :++ z// j.. :	"r   