-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from Wzb123456789/upload_hook
Upload request and response hook
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |