
    @                         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rS rSS\4S jjrS rS r " S S5      r " S S5      rg)z5Functions to add standardized flags in PoCo commands.    )path)messages)protos)base)parser_arguments)parser_extensions)	resources)	constants)
exceptions)util)
console_iozpolicy-essentials-v2022c                  6    [         R                  " S[        SS9$ )Nz--fleet-default-member-configa  The path to a policy-controller.yaml configuration
        file. If specified, this configuration will become the default Policy
        Controller configuration for all memberships in your fleet. It can be
        overridden with a membership-specific configuration by using the
        the `Update` command.

        To enable the Policy Controller Feature with a fleet-level default
        membership configuration, run:

          $ {command} --fleet-default-member-config=/path/to/policy-controller.yaml
      typehelpr   Argumentstr     Hlib/googlecloudsdk/command_lib/container/fleet/policycontroller/flags.pyfleet_default_cfg_flagr   "   s    	%


 r   
include_noc                     SR                  U (       a  SOS5      n[        R                  " USSR                  SU5      S9$ )z/Flag for unsetting fleet default configuration.z--{}fleet-default-member-configzno- 
store_truezRemoves the fleet default configuration for policy controller.
      Memberships configured with the fleet default will maintain their current
      configuration.

          $ {} {}
      z	{command}actionr   )formatr   r   )r   flags     r   no_fleet_default_cfg_flagr!   4   s@    	*	1	1:%2	N$	


 &d
#	
 	r   c                      [         R                  " SSS9n U R                  [        5       5        U R                  [	        S5      5        U $ )z<Flag group for accepting a Fleet Default Configuration file.z4Flags for setting Fleet Default Configuration files.Tmutex)r   ArgumentGroupAddArgumentr   r!   )config_groups    r   fleet_default_cfg_groupr(   C   sE    ##<D, 1344T:;	r   c                  :    [         R                  " SS/[        SS9$ )z;Builds flag for setting configuration to the fleet default.z--originFLEETzaIf --origin=FLEET will set the configuration of the membership to
      the fleet default.
      )choicesr   r   r   r   r   r   origin_flagr,   M   s#    	i
	
 r   c                       \ rS rSrSrS\R                  S\4S jr\	S 5       r
\	S 5       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g)	PocoFlagsY   zHandle common flags for Poco Commands.

Use this class to keep command flags that touch similar configuration options
on the Policy Controller feature in sync across commands.
parsercommandc                     Xl         X l        g)zConstructor.

Args:
  parser: The argparse parser to add flags to.
  command: The command using this flag utility. i.e. 'enable'.
N)_parser_display_name)selfr0   r1   s      r   __init__PocoFlags.__init__`   s     L r   c                     U R                   $ N)r3   r5   s    r   r0   PocoFlags.parsern   s    <<r   c                     U R                   $ r9   )r4   r:   s    r   display_namePocoFlags.display_namer   s    r   c                 B    U R                   R                  S[        SS9  g)z7Adds handling for audit interval configuration changes.z--audit-intervalz=How often Policy Controller will audit resources, in seconds.r   Nr0   add_argumentintr:   s    r   add_audit_intervalPocoFlags.add_audit_intervalv   s"    KKL  r   c                 B    U R                   R                  S[        SS9  g)zCAdds handling for constraint violation limit configuration changes.z--constraint-violation-limitzSThe number of violations stored on the constraint resource. Must be greater than 0.r   Nr@   r:   s    r   add_constraint_violation_limit(PocoFlags.add_constraint_violation_limit~   s$    KK&"	  r   c                     U R                   R                  SSS9nUR                  S[        SS9  UR                  SSS	S
9  g)z4Adds handling for configuring exemptable namespaces.zExemptable Namespace flags.Tr#   z--exemptable-namespacesz^Namespaces that Policy Controller should ignore, separated by commas if multiple are supplied.r   z--clear-exemptable-namespacesr   zRemoves any namespace exemptions, enabling Policy Controller on all namespaces. Setting this flag will overwrite currently exempted namespaces, not append.r   N)r0   add_argument_grouprA   r   r5   groups     r   add_exemptable_namespaces#PocoFlags.add_exemptable_namespaces   s`    KK**%T + E 
!0	   
':	  r   c                 |    U R                   R                  SSS9nUR                  SSSS9  UR                  SSS	S9  g
)z(Adds handling for log denies enablement.zLog Denies flags.Tr#   z--no-log-deniesr   zIf set, disable all log denies.r   z--log-denieszNIf set, log all denies and dry run failures. (To disable, use --no-log-denies)Nr0   	add_grouprA   rJ   s     r   add_log_denies_enabled PocoFlags.add_log_denies_enabled   sX    KK!!"5T!BE	.  
 
 	  r   c                     U R                   R                  SSS9n[        R                  " USSS9  UR	                  SSSS	S
9  g)z6Adds handling for single, multiple or all memberships.zMembership flags.Tr#   zThe membership names to act on, separated by commas if multiple are supplied. Ignored if --all-memberships is supplied; if neither is supplied, a prompt will appear with all available memberships.)pluralmembership_helpz--all-membershipsr   zFIf supplied, apply to all Policy Controllers memberships in the fleet.F)r   r   defaultN)r0   rI   r	   AddMembershipResourceArgrA   rJ   s     r   add_membershipsPocoFlags.add_memberships   sZ    KK**+>d*KE&&		 
   r   c           	          U R                   R                  SSS9nUR                  S[        SR	                  SR                  [        R                  5      5      S9  UR                  SS	S
S9  g)z3Adds handling for monitoring configuration changes.zMonitoring flags.Tr#   z--monitoringzMonitoring backend options Policy Controller should export metrics to, separated by commas if multiple are supplied.  Setting this flag will overwrite currently enabled backends, not append. Options: {}z, r   z--no-monitoringr   zOInclude this flag to disable the monitoring configuration of Policy Controller.r   N)r0   rI   rA   r   r   joinr
   MONITORING_BACKENDSrJ   s     r   add_monitoringPocoFlags.add_monitoring   su    KK**+>d*KE	 "6$))I,I,I"JK  	 
"	  r   c                 |    U R                   R                  SSS9nUR                  SSSS9  UR                  SSS	S9  g
)z&Adds handling for mutation enablement.zMutation flags.Tr#   z--no-mutationr   zDisables mutation support.r   z
--mutationzDIf set, enable support for mutation. (To disable, use --no-mutation)NrO   rJ   s     r   add_mutationPocoFlags.add_mutation   sW    KK!!"34!@E	3O   
	  r   c                 :    U R                   R                  SSSS9  g)zcAdds handling for no content enablement.

