Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Misc} Remove misc Python 2.7 fallbacks. #30474

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# --------------------------------------------------------------------------------------------

import os
import sys

from azure.cli.core.util import CLIError
from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer, StorageAccountPreparer
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# --------------------------------------------------------------------------------------------

import os
import sys
import zipfile
import requests

Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -1096,8 +1093,3 @@ def dim_value(self):
finally:
self.exitRule()
return localctx





Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
4 changes: 0 additions & 4 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os
import re
import ssl
import sys
import uuid
import base64

Expand Down Expand Up @@ -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()


Expand Down