
    s[                     P   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	rS
rSrSrSrSrSrSr\\4r\\\4r\\\\4r\\\\\\\4r\\\\\\\\4rS rS rS r S r!S r" S$S jr#S r$ S$S jr%S r&S r'S r(S r)S r* S$S jr+S r, S$S  jr-S! r.S" r/g#)%zUtils for IAP commands.    )absolute_import)division)unicode_literals)util)
exceptions)iam_util)
propertiesz
app-enginezbackend-servicesiap_webcomputeorganizationfolderzforwarding-rulez	cloud-runc                 H    U R                  SSSS9  U R                  SSSS9  g)zAdds DestGroup args for managing IAM policies.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
z--dest-groupTName of the Destination Group.requiredhelp--region Region of the Destination Group.Nadd_argumentparsers    *lib/googlecloudsdk/command_lib/iap/util.pyAddIamDestGroupArgsr   I   s>     	+  - 	-  /    c                 H    U R                  SSS9  U R                  SSSSS9  g	)
zAdds DestGroup args for managing the resource.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.

group_namer   r   r   REGIONTr   )metavarr   r   Nr   r   s    r   AddDestGroupArgsr!   Z   s>     	+  - 	-	  /r   c                 D    U R                  SSS9  U R                  SSS9  g)zAdds IP and FQDN args for DestGroup Create command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
--ip-range-list+List of ip-ranges in the Destination Group.r   --fqdn-list'List of FQDNs in the Destination Group.Nr   r   s    r   AddDestGroupCreateIpAndFqdnArgsr'   k   s8     	8  : 	4  6r   c                 b    U R                  SS9nUR                  SSS9  UR                  SSS9  g)	zAdds IP and FQDN args for DestGroup Update command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
T)r   r#   r$   r   r%   r&   N	add_groupr   r   groups     r   AddDestGroupUpdateIpAndFqdnArgsr-   z   sK     

