
    _#                       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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dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#d Z$d!Z%d"Z&d#Z'd$Z(d%Z)d&Z*d'Z+d(Z,d)Z- G d* d+e
j\                        Z/y),zBWraps a Serverless Service message, making fields more convenient.    )absolute_importannotations)division)unicode_literalsN)List)
k8s_object)revision)traffic)threat_detection_utilzgcr.io/buildpacks/google-22/runz!networking.knative.dev/visibilityzcluster-localzrun.googleapis.com/iap-enabledzrun.googleapis.com/ingressz!run.googleapis.com/ingress-statusallinternalz!internal-and-cloud-load-balancingzrun.googleapis.com/minScalezrun.googleapis.com/maxScalez&run.googleapis.com/manualInstanceCountzrun.googleapis.com/scalingModezrun.googleapis.com/operation-idzrun.googleapis.com/presetsz"run.googleapis.com/build-image-urizrun.googleapis.com/build-idz.run.googleapis.com/build-environment-variablesz(run.googleapis.com/build-source-locationz(run.googleapis.com/build-function-targetz$run.googleapis.com/build-worker-poolz(run.googleapis.com/build-service-accountzrun.googleapis.com/build-namez#run.googleapis.com/build-base-imagez1run.googleapis.com/build-enable-automatic-updatesz"run.googleapis.com/source-locationz"run.googleapis.com/function-targetzrun.googleapis.com/image-uriz+run.googleapis.com/enable-automatic-updateszrun.googleapis.com/sourcesc                  @    e Zd ZdZdZd Z fdZed        Zed        Z	ed        Z
ed        Zed        Zej                  d	        Zed
        Zed        Zed        Zd Zed        Zed        Zed d       Zed        Zej                  d        Z fdZed        Zed        Zed        Zed        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zed        Z xZ S )!ServicezWraps a Serverless Service message, making fields more convenient.

  Setting properties on a Service (where possible) writes through to the
  nested Kubernetes-style fields.
  zserving.knative.devc                b    t        |   |i | t        j                  j                  | _        y N)super__init__	crtd_utilThreatDetectionStateDISABLEDthreat_detection_state)selfargskwargs	__class__s      )lib/googlecloudsdk/api_lib/run/service.pyr   zService.__init___   s)    	Gd%f%"+"@"@"I"ID    c                    | j                   j                  t              | j                   j                  t              | j                   j                  t              | j                   j                  t
              fS r   )r   get.RUN_FUNCTIONS_BUILD_SERVICE_ACCOUNT_ANNOTATION*RUN_FUNCTIONS_BUILD_WORKER_POOL_ANNOTATION'RUN_FUNCTIONS_BUILD_ENV_VARS_ANNOTATION(RUN_FUNCTIONS_BUILD_IMAGE_URI_ANNOTATIONr   s    r   run_functions_annotationsz!Service.run_functions_annotationsc   sb     	KLGHDEEF	 r   c                B   | j                   j                  j                  s<t        j                  | j                               | j                   j                  _        t        j                  j                  | j                   j                  | j                               }|S r   )	spectemplatemetadatar	   MakeMetaMessagesModuler
   RevisionTemplate)r   rets     r   r)   zService.templatel   sk    99&&$.$7$78K8K8M$Ndii!



$
$TYY%7%79L9L9N
OCJr   c                    | j                          t        j                  | j                  | j                  j
                        S r   )AssertFullObjectr	   AnnotationsFromMetadata	_messagesr)   r*   r%   s    r   template_annotationszService.template_annotationss   s4    --.. r   c                .    | j                   j                  S r   )r)   labelsr%   s    r   revision_labelszService.revision_labelsz   s    ==r   c                .    | j                   j                  S r   r)   namer%   s    r   revision_namezService.revision_name~   s    ==r   c                &    || j                   _        y r   r9   r   values     r   r;   zService.revision_name   s    DMMr   c                .    | j                   j                  S r   )statuslatestCreatedRevisionNamer%   s    r   latest_created_revisionzService.latest_created_revision   s    ;;000r   c                .    | j                   j                  S r   )r@   latestReadyRevisionNamer%   s    r   latest_ready_revisionzService.latest_ready_revision   s    ;;...r   c                    | j                   j                  D cg c]  }|j                  s|j                   c}S c c}w r   )r@   r   percentrevisionName)r   ts     r   serving_revisionszService.serving_revisions   s0    $(KK$7$7E$7q199ANN$7EEEs   <<c                    | j                   j                  xr# |j                  | j                   j                  k(  }|j                  xs |S )zCReturns True if the target's percent is part of the latest percent.)r@   rD   rH   latestRevision)r   targetis_latest_by_names      r   _ShouldIncludeInLatestPercentz%Service._ShouldIncludeInLatestPercent   sH     	++ 	G4;;#F#FF    5$55r   c                T     t         fd j                  j                  D              S )z<The percent of traffic the latest ready revision is serving.c              3  `   K   | ]%  }j                  |      r|j                  xs d  ' yw)r   N)rO   rG   ).0rM   r   s     r   	<genexpr>z1Service.latest_percent_traffic.<locals>.<genexpr>   s3      )F--f5 	!)s   +.)sumr@   r   r%   s   `r   latest_percent_trafficzService.latest_percent_traffic   s)      kk))  r   c                    | j                   j                  D ].  }| j                  |      s|j                  s"|j                  c S  y)z6A url at which we can reach the latest ready revision.N)r@   r   rO   url)r   rM   s     r   
latest_urlzService.latest_url   s;     ++%%		+	+F	3

zz & r   c                j    | j                   j                  d      }|sg S t        j                  |      S )zList of the Service's URLs.

    Returns:
      A list of the URLs present in the Service's run.googleapis.com/urls
      annotation. If this annotation is missing an empty list is returned
      instead.
    zrun.googleapis.com/urls)r   r    jsonloads)r   anns     r   urlszService.urls   s1     



