
    K                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ  e	j(                  e	j*                  j,                         G d dej.                               Zd Zd Zd Zy)zDThe command to describe the status of the Config Management Feature.    )absolute_import)division)unicode_literals)util)base)	resources)utils)log)yaml)semverc                   *    e Zd ZdZdZed        Zd Zy)Fetcha?  Prints the Config Management configuration applied to the given membership.

  The output is in the format that is used by the apply subcommand. The fields
  that have not been configured will be shown with default values.

  ## EXAMPLES

  To fetch the applied Config Management configuration, run:

    $ {command}
  configmanagementc                 .    t        j                  |       y N)r   AddMembershipResourceArg)clsparsers     @lib/surface/container/fleet/config_management/fetch_for_apply.pyArgsz
Fetch.Args/   s    &&v.    c                 p   t        j                  |ddd      }| j                         }d }t        j                  ||      }| j
                  j                  |j                        j                         D ]@  \  }}t        j                  |      t        j                  |      k(  s2|5|j                  }B |.t        j                  j                  dj                  |             t!        j"                  t        j$                        }|d   }	t'        ||	|       t)        ||	|       t+        ||	       |S )NT)prompt
autoselectsearchzMembership {} not initializedspec)r   ParseMembership
GetFeaturer	   !get_backfill_version_from_feature	hubclientToPyDictmembershipSpecsitemsr   MembershipPartialNamer   r
   statusPrintformatr   loadAPPLY_SPEC_VERSION_1merge_config_syncmerge_policy_controllermerge_hierarchy_controller)
selfargs
membershipfmembership_specversion	full_namer   templatefull_configs
             r   Runz	Fetch.Run3   s   %%Td4J 	AO55aDG>>2213D3DEKKM	4

$
$Y
/''
34// N 	jj6==jIJ yy334H6"Ko{G<O['B<Or   N)__name__
__module____qualname____doc__feature_nameclassmethodr   r6    r   r   r   r      s%    
 $,/ /r   r   c                 j   | r| j                   sy|t        j                     }| j                   j                  }| j                   j                  }| j                   j
                  | j                   j
                  |d<   n!|r|j                  s|r|j                  rd|d<   | j                   j                  r| j                   j                  |d<   |r9t        j                  |      t        j                  t        j                        k\  r0| j                   j                  r| j                   j                  |d<   n|d= |s|sy|r9t        j                  |      t        j                  t        j                        k\  r|rd|d<   n|r	d|d<   n|d= |d   rT|d   dk(  rL|j                  r|j                  |d	<   d
D ]+  }t        ||      st        ||      t        ||      ||<   - y|j                  r|j                  |d	<   dD ]+  }t        ||      st        ||      t        ||      ||<   - y)#  Merge configSync set in feature spec with the config template.

  ConfigSync has nested object structs need to be flatten.

  Args:
    spec: the ConfigManagementMembershipSpec message
    config: the dict loaded from full config template
    version: the version string of the membership
  NenabledTsourceFormatpreventDriftgit
sourceTypeocisyncWait)	policyDir
secretTypesyncRepogcpServiceAccountEmail)rG   
httpsProxyrH   
syncBranchrI   syncRevrJ   )
configSyncr	   CONFIG_SYNCrC   rE   r@   rI   rA   r   SemVerPREVENT_DRIFT_VERSIONrB   OCI_SUPPORT_VERSIONsyncWaitSecshasattrgetattr)r   configr2   csrC   rE   fields          r   r*   r*   P   s    
T__
e "##	__(OO++ByM 	##,,bm	__!!55B~	FMM'*fmm!!/  ##??77b
>	S
	FMM'*fmm/  b	b
<"\*e3
''bn 
e	e!4!@C'5	 ''bn 
e	e!4!@C'5	r   c                    | r| j                   sy|t        j                     }t        |t        j                           D ]I  }t	        | j                   |      st        | j                   |      1t        | j                   |      ||<   K | xs9 t        j                  |      t        j                  t        j                        k\  }| j                   j                  }|s|j                  dd       y|r||d<   yy)r?   N
monitoring)policyControllerr	   POLICY_CONTROLLERlistrT   rU   r   rP   MONITORING_VERSIONrZ   pop)r   rV   r2   crX   valid_versionspec_monitorings          r   r+   r+      s     
T**
U$$%!F52234e%%u-D))51=..6ah 5 + w!76==< "- ))44/	EE,%AlO r   c                    | r| j                   sy |t        j                     }t        |t        j                           D ]I  }t	        | j                   |      st        | j                   |      1t        | j                   |      ||<   K y r   )hierarchyControllerr	   HNCr]   rT   rU   )r   rV   r`   rX   s       r   r,   r,      so    	T--
UYY!F599%&e((%0D,,e4@1159ah 'r   N)r:   
__future__r   r   r   &googlecloudsdk.api_lib.container.fleetr   googlecloudsdk.callioper   calliope_base*googlecloudsdk.command_lib.container.fleetr   <googlecloudsdk.command_lib.container.fleet.config_managementr	   3googlecloudsdk.command_lib.container.fleet.featuresgooglecloudsdk.corer
   r   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackALPHADescribeCommandr   r*   r+   r,   r=   r   r   <module>rs      sx    K &  ' 7 9 @ N D # $ + ]77==>-D   - ?-`D(N&<	:r   