diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py index 55d982ddc64..9cee734a086 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py @@ -1391,7 +1391,7 @@ def test_helm_push(self, mock_requests_get, mock_get_access_credentials): mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password' - builtins_open = '__builtin__.open' if sys.version_info[0] < 3 else 'builtins.open' + builtins_open = 'builtins.open' # Push a chart with mock.patch(builtins_open) as mock_open: diff --git a/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_streaming_endpoint_scenarios.py b/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_streaming_endpoint_scenarios.py index 39001addfd4..4e0c7bd923a 100644 --- a/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_streaming_endpoint_scenarios.py +++ b/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_streaming_endpoint_scenarios.py @@ -4,7 +4,6 @@ # -------------------------------------------------------------------------------------------- import os -import sys from azure.cli.core.util import CLIError from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer, StorageAccountPreparer @@ -383,8 +382,6 @@ def test_ams_streaming_endpoint_start_async(self, storage_account_for_create): @ResourceGroupPreparer() @StorageAccountPreparer(parameter_name='storage_account_for_create') def test_ams_streaming_endpoint_stop_async(self, storage_account_for_create): - if sys.version_info.major == 2: # azure-cli/issues/9386 - return amsname = self.create_random_name(prefix='ams', length=12) streaming_endpoint_name = self.create_random_name(prefix="strep", length=12) diff --git a/src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/test_appconfig_commands.py b/src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/test_appconfig_commands.py index c6c270dcfb6..e8fcb12074e 100644 --- a/src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/test_appconfig_commands.py +++ b/src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/test_appconfig_commands.py @@ -2016,7 +2016,7 @@ def test_azconfig_json_content_type(self, resource_group, location): entry_feature = 'Beta' internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature default_description = "" - default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}" + default_conditions = "{{\'client_filters\': []}}" default_locked = False default_state = "off" self.kwargs.update({ @@ -2201,7 +2201,7 @@ def test_azconfig_feature(self, resource_group, location): internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature entry_label = 'v1' default_description = "" - default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}" + default_conditions = "{{\'client_filters\': []}}" default_locked = False default_state = "off" @@ -2513,7 +2513,7 @@ def test_azconfig_feature_namespacing(self, resource_group, location): feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + feature_prefix + feature_name entry_label = 'v1' default_description = "" - default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}" + default_conditions = "{{\'client_filters\': []}}" default_locked = False default_state = "off" @@ -2618,7 +2618,7 @@ def test_azconfig_feature_filter(self, resource_group, location): internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature entry_label = 'Standard' default_description = "" - default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}" + default_conditions = "{{\'client_filters\': []}}" default_locked = False default_state = "off" @@ -2986,7 +2986,7 @@ def test_azconfig_aad_auth(self, resource_group, location): entry_feature = 'Beta' internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature default_description = "" - default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}" + default_conditions = "{{\'client_filters\': []}}" default_locked = False default_state = "off" self.kwargs.update({ diff --git a/src/azure-cli/azure/cli/command_modules/botservice/bot_json_formatter.py b/src/azure-cli/azure/cli/command_modules/botservice/bot_json_formatter.py index 628d2974cb7..51c0c977d86 100644 --- a/src/azure-cli/azure/cli/command_modules/botservice/bot_json_formatter.py +++ b/src/azure-cli/azure/cli/command_modules/botservice/bot_json_formatter.py @@ -5,7 +5,6 @@ import base64 from collections import Counter -import sys from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend from azure.cli.core._profile import Profile @@ -107,10 +106,7 @@ def __decrypt_bot_file(bot_file_data, bot_file_secret, logger, password_only=Tru """ services = bot_file_data['services'] - if sys.version_info.major >= 3: - decrypt = BotJsonFormatter.__decrypt_py3 - else: - decrypt = BotJsonFormatter.__decrypt_py2 + decrypt = BotJsonFormatter.__decrypt if password_only: # Get all endpoints that have potentially valid appPassword values @@ -171,7 +167,7 @@ def __decrypt_bot_file(bot_file_data, bot_file_secret, logger, password_only=Tru return services @staticmethod - def __decrypt_py3(secret, encrypted_value, logger): + def __decrypt(secret, encrypted_value, logger): # If the string length is 0 or no secret was passed in, return the empty string. if not encrypted_value or not secret: return encrypted_value @@ -199,33 +195,3 @@ def __decrypt_py3(secret, encrypted_value, logger): decrypted_string = decrypted_bytes.decode('utf-8') return ''.join([char for char in decrypted_string if ord(char) > 31]) - - @staticmethod - def __decrypt_py2(secret, encrypted_value, logger): - # If the string length is 0 or no secret was passed in, return the empty string. - if not encrypted_value or not secret: - return encrypted_value - - parts = encrypted_value.split("!") - if len(parts) != 2: - logger.warn('Encrypted value "%s" not in standard encrypted format, decryption skipped.' % encrypted_value) - return encrypted_value - - iv_text = parts[0] - encrypted_text = parts[1] - iv_bytes = base64.standard_b64decode(iv_text) - secret_bytes = base64.standard_b64decode(secret) - - if len(iv_bytes) != 16: - logger.warn('Initialization Vector for "%s" not valid, decryption skipped.' % encrypted_value) - return encrypted_value - if len(secret_bytes) != 32: - logger.warn('Passed in secret length is invalid, decryption skipped.') - return encrypted_value - - cipher = Cipher(algorithms.AES(secret_bytes), modes.CBC(iv_bytes), backend=default_backend()) - decryptor = cipher.decryptor() - decrypted_bytes = decryptor.update(base64.standard_b64decode(encrypted_text)) + decryptor.finalize() - - decrypted_string = decrypted_bytes.encode('utf-8') - return ''.join([char for char in decrypted_string if ord(char) > 31]) diff --git a/src/azure-cli/azure/cli/command_modules/botservice/bot_publish_prep.py b/src/azure-cli/azure/cli/command_modules/botservice/bot_publish_prep.py index 9245959de46..9c8841a977f 100644 --- a/src/azure-cli/azure/cli/command_modules/botservice/bot_publish_prep.py +++ b/src/azure-cli/azure/cli/command_modules/botservice/bot_publish_prep.py @@ -4,7 +4,6 @@ # -------------------------------------------------------------------------------------------- import os -import sys import zipfile import requests @@ -99,12 +98,8 @@ def __retrieve_node_v4_publish_zip(): :return: zipfile.ZipFile instance """ response = requests.get('https://icscratch.blob.core.windows.net/bot-packages/node_v4_publish.zip') - if sys.version_info.major >= 3: - import io - return zipfile.ZipFile(io.BytesIO(response.content)) - # If Python version is 2.X, use StringIO instead. - import StringIO # pylint: disable=import-error - return zipfile.ZipFile(StringIO.StringIO(response.content)) + import io + return zipfile.ZipFile(io.BytesIO(response.content)) @staticmethod def __extract_specific_file_from_zip(logger, zip_file, web_config_exists, iisnode_yml_exists): diff --git a/src/azure-cli/azure/cli/command_modules/monitor/grammar/autoscale/AutoscaleConditionParser.py b/src/azure-cli/azure/cli/command_modules/monitor/grammar/autoscale/AutoscaleConditionParser.py index d9069556b6c..fd629dbed08 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/grammar/autoscale/AutoscaleConditionParser.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/grammar/autoscale/AutoscaleConditionParser.py @@ -8,10 +8,7 @@ from antlr4 import * from io import StringIO import sys -if sys.version_info[1] > 5: - from typing import TextIO -else: - from typing.io import TextIO +from typing import TextIO def serializedATN(): return [ @@ -1096,8 +1093,3 @@ def dim_value(self): finally: self.exitRule() return localctx - - - - - diff --git a/src/azure-cli/azure/cli/command_modules/monitor/grammar/metric_alert/MetricAlertConditionParser.py b/src/azure-cli/azure/cli/command_modules/monitor/grammar/metric_alert/MetricAlertConditionParser.py index 711c7f0c2ca..3734692f060 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/grammar/metric_alert/MetricAlertConditionParser.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/grammar/metric_alert/MetricAlertConditionParser.py @@ -6,12 +6,8 @@ # encoding: utf-8 # pylint: disable=all from antlr4 import * -from io import StringIO import sys -if sys.version_info[1] > 5: - from typing import TextIO -else: - from typing.io import TextIO +from typing import TextIO def serializedATN(): return [ diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index 74181ca85b4..f0b90a583e0 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -12,7 +12,6 @@ import os import re import ssl -import sys import uuid import base64 @@ -341,9 +340,6 @@ def _is_bicepparam_file_provided(parameters): def _ssl_context(): - if sys.version_info < (3, 4): - return ssl.SSLContext(ssl.PROTOCOL_TLSv1) - return ssl.create_default_context()