8
9Ci::c?r   c                   | j                   }|r|d   S | j                  j                  j                  r | j                  j                  j                  S 	 | j                  j                  j                  S # t
        $ r Y y w xY w)Nr   )r]   _mr@   rW   domainAttributeError)r   r]   s     r   r`   zService.domain   si    99D!Wnww~~WW^^WW^^"""  s   A5 5	B Bc                    || j                   j                  _        	 || j                   j                  _        y # t        $ r Y y w xY wr   )r_   r@   rW   r`   ra   )r   r`   s     r   r`   zService.domain   s;    DGGNN$dggnn  s   9 	AAc                    | j                   du r&| j                  r| j                  | j                  k7  ryt        t        |          S )NF)!yellow)readyrE   rB   r   r   ReadySymbolAndColor)r   r   s    r   rg   zService.ReadySymbolAndColor   s?    

e&&((D,F,FF$355r   c                8    | j                   j                  d      S )Nz serving.knative.dev/lastModifierr   r    r%   s    r   last_modifierzService.last_modifier   s     BCCr   c                    | j                          t        j                  | j                  | j                  j                        S r   )r1   r   TrafficTargetsr3   r(   r%   s    r   spec_trafficzService.spec_traffic   s/    !!$..$))2C2CDDr   c                    | j                          t        j                  | j                  | j                  g       S | j                  j                        S r   )r1   r   rl   r3   r@   r%   s    r   status_trafficzService.status_traffic   sJ    !!dkk1 7;{{7J7J r   c                8    | j                   j                  d      S )Nz'run.googleapis.com/vpc-access-connectorri   r%   s    r   vpc_connectorzService.vpc_connector   s     IJJr   c                .    | j                   j                  S r   r)   imager%   s    r   rt   zService.image   s    ==r   c                &    || j                   _        y r   rs   r=   s     r   rt   zService.image   s    DMMr   c                @    | j                   j                  t              S r   )r   r    OPERATION_ID_ANNOTATIONr%   s    r   operation_idzService.operation_id   s     788r   c                *    || j                   t        <   y r   )r   rw   r=   s     r   rx   zService.operation_id   s    05D,-r   c                T    | j                   j                  t        j                        S r   )r   r    r	   DESCRIPTION_ANNOTATIONr%   s    r   descriptionzService.description   s    
 A ABBr   c                "    || j                   d<   y )Nzrun.googleapis.com/descriptionr   r=   s     r   r|   zService.description  s    9>D56r   c                |    | j                   j                  t        | j                   j                  t                    S )z?Returns the build source location from the service annotations.)r   r    .RUN_FUNCTIONS_BUILD_SOURCE_LOCATION_ANNOTATION3RUN_FUNCTIONS_SOURCE_LOCATION_ANNOTATION_DEPRECATEDr%   s    r   source_locationzService.source_location  s7     6?	
 r   c                B    | j                   j                  t        d      S )z9Returns the function target from the service annotations.N)r4   r    1SOURCE_DEPLOY_NO_BUILD_SOURCE_LOCATION_ANNOTATIONr%   s    r   *source_deploy_no_build_source_location_mapz2Service.source_deploy_no_build_source_location_map  s"     $$((94 r   )returnz	List[str])!__name__
__module____qualname____doc__API_CATEGORYKINDr   propertyr&   r)   r4   r7   r;   setterrB   rE   rJ   rO   rU   rX   r]   r`   rg   rj   rm   ro   rq   rt   rx   r|   r   r   __classcell__)r   s   @r   r   r   U   sP    ',	$J               1 1 / / F F6         
== 6 D D E E   K K   	<<    9 9 6 6 C C ? ?    r   r   )0r   
__future__r   r   r   r   rZ   typingr   googlecloudsdk.api_lib.runr	   r
   r   googlecloudsdk.command_lib.runr   r   DEFAULT_BASE_IMAGEENDPOINT_VISIBILITYCLUSTER_LOCALIAP_ANNOTATIONINGRESS_ANNOTATIONINGRESS_STATUS_ANNOTATIONINGRESS_ALLINGRESS_INTERNAL)INGRESS_INTERNAL_AND_CLOUD_LOAD_BALANCINGSERVICE_MIN_SCALE_ANNOTATIONSERVICE_MAX_SCALE_ANNOTATION MANUAL_INSTANCE_COUNT_ANNOTATIONSERVICE_SCALING_MODE_ANNOTATIONrw   PRESETS_ANNOTATIONr$   !RUN_FUNCTIONS_BUILD_ID_ANNOTATIONr#   r   .RUN_FUNCTIONS_BUILD_FUNCTION_TARGET_ANNOTATIONr"   r!   #RUN_FUNCTIONS_BUILD_NAME_ANNOTATIONRUN_FUNCTIONS_BUILD_BASE_IMAGE,RUN_FUNCTIONS_BUILD_ENABLE_AUTOMATIC_UPDATESr   3RUN_FUNCTIONS_FUNCTION_TARGET_ANNOTATION_DEPRECATED-RUN_FUNCTIONS_IMAGE_URI_ANNOTATION_DEPRECATED1RUN_FUNCTIONS_ENABLE_AUTOMATIC_UPDATES_DEPRECATEDr   KubernetesObjectr    r   r   <module>r      s   I & "  '   1 / . M6 9 11 ?  ,O )< < #K  "B ; 1 +O ($A !4 ( / / / / + + / / 'F #!F 7 -
 ) 4 ) 4 1O -1 2 5Q 1@j)) @r   