
                         2   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
 ej                  ej                   ej                  ej                  j                  ej                  j                          G d d	ej"                                             Zy
)z!services policies update command.    )
exceptions)services_util)serviceusage)base)common_flags)yamlc                   &    e Zd ZdZed        Zd Zy)Updatea  Update consumer policy for a project, folder or organization.

  Update consumer policy for a project, folder or organization.

  ## EXAMPLES

  Update consumer policy

   $ {command} --consumer-policy-file=/path/to/the/file.yaml

  Validate the update action on the policy:

   $ {command} --consumer-policy-file=/path/to/the/file.yaml --validate-only

  Update consumer policy and bypass dependency check:

   $ {command} --consumer-policy-file=/path/to/the/file.yaml
   --bypass-dependency-check

  Update consumer policy and bypass api usage check:

   $ {command} --consumer-policy-file=/path/to/the/file.yaml
   --bypass-api-usage-check
  c                    t        j                         j                  |        t        j                  | d       t        j                         j                  |        t        j
                         j                  |        y )Nz	to update)suffix)r   consumer_policy_file_flagAddToParservalidate_only_argsbypass_api_usage_checkbypass_dependency_check)parsers    'lib/surface/services/policies/update.pyArgszUpdate.Args7   sW    **,88@##F;?'')55f=((*66v>    c                 V   |j                   j                  d      st        j                  d      t	        j
                  |j                         }t        |t              st        j                  d      d|vrt        j                  d      t        j                  ||j                  |j                  |j                        }t        j                  |j                  t        j                         }|j                  rt        j"                  |       yt        j$                  |       y)zRun command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Response from longrunning.operations from UpdateConsumerPolicy API call.
    z.yamlzHInvalid consumer_policy_file format. Please provide path to a yaml file.z<Invalid consumer-policy-file. Please provide a valid policy.namez/Invalid Consumer Policy. Please provide a name.)validate_onlyr   forceN)consumer_policy_fileendswithr   ConfigErrorr   	load_path
isinstancedictr   UpdateConsumerPolicyr   r   r   r   WaitOperationr   GetOperationV2BetaPrintOperationPrintOperationWithResponse)selfargspolicyops       r   Runz
Update.Run>   s     $$--g6"" 
 ^^D556Ffd#""
H  V""
;  
	*	*(( $ < <))	
B 
	$	$RWWl.M.M	NB""2&..r2r   N)__name__
__module____qualname____doc__staticmethodr   r)    r   r   r
   r
      s     2 ? ?(3r   r
   N)r-   googlecloudsdk.api_lib.servicesr   r   r   googlecloudsdk.callioper   #googlecloudsdk.command_lib.servicesr   googlecloudsdk.corer   UniverseCompatibleHiddenReleaseTracksReleaseTrackALPHABETACommandr
   r/   r   r   <module>r;      s    ( 6 9 8 ( < $ D%%++T->->-C-CDI3T\\ I3 E  I3r   