
    '                         d Z ddlmZ ddlmZ ddlmZ ddl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 Zd Ze
j,                   e
j.                  e
j0                  j2                  e
j0                  j4                  e
j0                  j6                         G d de
j8                                      Zy)z6gcloud service-extensions wasm-plugins update command.    )absolute_import)division)unicode_literalsN)wasm_plugin_api)wasm_plugin_version_api)base)
exceptions)flags)util)labels_util)logc                 b    | j                   yt        j                  | j                   d   |      S )aS  Converts the dict representation of the log_config to proto.

  Args:
    args: args with log_level parsed ordered dict. If log-level flag is set,
      enable option should also be set.
    api_version: API version (e.g. v1apha1)

  Returns:
    a value of messages.WasmPluginLogConfig or None,
    if log-level flag were not provided.
  Nr   )
log_configr   GetLogConfig)argsapi_versions     5lib/surface/service_extensions/wasm_plugins/update.py_GetLogConfigr   !   s-     
__			4??1-{	;;    c                 6    | j                   xs | j                  S )N)plugin_configplugin_config_file)r   s    r   GetPluginConfigDatar   3   s    				6t666r   c                   p    e Zd ZdZ ej
                  d       ej
                  d      dZed        Zd Z	y)UpdatezUpdate a `WasmPlugin` resource.a            Update an existing `WasmPlugin` resource and optionally create
          a `WasmPluginVersion` resource and set it as the main (serving) one.

          If `--image` is not specified:
              * the method only updates the `WasmPlugin` resource without
                creating a `WasmPluginVersion`.
              * the `--plugin-config***` flags are disallowed.
              * if `--main-version` is set, then the referenced
                `WasmPluginVersion` must already exist and it is set as the
                main (serving) one.

          If `--image` is specified:
              * the `--main-version` flag must also be specified.
              * the method updates the `WasmPlugin` resource and creates a new
                `WasmPluginVersion` with `--main-version` name and sets it as
                the main (serving) one.
              * the `--plugin-config***` flags are allowed.
              * the `--async` flag is disallowed.
      a            To update a `WasmPlugin` called `my-plugin`, run:

          $ {command} my-plugin --main-version=new-version
          --description="A new description." --labels=label1=value1

          To update a `WasmPlugin` called `my-plugin` and also create a new
          version called `v1` and set it as main:

          $ {command} my-plugin --main-version=v1
          --description="A new description." --labels=label1=value1
          --image=...-docker.pkg.dev/my-project/repository/container:tag
          )DESCRIPTIONEXAMPLESc                    t        j                  | j                               }t        j                  ||d       t
        j                  j                  |       t        j                  |       t        j                  |       t        j                  ||       t        j                  |d       |j                  j                  d       y )Nz%The ID of the `WasmPlugin` to update.)parserr   messageap  
            The ID of the `WasmPluginVersion` that should be the currently
            serving one. The version referred to must be a child of this
            `WasmPlugin`.

            If the `--image` flag was also provided, the `WasmPluginVersion`
            will be created for that `WasmPlugin` and will be set as the
            current main version.
        )r   version_messageyaml)r   GetApiVersionReleaseTrackr
   AddWasmPluginResourcer   
ASYNC_FLAGAddToParserr   AddCreateLabelsFlagsAddDescriptionFlagAddLogConfigFlagAddWasmPluginVersionArgsdisplay_info	AddFormat)clsr   r   s      r   ArgszUpdate.Argsb   s    $$S%5%5%78K	7 	OO'$$V,	V$	6;/	"" !!&)r   c           	      h   t        j                  | j                               }d }|j                  |j                  |j
                  sd}nG|j                  d}n8|j                  t        j                  dd      t        j                  dd      |j                  d      r"|j                  st        j                  dd      |s-t        |      |j                  t        j                  d	d
      |j                  j                  j                         }|j                  }|rt        j                   | j                               }|j#                  |j%                         ||j                  t        |      |j                        }t&        j(                  j+                  dj-                  |             |j/                  |dj-                  |j0                              }t&        j(                  j+                  dj-                  |             t3        j                   | j                               }	t5        j6                  ||	j8                  j:                  j<                        }
t?        ||      }g }|j                  d      r|jA                  d       |j                  d      r|jA                  d       |j                  d      r|jA                  d       |j                  d      r|jA                  d       |	jC                  |j%                         |djE                  tG        |            |jH                  |
|      }t&        j(                  j+                  dj-                  |jK                                      |j
                  r:t&        j(                  j+                  dj-                  |j0                               |S |	j/                  |dj-                  |j0                              }t&        j(                  j+                  dj-                  |jK                                      |S )NTFz--main-versionzGBoth flags --image and --main-version should be set or neither of them.z--asynczAIf --async flag is set, --image and --config flags can't be used.main_versionz$Flag --main-version cannot be empty.z>--plugin_config or --plugin_config_file or --plugin_config_urizUIf one of the flags is set, then --image and --main-version flags also should be set.)parentnameimageplugin_config_dataplugin_config_urizCreate request issued for: [{}]z&Waiting for operation [{}] to complete)operation_refr    zCreated WasmPluginVersion [{}].descriptionlabelsr   	logConfigmainVersionId,)r3   r1   update_maskr8   r9   r   zUpdate request issued for: [{}]z Check operation [{}] for status.zUpdated WasmPlugin [{}].)&r   r#   r$   r1   r4   async_calliope_exceptionsRequiredArgumentExceptionConflictingArgumentsExceptionIsSpecifiedr   r6   CONCEPTSwasm_pluginParser   ClientCreateWasmPluginVersionRelativeNamer   statusPrintformatWaitForOperationr3   r   r   ParseCreateArgsmessages
WasmPluginLabelsValuer   appendUpdateWasmPluginjoinsortedr8   Name)selfr   r   %update_wasm_plugin_and_create_versionwasm_plugin_refr1   
wpv_clientop_ref_	wp_clientr9   r   r=   results                 r   Runz
Update.Run   s   $$T%6%6%89K,0)%JJ".2+		.3+				"99
   ==

M 
 '0A0A99

0  1
d
#
/##/!??L)
 	
 mm//557O$$L,*11$2C2C2EFj11 --/

06 22 2 f 
jj8??MN

%
%:AA&++N & a 
jj8??MN&&t'8'8':;I((i  ++77F t[1JK&'!"%%')''))+!HHVK01$$ ( F JJ)001E1E1GH {{	jj9@@MNm''8??L ( F
 JJ/667K7K7MNOMr   N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpclassmethodr/   r^    r   r   r   r   7   sS    
 ( %X__ &
 ( "(// # +"-H * *:cr   r   )rb   
__future__r   r   r   rc   )googlecloudsdk.api_lib.service_extensionsr   r   googlecloudsdk.callioper   r	   r?   -googlecloudsdk.command_lib.service_extensionsr
   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   DefaultUniverseOnlyReleaseTracksr$   ALPHABETAGAUpdateCommandr   rg   r   r   <module>rt      s    = &  '  E M ( E ? > < #<$7 T..33T5F5F5I5IhT h hr   