@@ -789,11 +789,16 @@ def enable_zip_deploy(cmd, resource_group_name, name, src, timeout=None, slot=No
789
789
import os
790
790
import requests
791
791
from azure .cli .core .util import should_disable_connection_verify
792
- # Read file content
792
+ # check if the app is a linux web app
793
+ app_is_linux_webapp = is_linux_webapp (app )
793
794
795
+ # Read file content
794
796
with open (os .path .realpath (os .path .expanduser (src )), 'rb' ) as fs :
795
797
zip_content = fs .read ()
796
798
logger .warning ("Starting zip deployment. This operation can take a while to complete ..." )
799
+ if app_is_linux_webapp and track_status is not None and track_status :
800
+ headers ["x-ms-artifact-checksum" ] = _compute_checksum (zip_content )
801
+
797
802
res = requests .post (zip_url , data = zip_content , headers = headers , verify = not should_disable_connection_verify ())
798
803
logger .warning ("Deployment endpoint responded with status code %d" , res .status_code )
799
804
@@ -6990,12 +6995,22 @@ def _get_onedeploy_status_url(params):
6990
6995
6991
6996
def _get_onedeploy_request_body (params ):
6992
6997
import os
6998
+ file_hash = None
6999
+ app_is_linux_webapp = False
6993
7000
6994
7001
if params .src_path :
6995
7002
logger .warning ('Deploying from local path: %s' , params .src_path )
7003
+
7004
+ if params .track_status is not None and params .track_status :
7005
+ client = web_client_factory (params .cmd .cli_ctx )
7006
+ app = client .web_apps .get (params .resource_group_name , params .webapp_name )
7007
+ app_is_linux_webapp = is_linux_webapp (app )
7008
+
6996
7009
try :
6997
7010
with open (os .path .realpath (os .path .expanduser (params .src_path )), 'rb' ) as fs :
6998
7011
body = fs .read ()
7012
+ if app_is_linux_webapp :
7013
+ file_hash = _compute_checksum (body )
6999
7014
except Exception as e : # pylint: disable=broad-except
7000
7015
raise ResourceNotFoundError ("Either '{}' is not a valid local file path or you do not have permissions to "
7001
7016
"access it" .format (params .src_path )) from e
@@ -7016,7 +7031,7 @@ def _get_onedeploy_request_body(params):
7016
7031
else :
7017
7032
raise ResourceNotFoundError ('Unable to determine source location of the artifact being deployed' )
7018
7033
7019
- return body
7034
+ return body , file_hash
7020
7035
7021
7036
7022
7037
def _update_artifact_type (params ):
@@ -7043,11 +7058,14 @@ def _make_onedeploy_request(params):
7043
7058
from azure .cli .core .util import should_disable_connection_verify
7044
7059
7045
7060
# Build the request body, headers, API URL and status URL
7046
- body = _get_onedeploy_request_body (params )
7061
+ body , file_hash = _get_onedeploy_request_body (params )
7047
7062
deploy_url = _build_onedeploy_url (params )
7048
7063
deployment_status_url = _get_onedeploy_status_url (params )
7049
7064
headers = _get_ondeploy_headers (params )
7050
7065
7066
+ if file_hash :
7067
+ headers ["x-ms-artifact-checksum" ] = file_hash
7068
+
7051
7069
# For debugging purposes only, you can change the async deployment into a sync deployment by polling the API status
7052
7070
# For that, set poll_async_deployment_for_debugging=True
7053
7071
logger .info ("Deployment API: %s" , deploy_url )
@@ -8322,3 +8340,16 @@ def _encrypt_github_actions_secret(public_key, secret_value):
8322
8340
8323
8341
def show_webapp (cmd , resource_group_name , name , slot = None ): # adding this to not break extensions
8324
8342
return show_app (cmd , resource_group_name , name , slot )
8343
+
8344
+
8345
+ def _compute_checksum (input_bytes ):
8346
+ file_hash = None
8347
+ try :
8348
+ import hashlib
8349
+ logger .info ("Computing checksum of the file ..." )
8350
+ file_hash = hashlib .sha256 (input_bytes ).hexdigest ()
8351
+ logger .info ("Computed checksum for deployment request header x-ms-artifact-checksum '%s'" , file_hash )
8352
+ except Exception as ex : # pylint: disable=broad-except
8353
+ logger .info ("Computing the checksum of the file failed with exception:'%s'" , ex )
8354
+
8355
+ return file_hash
0 commit comments