Skip to content

Commit 4349628

Browse files
committed
Refactor eol message
1 parent 5814523 commit 4349628

File tree

1 file changed

+15
-8
lines changed
  • src/azure-cli/azure/cli/command_modules/appservice

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4363,29 +4363,34 @@ def __init__(self, cmd, linux=False, windows=False):
43634363
self.KEYS = FUNCTIONS_STACKS_API_KEYS()
43644364
super().__init__(cmd, linux=linux, windows=windows)
43654365

4366-
def validate_end_of_life_date(self, runtime, version):
4366+
def validate_end_of_life_date(self, runtime, version, linux):
43674367
from dateutil.relativedelta import relativedelta
43684368
# we would not be able to validate for a custom runtime
43694369
if runtime == 'custom':
43704370
return
43714371

43724372
today = datetime.datetime.now(datetime.timezone.utc)
43734373
six_months = today + relativedelta(months=+6)
4374-
runtimes = [r for r in self.stacks if runtime == r.name]
4374+
runtimes = [r for r in self.stacks if r.linux == linux and runtime == r.name]
4375+
runtimes.sort(key=lambda r: r.end_of_life_date or
4376+
datetime.datetime.min.replace(tzinfo=datetime.timezone.utc), reverse=True)
43754377
matched_runtime = next((r for r in runtimes if r.version == version), None)
43764378
if matched_runtime:
43774379
eol = matched_runtime.end_of_life_date
43784380
runtime_deprecation_link = matched_runtime.deprecation_link
4381+
latest_runtime = runtimes[0].version
43794382

43804383
if eol is None:
43814384
return
43824385

43834386
if eol < today:
4384-
raise ValidationError('{} has reached EOL on {} and is no longer supported. {}'
4385-
.format(runtime, eol.date(), runtime_deprecation_link))
4387+
raise ValidationError('Use {} version {} as {} has reached end-of-life on {} and is '
4388+
'no longer supported. {}'
4389+
.format(runtime, latest_runtime, version, eol.date(), runtime_deprecation_link))
43864390
if eol < six_months:
4387-
logger.warning('%s will reach EOL on %s and will no longer be supported. %s',
4388-
runtime, eol.date(), runtime_deprecation_link)
4391+
logger.warning('Use %s version %s as %s will reach end-of-life on %s and will no '
4392+
'longer be supported. %s',
4393+
runtime, latest_runtime, version, eol.date(), runtime_deprecation_link)
43894394

43904395
def resolve(self, runtime, version=None, functions_version=None, linux=False, disable_version_error=False):
43914396
stacks = self.stacks
@@ -4400,7 +4405,8 @@ def resolve(self, runtime, version=None, functions_version=None, linux=False, di
44004405
matched_runtime_version = self.get_default_version(runtime, functions_version, linux)
44014406
self.validate_end_of_life_date(
44024407
matched_runtime_version.name,
4403-
matched_runtime_version.version
4408+
matched_runtime_version.version,
4409+
linux
44044410
)
44054411
return matched_runtime_version
44064412
matched_runtime_version = next((r for r in runtimes if r.version == version), None)
@@ -4422,7 +4428,8 @@ def resolve(self, runtime, version=None, functions_version=None, linux=False, di
44224428

44234429
self.validate_end_of_life_date(
44244430
runtime,
4425-
version
4431+
version,
4432+
linux
44264433
)
44274434

44284435
if not matched_runtime_version:

0 commit comments

Comments
 (0)