
    8                         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	Z G d
 dej                        Z G d dej                        Zy)z.Policy Controller content policy library code.    )absolute_import)division)unicode_literals)messages)protos)
exceptions)flagsbundle_namec                       e Zd ZdZd Zy)Flagsz>Flags common to Policy Controller content management commands.c                     | j                   j                  dd      }|j                  dt        d       |j                  ddd	
       y)zEAdds handling for configuring exempted namespaces on content bundles.zExempted Namespaces flags.T)mutexz--exempted-namespaceszdExempted namespaces are ignored by Policy Controller when applying constraints added by this bundle.)typehelpz--no-exempted-namespaces
store_truez:Removes all exempted namespaces from the specified bundle.)actionr   N)parseradd_argument_groupadd_argumentstr)selfgroups     Jlib/googlecloudsdk/command_lib/container/fleet/policycontroller/content.pyadd_exempted_namespaceszFlags.add_exempted_namespaces"   s^    KK**$D + E 
1	   
"I      N)__name__
__module____qualname____doc__r    r   r   r   r      s
    Fr   r   c                      e Zd ZdZed        Zedej                  fd       Zdej                  dej                  fdZ	d Z
dej                  dej                  fdZd	edej                  fd
Zdej                  fdZdej                  d	edej                  fdZdej                  dej                  fdZdej                  dej                  fdZy)
FlagParserz:Parses content flags for content policy library functions.c                 |    | j                   j                  %| j                   j                  j                  d      S g S )N,)argsexempted_namespacessplitr   s    r   r&   zFlagParser.exempted_namespaces9   s=     99((4 			%%++C0 r   returnc                 B    | j                   j                  j                  S )zDReturns an reference to the BundlesValue class for this API channel.)r   !PolicyControllerPolicyContentSpecBundlesValuer(   s    r   bundle_messagezFlagParser.bundle_messageA   s     ==::GGGr   policy_content_specc                 4   t        | j                  t              }|t        j                  d      t        j                  |j                        }| j                  | j                        ||<   t        j                  | j                         |      |_        |S )aZ  Installs a bundle to provided policy content spec message.

    This assumes the bundle is passed in the args of the namespace used to build
    this parser.

    Args:
      policy_content_spec: A 'PolicyControllerPolicyContentSpec' proto message.

    Returns:
      A modified policy_content_spec, adding the bundle from args.bundle_name.
    No bundle name specified!)getattrr%   ARG_LABEL_BUNDLEr   SafetyErrorr   additional_properties_to_dictbundles_ns_msgsr&   set_additional_propertiesr-   )r   r.   
new_bundler5   s       r   install_bundlezFlagParser.install_bundleF   s     $45J""#>??223F3N3NOG--(@(@AGJ"("B"Bw# r   c                 H    | j                   j                         }||_        |S )zABuilds the PolicyControllerBundleInstallSpec from namespace list.)r   !PolicyControllerBundleInstallSpecexemptedNamespaces)r   nsinstall_specs      r   r6   zFlagParser._ns_msgs_   s"    ==BBDL&(L#r   c                 h   t        | j                  t              }|t        j                  d      t        j                  |j                        }|j                  |d       }|$t        j                  dj                  |            t        j                  | j                         |      |_        |S )Nr0   zC{} is not installed.  Check that the name of the bundle is correct.)r1   r%   r2   r   r3   r   r4   r5   popNoSuchContentErrorformatr7   r-   )r   r.   doomed_bundler5   founds        r   remove_bundlezFlagParser.remove_bundlee   s     DII'78M""#>??223F3N3NOGKKt,E}));;A6-;P  #)"B"Bw# r   statec                     | j                   j                  j                  }t        ||d       }|$t	        j
                  dj                  |            |S )Nz"Invalid template install state: {})r   %PolicyControllerTemplateLibraryConfigInstallationValueValuesEnumr1   r   r3   rB   )r   rF   enumsenums       r   _get_template_install_enumz%FlagParser._get_template_install_enumx   sW    ;;WW 
 5%&D|""
.
5
5e
<  Kr   c                     |j                   j                  j                  	 | j                  j	                         S |j                   j                  j                  S )zGets the PolicyControllerPolicyContentSpec message from the hub config.

    Args:
      poco_cfg: The MembershipFeatureSpec message.

    Returns:
      The PolicyControllerPolicyContentSpec message or an empty one if not
      found.
    )policycontrollerpolicyControllerHubConfigpolicyContentr   r+   r   poco_cfgs     r   _extract_policy_contentz"FlagParser._extract_policy_content   sN     	!!;;II	 ]]<<>>$$>>LLLr   rR   c                     | j                  |      }| j                  j                  | j                  |            }||_        ||j
                  j                  _        |S )N)installation)rS   r   rH   rL   templateLibraryrN   rO   rP   )r   rR   rF   policy_contentnew_cfgs        r   _update_template_cfgzFlagParser._update_template_cfg   sd     11(;NmmAA44U; B G &-N" 77E Or   c                 &    | j                  |d      S )NALLrY   rQ   s     r   install_template_libraryz#FlagParser.install_template_library   s     $$Xu55r   c                 &    | j                  |d      S )NNOT_INSTALLEDr\   rQ   s     r   uninstall_template_libraryz%FlagParser.uninstall_template_library   s     $$X??r   N)r   r   r   r   propertyr&   r   Messager-   r9   r6   rE   r   rL   rS   rY   r]   r`   r    r   r   r"   r"   6   s   B  Hh.. H H!)!1!12!)!1!1&	c 	h6F6F 	M1A1A M"&&/26&&66
@&&@@r   r"   N)r   
__future__r   r   r   apitools.base.protorpcliter   7googlecloudsdk.api_lib.container.fleet.policycontrollerr   ;googlecloudsdk.command_lib.container.fleet.policycontrollerr   r	   r2   	PocoFlagsr   PocoFlagParserr"   r    r   r   <module>ri      sM    5 &  ' / J R M ! EOO .s@%% s@r   