
    L                         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	 S
\R                  5      rS rS rg)z;Common logic between commands on Config Management surface.    )utils)base)	constants)
exceptions)yamlz{} must be a YAML mapping node. This field should either contain indented key, value pairs or have the empty map {{}} as its value. See --help flag output for links to examples.zw{} must be a YAML list. This field should contain indented list elements. See --help flag output for links to examples.c                   \    \ 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\4S jrSrg)Common'   zCCommon operations between commands on Config Management surface.
  c           
          [         R                  " U5      n[        U5        U R                  R                  U R                  U5      U R                  U5      U R                  U5      U R                  U5      UR                  S0 5      R                  SS5      US   R                  [        R                  5      S9$ ! [         R                   a+  n[        R                  " SR	                  U5      U5      eSnAff = f)aP  Parse a Config Management membership spec from config_file_path.

Args:
  config_file_path: Path to file with syntax following the --config flag of
    the apply command.
Returns:
  config_management: Populated ConfigManagementMembershipSpec message.
Raises: Any errors during parsing. May not check semantic meaning of
  field values.
zInvalid config yaml file {}Nspeccluster )
configSyncpolicyControllerhierarchyController
managementr   version)r   	load_pathErrorr   format_validate_metamessagesConfigManagementMembershipSpec_parse_config_sync_parse_policy_controller"_parse_hierarchy_controller_config_parse_upgradesgetr   VERSION)selfconfig_file_pathconfiges       Klib/googlecloudsdk/command_lib/container/fleet/config_management/command.pyparse_config_managementCommon.parse_config_management+   s    ~~./f
 6 ==77**6266v> CCFK''/

62&**9b9v""5==1 8   :: 
'
.
./?
@! s   B= =C<&C77C<c                    SU;  d  [         R                  US   ;  a  g[        US   [         R                     [        5      (       d:  [        R
                  " [        R                  S[         R                  -   5      5      eUS   [         R                     n[        U[        R                  " [         R                  5      S   [         R                     5      nU(       ac  [        R
                  " SR                  SR                  U Vs/ s H#  nSR                  [         R                  U5      PM%     sn5      5      5      eU R                  R                  5       n[         R                  U;   a;  [!        U[         R                  U R#                  U[         R                     5      5        SUl        SU;   a
  US   Ul        UR'                  S	S
5      nUS
:X  a  U R)                  U5      Ul        OQUS:X  a  U R-                  U5      Ul        O4[        R
                  " SR                  [         R                  U5      5      eSU;   a
  US   Ul        SU;   a
  US   Ul        SU;   a
  US   Ul        SU;   a
  US   Ul        U$ s  snf )a  Load ConfigSync configuration with the parsed configmanagement yaml.

Args:
  configmanagement: dict, The data loaded from the config-management.yaml
    given by user.

Returns:
  config_sync: The ConfigSync configuration holds configmanagement.spec.git
  or configmanagement.spec.oci being used in MembershipConfigs
Raises: gcloud core Error, if the configSync field on configmanagement has
  invalid syntax. Note that this function does not check semantic meaning of
  field values, other than for .spec.configSync.sourceType.
r   N.spec.!Please remove illegal field(s) {}, z.spec.{}.{}Tenabled
sourceTypegitocizL.spec.{}.sourceType has illegal value {}. Please replace with `git` or `oci`sourceFormatstopSyncingpreventDriftmetricsGcpServiceAccountEmail)r   CONFIG_SYNC
isinstancedictr   r   MAP_NODE_EXCEPTION_FORMATr   _find_unknown_fieldsr   loadAPPLY_SPEC_VERSION_1joinr   ConfigManagementConfigSyncDEPLOYMENT_OVERRIDESsetattr_parse_deployment_overridesr+   r   _parse_git_configr-   _parse_oci_configr.   r/   r0   r1   r2   )r    configmanagementspec_sourceillegal_fieldsfconfig_syncsource_types          r$   r   Common._parse_config_syncM   sd     	&&$4V$<<&v.u/@/@A4HH
#
*
*8E4E4E+E
F  #6*5+<+<=K)+*.))E4N4N*O+1+3383D3D+FGN @GG
)),., #))%*;*;Q?,. / 	 	
 --::<K!![0


$
$

*
*%445 KK'	2k//,6Ke..{;ko		..{;ko0061	 	 $!,^!<k# +M :k$!,^!<k&+52=
)3k/ Q.s   *Jc                    [        U[        5      (       d:  [        R                  " [        R                  S[        R                  -   5      5      e/ nU H  n[        USS[        R                  15      nU(       aH  [        R                  " SR                  SR                  U Vs/ s H  nSU-   PM
     sn5      5      5      eUR                  U R                  R                  UR                  SS5      UR                  SS5      U R                  UR                  [        R                  / 5      5      S95        M     U$ s  snf )	z@Load DeploymentOverrides with the parsed config-management.yaml..spec.configSync.name	namespacer)   r*   z%.spec.configSync.deploymentOverrides.r   )deploymentNamedeploymentNamespace
containers)r4   listr   r   LIST_EXCEPTION_FORMATr   r   r<   r7   CONTAINER_OVERRIDESr:   appendr   "ConfigManagementDeploymentOverrider   _parse_containers)r    spec_deployment_overridesdeployment_overridesdeployment_overriderC   rD   s         r$   r>   "Common._parse_deployment_overrides   sB   /66

&
&!E$>$>> 
 8+
''n 
/66		++ <a?+ 
 	
 !!
--
:
:044VR@"5"9"9r# //%))%*C*CRH ; 
%  9:  #s   %E c                    [        U[        5      (       dN  [        R                  " [        R                  S[        R                  -   S-   [        R                  -   5      5      e/ nU H  n[        U1 Sk5      nU(       aH  [        R                  " SR                  SR                  U Vs/ s H  nSU-   PM
     sn5      5      5      eUR                  U R                  R                  UR                  SS5      UR                  S	S5      UR                  S
S5      UR                  SS5      UR                  SS5      S95        M     U$ s  snf )z7Load Containers with the parsed config-management.yaml.rI   .>   rJ   cpuLimit
cpuRequestmemoryLimitmemoryRequestr)   r*   z0.spec.configSync.deploymentOverrides.containers.rJ   r   r\   r^   r[   r]   )containerNamer\   r^   r[   r]   )r4   rO   r   r   rP   r   r   r<   rQ   r7   r:   rR   r   !ConfigManagementContainerOverrider   )r    spec_containersrN   	containerrC   rD   s         r$   rT   Common._parse_containers   sI   ot,,

&
&!**+ ))*  J$	+
	n 
