
    U                     N   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r " S S\5      r0 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*                  _\R*                  \R,                  \R,                  \R(                  \R(                  \R*                  \R*                  \R,                  \R,                  \R,                  \R*                  \R*                  \R,                  S .E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&S0 r'S1 r(S2 r)S3 r*S4 r+S5 r,S6 r-S7 r.S8 r/S9 r0S: r1 SAS; jr2S< r3S= r4S> r5S? r6S@ r7g)Bz-Utility functions for GCE OS Config commands.    )Enum)encoding)apis)base)
exceptions)common_args)log)
properties)	resources)yamlNc                   $    \ rS rSrSrSrSrSrSrg)InstanceDetailsStates!   z9Indicates instance progress during a patch job execution.          N)	__name__
__module____qualname____firstlineno____doc__NOTIFIEDPATCHINGFINISHED__static_attributes__r       9lib/googlecloudsdk/command_lib/compute/os_config/utils.pyr   r   !   s    A(((r   r   instancesAckedinstancesApplyingPatchesinstancesDownloadingPatchesinstancesFailedinstancesInactiveinstancesNotifiedinstancesPendinginstancesRebootinginstancesStartedinstancesSucceeded instancesSucceededRebootRequiredinstancesTimedOutinstancesRunningPrePatchStepinstancesRunningPostPatchStepinstancesNoAgentDetectedackedInstanceCountapplyingPatchesInstanceCount)downloadingPatchesInstanceCountfailedInstanceCountinactiveInstanceCountnotifiedInstanceCountpendingInstanceCountrebootingInstanceCountstartedInstanceCountsucceededInstanceCount$succeededRebootRequiredInstanceCounttimedOutInstanceCountprePatchStepInstanceCountpostPatchStepInstanceCountnoAgentDetectedInstanceCount)zgs://z&https://www.googleapis.com/storage/v1/zhttps://storage.googleapis.com/d   c                     U R                   (       a  U R                   $ U R                  (       a  [        U R                  [        5      $ g)z-Returns the batch size for listing resources.N)	page_sizelimitmin_MAX_LIST_BATCH_SIZE)argss    r   GetListBatchSizerD   R   s/    	^^>>zztzz/00r   c                 &    SR                  X/5      $ )z.Returns the URI path of a GCP parent resource./join)parent_name	parent_ids     r   GetParentUriPathrK   \   s    	;*	++r   c                     [        SU 5      $ )z&Returns the URI path of a GCP project.projectsrK   )projects    r   GetProjectUriPathrP   a   s    	*g	..r   c                 B    [        [        SU 5      [        SU5      5      $ )z/Returns the URI path of projects/*/locations/*.rM   	locationsrN   )rO   locations     r   GetProjectLocationUriPathrT   f   s#    	z7+{H-
/ /r   c                     [        SU 5      $ )z%Returns the URI path of a GCP folder.foldersrN   )folders    r   GetFolderUriPathrX   m   s    	)V	,,r   c                     [        SU 5      $ )z+Returns the URI path of a GCP organization.organizationsrN   )organizations    r   GetOrganizationUriPathr\   r   s    	/<	88r   c                 ,    SR                  SU SU/5      $ )z.Returns the URI path of an osconfig patch job.rF   rM   	patchJobsrG   )rO   	patch_jobs     r   GetPatchJobUriPathr`   w   s    	:wY?	@@r   c                 *    U R                  S5      S   $ )z0Returns the name of a GCP resource from its URI.rF   r   )split)uris    r   GetResourceNamerd   |   s    	3	r   c                 *    SR                  U SU/5      $ )z6Returns the relative path of an osconfig guest policy.rF   guestPoliciesrG   )parentguest_policys     r   GetGuestPolicyRelativePathri      s    	6?L9	::r   c                 *    SR                  U SU/5      $ )z>Returns the relative path of an osconfig os policy assignment.rF   osPolicyAssignmentsrG   )rg   os_policy_assignments     r   !GetOsPolicyAssignmentRelativePathrm      s    	602FG	HHr   c                 0    [         R                  " SU 5      $ )z7Returns the messages module with the given api_version.osconfig)r   GetMessagesModule)api_versions    r   GetApiMessagerr      s    			
K	88r   c                    U R                   R                  5       nU[        R                  R                  :X  a  gU[        R                  R                  :X  a  gU[        R                  R
                  :X  a  g[        R                  " U5      e)z7Return api version for the corresponding release track.v1alphav1betav1calliope_commandReleaseTrackr   ALPHABETAGAcore_exceptionsUnsupportedReleaseTrackErrorrC   release_tracks     r   GetApiVersionr      l    ''446-d''---))...)),,,

6
6}
EEr   c                    U R                   R                  5       nU[        R                  R                  :X  a  gU[        R                  R                  :X  a  gU[        R                  R
                  :X  a  g[        R                  " U5      e)z:Return v2 api version for the corresponding release track.v2alphav2betav2rw   r   s     r   GetApiVersionV2r      r   r   c                     U R                   R                  5       nU[        R                  R                  :X  a  gU[        R                  R                  :X  a   g[
        R                  " U5      e)z8Returns api version for the corresponding release track.zkTo check operation status, run: gcloud alpha compute os-config os-policy-assignments operations describe {}zeTo check operation status, run: gcloud compute os-config os-policy-assignments operations describe {})rx   ry   r   rz   r|   r}   r~   r   s     r   !GetOperationDescribeCommandFormatr      s`    ''446-d''---;)),,,	78 
