fix: force https for shopify webhook registration (#25630)

This commit is contained in:
Ankush Menat 2021-05-07 20:27:51 +05:30 committed by GitHub
parent da7fefe29d
commit e28165ea87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -37,7 +37,7 @@ class ShopifySettings(Document):
res = session.post(url, data=json.dumps({ res = session.post(url, data=json.dumps({
"webhook": { "webhook": {
"topic": method, "topic": method,
"address": get_webhook_address(connector_name='shopify_connection', method='store_request_data'), "address": get_webhook_address(connector_name='shopify_connection', method='store_request_data', force_https=True),
"format": "json" "format": "json"
} }
}), headers=get_header(self)) }), headers=get_header(self))

View File

@ -28,7 +28,7 @@ def validate_webhooks_request(doctype, hmac_key, secret_key='secret'):
return innerfn return innerfn
def get_webhook_address(connector_name, method, exclude_uri=False): def get_webhook_address(connector_name, method, exclude_uri=False, force_https=False):
endpoint = "erpnext.erpnext_integrations.connectors.{0}.{1}".format(connector_name, method) endpoint = "erpnext.erpnext_integrations.connectors.{0}.{1}".format(connector_name, method)
if exclude_uri: if exclude_uri:
@ -39,7 +39,11 @@ def get_webhook_address(connector_name, method, exclude_uri=False):
except RuntimeError: except RuntimeError:
url = "http://localhost:8000" url = "http://localhost:8000"
server_url = '{uri.scheme}://{uri.netloc}/api/method/{endpoint}'.format(uri=urlparse(url), endpoint=endpoint) url_data = urlparse(url)
scheme = "https" if force_https else url_data.scheme
netloc = url_data.netloc
server_url = f"{scheme}://{netloc}/api/method/{endpoint}"
return server_url return server_url