
                         X   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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<                  j>                         G d dej@                               Z!y)z6gcloud service-extensions wasm-actions create command.    )absolute_import)division)unicode_literalsN)apis)waiter)arg_parsers)base)concepts)flags)util)	yaml_data)labels_util)concept_parsers)presentation_specs)log)	resourcesc                  
    ddgS )z_Returns the possible values of the --supported-events flag.

  Returns:
    List of strings.
  zrequest-headerszresponse-headers r       5lib/surface/service_extensions/wasm_actions/create.py#_GetPossibleValuesOfSupportedEventsr   &   s     /	00r   c                     |j                         j                  dd      }t        | j                  j                  |      st        d|z         t        | j                  j                  |      S )a~  Converts the text representation of an event to enum.

  Args:
    messages: module containing the definitions of messages for the API.
    supported_event: string, for example 'request_headers'.

  Returns:
    a value of messages.WasmAction.SupportedEventsValueListEntryValuesEnum,
    for example
    messages.WasmAction.SupportedEventsValueListEntryValuesEnum.REQUEST_HEADERS
  -_zUnsupported value: )upperreplacehasattr
WasmAction'SupportedEventsValueListEntryValuesEnum
ValueErrorgetattr)messagessupported_eventuppercase_events      r   "_ConvertStringSupportedEventToEnumr%   /   si     $))+33C=/	$$LL 
" *_<
==	$$LL 
" "r   c                   p    e Zd ZdZ ej
                  d       ej
                  d      dZed        Zd Z	y)CreatezCreate a `WasmAction` resource.zS          Create a `WasmAction` resource that uses the specified plugin.
          a>            To create a `WasmAction` called `my-action` using the
          `my-plugin` plugin, run:

          $ {command} my-action --wasm-plugin=my-plugin

          You may also specify the full resource path to a plugin, for example,
          `projects/my-project/locations/global/wasmPlugins/my-plugin`
          )DESCRIPTIONEXAMPLESc                    t         j                  j                  d      }t         j                  j                  d      }t        j                  t        j                  dt        j                  j                  |j                         t        j                  | j                                     dd      t        j                  dt        j                  j                  |j                         t        j                  | j                                     d	d
did      gddgi      j                  |       |j                  dt!        j"                  t%                     ddg t'        j(                  d             t*        j,                  j                  |       t/        j0                  |       t3        j4                  |       y )Nzservice_extensions.wasmActionzservice_extensions.wasmPluginwasm_action)api_versionzThe ID of the `WasmAction`.T)requiredz--wasm-pluginz.ID of the `WasmPlugin` to use for this action.location )flag_name_overridesr-   z--wasm-plugin.locationzwasm_action.location)command_level_fallthroughsz--supported-events)choicesFEVENTzf          Specify the portion of the request/response payload to be processed by
          the plugin.)typer-   metavardefaulthelp)r   ResourceYAMLDataFromPathr   ConceptParserr   ResourcePresentationSpecr
   ResourceSpecFromYamlGetDatar   GetApiVersionReleaseTrackAddToParseradd_argumentr   ArgListr   textwrapdedentr	   
ASYNC_FLAGr   AddCreateLabelsFlagsr   AddDescriptionFlag)clsparserwasm_action_datawasm_plugin_datas       r   ArgszCreate.Args\   s    11::') 11::') !!77%%..$,,. $ 2 233C3C3E F / H . 77%%..$,,. $ 2 233C3C3E F / H A%/$4	
$ %'=&>$
%( ;v
  )L)NO__    	 	OO'$$V,	V$r   c           
      h   t        j                  | j                               }t        j                  d|      }|j
                  j                  j                         }|j
                  j                  j                         }t        j                  ||j                  j                        }|j                  D cg c]  }t        ||       }}|j                  |j!                         j#                         |j%                         |j                  |j#                         |j&                  ||            }	t        j(                  d|      }
|
j*                  j-                  |	      }t.        j0                  j3                  dj5                  |j%                                      |j6                  r:t.        j0                  j3                  dj5                  |j8                               |S t:        j<                  j?                  |j8                  d|      }tA        jB                  |
j*                  |
jD                        }tA        jF                  ||dj5                  |j8                              }t.        j0                  j3                  d	j5                  |j%                                      |S c c}w )
Nnetworkservices)
wasmPlugindescriptionlabelssupportedEvents)parentwasmActionId
wasmActionzCreate request issued for: [{}]z Check operation [{}] for status.z-networkservices.projects.locations.operations)
collectionr,   z&Waiting for operation [{}] to completezCreated WasmAction [{}].)$r   r?   r@   r   GetMessagesModuleCONCEPTSr+   Parsewasm_pluginr   ParseCreateArgsr   LabelsValuesupported_eventsr%   8NetworkservicesProjectsLocationsWasmActionsCreateRequestParentRelativeNameNamerQ   GetClientInstanceprojects_locations_wasmActionsr'   r   statusPrintformatasync_namer   REGISTRYParseRelativeNamer   CloudOperationPollerprojects_locations_operationsWaitFor)selfargsr,   r"   wasm_action_refwasm_plugin_refrR   eventconverted_eventsrequestclientop_refop_resourcepollerresults                  r   Runz
Create.Run   sA   $$T%6%6%89K%%&7EHmm//557Omm//557O((x/B/B/N/NOF **,*E 	+8U;*  , OO%%'446$))+&&&335((,	 ' 
 P 	G ##$5{CF2299'BFJJ6==  ! {{	jj9@@MNm $$66B 7 !K (()N)N)/)M)MOF^^077DFF JJ/667K7K7MNOMO,s   :J/N)
__name__
__module____qualname____doc__rD   rE   detailed_helpclassmethodrM   r{   r   r   r   r'   r'   G   sP    ' (//   (//  -" +% +%Z/r   r'   )"r   
__future__r   r   r   rD   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   r	    googlecloudsdk.calliope.conceptsr
   -googlecloudsdk.command_lib.service_extensionsr   r   $googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   r   r   r%   ReleaseTracksr@   ALPHACreateCommandr'   r   r   r   <module>r      s    = &  '  , . / ( 5 ? > : < D G # )1"0 D%%++,qT q -qr   