
    v                        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S	S
.r	SSSS
.r	S r
S r\R                  " \R                  R                  5      \R                   " S S\R                   5      5       5       r\R                  " \R                  R$                  5      \R                   " S S\R                   5      5       5       r\R                  " \R                  R(                  5       " S S\R                   5      5       rg)zCommand to query activities.    )absolute_import)division)unicode_literals)policy_troubleshooter)basez%Troubleshoot the IAM Policy.
        z      Performs a check on whether a principal is granted a
      permission on a resource and how that access is determined according to
      the resource's effective IAM policy interpretation.
        am      To troubleshoot a permission of a principal on a resource, run:

      $ {command} //cloudresourcemanager.googleapis.com/projects/project-id       --principal-email=my-iam-account@somedomain.com       --permission=resourcemanager.projects.get

    See https://cloud.google.com/iam/help/allow-policies/overview for more
    information about IAM policies.
      )briefDESCRIPTIONEXAMPLESz2Troubleshoot IAM allow and deny policies.
        z      Uses a resource's effective IAM allow policy and IAM deny policy to
      check whether a principal has a specific permission on the resource.
        aI        The following command checks whether the principal ``my-user@example.com''
      has the permission ``resourcemanager.projects.get'' on the project
      ``my-project'':

        $ {command} //cloudresourcemanager.googleapis.com/projects/my-project
        --principal-email=my-user@example.com
        --permission=resourcemanager.projects.get

      The following command checks whether the principal ``my-user@example.com''
      has the ``compute.images.get'' permission on the project
      ``my-project''. The command also provides additional context that lets
      Troubleshooter evaluate conditional role bindings:

        $ {command} //cloudresourcemanager.googleapis.com/projects/my-project         --principal-email=my-user@example.com         --permission=compute.images.get         --resource-name=//compute.googleapis.com/projects/my-project/zones/images/my-image'        --resource-service='compute.googleapis.com'         --resource-type='compute.googleapis.com/Image'         --destination-ip='192.2.2.2'--destination-port=8080 --request-time='2023-01-01T00:00:00Z'
      c                    U R                  SS[        SS9  U R                  SSS[        SS	9  U R                  S
SS[        SS	9  U R                  SS[        SS9  U R                  SS[        SS9  U R                  SS[        SS9  U R                  SS[        SS9  U R                  SS[        SS9  U R                  SS[        SS9  g)"Parses arguments for the commands.resourceRESOURCEzFull resource name that access is checked against.
      For a list of full resource name formats, see: https://cloud.google.com/iam/docs/resource-names.
      )metavartypehelpz--principal-emailTEMAILz{Email address that identifies the principal to check. Only Google Accounts and
      service accounts are supported.
      )requiredr   r   r   z--permission
PERMISSIONa[  IAM permission to check. The permssion can be in the `v1` or `v2`
      format. For example, `resourcemanager.projects.get` or
      `cloudresourcemanager.googleapis.com/projects.get`.
      For a list of permissions, see https://cloud.google.com/iam/docs/permissions-reference and https://cloud.google.com/iam/docs/deny-permissions-support
      z--resource-serviceFzThe resource service value to use when checking conditional bindings.
      For accepted values, see: https://cloud.google.com/iam/docs/conditions-resource-attributes#resource-service
      )r   r   r   z--resource-typezThe resource type value to use when checking conditional bindings.
      For accepted values, see: https://cloud.google.com/iam/docs/conditions-resource-attributes#resource-type
      z--resource-namezThe resource name value to use when checking conditional bindings.
      For accepted values, see: https://cloud.google.com/iam/docs/conditions-resource-attributes#resource-name.
      z--request-timezThe request timestamp to use when checking conditional bindings. This string must adhere to UTC format
      (RFC 3339). For example,2021-01-01T00:00:00Z. For more information, see:
      https://tools.ietf.org/html/rfc3339
      z--destination-ipznThe request destination IP address to use when checking conditional bindings. For example, `198.1.1.1`.
      z--destination-portzaThe request destination port to use when checking conditional bindings. For example, 8080.
      N)add_argumentstrintparsers    :lib/surface/policy_intelligence/troubleshoot_policy/iam.py_Argsr   L   sA   
	   	
   	
  
 	
	   	
	   	
	   	
	   	
	   	
	      c                 ~   U R                  UR                  UR                  S9nU R                  UR                  S9nU R                  UR                  UR                  UR                  S9nU R                  UUUS9nU R                  UUR                  UR                  UR                  S9nU R                  U5      $ )Troubleshoot the IAM Policies.)destination_ipdestination_port)request_time)resource_nameresource_serviceresource_type)destinationrequestr   )condition_contextfull_resource_nameprincipal_email
permission)GetPolicyTroubleshooterPeerr   r    GetPolicyTroubleshooterRequestr!   GetPolicyTroubleshooterResourcer"   r#   r$   'GetPolicyTroubleshooterConditionContext"GetPolicyTroubleshooterAccessTupler   r)   r*   TroubleshootIAMPolicies)policy_troubleshooter_apiargsdestination_contextrequest_contextresource_contextr'   access_tuples          r   _Runr7      s    1MM((,, N  .LL$$ M / /NN&&,,&& O   GG)!# H   +MM)**	 N , 
#	:	:<	HHr   c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)TroubleshootAlpha   r   c                     [        U 5        gr   Nr   r   s    r   ArgsTroubleshootAlpha.Args        
&Mr   c                 ^    [        [        R                  " U R                  5       5      U5      $ Nr7   r   PolicyTroubleshooterApiReleaseTrackselfr2   s     r   RunTroubleshootAlpha.Run   (    55d6G6G6IJD r    N__name__
__module____qualname____firstlineno____doc___DETAILED_HELPdetailed_helpstaticmethodr>   rH   __static_attributes__rK   r   r   r9   r9      s#     ' - r   r9   c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)TroubleshootBeta   )Troubleshoot IAM allow and deny policies.c                     [        U 5        gr<   r=   r   s    r   r>   TroubleshootBeta.Args   r@   r   c                 ^    [        [        R                  " U R                  5       5      U5      $ rB   rC   rF   s     r   rH   TroubleshootBeta.Run   rJ   r   rK   NrL   rK   r   r   rW   rW      s#     2 - r   rW   c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)Troubleshoot   rY   c                     [        U 5        gr<   r=   r   s    r   r>   Troubleshoot.Args   r@   r   c                 ^    [        [        R                  " U R                  5       5      U5      $ rB   rC   rF   s     r   rH   Troubleshoot.Run   rJ   r   rK   NrL   rK   r   r   r_   r_      s!    1 - r   r_   N)rQ   
__future__r   r   r   *googlecloudsdk.api_lib.policy_intelligencer   googlecloudsdk.callioper   rR   r   r7   ReleaseTracksrE   ALPHAHiddenCommandr9   BETArW   GAr_   rK   r   r   <module>rn      s   # &  ' L (
	
*
@L^I< D%%++,   -  D%%**+t||   ,  D%%(()4<<  *r   