Skip to content

Commit c4d1bba

Browse files
committed
style and linter, fix test and errors
1 parent e739dd7 commit c4d1bba

67 files changed

Lines changed: 11185 additions & 25414 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/azure-cli/azure/cli/command_modules/appservice/_create_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ def get_site_availability(cmd, name):
341341
return availability
342342

343343

344-
def get_regional_site_availability(cmd, location, name, resource_group_name, auto_generated_domain_name_label_scope):
344+
def get_regional_site_availability(cmd, location, name, resource_group_name=None, # pylint: disable=unused-argument
345+
auto_generated_domain_name_label_scope=None): # pylint: disable=unused-argument
345346
""" This is used by az webapp up to verify if a site needs to be created or should just be deployed
346347
(regional check)"""
347348
from azure.mgmt.web.models import ResourceNameAvailabilityRequest

src/azure-cli/azure/cli/command_modules/appservice/appservice_domains.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def create_domain(cmd, resource_group_name, hostname, contact_info, privacy=True
151151

152152

153153
def show_domain_purchase_terms(cmd, hostname):
154-
from azure.mgmt.web.models import TopLevelDomainAgreementOption
154+
TopLevelDomainAgreementOption = cmd.get_models('TopLevelDomainAgreementOption')
155155
domain_identifier = NameIdentifier(name=hostname)
156156
web_client = web_client_factory(cmd.cli_ctx)
157157
hostname_availability = web_client.domains.check_availability(domain_identifier)

src/azure-cli/azure/cli/command_modules/appservice/custom.py

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@
6969
is_functionapp,
7070
is_linux_webapp,
7171
_rename_server_farm_props,
72-
_get_location_from_webapp,
7372
_normalize_flex_location,
7473
_normalize_location,
75-
get_pool_manager, use_additional_properties, get_app_service_plan_from_webapp,
74+
get_pool_manager, get_app_service_plan_from_webapp,
7675
get_resource_if_exists, repo_url_to_name, get_token,
7776
app_service_plan_exists, is_centauri_functionapp, is_flex_functionapp,
7877
_remove_list_duplicates, get_raw_functionapp,
@@ -4638,7 +4637,7 @@ def create_functionapp_slot(cmd, resource_group_name, name, slot, configuration_
46384637

46394638
docker_registry_server_url = parse_docker_image_name(image)
46404639

4641-
Site = cmd.get_models('Site')
4640+
Site, SitePatchResource = cmd.get_models('Site', 'SitePatchResource')
46424641
client = web_client_factory(cmd.cli_ctx)
46434642
site = client.web_apps.get(resource_group_name, name)
46444643
if not site:
@@ -4649,6 +4648,12 @@ def create_functionapp_slot(cmd, resource_group_name, name, slot, configuration_
46494648
poller = client.web_apps.begin_create_or_update_slot(resource_group_name, name, site_envelope=slot_def, slot=slot)
46504649
result = LongRunningOperation(cmd.cli_ctx)(poller)
46514650

4651+
# Azure service may default https_only to True during slot creation.
4652+
# Use PATCH to explicitly update the slot if https_only is False.
4653+
if not https_only:
4654+
patch_resource = SitePatchResource(https_only=False)
4655+
result = client.web_apps.update_slot(resource_group_name, name, slot, patch_resource)
4656+
46524657
if configuration_source:
46534658
update_slot_configuration_from_source(cmd, client, resource_group_name, name, slot, configuration_source,
46544659
image, registry_password,
@@ -5232,6 +5237,7 @@ def show_plan(cmd, resource_group_name, name):
52325237
client = web_client_factory(cmd.cli_ctx)
52335238
serverfarm_url_base = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/serverfarms/{}?api-version={}'
52345239
subscription_id = get_subscription_id(cmd.cli_ctx)
5240+
# pylint: disable-next=protected-access
52355241
serverfarm_url = serverfarm_url_base.format(subscription_id, resource_group_name, name, client._config.api_version)
52365242
request_url = cmd.cli_ctx.cloud.endpoints.resource_manager + serverfarm_url
52375243
response = send_raw_request(cmd.cli_ctx, "GET", request_url)
@@ -7519,15 +7525,15 @@ def _get_java_versions_from_windows_container(container_settings):
75197525
try:
75207526
settings_dict = container_settings.as_dict()
75217527
runtimes_array = settings_dict.get('runtimes', [])
7522-
except Exception:
7528+
except (AttributeError, TypeError, KeyError):
75237529
pass
75247530

75257531
# 4. Try serialize() if available
75267532
if not runtimes_array and hasattr(container_settings, 'serialize'):
75277533
try:
75287534
settings_dict = container_settings.serialize()
75297535
runtimes_array = settings_dict.get('runtimes', [])
7530-
except Exception:
7536+
except (AttributeError, TypeError, KeyError):
75317537
pass
75327538

75337539
for runtime_info in runtimes_array:
@@ -7611,7 +7617,7 @@ def _parse_major_version_windows(self, major_version, parsed_results, config_map
76117617
container_settings.is_auto_update)
76127618
# Look up EOL from the Java stack if the container doesn't have one
76137619
java_ver = self._extract_java_version_from_runtime(runtime.display_name) or \
7614-
("8" if java.startswith("1.8") else java.split('.')[0])
7620+
("8" if java.startswith("1.8") else java.split('.', maxsplit=1)[0])
76157621
runtime.eol_date = eol_date or (java_eol_map or {}).get(java_ver)
76167622
runtime.runtime_family = self._get_java_runtime_family(runtime.display_name)
76177623
runtime.version_label = self._get_java_version_label(runtime.display_name)
@@ -8266,11 +8272,13 @@ def update_functionapp_polling(cmd, resource_group_name, name, functionapp):
82668272
from azure.cli.core.commands.client_factory import get_subscription_id
82678273
client = web_client_factory(cmd.cli_ctx)
82688274
sub_id = get_subscription_id(cmd.cli_ctx)
8275+
# pylint: disable-next=protected-access
8276+
api_version = client._config.api_version
82698277
base_url = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/sites/{}?api-version={}'.format(
82708278
sub_id,
82718279
resource_group_name,
82728280
name,
8273-
client._config.api_version
8281+
api_version
82748282
)
82758283
url = cmd.cli_ctx.cloud.endpoints.resource_manager + base_url
82768284

@@ -9814,43 +9822,64 @@ def list_hc(cmd, name, resource_group_name, slot=None):
98149822

98159823
# reformats hybrid connection, to prune unnecessary fields
98169824
mod_list = []
9817-
# Handle both old SDK (additional_properties["value"]) and new SDK (direct access or iteration)
9825+
# Handle both old SDK (additional_properties["value"]) and new SDK (dict-like access)
98189826
items = []
98199827
if hasattr(listed_vals, 'additional_properties') and listed_vals.additional_properties:
98209828
items = listed_vals.additional_properties.get("value", [])
9821-
elif hasattr(listed_vals, 'value'):
9822-
items = listed_vals.value or []
9823-
elif hasattr(listed_vals, '__iter__'):
9824-
items = list(listed_vals)
9825-
9829+
else:
9830+
# Try dictionary-style access first (new SDK with hybrid dict/model nature)
9831+
try:
9832+
items = listed_vals["value"] or []
9833+
except (KeyError, TypeError):
9834+
# Fall back to attribute access (old SDK)
9835+
if hasattr(listed_vals, 'value'):
9836+
items = listed_vals.value or []
9837+
elif hasattr(listed_vals, '__iter__'):
9838+
items = list(listed_vals)
9839+
9840+
# Helper to get property value from either dict or object
9841+
def get_prop(props, prop_dict_key, prop_attr_name):
9842+
# Try dictionary-style access first (new SDK with hybrid dict/model)
9843+
try:
9844+
return props[prop_dict_key]
9845+
except (KeyError, TypeError):
9846+
pass
9847+
# Fall back to attribute access (old SDK)
9848+
return getattr(props, prop_attr_name, None)
9849+
98269850
for x in items:
9827-
# Handle both dict-like and object-like access
9828-
if isinstance(x, dict):
9829-
properties = x.get("properties", {})
9830-
x_id = x.get("id", "")
9831-
x_location = x.get("location")
9832-
x_name = x.get("name")
9833-
x_type = x.get("type")
9834-
else:
9851+
# Try dictionary-style access first (new SDK with hybrid dict/model nature)
9852+
try:
9853+
properties = x["properties"] or {}
9854+
x_id = x["id"] or ""
9855+
x_name = x["name"] or ""
9856+
x_type = x["type"] or ""
9857+
# location may not always be present
9858+
try:
9859+
x_location = x["location"]
9860+
except (KeyError, TypeError):
9861+
x_location = None
9862+
except (KeyError, TypeError):
9863+
# Fall back to attribute access (old SDK)
98359864
props = x.properties if hasattr(x, 'properties') else x
98369865
properties = props.as_dict() if hasattr(props, 'as_dict') else {}
98379866
x_id = x.id if hasattr(x, 'id') else ""
98389867
x_location = getattr(x, 'location', None)
98399868
x_name = x.name if hasattr(x, 'name') else ""
98409869
x_type = x.type if hasattr(x, 'type') else ""
9841-
98429870
resourceGroup = x_id.split("/")
9871+
98439872
mod_hc = {
98449873
"id": x_id,
98459874
"location": x_location,
98469875
"name": x_name,
98479876
"properties": {
9848-
"hostname": properties.get("hostname") if isinstance(properties, dict) else getattr(properties, 'hostname', None),
9849-
"port": properties.get("port") if isinstance(properties, dict) else getattr(properties, 'port', None),
9850-
"relayArmUri": properties.get("relayArmUri") if isinstance(properties, dict) else getattr(properties, 'relay_arm_uri', None),
9851-
"relayName": properties.get("relayName") if isinstance(properties, dict) else getattr(properties, 'relay_name', None),
9852-
"serviceBusNamespace": properties.get("serviceBusNamespace") if isinstance(properties, dict) else getattr(properties, 'service_bus_namespace', None),
9853-
"serviceBusSuffix": properties.get("serviceBusSuffix") if isinstance(properties, dict) else getattr(properties, 'service_bus_suffix', None)
9877+
"hostname": get_prop(properties, "hostname", "hostname"),
9878+
"port": get_prop(properties, "port", "port"),
9879+
"relayArmUri": get_prop(properties, "relayArmUri", "relay_arm_uri"),
9880+
"relayName": get_prop(properties, "relayName", "relay_name"),
9881+
"serviceBusNamespace": get_prop(properties, "serviceBusNamespace", "service_bus_namespace"),
9882+
"serviceBusSuffix": get_prop(properties, "serviceBusSuffix", "service_bus_suffix")
98549883
},
98559884
"resourceGroup": resourceGroup[4] if len(resourceGroup) > 4 else "",
98569885
"type": x_type
@@ -10781,6 +10810,7 @@ def _build_kudu_warmup_arm_url(params, instance_id=None):
1078110810
client = web_client_factory(params.cmd.cli_ctx)
1078210811
sub_id = get_subscription_id(params.cmd.cli_ctx)
1078310812
instances_segment = f"/instances/{instance_id}" if instance_id is not None else ""
10813+
# pylint: disable=protected-access
1078410814
if not params.slot:
1078510815
base_url = (
1078610816
f"subscriptions/{sub_id}/resourceGroups/{params.resource_group_name}/providers/Microsoft.Web/sites/"
@@ -10793,6 +10823,7 @@ def _build_kudu_warmup_arm_url(params, instance_id=None):
1079310823
f"{params.webapp_name}/slots/{params.slot}{instances_segment}/deployments"
1079410824
f"?api-version={client._config.api_version}&warmup=true"
1079510825
)
10826+
# pylint: enable=protected-access
1079610827
return params.cmd.cli_ctx.cloud.endpoints.resource_manager + base_url
1079710828

1079810829

@@ -10823,6 +10854,7 @@ def _build_onedeploy_arm_url(params, instance_id):
1082310854
client = web_client_factory(params.cmd.cli_ctx)
1082410855
sub_id = get_subscription_id(params.cmd.cli_ctx)
1082510856
instances_param = f"/instances/{instance_id}" if instance_id is not None else ""
10857+
# pylint: disable=protected-access
1082610858
if not params.slot:
1082710859
base_url = (
1082810860
f"subscriptions/{sub_id}/resourceGroups/{params.resource_group_name}/providers/Microsoft.Web/sites/"
@@ -10834,6 +10866,7 @@ def _build_onedeploy_arm_url(params, instance_id):
1083410866
f"{params.webapp_name}/slots/{params.slot}{instances_param}/extensions/onedeploy"
1083510867
f"?api-version={client._config.api_version}"
1083610868
)
10869+
# pylint: enable=protected-access
1083710870
return params.cmd.cli_ctx.cloud.endpoints.resource_manager + base_url
1083810871

1083910872

@@ -10843,10 +10876,12 @@ def _build_deploymentstatus_url(cmd, resource_group_name, webapp_name, slot, dep
1084310876
sub_id = get_subscription_id(cmd.cli_ctx)
1084410877

1084510878
slot_info = "/slots/" + slot if slot else ""
10879+
# pylint: disable-next=protected-access
10880+
api_version = client._config.api_version
1084610881
base_url = (
1084710882
f"subscriptions/{sub_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Web/sites/"
1084810883
f"{webapp_name}{slot_info}/deploymentStatus/{deployment_id}"
10849-
f"?api-version={client._config.api_version}"
10884+
f"?api-version={api_version}"
1085010885
)
1085110886
return cmd.cli_ctx.cloud.endpoints.resource_manager + base_url
1085210887

@@ -10935,6 +10970,7 @@ def _get_instance_id_internal(cmd, resource_group_name, webapp_name, slot):
1093510970
try:
1093610971
client = web_client_factory(cmd.cli_ctx)
1093710972
sub_id = get_subscription_id(cmd.cli_ctx)
10973+
# pylint: disable=protected-access
1093810974
if slot:
1093910975
base_url = (
1094010976
f"subscriptions/{sub_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Web/sites/"
@@ -10946,6 +10982,7 @@ def _get_instance_id_internal(cmd, resource_group_name, webapp_name, slot):
1094610982
f"subscriptions/{sub_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Web/sites/"
1094710983
f"{webapp_name}/instances?api-version={client._config.api_version}"
1094810984
)
10985+
# pylint: enable=protected-access
1094910986

1095010987
url = cmd.cli_ctx.cloud.endpoints.resource_manager + base_url
1095110988
response = send_raw_request(cmd.cli_ctx, "GET", url)
@@ -12361,4 +12398,3 @@ def _compute_checksum(input_bytes):
1236112398
logger.info("Computing the checksum of the file failed with exception:'%s'", ex)
1236212399

1236312400
return file_hash
12364-

0 commit comments

Comments
 (0)