
                         ~   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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 rS r\R.                  " \R0                  R2                  5      \R4                   " S S\R6                  5      5       5       r\R.                  " \R0                  R:                  5      \R4                   " S S\R6                  5      5       5       r\R.                  " \R0                  R>                  5      \R4                   " S S\R6                  5      5       5       r g)zCommand to simulate orgpolicy.    )absolute_import)division)unicode_literals)encoding_helper)
list_pager)utils)orgpolicy_simulator)arg_parsers)base)
exceptions)logza      Understand how changes to organization policies could affect your
      resources.
        ad        To simulate changes to custom constraints defined in
      `./custom-constraint.json`, run:

        $ {command}
        --organization=ORGANIZATION_ID
        --custom-constraints=custom-constraint.json

      To simulate changes to organization policies defined in `./policy.json`,
      run:

        $ {command}
        --organization=ORGANIZATION_ID
        --policies=policy.json

      To simulate changes to both custom constraints defined in
      `./custom-constraint.json` and organization policies defined in
      `./policy.json`, run:

        $ {command}
        --organization=ORGANIZATION_ID
        --policies=policy.json
        --custom-constraints=custom-constraint.json

      See https://cloud.google.com/policy-intelligence/docs/test-organization-policies
      for more information about Policy Simulator for Organization Policy.

      )briefDESCRIPTIONEXAMPLESc                     U R                  SSSSS9  U R                  S[        R                  " 5       S[        R                  SS	9  U R                  S
[        R                  " 5       S[        R                  SS	9  g)"Parses arguments for the commands.z--organizationORGANIZATION_IDTzOrganization ID.)metavarrequiredhelpz
--policiesPOLICIESzPath to the JSON or YAML file that contains the organization
      policy to simulate. Multiple policies can be simulated by providing
      multiple, comma-separated paths. For example: `--policies=p1.json,p2.json`
      )typer   actionr   z--custom-constraintsCUSTOM_CONSTRAINTSa	  Path to the JSON or YAML file that contains the custom constraints
      to simulate. Multiple custom constraints can be simulated by providing
      multiple, comma-separated paths. For example:
      `--custom-constraints=constraint1.json,constraint2.json`
      N)add_argumentr
   ArgListUpdateActionparsers    5lib/surface/policy_intelligence/simulate/orgpolicy.py
