Skip to content

Commit

Permalink
Merge pull request #103 from Wzb123456789/upload_hook
Browse files Browse the repository at this point in the history
Upload request and response hook
  • Loading branch information
msyyc authored Sep 15, 2022
2 parents 8cd53c6 + b6b454e commit 1daaa64
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
30 changes: 30 additions & 0 deletions samples/network/raw_request_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json
import os

from azure.identity import DefaultAzureCredential
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.network.models import VirtualNetworkGateway


# This sample is just to show how to customize request if needed
def main():
credentials = DefaultAzureCredential()
subscription = os.getenv('SUBSCRIPTION_ID')

def callback(request):
origin_req = json.loads(request.http_request.body)
with open('result.json', 'w') as file:
file.write(json.dumps(origin_req, indent=4))

client = NetworkManagementClient(credentials, subscription)

virtual_network_gateway = client.virtual_network_gateways.begin_create_or_update(
resource_group_name='GROUP_NAME',
vm_name='NEW_VIRTUAL_NETWORK_GATEWAY',
parameters='vn_para',
raw_request_hook=callback
).result()


if __name__ == '__main__':
main()
29 changes: 29 additions & 0 deletions samples/network/raw_response_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json
import os

from azure.identity import DefaultAzureCredential
from azure.mgmt.network import NetworkManagementClient


# This sample is just to show how to customize response if needed
def main():

credentials = DefaultAzureCredential()
subscription = os.getenv('SUBSCRIPTION_ID')

def callback(response):
origin_req = json.loads(response.http_response.internal_response.text)
with open('result.json', 'w') as file:
file.write(json.dumps(origin_req, indent=4))

client = NetworkManagementClient(credentials, subscription)

virtual_network_gateway = client.network_managers.get(
resource_group_name='resource_group_name',
network_manager_name='network_manager_name',
raw_response_hook=callback
)


if __name__ == '__main__':
main()

0 comments on commit 1daaa64

Please sign in to comment.