-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for IP Connect and partial for Quick connect. (#5800)
* Initial changes for ipconnect and quickconnect * adding endpoints for quickconnect/developer sku * stlying fixes * adding constant file with enum for skus * Documentation and final changes * Documentation and final changes * Documentation and final changes
- Loading branch information
Showing
9 changed files
with
192 additions
and
38 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
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
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,16 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=import-error,unused-import | ||
|
||
from enum import Enum | ||
|
||
|
||
class BastionSku(Enum): | ||
|
||
Basic = "Basic" | ||
Standard = "Standard" | ||
Developer = "Developer" | ||
QuickConnect = "QuickConnect" |
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
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
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,28 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import ipaddress | ||
from azure.cli.core.azclierror import InvalidArgumentValueError | ||
|
||
|
||
def validate_ip_address(namespace): | ||
if namespace.target_ip_address is not None: | ||
_validate_ip_address_format(namespace) | ||
|
||
|
||
def _validate_ip_address_format(namespace): | ||
if namespace.target_ip_address is not None: | ||
input_value = namespace.target_ip_address | ||
if ' ' in input_value: | ||
raise InvalidArgumentValueError("Spaces not allowed: '{}' ".format(input_value)) | ||
input_ips = input_value.split(',') | ||
if len(input_ips) > 8: | ||
raise InvalidArgumentValueError('Maximum 8 IP addresses are allowed per rule.') | ||
validated_ips = '' | ||
for ip in input_ips: | ||
# Use ipaddress library to validate ip network format | ||
ip_obj = ipaddress.ip_network(ip) | ||
validated_ips += str(ip_obj) + ',' | ||
namespace.target_ip_address = validated_ips[:-1] |
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
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 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=import-error,unused-import | ||
|
||
|
||
def _get_data_pod(cmd, resource_port, target_resource_id, bastion): | ||
from azure.cli.core._profile import Profile | ||
from azure.cli.core.util import should_disable_connection_verify | ||
import requests | ||
|
||
profile = Profile(cli_ctx=cmd.cli_ctx) | ||
auth_token, _, _ = profile.get_raw_token() | ||
content = { | ||
'resourceId': target_resource_id, | ||
'bastionResourceId': bastion.id, | ||
'vmPort': resource_port, | ||
'azToken': auth_token[1], | ||
'connectionType': 'nativeclient' | ||
} | ||
headers = {'Content-Type': 'application/json'} | ||
|
||
web_address = f"https://{bastion['dnsName']}/api/connection" | ||
response = requests.post(web_address, json=content, headers=headers, | ||
verify=(not should_disable_connection_verify())) | ||
|
||
return response.content.decode("utf-8") |
Oops, something went wrong.