
    -                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  S rSS jr  SS jrg)z/V1-specific utilities for function source code.    )absolute_import)division)unicode_literalsN)
exceptions)	cmek_util)util)source_util)log)filesc                 J    Sn[         R                  " X5      (       a  U S-   $ U $ )NzD^https://source\.developers\.google\.com/projects/[^/]+/repos/[^/]+$z/moveable-aliases/master)rematch)source_archive_urlcloud_repo_patterns     Alib/googlecloudsdk/command_lib/functions/v1/deploy/source_util.py_AddDefaultBranchr      s0     
 XX 55 :::	    c                 >   SnU(       a  U R                  US9nU R                  SR                  UR                  UR                  5      US9n UR                  U5      nUR                  $ ! [        R                   a  n[        R                  " Xs5        UeSnAff = f)z/Retrieves the upload url to upload source code.N)
kmsKeyNamezprojects/{}/locations/{})parentgenerateUploadUrlRequest)GenerateUploadUrlRequest@CloudfunctionsProjectsLocationsFunctionsGenerateUploadUrlRequestformat
projectsIdlocationsIdGenerateUploadUrl	uploadUrlhttp_exceptions	HttpErrorr   ProcessException)messagesservicefunction_refkms_keygenerate_upload_url_requestrequestresponsees           r   _GetUploadUrlr*   *   s     $"*"C"C #D # OO'..

!
!<#;#;  ; P  
((1H		"	" q*
Gs   A+ +B?BBc                 :   SU l         SU l        SU l        [        R                  " 5       nUc  SnU=(       d    SnUR                  S5      (       aD  UR                  S5      (       d%  [        R                  " SR                  U5      5        X l         S/$ UR                  S5      (       a   UR                  [        U5      S9U l        S	/$ [        R                  " 5        n[        R                  " UUUS
S9n[        R                   " 5       R"                  n	U(       a8  [        R$                  " XU5      n
U
R'                  5       U l         S/sSSS5        $ [)        XiX5      n[        R*                  " UUSS0S9  Xl        S/sSSS5        $ ! , (       d  f       g= f)aD  Add sources to function.

Args:
  function: The function to add a source to.
  function_ref: The reference to the function.
  source_arg: Location of source code to deploy.
  stage_bucket: The name of the Google Cloud Storage bucket where source code
    will be stored.
  ignore_file: custom ignore_file name. Override .gcloudignore file to
    customize files to be skipped.
  kms_key: KMS key configured for the function.

Returns:
  A list of fields on the function that have been changed.
Raises:
  FunctionsError: If the kms_key doesn't exist or GCF P4SA lacks permissions.
N.zgs://z.zipz[{}] does not end with extension `.zip`. The `--source` argument must designate the zipped source archive when providing a Google Cloud Storage URI.sourceArchiveUrlzhttps://)urlsourceRepositoryT)enforce_size_limitzx-goog-content-length-rangez0,104857600)extra_headerssourceUploadUrl)r-   r/   r2   api_utilGetApiMessagesModule
startswithendswithr
   warningr   SourceRepositoryr   
file_utilsTemporaryDirectoryr	   CreateSourcesZipFileGetApiClientInstanceprojects_locations_functionsUploadToStageBucketToUrlr*   UploadToGeneratedUrl)functionr$   
source_argstage_bucketignore_filer%   r"   tmp_dirzip_filer#   dest_object
upload_urls               r   SetFunctionSourcePropsrI   A   s   2 #("(!(**,(J S*7##v&& 
kk77=vj7I
 !+Z(( ( 9 9j) !: !H $$&'//	H ++-JJG33
,k #."3"3"5h ! '&  x,HJ$$ *=
  *7 '&&s    A,F,F
F)N)NN)__doc__
__future__r   r   r   r   apitools.base.pyr   r    googlecloudsdk.api_lib.functionsr   #googlecloudsdk.api_lib.functions.v1r   r3   $googlecloudsdk.command_lib.functionsr	   googlecloudsdk.corer
   googlecloudsdk.core.utilr   r9   r   r*   rI    r   r   <module>rS      s@    6 &  ' 	 : 6 @ < # 88 Nr   