_ArgsParser!   K   s    	  ! 	 %%
   	 "%%
  	    c                 N   U R                   (       d'  U R                  (       d  [        R                  " S5      e[        R
                  " U5      n/ nU R                   (       a  U R                    H  n[        R                  " UU5      nUR                  (       d  [        R                  " SS5      e[        R                  " UR                  5      nUR                  UUS9nUR                  U5        M     / nU R                  (       a  U R                   H  n	[        R                  " U	U5      n
U
R                  (       d  [        R                  " SS5      e[        R                  " U
R                  5      nUR                  U
US9nUR                  U5        M     UR!                  X8S9nS	U R"                  -   n[        R$                  " U5      nUR'                  US
9nUR)                  UUS9nUR*                  R-                  UR*                  5      nUR/                  US9nUR1                  USR3                  UR                  5      5      n[4        R6                  " UR9                  5       [4        R:                  " U5      5      nUR<                  (       a  UR>                  (       d  [@        RB                  RE                  S5        URF                  RI                  UR                  S9nUR*                  RK                  UR*                  5      n[L        RN                  " UUSSSS9$ )z>Run the workflow for Policy Simulator for Organization Policy.zBMust specify either `--policies`, `--custom-constraints`, or both.zPolicy namez4'name' field not present in the organization policy.)policypolicy_parentzCustom constraint namez2'name' field not present in the custom constraint.)custom_constraintcustom_constraint_parent)policiescustom_constraintszorganizations/)overlay)violations_previewparent)requestz&Waiting for operation [{}] to completez/No violations found in the violations preview.
)r,   i  orgPolicyViolationspageSize)
batch_sizefieldbatch_size_attribute)(r(   r)   r   ConflictingArgumentsExceptionr	   OrgPolicySimulatorApir   GetPolicyMessageFromFilenameInvalidArgumentExceptionorgpolicy_utilsGetResourceFromPolicyNameGetOrgPolicyPolicyOverlayappend"GetCustomConstraintMessageFromFile#GetOrgPolicyCustomConstraintOverlayGetOrgPolicyOverlayorganizationGetParentFromOrganization,GetPolicysimulatorOrgPolicyViolationsPreview'CreateOrgPolicyViolationsPreviewRequestclient8OrganizationsLocationsOrgPolicyViolationsPreviewsServiceCreateWaitForOperationformatr   JsonToMessage$GetOrgPolicyViolationsPreviewMessageMessageToJsonviolationsCountresourceCountsr   errPrintmessages^PolicysimulatorOrganizationsLocationsOrgPolicyViolationsPreviewsOrgPolicyViolationsListRequestKOrganizationsLocationsOrgPolicyViolationsPreviewsOrgPolicyViolationsServicer   YieldFromList)argsversionop_apir(   policy_filer$   r%   policy_overlayr)   custom_constraint_filer&   r'   constraint_overlayr*   organization_resourcer,   
violationsr-   
op_serviceviolations_preview_operationoperation_response_rawpreviewlist_violations_requestpov_services                           r    _Runrb   i   s
   	t66

2
2LN N44& (	]]}}--k.57f[[11BD 	D &??
++m77% 8 'n oon% % 	"&"9"9BB
 
 ##11$@B 	B "1!J!J

 
 ""!EE-#; F =  23 #: && ' @' +T->->>**+@A&BB C *::# ; ' }}UUmm*!+!2!2 "3 " "22".55
&
+
+-.
 ))113##$:;=' 
	 	 (>(>GGMMDE #OO  K  K\\ K iimm+ 
	!	!!%
' 'r"   c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)SimulateAlpha   *Simulate changes to organization policies.c                     [        U 5        gr   Nr!   r   s    r    ArgsSimulateAlpha.Args        vr"   c                 4    [        XR                  5       5      $ Nrb   ReleaseTrackselfrS   s     r    RunSimulateAlpha.Run       '')**r"    N__name__
__module____qualname____firstlineno____doc___DETAILED_HELPdetailed_helpstaticmethodrj   rs   __static_attributes__rv   r"   r    rd   rd      #     3 - +r"   rd   c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)SimulateBeta   rf   c                     [        U 5        grh   ri   r   s    r    rj   SimulateBeta.Args   rl   r"   c                 4    [        XR                  5       5      $ rn   ro   rq   s     r    rs   SimulateBeta.Run   ru   r"   rv   Nrw   rv   r"   r    r   r      r   r"   r   c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)
SimulateGA   rf   c                     [        U 5        grh   ri   r   s    r    rj   SimulateGA.Args   rl   r"   c                 4    [        XR                  5       5      $ rn   ro   rq   s     r    rs   SimulateGA.Run   ru   r"   rv   Nrw   rv   r"   r    r   r      r   r"   r   N)!r|   
__future__r   r   r   apitools.base.pyr   r    googlecloudsdk.api_lib.orgpolicyr   r8   *googlecloudsdk.api_lib.policy_intelligencer	   googlecloudsdk.callioper
   r   r   Bgooglecloudsdk.command_lib.policy_intelligence.simulator.orgpolicygooglecloudsdk.corer   r}   r!   rb   ReleaseTracksrp   ALPHADefaultUniverseOnlyCommandrd   BETAr   GAr   rv   r"   r    <module>r      s   % &  ' , ' E J / ( . T #
	
	
	
(V<S'l D%%++,+DLL +  -+ D%%**++4<< +  ,+ D%%(()+ +  *+r"   