
    8S                         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rSrSrS	rS
rSrSrSr\\4r\\\\4r\\\\\\\\4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Utils for IAP commands.    )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   8   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   I   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$   Z   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*   i   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   AddDestGroupListRegionArgsr.   y   s&     	N  r   c                     U R                  5       nUR                  S[        SS9  UR                  SSS9  UR                  SSS9  UR                  S	S
S9  g)zAdds 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.
--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`.	--versionzLService version. Should only be specified with `--resource-type=app-engine`.N)r'   r   IAM_RESOURCE_TYPE_ENUMr(   s     r   AddIapIamResourceArgsr7      s{     


%$/  
 [7(   *  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.
r0   Tr1   )r   r3   r   r4   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                    U R                  5       nUR                  SSS9  UR                  SSS9  UR                  SSS9  UR                  S[        S	S
9  UR                  SSS9  UR                  SSS9  UR                  SSS9  g)zAdds 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.
z--organizationzOrganization ID.r   z--folderz
Folder ID.	--projectzProject ID.r0   z|Resource type of the IAP resource. For Backend Services, you can use both `compute` and `backend-services` as resource type.r2   r4   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`.r5   zUVersion name. Not applicable for `compute`. Optional when `resource-type=app-engine`.N)r'   r   SETTING_RESOURCE_TYPE_ENUMr(   s     r   AddIapSettingArgr>      s     


%%,>?Zl3[}5(I	      (   )  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   AddOauthClientArgsr@      sL     


%(  * ,  .r   c                 .    [         R                  " U SS9  g NT)add_condition)r   AddArgsForAddIamPolicyBindingr   s    r   AddAddIamPolicyBindingArgsrE   
  s    
((r   c                 .    [         R                  " U SS9  g rB   )r    AddArgsForRemoveIamPolicyBindingr   s    r   AddRemoveIamPolicyBindingArgsrH     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   AddIAMPolicyFileArgrK     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   AddIapSettingFileArgrN   !  s     	6  8r   c                 f   [         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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.

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
r4   :`--service` cannot be specified without `--resource-type`.r   9`--region` cannot be specified without `--resource-type`.r5   :`--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argsrX   s      r   ParseIapIamResourcert   c  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44||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
r4   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   rV   rW   rX   rY   rZ   rb   r[   r\   r]   r`   re   rf   RequiredArgumentExceptionrg   r^   ro   rp   rq   s      r   ParseIapResourcerw     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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.

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

Returns:
  The specified IapSettingsResource
r0   z?`--resource-type` should not be specified at organization levelr<   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}r4   rP   r   rQ   r5   rR   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/rS   zforwarding_rule-{}forwarding_rulerT   rU   zcloud_run-{}z'Unsupported IAP settings resource type.z&Could not parse IAP settings resource.)r	   rZ   r\   r]   rX   r`   IapSettingsResourceformatr
   r[   r^   r_   WEB_RESOURCE_TYPErb   COMPUTE_RESOURCE_TYPErf   appendextendjoinri   rl   ro   rp   )rr   rs   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   rV   rW   rX   rY   getattr
dest_groupr`   IapTunnelDestGroupResourcer^   )rr   rs   rX   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   rV   rW   rX   rY   r`   r   r^   rq   s      r   &ParseIapDestGroupResourceWithNoGroupIdr     s;     ""**446'		+	+MDKK	PPr   N)*__doc__googlecloudsdk.api_lib.iapr   r`   googlecloudsdk.callioper   r\   googlecloudsdk.command_lib.iamr   googlecloudsdk.command_lib.iapro   googlecloudsdk.corer   rb   rf   r   r   ORG_RESOURCE_TYPEFOLDER_RESOURCE_TYPEri   rl   r9   r6   r=   r   r   r$   r*   r.   r7   r:   r>   r@   rE   rH   rK   rN   rt   rw   r   r   r    r   r   <module>r      s      7 > 3 @ * ( !3  ! "   1 % ") %
 "!	  "!	 /"/"66  !H2/d.$J?DgPT'LTL0^3&Qr   