6
6}
EEr   c           	         U R                  SR                  U5      SS9n[        R                  " SR                  X5      SR                  [        R
                  R                  R                  [        R
                  R                  R                  S9S9R                  U5        UR                  SS	[        S
R                  X5      S9  UR                  SS[        SR                  X5      S9  g)z;Adds project, folder, and organization flags to the parser.zi      The scope of the {}. If a scope is not specified, the current project is
      used as the default.T)helpmutexzThe project of the {} {}.aj        The project name to use. If a project name is not specified, then the
      current project is used. The current project can be listed using gcloud
      config list --format='text(core.project)' and can be set using gcloud
      config set project PROJECTID.

      `--project` and its fallback `{core_project}` property play two roles. It
      specifies the project of the resource to operate on, and also specifies
      the project for API enablement check, quota, and billing. To specify a
      different project for quota and billing, use `--billing-project` or
      `{billing_project}` property.
      )core_projectbilling_project)help_text_to_prependhelp_text_to_overwritez--folder	FOLDER_IDzThe folder of the {} {}.)metavartyper   z--organizationORGANIZATION_IDzThe organization of the {} {}.N)	add_groupformatr   ProjectArgumentr
   VALUEScorerO   billingquota_projectAddToParseradd_argumentstr)parsernounverbparent_resource_groups       r   AddResourceParentArgsr      s     **$fTl	 +  6==dI
 &!((--55$++33AA  CD EPK#E%$$%,,T8	 %  $$+224>	 % r   c                 ,    SR                  SU SU/5      $ )z5Returns the URI path of an osconfig patch deployment.rF   rM   patchDeploymentsrG   )rO   patch_deployments     r   GetPatchDeploymentUriPathr      s    	:w(:<LM	NNr   c                 *    SR                  XSU/5      $ )z1Returns the URI path of an osconfig guest policy.rF   rf   rG   )parent_typerI   	policy_ids      r   GetGuestPolicyUriPathr      s    	;_iH	IIr   c           	          [         R                  " U 5      n[        U[        5      (       d%  [        R                  " SR                  U 5      5      e[        UR                  5       5      n [        R                  " UU5      nXT4$ ! [         R                   a?  n[        R                  " SR                  U [        R                  " U5      5      5      eSnAf[         R                   a?  n[        R                  " SR                  U [        R                  " U5      5      5      eSnAff = f! [         a?  n[        R                  " SR                  U [        R                  " U5      5      5      eSnAff = f)z7Returns the resource message and update fields in file.z.Policy config file [{0}] cannot be parsed. {1}Nz6Policy config file [{0}] cannot be opened or read. {1}zGPolicy config file [{0}] is not a properly formatted YAML or JSON file.zKPolicy config file [{0}] is not a properly formatted YAML or JSON file. {1})r   	load_pathYAMLParseErrorr   BadFileExceptionr   six	text_typeFileLoadError
isinstancedictlistkeysr   PyValueToMessageAttributeError)	file_pathresource_message_typeresource_to_parseeupdate_fieldsresources         r   "GetResourceAndUpdateFieldsFromFiler      sI   	*y1 
%t	,	,

%
%	y!# # (--/0-9(()>):<H 	""1 
		 *

%
%8??s}}Q'	)* * 
		 *