This prevents the template library from being installed.
z--no-contentr   zaIf set, Policy content, including the template library and policy bundles, will not be installed.r   Nr0   rA   r:   s    r   add_no_contentPocoFlags.add_no_content   s&    
 	KK/	  r   c                 :    U R                   R                  SSSS9  g )Nz--no-default-bundlesr   z@If set, skip installing the default bundle of policy-essentials.r   rc   r:   s    r   add_no_default_bundles PocoFlags.add_no_default_bundles   s"    KKO  r   c                 |    U R                   R                  SSS9nUR                  SSSS9  UR                  SSS	S9  g
)z/Adds handling for referential rules enablement.zReferential Rules flags.Tr#   z--no-referential-rulesr   z#Disables referential rules support.r   z--referential-rulesz\If set, enable support for referential constraints. (To disable, use --no-referential-rules)NrO   rJ   s     r   add_referential_rulesPocoFlags.add_referential_rules  sX    KK!!"<D!IE	 2  
 
+	  r   c                 B    U R                   R                  S[        SS9  g)zAdds handling for version flag.z	--versionzHThe version of Policy Controller to install; defaults to latest version.r   N)r0   rA   r   r:   s    r   add_versionPocoFlags.add_version  s$    KK	  r   )r4   r3   N)__name__
__module____qualname____firstlineno____doc__r   ArgumentInterceptorr   r6   propertyr0   r=   rC   rF   rL   rQ   rX   r]   r`   rd   rg   rj   rm   __static_attributes__r   r   r   r.   r.   Y   s    !22! !    	."0,"	r   r.   c                      \ rS rSrSrS\R                  4S jrS\R                  S\R                  4S jr
S\R                  S\R                  4S jrS\R                  S\R                  4S	 jrS\R                  S\R                  4S
 jrS\R                  S\R                  4S jrS\R                  S\R                  4S jrS\R                  S\R                  4S jr\S\R                  4S j5       r\S\R                  4S j5       rS\R                  4S jrS\R                  S\R                  4S jr\S\R                  4S j5       rS\R                  S\R                  4S jrS\4S jrS\R                  4S jr\S\R                  4S j5       r\S\R                  4S j5       rS\R                  S\R                  4S jrS\R                  S\R                  4S jrS\4S jrS\R                  S\R                  S\R                  4S jr S\R                  S\R                  4S  jr!S!r"g")#PocoFlagParseri   zConverts PocoFlag arguments to internal representations.

hub_cfg references the PolicyControllerHubConfig object in:
third_party/py/googlecloudsdk/generated_clients/apis/gkehub/v1alpha/gkehub_v1alpha_messages.py
argsc                     Xl         X l        g r9   ry   r   )r5   ry   msgss      r   r6   PocoFlagParser.__init__'  s    IMr   hub_cfgreturnc                 r    U R                   R                  (       a  U R                   R                  Ul        U$ r9   )ry   audit_intervalauditIntervalSecondsr5   r~   s     r   update_audit_interval$PocoFlagParser.update_audit_interval+  s(     yy%)YY%=%=g"Nr   c                 r    U R                   R                  (       a  U R                   R                  Ul        U$ r9   )ry   constraint_violation_limitconstraintViolationLimitr   s     r   !update_constraint_violation_limit0PocoFlagParser.update_constraint_violation_limit2  s(     yy++)-)M)Mg&Nr   c                     U R                   R                  (       a  / nX!l        U R                   R                  (       a+  U R                   R                  R	                  S5      nX!l        U$ )N,)ry   clear_exemptable_namespacesexemptableNamespacesexemptable_namespacessplit)r5   r~   
namespacess      r   update_exemptable_namespaces+PocoFlagParser.update_exemptable_namespaces9  sN     yy,,j%/"yy&&992288=j%/"Nr   c                     U R                   R                  (       a  SUl        U R                   R                  (       a  SUl        U$ NTF)ry   
log_denieslogDeniesEnabledno_log_deniesr   s     r   update_log_denies PocoFlagParser.update_log_deniesD  s1    yy!%gyy!&gNr   c                     U R                   R                  (       a  SUl        U R                   R                  (       a  SUl        U$ r   )ry   mutationmutationEnabledno_mutationr   s     r   update_mutationPocoFlagParser.update_mutationK  s1    yy $gyy %gNr   c                    U R                   R                  (       ao  U R                  R                  5       Ul        U R                  R                  U R                  R
                  R                  R                  S9UR                  l        U$ )N)installation)	ry   
no_contentr   !PolicyControllerPolicyContentSpecpolicyContent%PolicyControllerTemplateLibraryConfigInstallationValueValuesEnumNOT_INSTALLEDtemplateLibraryr   s     r   update_no_content PocoFlagParser.update_no_contentR  sg    yy"mmMMOg.2mm.a.a}}JJfftt /b /g+ Nr   c                     U R                   R                  (       a  SUl        U R                   R                  (       a  SUl        U$ r   )ry   referential_rulesreferentialRulesEnabledno_referential_rulesr   s     r   update_referential_rules'PocoFlagParser.update_referential_rulesZ  s3     yy""(,g%yy%%(-g%Nr   c                 .    U R                   R                  $ r9   )r    PolicyControllerMonitoringConfigr:   s    r   monitoring_backend_cfg%PocoFlagParser.monitoring_backend_cfgc  s    ==999r   c                 .    U R                   R                  $ r9   )r    BackendsValueListEntryValuesEnumr:   s    r   monitoring_backend_enum&PocoFlagParser.monitoring_backend_enumg  s    &&GGGr   c                 6   [         R                  R                  U5      nUb,  [        U R                  [         R                  U   5      (       d%  [
        R                  " SR                  U5      5      e[        U R                  [         R                  U   5      $ )NzNo such monitoring backend: {})	r
   r\   gethasattrr   r   InvalidMonitoringBackendErrorr   getattr)r5   backendinternal_names      r   _get_monitoring_enum#PocoFlagParser._get_monitoring_enumk  s    1155g>MG$$%%g.% % 44
*
1
1'
:  

&
&

'
'
0 r   c                    U R                   R                  (       a  U R                  R                  / S9nX!l        U R                   R                  (       ac  U R                   R                  R                  S5       Vs/ s H  nU R                  U5      PM     nnU R                  R                  US9nX!l        U$ s  snf )z2Sets or removes monitoring backends based on args.)backendsr   )ry   no_monitoringr   r   
monitoringr   r   )r5   r~   configr   r   s        r   update_monitoring PocoFlagParser.update_monitoringz  s    yy}}==r=Jf!yy --33C88g 
#
#G
,8   }}==x=Pf!Ns   =B;c                 B    U R                   R                  R                  $ )zDReturns an reference to the BundlesValue class for this API channel.)r   r   BundlesValuer:   s    r   bundle_messagePocoFlagParser.bundle_message  s     ==::GGGr   c                 z   U R                   R                  (       d  U R                   R                  (       a  U$ U R                  U5      n[        R
                  " UR                  5      nU R                  R                  5       U[        '   [        R                  " U R                  5       U5      Ul        X!l        U$ )a4  Sets default bundles based on args.

This function assumes that the hub config is being initialized for the first
time.

Args:
  hub_cfg: A 'PolicyControllerHubConfig' proto message.

Returns:
  A modified hub_config, adding the default bundle; or unmodified if the
  --no-default-bundles flag is specified.
)ry   r   no_default_bundles_get_policy_contentr   additional_properties_to_dictbundlesr   !PolicyControllerBundleInstallSpecDEFAULT_BUNDLE_NAMEset_additional_propertiesr   r   )r5   r~   policy_content_specr   s       r   update_default_bundles%PocoFlagParser.update_default_bundles  s     yytyy;;n227;22##G 	779   #)"B"Bw# 0Nr   c                 h    U R                   R                  =(       d    U R                   R                  $ r9   )ry   fleet_default_member_configno_fleet_default_member_configr:   s    r   is_feature_update PocoFlagParser.is_feature_update  s&    		-- 	49933r   c                    U R                   R                  (       aj  [        R                  " U R                   R                  5      n[        R
                  " USS9n[        R                  " U R                  R                  U5      $ g )NF)binary)
ry   r   r   
expanduserr   ReadFromFileOrStdinr   Importr   PolicyControllerMembershipSpec)r5   config_pathdatas      r   load_fleet_default_cfg%PocoFlagParser.load_fleet_default_cfg  s^    yy,,OODII$I$IJk++
ed [[EEtLL -r   c                 .    U R                   R                  $ r9   )r   r   r:   s    r   template_lib_cfgPocoFlagParser.template_lib_cfg  s    ==>>>r   c                 .    U R                   R                  $ r9   )r   r   r:   s    r   template_lib_enum PocoFlagParser.template_lib_enum  s      <<<r   poco_cfgc                 h    UR                   c  U R                  R                  5       $ UR                   $ )z4Get or create new PolicyControllerPolicyContentSpec.)r   r   r   )r5   r   s     r   r   "PocoFlagParser._get_policy_content  s-    %]]<<>>!!!r   pococ                 r    U R                   R                  (       a  U R                   R                  Ul        U$ r9   )ry   version)r5   r   s     r   update_versionPocoFlagParser.update_version  s%    yyYY&&dlKr   c                 n    U R                   R                  =(       a    U R                   R                  S:H  $ )Nr*   )ry   originr:   s    r   use_default_cfgPocoFlagParser.use_default_cfg  s&    99;		 0 0G ;;r   feature
membershipc                     UR                   cE  UR                  R                  S5      S   nSn[        R                  " UR                  U5      5      eU R                  U5        UR                   R                  Ul        g)a  Sets membership to the default fleet configuration.

Args:
  feature: The feature spec for the project.
  membership: The membership spec being updated.

Returns:
  Updated MembershipFeatureSpec.
Raises:
  MissingFleetDefaultMemberConfig: If none exists on the feature.
N/   ztNo fleet default member config specified for project {}. Use '... enable --fleet-default-member-config=config.yaml'.)fleetDefaultMemberConfignamer   r   MissingFleetDefaultMemberConfigr   set_origin_fleetpolicycontroller)r5   r   r   projectmsgs        r   set_default_cfgPocoFlagParser.set_default_cfg  su     ''/""3'*gE 
 66szz'7JKK*%((99 r   c                     U R                   R                  U R                   R                  R                  R                  S9Ul        g )N)r   )r   OriginTypeValueValuesEnumr*   r   )r5   r   s     r   r  PocoFlagParser.set_origin_fleet  s7    ,,]]!!55;; - Jr   r{   N)#ro   rp   rq   rr   rs   r   	Namespacer6   r   Messager   r   r   r   r   r   r   ru   r   r   r   r   r   r   boolr   r   r   r   r   r   r   r  r  rv   r   r   r   rx   rx      s   ,66 %%%%	%%		x'7'7 H<L<L X%5%5 (:J:J x'7'7 H<L<L %% :h&6&6 : : Hx'7'7 H HX-=-= x'7'7 H<L<L   Hh.. H H%%> Mh&6&6 M ? 0 0 ? ? =!1!1 = ="(*:*: "x?O?O "!1!1 h6F6F 
<t <%%3;3C3C6)9)9 h>N>N r   rx   N)F)rs   osr   apitools.base.protorpcliter   7googlecloudsdk.api_lib.container.fleet.policycontrollerr   googlecloudsdk.callioper   r   r   *googlecloudsdk.command_lib.container.fleetr	   ;googlecloudsdk.command_lib.container.fleet.policycontrollerr
   r   !googlecloudsdk.command_lib.exportr   googlecloudsdk.core.consoler   r   r   r  r!   r(   r,   r.   rx   r   r   r   <module>r     sg    <  / J ( 4 5 @ Q R 2 2/ $$ 	D DNP Pr   