
                         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d	lmZ  e
j                  e
j                  j                   e
j                  j"                  e
j                  j$                         G d
 de
j&                               Zy)z<Command for adding user defined fields to security policies.    )absolute_import)division)unicode_literals)base_classes)client)base)flags)security_policies_utilsc                   *    e Zd ZdZdZed        Zd Zy)AddUserDefinedFieldaI  Add a user defined field to a Compute Engine security policy.

  *{command}* is used to add user defined fields to security policies.

  ## EXAMPLES

  To add a user defined field run this:

    $ {command} SECURITY_POLICY \
       --user-defined-field-name=my-field \
       --base=ipv6 \
       --offset=10 \
       --size=3
  Nc                 P   t        j                         | _        | j                  j                  |d       |j	                  ddd       |j	                  dg ddd	
       |j	                  dt
        dd       |j	                  dt
        dd       |j	                  dd       y )Nupdate)operation_typez--user-defined-field-nameTz$The name for the user defined field.)requiredhelpz--base)ipv4ipv6tcpudpz.The base relative to which offset is measured.)choicesr   r   z--offsetzOOffset of the first byte of the field (in network byte order) relative to base.)typer   r   z--sizez.Size of the field in bytes. Valid values: 1-4.z--maskzIf specified, apply this mask (bitwise AND) to the field to ignore bits before matching. Encoded as a hexadecimal number (starting with "0x").)r   )r	   SecurityPolicyRegionalArgumentSECURITY_POLICY_ARGAddArgumentadd_argumentint)clsparsers     ?lib/surface/compute/security_policies/add_user_defined_field.pyArgszAddUserDefinedField.Args1   s    #BBDC''x'H
#3  
 .=	   !   =	         c                    t        j                  | j                               }| j                  j	                  ||j
                        }t        j                  ||j                        }|j                         d   }t        j                  |j                  |      }|j                  }|j                  |       |j                  j                  j                  ||j                        }|j                  |      S )N)refcompute_clientr   )userDefinedFieldsfingerprint)security_policy)r   ComputeApiHolderReleaseTrackr   ResolveAsResource	resourcesr   SecurityPolicyDescriber
   CreateUserDefinedFieldr%   appendmessagesr&   Patch)	selfargsholderr#   r'   existing_security_policyuser_defined_fielduser_defined_fieldsupdated_security_policys	            r   RunzAddUserDefinedField.RunX   s    **4+<+<+>?F

"
"
4
4T6;K;K
LC++O  /779!<0GGt 3DD12$mm44CC-,88 D 
   1H IIr!   )__name__
__module____qualname____doc__r   classmethodr    r9    r!   r   r   r      s(     $ $LJr!   r   N)r=   
__future__r   r   r   googlecloudsdk.api_lib.computer   0googlecloudsdk.api_lib.compute.security_policiesr   googlecloudsdk.callioper   4googlecloudsdk.command_lib.compute.security_policiesr	   r
   ReleaseTracksr)   ALPHABETAGAUpdateCommandr   r?   r!   r   <module>rJ      s    C &  ' 7 C ( F X T..33T5F5F5I5ILJ$,, LJLJr!   