%
%@GGs}}Q'	)* **  9

%
%	F9cmmA&679 99s;   B ,D- D*:CD*+:D%%D*-
E67:E11E6c                 <   Sn[          H:  nUR                  U5      (       d  M  [        R                  R	                  U5      n  O   U(       d  g[        US5      (       a  [        US5      (       d&  [        R                  " U SR                  U5      5      eUR                  R                  S5      n[        U5      S:w  d  US   R                  5       (       d&  [        R                  " U SR                  U5      5      eUR                  US	   [        US   5      S
.$ )zReturns information for a Google Cloud Storage object.

Args:
    arg_name: The name of the argument whose value may be a GCS object path.
    path: A string whose value may be a GCS object path.
Nbucketobjectz7The provided Google Cloud Storage path [{}] is invalid.#r   r   zWThe provided Google Cloud Storage path [{}] does not contain a valid generation number.r   )r   r   generationNumber)_GCS_PREFIXES
startswithr   REGISTRYParsehasattrr   InvalidArgumentExceptionr   r   rb   lenisdigitr   int)arg_namepathobj_refprefixobj_strs        r   GetGcsParamsr     s     'fv""((.g 
 
	(	#	#77H+E+E

-
-AHHNP P NN  %'\Qgaj0022

-
-	#VD\+ + 
gaj/
 r   c                     A [        U5      n[        U5      n[        UR                  UR                  5      u  nnXRl        UR                  5         SUR                  ;   a  SR                  U5      Ul	        U$ )zJReturns modified request with parsed OS policy assignment and update mask.update,)
r   rr   r   fileOSPolicyAssignmentoSPolicyAssignmentsortcommand_pathrH   
updateMask)refrC   reqrq   messagespolicy_assignment_configr   s          r   ParseOSConfigAssignmentFiler   .  sp    	d#+;'(6yy(--/3"""XXm,CN	*r   c                     US:X  a  U R                  5       $ US:X  a  U R                  5       $ US:X  a  U R                  5       $ [        R                  " U5      e)zBReturns the orchestration scope message for the given API version.r   r   r   ),GoogleCloudOsconfigV2alphaOrchestrationScope+GoogleCloudOsconfigV2betaOrchestrationScope'GoogleCloudOsconfigV2OrchestrationScoper}   r~   r   rq   s     r   GetOrchestrationScopeMessager   =  sX    I@@BBh??AAd;;==

6
6{
CCr   c                     US:X  a  U R                  5       $ US:X  a  U R                  5       $ US:X  a  U R                  5       $ [        R                  " U5      e)zKReturns the orchestration scope selector message for the given API version.r   r   r   )4GoogleCloudOsconfigV2alphaOrchestrationScopeSelector3GoogleCloudOsconfigV2betaOrchestrationScopeSelector/GoogleCloudOsconfigV2OrchestrationScopeSelectorr}   r~   r   s     r   $GetOrchestrationScopeSelectorMessager   I  sX    IHHJJhGGIIdCCEE

6
6{
CCr   c                     US:X  a  U R                  5       $ US:X  a  U R                  5       $ US:X  a  U R                  5       $ [        R                  " U5      e)zJReturns the resource hierarchy selector message for the given API version.r   r   r   )EGoogleCloudOsconfigV2alphaOrchestrationScopeResourceHierarchySelectorDGoogleCloudOsconfigV2betaOrchestrationScopeResourceHierarchySelector@GoogleCloudOsconfigV2OrchestrationScopeResourceHierarchySelectorr}   r~   r   s     r   #GetResourceHierarchySelectorMessager   U  sd    IVVX hUUW dQQS 
6
6{
CCr   c                     US:X  a  U R                  5       $ US:X  a  U R                  5       $ US:X  a  U R                  5       $ [        R                  " U5      e)z@Returns the location selector message for the given API version.r   r   r   )<GoogleCloudOsconfigV2alphaOrchestrationScopeLocationSelector;GoogleCloudOsconfigV2betaOrchestrationScopeLocationSelector7GoogleCloudOsconfigV2OrchestrationScopeLocationSelectorr}   r~   r   s     r   GetLocationSelectorMessager   g  s`    IMMO hLLN dKKMM

6
6{
CCr   c                    U R                   =(       ds    U=(       a    U R                  =(       dW    U R                  =(       dD    U=(       a    U R                  =(       d(    U R                  =(       d    U=(       a    U R
                  nU(       d  US4$ SnSnSn	U(       a  U R                  (       a  / nU(       a  U R                  (       a  / nU(       a  U R
                  (       a  / n	U R                   (       a8  / nU R                   R                  S5       H  n
UR                  SU
-   5        M     U R                  (       a8  / nU R                  R                  S5       H  nUR                  SU-   5        M     U R                  (       a5  / n	U R                  R                  S5       H  nU	R                  U5        M     UR                  (       d  [        X#5      Ul        SnSnUR                  R                  (       aG  UR                  R                   H-  nUR                  (       a  UnM  UR                  (       d  M+  UnM/     U(       d  [        X#5      nU(       d  [        X#5      nUU/UR                  l
        UR                  (       d  [        X#5      Ul        UR                  (       d  [        X#5      Ul        Ub  UUR                  l        Ub  UUR                  l        U	b  XR                  l        US4$ )at  Sets selectors inside policy orchestrator.

Args:
  args: args to the command
  req: request
  messages: messages for selected v2 API version
  api_version: api version
  orchestrator: orchestrator to set selectors in
  use_clear: if true, clear_projects flag is used to clear selectors
  (optional)

Returns:
  modified request, boolean  indicating if selectors were set
FNr   z	projects/zfolders/T)include_projectsclear_projectsinclude_foldersclear_foldersinclude_locationsclear_locationsrb   appendorchestrationScoper   	selectorsresourceHierarchySelectorlocationSelectorr   r   r   includedProjectsincludedFoldersincludedLocations)rC   r   r   rq   orchestrator	use_clearselectors_setincluded_projectsincluded_foldersincluded_locations
project_id	folder_idrS   hierarchy_selectorlocation_selectorselectors                   r   $ModifyOrchestratorPolicySetSelectorsr  w  s   $  .

+++.			. 
***. 
			.
 
,,,  
:  4&& 4%% 4''	++11#6
{Z78 7 
))//4	j945 5 
**005) 6 
	(	($X; #
 $$.. 33==		+	+%$$$$	 >
 
=	< /,!!+
 
	5	5+HB 0 
	+	+"89 & " 00A ! 00@ #;M&&8	dr   c                    [        U5      n[        U5      nUR                  5       nUR                  S:X  a"  [	        UR
                  UR                  5      u  pVSnUS:X  a,  UR                  5       nUR                  5       Ul        Xrl	        OcUS:X  a,  UR                  5       nUR                  5       Ul        Xrl        O1US:X  a+  UR                  5       nUR                  5       Ul        Xrl        UUR                  l        UR"                  (       a  UR"                  UR                  l        UR                  R'                  5       Ul        UR(                  R'                  5       Ul        [+        XXCU5      u  p&U R-                  5       Ul        SR1                  UR2                  R5                  S5      SS 5      Ul        U$ )FReturns modified request with parsed orchestartor's policy assignment.upsertNr   r   r   rF   )r   rr   r   actionr   policy_file,GoogleCloudOsconfigV2alphaPolicyOrchestrator.GoogleCloudOsconfigV2alphaOrchestratedResourceorchestratedResource,googleCloudOsconfigV2alphaPolicyOrchestrator+GoogleCloudOsconfigV2betaPolicyOrchestrator-GoogleCloudOsconfigV2betaOrchestratedResource+googleCloudOsconfigV2betaPolicyOrchestrator'GoogleCloudOsconfigV2PolicyOrchestrator)GoogleCloudOsconfigV2OrchestratedResource'googleCloudOsconfigV2PolicyOrchestratorosPolicyAssignmentV1Payloadr   idupperstater  NamepolicyOrchestratorIdrH   rg   rb   )r   rC   r   rq   r   r   _req_orchestrators           r   #ModifyOrchestrorPolicyCreateRequestr*    s     %+;'( &88:	[[H$F(55%! ILLN??A ) 8H4hKKM>>@ ) 7G3dGGI::< ) 3C/  ''C 
^^/3~~)), KK--/::++-/
(8&#
 !XXZ#xx

((-cr23#*	*r   c           	      J   [        U5      n[        U5      nSnUS:X  a  UR                  nO%US:X  a  UR                  nOUS:X  a  UR                  n/ nUR
                  (       a0  UR
                  R                  5       Ul        UR                  S5        UR                  (       aD  [        UR                  UR                  5      u  pxUUR                  l        UR                  S5        UR                  (       a,  UR                  UR                  l        UR                  S5        UR                  (       a0  UR                  R                  5       Ul        UR                  S5        [!        XXCUS	S
9u  p)U	(       a  UR                  S5        SR#                  U5      Ul        U$ )r  Nr   r   r   r  z5orchestrated_resource.os_policy_assignment_v1_payloadzorchestrated_resource.idr%  T)r  zorchestration_scope.selectorsr   )r   rr   r  r  r!  r  r$  r   r  r   r   r  r"  r   r#  r%  r  rH   r   )

unused_refrC   r   rq   r   r)  update_maskr   r(  modifieds
             r   #ModifyOrchestrorPolicyUpdateRequestr/    so     %+;'( IGGhFFdBB+	[["kk//1x 	$F(55%! 	! ))E ? 
^^/3~~)),12	ZZ!ZZ--/w6
(8D-# 6788K(#.	*r   c                 0    U=R                   S-  sl         U$ )z*Extends request with global location part.z/locations/global)rg   r,  unused_argsr   s      r   !ModifyOrchestrorPolicyListRequestr3  T  s     **##*	*r   c                     UR                   (       aA  [        R                  R                  [	        U5      R                  U R                  5      5        U $ )zReminds user of the command to check operation status.

Args:
  response: Response from CreateOsPolicyAssignment
  args: gcloud args

Returns:
  The original response
)async_r	   outPrintr   r   name)responserC   s     r   &LogOutOperationCommandForAsyncResponser:  [  s8     
[[GGMM)$/66x}}EG	/r   c                 .    UR                   S-   Ul         U$ )Nz/projectFeatureSettings)r8  r1  s      r   $UpdateProjectFeatureSettingsResourcer<  m  s    XX11#(	*r   )F)8r   enumr   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer}   r	   r
   r   r   r   r   r   r   r   INSTANCE_DETAILS_KEY_MAPr   rB   rD   rK   rP   rT   rX   r\   r`   rd   ri   rm   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r*  r/  r3  r:  r<  r   r   r   <module>rD     s   4  % , ( . < = # * ) $ 
D "+44"  5 > >" "#8#A#A	"
 ,55" .77" .77" -66" /88" -66" /88" '(=(F(F" .77" #$9$B$B" $%:%C%C"   5 > >!"& /88'"( #$9$B$B)"* (='E'E0992;;2;;1::3<<1::3<<,A,J,J2;;!6!?!?"7"@"@$9$B$BC" H4  ,
/
/-
9
A

;
I
9
FFF$NO
J
#> F	D	DD$D" ?Dnb3l3l$r   