D

)%8  : 4  6r   c                 *    U R                  SSSSSS9  g)zAdds Region arg for DestGroup List command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
r   r   FzARegion of the Destination Group, will list all regions by default-)r    r   r   defaultNr   r   s    r   AddDestGroupListRegionArgsr1      s&     	N  r   c                    U R                  5       nU(       a  UR                  S[        SS9  OUR                  S[        SS9  UR                  SSS9  U(       a  UR                  SSS9  OUR                  SS	S9  UR                  S
SS9  g)a  Adds flags for an IAP IAM resource.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
  support_cloud_run: bool, provide support to cloud-run resource-type.
--resource-type"Resource type of the IAP resource.choicesr   	--servicezService name.r   r   zRegion name. Not applicable for `resource-type=app-engine`. Required when `resource-type=backend-services` and regional scoped. Not applicable for global backend-services. Required when `resource-type=cloud-run`.zRegion name. Should only be specified with `--resource-type=backend-services` if it is a regional scoped. Not applicable for global scoped backend services.	--versionzLService version. Should only be specified with `--resource-type=app-engine`.N)r*   r   !IAM_RESOURCE_TYPE_ENUM_ALPHA_BETAIAM_RESOURCE_TYPE_ENUMr   support_cloud_runr,   s      r   AddIapIamResourceArgsr=      s     


%	11   
&1  
 [7	*   
B   *  r   c                     U R                  5       nUR                  SS[        SS9  UR                  SSS9  UR                  SS	S9  g
)zAdds flags for an IAP resource.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
r3   Tr4   )r   r6   r   r7   z?Service name. Required with `--resource-type=backend-services`.r   r   z_Region name. Not applicable for ``app-engine''. Optional when ``resource-type'' is ``compute''.N)r*   r   %WEB_ENABLE_DISABLE_RESOURCE_TYPE_ENUMr+   s     r   AddIapResourceArgsr@      sj     


%3/	  1
 L  N /  r   c                 x   U R                  5       nUR                  SSS9  UR                  SSS9  UR                  SSS9  U(       a  UR                  S[        S	S
9  OUR                  S[        S	S
9  UR                  SSS9  U(       a  UR                  SSS9  OUR                  SSS9  UR                  SSS9  g)a  Adds flags for an IAP settings resource.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
  support_cloud_run: bool, provide support to cloud-run resource-type.
z--organizationzOrganization ID.r   z--folderz
Folder ID.	--projectzProject ID.r3   z|Resource type of the IAP resource. For Backend Services, you can use both `compute` and `backend-services` as resource type.r5   r7   zIService name. Optional when `resource-type` is `compute` or `app-engine`.r   zRegion name. Not applicable for `app-engine`. Required when `resource-type=compute` and regional scoped. Not applicable for global scoped compute. Required when `resource-type=cloud-run`.zRegion name. Not applicable for `app-engine`. Required when `resource-type=compute` and regional scoped. Not applicable for global scoped compute.r8   zUVersion name. Not applicable for `compute`. Optional when `resource-type=app-engine`.N)r*   r   %SETTING_RESOURCE_TYPE_ENUM_ALPHA_BETASETTING_RESOURCE_TYPE_ENUMr;   s      r   AddIapSettingArgrE      s    


%%,>?Zl3[}5	5K	   
*K	      	*   
5   )  r   c                 h    U R                  5       nUR                  SSSS9  UR                  SSSS9  g)zAdds OAuth client args.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
z--oauth2-client-idTzOAuth 2.0 client ID to use.r   z--oauth2-client-secretzOAuth 2.0 client secret to use.Nr)   r+   s     r   AddOauthClientArgsrG   -  sL     


%(  * ,  .r   c                 .    [         R                  " U SS9  g NT)add_condition)r   AddArgsForAddIamPolicyBindingr   s    r   AddAddIamPolicyBindingArgsrL   ?  s    
((r   c                 .    [         R                  " U SS9  g rI   )r    AddArgsForRemoveIamPolicyBindingr   s    r   AddRemoveIamPolicyBindingArgsrO   E  s    
++r   c                 $    U R                  SSS9  g)zAdds flags for an IAM policy file.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
policy_filez,JSON or YAML file containing the IAM policy.r   Nr   r   s    r   AddIAMPolicyFileArgrR   K  s     	H  Jr   c                 $    U R                  SSS9  g)zAdd flags for the IAP setting file.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
setting_filea  JSON or YAML file containing the IAP resource settings.

JSON example:

```
{
  "access_settings": {
    "oauth_settings": {
      "login_hint": {
        "value": "test_hint"
      }
    },
    "gcip_settings": {
      "tenant_ids": [
        "tenant1-p9puj",
        "tenant2-y8rxc"
      ],
      "login_page_uri": {
        "value": "https://test.com/?apiKey=abcd_efgh"
      }
    },
    "cors_settings": {
      "allow_http_options": {
        "value": true
      }
    }
  },
  "application_settings": {
    "csm_settings": {
      "rctoken_aud": {
        "value": "test_aud"
      }
    }
  }
}
```

YAML example:

```
accessSettings :
  oauthSettings:
    loginHint: test_hint
  gcipSettings:
    tenantIds:
    - tenant1-p9puj
    - tenant2-y8rxc
    loginPageUri: https://test.com/?apiKey=abcd_efgh
  corsSettings:
    allowHttpOptions: true
applicationSettings:
  csmSettings:
    rctokenAud: test_aud
```
r   Nr   r   s    r   AddIapSettingFileArgrU   V  s     	6  8r   c                 t   [         R                  R                  R                  R	                  5       nUR
                  (       d  UR                  (       a  [        R                  " SS5      eUR                  (       a  [        R                  " SS5      eUR                  (       a  [        R                  " SS5      e[        R                  " X5      $ UR
                  [        :X  a  UR                  (       a  [        R                  " SS5      eUR                  (       a=  UR                  (       a,  [        R                  " XUR                  UR                  5      $ UR                  (       a!  [        R                  " XUR                  5      $ UR                  (       a  [        R                  " SS5      e[        R                   " X5      $ UR
                  ["        :X  a  UR                  (       a  [        R                  " SS	5      eUR                  (       a^  UR                  (       a,  [        R$                  " XUR                  UR                  5      $ [        R&                  " XUR                  5      $ UR                  (       a"  [        R$                  " XS
UR                  5      $ [        R&                  " XS
5      $ UR
                  [(        :X  a  UR                  (       a  [        R                  " SS5      eUR                  (       a,  [        R*                  " XUR                  UR                  5      $ [        R,                  " XUR                  5      $ U(       a  UR
                  [.        :X  a  UR                  (       a  [        R                  " SS5      eUR                  (       d  [        R                  " SS5      eUR                  (       a,  [        R0                  " XUR                  UR                  5      $ [        R2                  " XUR                  5      $ [4        R6                  " S5      e)a&  Parse an IAP IAM resource from the input arguments.

Args:
  release_track: base.ReleaseTrack, release track of command.
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.
  support_cloud_run: bool, whether to support cloud run.

Raises:
  calliope_exc.InvalidArgumentException: if a provided argument does not apply
      to the specified resource type.
  iap_exc.InvalidIapIamResourceError: if an IapIamResource could not be parsed
      from the arguments.

Returns:
  The specified IapIamResource
r7   :`--service` cannot be specified without `--resource-type`.r   9`--region` cannot be specified without `--resource-type`.r8   :`--version` cannot be specified without `--resource-type`.z@`--region` cannot be specified for `--resource-type=app-engine`.z4`--version` cannot be specified without `--service`.zG`--version` cannot be specified for `--resource-type=backend-services`.NF`--version` cannot be specified for `--resource-type=forwarding-rule`.@`--version` cannot be specified for `--resource-type=cloud-run`.=`--region` must be specified for `--resource-type=cloud-run`.z!Could not parse IAP IAM resource.)r	   VALUEScoreproject	GetOrFailresource_typeservicecalliope_excInvalidArgumentExceptionregionversioniap_apiIAPWebAPP_ENGINE_RESOURCE_TYPEAppEngineServiceVersionAppEngineServiceAppEngineApplicationBACKEND_SERVICES_RESOURCE_TYPEBackendServiceBackendServicesFORWARDING_RULE_RESOURCE_TYPEForwardingRuleForwardingRulesCLOUD_RUN_RESOURCE_TYPECloudRun	CloudRunsiap_excInvalidIapIamResourceError)release_trackargsr<   r_   s       r   ParseIapIamResourcerz     s!   , ""**446'			||11

F  {{11

E  ||11

F  >>-1155{{11

L  ||,,
$,,  
%%mdllKK||11
M  ''??;;||11
0 
 {{	%%DKK
 	
 &&}t{{KK	##MD$,,OO""=4@@::||11
/ 
 ||##MDKK$(LL2 2 $$]T[[IId004KK||11
) 
 ;;11
) 
 ||mdkk4<<PP}t{{CC 	**+NOOr   c                 *   [         R                  R                  R                  R	                  5       nUR
                  (       a  UR
                  [        :X  a?  UR                  (       a  [        R                  " SS5      e[        R                  " U U5      $ UR
                  [        :X  aT  UR                  (       d  [        R                  " SS5      e[        R                  " XUR                  UR                  5      $ [         R"                  " S5      e)a  Parse an IAP resource from the input arguments.

Args:
  release_track: base.ReleaseTrack, release track of command.
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Raises:
  calliope_exc.InvalidArgumentException: if `--version` was specified with
      resource type 'backend-services'.
  iap_exc.InvalidIapIamResourceError: if an IapIamResource could not be parsed
      from the arguments.

Returns:
  The specified IapIamResource
r7   zA`--service` cannot be specified for `--resource-type=app-engine`.zE`--service` must be specified for `--resource-type=backend-services`.zCould not parse IAP resource.)r	   r]   r^   r_   r`   ra   ri   rb   rc   rd   rg   rl   rm   RequiredArgumentExceptionrn   re   rv   rw   rx   ry   r_   s      r   ParseIapResourcer~     s    " ""**446'	55	33,- 	- ))

  
		=	=\\4423 	3
 ##
$++t||  	**+JKKr   c           	         UR                   (       a  UR                  (       a  [        R                  " SS5      eUR                  (       a  [        R                  " SS5      e[
        R                  " U SR                  UR                   5      5      $ UR                  (       a  UR                  (       a  [        R                  " SS5      eUR                  (       a  [        R                  " SS5      e[
        R                  " U SR                  UR                  5      5      $ UR                  (       Ga
  UR                  (       a(  UR                  (       d  [        R                  " S	S
5      eUR                  (       a(  UR                  (       d  [        R                  " SS5      eUR                  (       a(  UR                  (       d  [        R                  " SS5      eUR                  (       d0  [
        R                  " U SR                  UR                  5      5      $ UR                  [        :X  a0  [
        R                  " U SR                  UR                  5      5      $ UR                  [        :X  a  UR                  (       d;  [
        R                  " U SR                  UR                  UR                  5      5      $ UR                  (       aQ  [
        R                  " U SR                  UR                  UR                  UR                  UR                  5      5      $ [
        R                  " U SR                  UR                  UR                  UR                  5      5      $ UR                  [        :X  d  UR                  [        :X  a  SUR                  S/nUR                  (       a+  UR!                  SR                  UR                  5      5        OUR!                  S5        UR                  (       a  UR#                  SUR                  /5        [
        R                  " U SR%                  U5      5      $ UR                  [&        :X  a  SUR                  S/nUR                  (       a  [        R                  " SS5      eUR                  (       a+  UR!                  SR                  UR                  5      5        OUR!                  S5        UR                  (       a  UR#                  SUR                  /5        [
        R                  " U SR%                  U5      5      $ U(       a  UR                  [(        :X  a  SUR                  S/nUR                  (       a  [        R                  " SS5      eUR                  (       d  [        R                  " SS5      eUR!                  SR                  UR                  5      5        UR                  (       a  UR#                  SUR                  /5        [
        R                  " U SR%                  U5      5      $ [*        R,                  " S 5      e[*        R,                  " S!5      e)"a  Parse an IAP setting resource from the input arguments.

Args:
  release_track: base.ReleaseTrack, release track of command.
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.
  support_cloud_run: bool, whether to support cloud run.

Raises:
  calliope_exc.InvalidArgumentException: if `--version` was specified with
      resource type 'backend-services'.

Returns:
  The specified IapSettingsResource
r3   z?`--resource-type` should not be specified at organization levelrB   z9`--project` should not be specified at organization levelzorganizations/{0}z9`--resource-type` should not be specified at folder levelz3`--project` should not be specified at folder levelzfolders/{0}r7   rW   r   rX   r8   rY   zprojects/{0}zprojects/{0}/iap_webz"projects/{0}/iap_web/appengine-{1}z<projects/{0}/iap_web/appengine-{1}/services/{2}/versions/{3}z/projects/{0}/iap_web/appengine-{1}/services/{2}projectsr
   z
compute-{}r   services/rZ   zforwarding_rule-{}forwarding_ruler[   r\   zcloud_run-{}z'Unsupported IAP settings resource type.z&Could not parse IAP settings resource.)r   ra   rc   rd   r_   rg   IapSettingsResourceformatr   rb   re   rf   WEB_RESOURCE_TYPEri   COMPUTE_RESOURCE_TYPErm   appendextendjoinrp   rs   rv   rw   )rx   ry   r<   paths       r   ParseIapSettingsResourcer   .  s   ( 
11

K  ||11

E  &&*11$2C2CD  
[[11

E  ||11
L  &&}++DKK8  
\\\||D..11

FH H {{4--11

EG G ||D..11

FH H ((
..t||<  
		0	0**188F
 	
 !99||,,299,,  \\..NdllDLL$,,O  ..AHHLL$,,  

 5
5#AADLL)4;;
++l))$++6
7
++i
 <<
++z4<<0
1**=#((4.II"??DLL)4<<553 
 ;;
++*11$++>
?
++'
(<<
++z4<<0
1**=#((4.II"99DLL)4<<55- 
 {{55- 
 	N))$++67<<
++z4<<0
1**=#((4.II0057 	7 	**.	0 0r   c                     [         R                  R                  R                  R	                  5       n[        USS5      nUc  UR                  n[        R                  " XUR                  U5      $ )a  Parses an IAP TCP DestGroup resource from the input arguments.

Args:
  release_track: base.ReleaseTrack, release track of command.
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  The specified IAP TCP DestGroup resource.
r   N)
r	   r]   r^   r_   r`   getattr
dest_grouprg   IapTunnelDestGroupResourcere   )rx   ry   r_   r,   s       r   ParseIapDestGroupResourcer     s^     ""**446'
$d
+%
]OOE		+	+MDKK,1
3 3r   c                     [         R                  R                  R                  R	                  5       n[
        R                  " XUR                  5      $ )a  Parses an IAP TCP Tunnel resource from the input arguments.

Args:
  release_track: base.ReleaseTrack, release track of command.
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  The specified IAP TCP Tunnel resource.
)r	   r]   r^   r_   r`   rg   r   re   r}   s      r   &ParseIapDestGroupResourceWithNoGroupIdr     s;     ""**446'		+	+MDKK	PPr   N)F)0__doc__
__future__r   r   r   googlecloudsdk.api_lib.iapr   rg   googlecloudsdk.callioper   rc   googlecloudsdk.command_lib.iamr   googlecloudsdk.command_lib.iaprv   googlecloudsdk.corer	   ri   rm   r   r   ORG_RESOURCE_TYPEFOLDER_RESOURCE_TYPErp   rs   r?   r:   r9   rD   rC   r   r!   r'   r-   r1   r=   r@   rE   rG   rL   rO   rR   rU   rz   r~   r   r   r    r   r   <module>r      sG     &  ' 6 > 3 @ * ( !3  ! "   1 % ") %
 "!  "!	% ! "!  !"	) %/"/"66 " $2j4 $BJ.$J?J iPX'LZ O0d3&Qr   