/66		++ GJ+ 
 	
 
--
9
9%MM&"5"|R8%MM/2> }}Z4#--r: : ) %: s   *E
c                     U R                   R                  5       nSU;   a
  US   Ul        S H  nX1;   d  M
  [        X#X   5        M     U$ )zLoad GitConfig with the parsed config_sync yaml.

Args:
  spec_source: The config_sync dict loaded from the config-management.yaml
    given by user.

Returns:
  git_config: The GitConfig configuration being used in MembershipConfigs
syncWait)	policyDir
secretType
syncBranchsyncReposyncRev
httpsProxygcpServiceAccountEmail)r   ConfigManagementGitConfigsyncWaitSecsr=   )r    rB   
git_configfields       r$   r?   Common._parse_git_config   sT     88:J[  +J 7j 
	
;#56     c                     U R                   R                  5       nSU;   a
  US   Ul        S H  nX1;   d  M
  [        X#X   5        M     U$ )zLoad OciConfig with the parsed config_sync yaml.

Args:
  spec_source: The config_sync dict loaded from the config-management.yaml
    given by user.

Returns:
  oci_config: The OciConfig being used in MembershipConfigs
re   )rf   rg   ri   rl   )r   ConfigManagementOciConfigrn   r=   )r    rB   
oci_configrp   s       r$   r@   Common._parse_oci_config  sT     88:J[  +J 7j 
	
;#56 rr   c                    SU;  d	  SUS   ;  a  g[        US   S   [        5      (       d)  [        R                  " [        R                  S5      5      eUS   S   nSU;  a  [        R                  " S5      eUS   n[        U[        5      (       d  [        R                  " S5      eU R                  R                  5       n[        U1 Sk5      nU(       aH  [        R                  " S	R                  S
R                  U Vs/ s H  nSU-   PM
     sn5      5      5      eU H8  nUS:X  a!  U R                  X'   5      n[        XGU5        M*  [        XGX'   5        M:     U$ s  snf )a  Load PolicyController with the parsed config-management.yaml.

