
                            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dZ ej(                  ej*                  j,                         G d dej.                               Zee_        y)z5Set-custom-constraint command for the Org Policy CLI.    )absolute_import)division)unicode_literals)
exceptions)
completers)service)base)utils)logz      Sets a Custom Constraint from a JSON or YAML file. The custom
      constraint will be created if it does not exist, or updated if it
      already exists.
      z|      To set the custom constraint from the file on the path './sample_path', run:

        $ {command} ./sample_path
      )DESCRIPTIONEXAMPLESc                   &    e Zd ZdZed        Zd Zy)SetCustomConstraintz1Set a custom constraint from a JSON or YAML file.c                 J    | j                  ddt        j                  d       y )Ncustom_constraint_fileCUSTOM_CONSTRAINT_FILEz@Path to JSON or YAML file that contains the organization policy.)metavar	completerhelp)add_argumentr   FilesCompleter)parsers    1lib/surface/org_policies/set_custom_constraint.pyArgszSetCustomConstraint.Args1   s(    
 (++O	  Q    c                    t        j                  | j                               }t        j                  |j
                  | j                               }|j                  st        j                  d      |j                  j                  d      s%t        j                  d|j                  z   dz         	 |j                  |j                        }||k(  r|S |j!                  |      }t        j"                  |j                  d       |S # t        j                  $ r6 |j                  |      }t        j                  |j                  d       |cY S w xY w)a  Creates or updates a custom constraint from a JSON or YAML file.

    This first converts the contents of the specified file into a custom
    constraint object. It then fetches the current custom constraint using
    GetCustomConstraint. If it does not exist, the custom constraint is created
    using CreateCustomConstraint. If it does, the retrieved custom constraint is
    checked to see if it needs to be updated. If so, the custom constraint is
    updated using UpdateCustomConstraint.

    Args:
      args: argparse.Namespace, An object that contains the values for the
        arguments specified in the Args method.

    Returns:
      The created or updated custom constraint.
    z0Name field not present in the custom constraint.zorganizations/z+Name field contains invalid resource type: zC. Custom constraints can be created only on organization resources.zcustom constraint)org_policy_serviceOrgPolicyApiReleaseTrackr
   "GetCustomConstraintMessageFromFiler   namer   InvalidInputError
startswithGetCustomConstraintapi_exceptionsHttpNotFoundErrorCreateCustomConstraintr   CreatedResourceUpdateCustomConstraintUpdatedResource)selfargsorg_policy_apiinput_custom_constraintcustom_constraintcreate_responseupdate_responses          r   RunzSetCustomConstraint.Run9   sN   " (44T5F5F5HIN#FF##T%6%6%8:"''((
<> >"''223CD((
7
!
&
&'
OPQ Q(<<
!
&
&( 33$;;!O/446IJ ++ &==
!#o	1668KL	s   4D	 	AEEN)__name__
__module____qualname____doc__staticmethodr   r2    r   r   r   r   -   s    9Q Q)r   r   N)r6   
__future__r   r   r   apitools.base.pyr   r%   argcompleter    googlecloudsdk.api_lib.orgpolicyr   r   googlecloudsdk.callioper	   'googlecloudsdk.command_lib.org_policiesr
   googlecloudsdk.corer   DETAILED_HELPReleaseTracksr   GACommandr   detailed_helpr8   r   r   <module>rE      s}    < &  ' 9 " J ( > 9 #	
	
  D%%(()4$,, 4 *4n %2  !r   