Args:
  configmanagement: dict, The data loaded from the config-management.yaml
    given by user.

Returns:
  policy_controller: The Policy Controller configuration for
  MembershipConfigs, filled in the data parsed from
  configmanagement.spec.policyController
Raises:
  gcloud core Error, if Policy Controller has invalid syntax. Note that
  this function does not check semantic meaning of field values other than
  monitoring backends.
r   r   Nz.spec.policyControllerr+   z5Missing required field .spec.policyController.enabledz4policyController.enabled should be `true` or `false`>   r+   
monitoringmutationEnabledlogDeniesEnabledauditIntervalSecondsexemptableNamespacesreferentialRulesEnabledtemplateLibraryInstalledr)   r*   z.spec.policyController.rx   )r4   r5   r   r   r6   r   boolr    ConfigManagementPolicyControllerr7   r:   _build_monitoring_msgr=   )	r    rA   spec_policy_controllerr+   policy_controllerrC   rD   rp   rx   s	            r$   r   Common._parse_policy_controller  s{   $ 	&&%5f%==&v./ABDII
#
*
*+C
D  .f56HI..
A  %Y/Ggt$$
@  FFH **@ 	C 	N @GG
)).I.Q.q0.I
J 	 	 (	,	//0F0MN
!*5!*@*GH (  Js   E c                   ^ [        U[        5      (       d)  [        R                  " [        R                  S5      5      eUR                  S/ 5      nU(       d  g[        R                  " U R                  5      mU4S jn U Vs/ s H
  oC" U5      PM     nnU R                  R                  US9$ s  snf ! [        [        4 a    [        R                  " S5      ef = f)a  Build PolicyControllerMonitoring message from the parsed spec.

Args:
  spec_monitoring: dict, The monitoring data loaded from the
    config-management.yaml given by user.

Returns:
  monitoring: The Policy Controller Monitoring configuration for
  MembershipConfigs, filled in the data parsed from
  configmanagement.spec.policyController.monitoring
Raises: gcloud core Error, if spec_monitoring is invalid, including its
  backend values.
z!.spec.policyController.monitoringbackendsNc                    > TR                  U R                  5       5      nU(       d%  [        R                  " SR	                  U 5      5      eU$ )Nz8policyController.monitoring.backend {} is not recognized)r   lowerr   r   r   )backendresult	converters     r$   convert-Common._build_monitoring_msg.<locals>.convertv  sE    }}W]]_-fFMM
 	

 mrr   zk.spec.policyController.monitoring.backend must be a sequence of strings. See --help flag output for details)r   )r4   r5   r   r   r6   r   r   r   monitoring_backend_converterr   	TypeErrorAttributeError*ConfigManagementPolicyControllerMonitoring)r    spec_monitoringr   r   r   monitoring_backendsr   s         @r$   r   Common._build_monitoring_msg]  s     ot,,
#
*
*+N
O  "":r2H 66t}}EI=EFX'WW-XF ==CC$ D   G~& : s   B6 B1B6 1B6 6'Cc                 x   SU;  d	  SUS   ;  a  g[        US   S   [        5      (       d)  [        R                  " [        R                  S5      5      eUS   S   nSU;  a  [        R                  " S5      e[        US   [        5      (       d  [        R                  " S5      eU R                  R                  5       n[        U1 Sk5      nU(       aH  [        R                  " S	R                  S
R                  U Vs/ s H  nSU-   PM
     sn5      5      5      eU H  n[        X6X&   5        M     U$ s  snf )a  Load HierarchyController with the parsed config-management.yaml.

Args:
  configmanagement: dict, The data loaded from the config-management.yaml
    given by user.

Returns:
  hierarchy_controller: The Hierarchy Controller configuration for
  MembershipConfigs, filled in the data parsed from
  configmanagement.spec.hierarchyController
Raises: gcloud core Error, if Hierarchy Controller has invalid syntax. Note
  that this function does not check semantic meaning of field values.
r   r   Nz.spec.hierarchyControllerr+   z8Missing required field .spec.hierarchyController.enabledz7hierarchyController.enabled should be `true` or `false`>   r+   enablePodTreeLabelsenableHierarchicalResourceQuotar)   r*   z.spec.hierarchyController.)r4   r5   r   r   r6   r   r   r   )ConfigManagementHierarchyControllerConfigr7   r:   r=   )r    rA   r   config_protorC   rD   rp   s          r$   r   )Common._parse_hierarchy_controller_config  sF     	&& (8(@@&v./DEtLL
#
*
*+F
G  F#$9:D
D  d9ot,,
C  ==JJLL *$ 1 N
 @GG
))^L^1!3^L
M 	 	 l4;/   Ms    D7returnc                    UR                  S0 5      R                  [        R                  S5      n[        R                  [        R                  [        R
                  /nSR                  S U 5       5      nX#;  a4  [        R                  " SR                  [        R                  U5      5      eU R                  R                  nU[        R                  :X  a  UR                  R                  $ UR                  R                  $ )a:  Parse configmanagement `.spec.upgrades` into management  enum.

Args:
  configmanagement: dict of file contents for --config flag on apply command
    that represents Config Management membership spec.
Returns:
  v1main ConfigManagementMembershipSpec management value.
Raises: gcloud core Error for invalid value.
r   r    c              3   .   #    U  H  nS U S 3v   M     g7f)'N ).0rp   s     r$   	<genexpr>)Common._parse_upgrades.<locals>.<genexpr>  s     ClUawaLls   z*The valid values of field .spec.{} are: {})r   r   UPGRADESUPGRADES_AUTOUPGRADES_MANUALUPGRADES_EMPTYr:   r   r   r   r   r   ManagementValueValuesEnumMANAGEMENT_AUTOMATICMANAGEMENT_MANUAL)r    rA   upgradeslegal_fieldsvalid_valuesspec_apis         r$   r   Common._parse_upgrades  s      ##FB/33ENNBGHL
 88ClCCL#
6
=
=nnl 
 }};;H5&&&//DDD//AAArr   r   N)__name__
__module____qualname____firstlineno____doc__r%   r   r>   rT   r?   r@   r   r   r   strr   __static_attributes__r   rr   r$   r	   r	   '   sK     DFP& P)V60@D+Z4lB Brr   r	   c                    [        U [        5      (       d  [        R                  " S5      e[	        U SS15      nU(       aH  [        R                  " SR                  SR                  U Vs/ s H  nSU-   PM
     sn5      5      5      eSU ;  a  [        R                  " S5      eU S   S:w  a  [        R                  " S	5      eSU ;  a  [        R                  " S
5      e[        U S   [        5      (       d)  [        R                  " [        R                  S5      5      e[	        U S   [        R                  [        R                  [        R                  [        R                  [        R                  [        R                  15      nU(       aH  [        R                  " SR                  SR                  U Vs/ s H  nSU-   PM
     sn5      5      5      egs  snf s  snf )zValidate the parsed configmanagement yaml.

Args:
  configmanagement: Data type loaded from yaml.
Raises: gcloud core Error, if the top-level fields have invalid syntax.
z"Invalid ConfigManagement template.applySpecVersionr   r)   r*   rZ   z(Missing required field .applySpecVersion   zOnly "applySpecVersion: 1" is supported. To use a later version,please fetch the config by running
gcloud container fleet config-management fetch-for-applyzMissing required field .specz.specr(   N)r4   r5   r   r   r7   r   r:   r6   r   r3   POLICY_CONTROLLERHNCCLUSTERr   r   )rA   illegal_root_fieldsrD   illegal_spec_fieldss       r$   r   r     s    
$d	+	+


?
@@,-=@  


>EE		"56"5Q3q5"567  
 //


E
FF()Q.


	C 
 ##


9
::	$V,d	3	3


4;;GD
EE,-=f-EiimmnnmmH  


>EE		':;':!8A:':;<   1 74 <s   +G;Gc                 L    / nU  H  nX1;  d  M
  UR                  U5        M     U$ )zReturns the list of string elements in source not in known_fields.

Args:
  source: The source iterable to check.
  known_fields: The collection of known fields.
)rR   )sourceknown_fieldsrC   rp   s       r$   r7   r7     s/     .e E"  
rr   N)r   <googlecloudsdk.command_lib.container.fleet.config_managementr   3googlecloudsdk.command_lib.container.fleet.featuresr   ;googlecloudsdk.command_lib.container.fleet.policycontrollerr   googlecloudsdk.corer   r   r6   rP   FeatureCommandr	   r   r7   r   rr   r$   <module>r      sO    B N D Q * $N 5 tBT   tBn*Zrr   