Skip to content

Commit

Permalink
[App Service] az functionapp create: Refactor EOL message (Azure#30791
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kamperiadis authored Feb 11, 2025
1 parent a00a332 commit 1ee9981
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4363,44 +4363,50 @@ def __init__(self, cmd, linux=False, windows=False):
self.KEYS = FUNCTIONS_STACKS_API_KEYS()
super().__init__(cmd, linux=linux, windows=windows)

def validate_end_of_life_date(self, runtime, version):
def validate_end_of_life_date(self, runtime, version, is_linux):
from dateutil.relativedelta import relativedelta
# we would not be able to validate for a custom runtime
if runtime == 'custom':
return

today = datetime.datetime.now(datetime.timezone.utc)
six_months = today + relativedelta(months=+6)
runtimes = [r for r in self.stacks if runtime == r.name]
runtimes = [r for r in self.stacks if r.linux == is_linux and runtime == r.name]
runtimes.sort(key=lambda r: r.end_of_life_date or
datetime.datetime.min.replace(tzinfo=datetime.timezone.utc), reverse=True)
matched_runtime = next((r for r in runtimes if r.version == version), None)
if matched_runtime:
eol = matched_runtime.end_of_life_date
runtime_deprecation_link = matched_runtime.deprecation_link
latest_runtime = runtimes[0].version

if eol is None:
return

if eol < today:
raise ValidationError('{} has reached EOL on {} and is no longer supported. {}'
.format(runtime, eol.date(), runtime_deprecation_link))
raise ValidationError('Use {} version {} as {} has reached end-of-life on {} and is '
'no longer supported. {}'
.format(runtime, latest_runtime, version, eol.date(), runtime_deprecation_link))
if eol < six_months:
logger.warning('%s will reach EOL on %s and will no longer be supported. %s',
runtime, eol.date(), runtime_deprecation_link)
logger.warning('Use %s version %s as %s will reach end-of-life on %s and will no '
'longer be supported. %s',
runtime, latest_runtime, version, eol.date(), runtime_deprecation_link)

def resolve(self, runtime, version=None, functions_version=None, linux=False, disable_version_error=False):
def resolve(self, runtime, version=None, functions_version=None, is_linux=False, disable_version_error=False):
stacks = self.stacks
runtimes = [r for r in stacks if r.linux == linux and runtime == r.name]
os = LINUX_OS_NAME if linux else WINDOWS_OS_NAME
runtimes = [r for r in stacks if r.linux == is_linux and runtime == r.name]
os = LINUX_OS_NAME if is_linux else WINDOWS_OS_NAME
if not runtimes:
supported_runtimes = [r.name for r in stacks if r.linux == linux]
supported_runtimes = [r.name for r in stacks if r.linux == is_linux]
raise ValidationError("Runtime {0} not supported for os {1}. Supported runtimes for os {1} are: {2}. "
"Run 'az functionapp list-runtimes' for more details on supported runtimes. "
.format(runtime, os, supported_runtimes))
if version is None:
matched_runtime_version = self.get_default_version(runtime, functions_version, linux)
matched_runtime_version = self.get_default_version(runtime, functions_version, is_linux)
self.validate_end_of_life_date(
matched_runtime_version.name,
matched_runtime_version.version
matched_runtime_version.version,
is_linux
)
return matched_runtime_version
matched_runtime_version = next((r for r in runtimes if r.version == version), None)
Expand All @@ -4422,7 +4428,8 @@ def resolve(self, runtime, version=None, functions_version=None, linux=False, di

self.validate_end_of_life_date(
runtime,
version
version,
is_linux
)

if not matched_runtime_version:
Expand All @@ -4441,8 +4448,8 @@ def resolve(self, runtime, version=None, functions_version=None, linux=False, di
.format(functions_version, runtime, version, os, supported_func_versions))
return matched_runtime_version

def get_default_version(self, runtime, functions_version, linux=False):
runtimes = [r for r in self.stacks if r.linux == linux and r.name == runtime]
def get_default_version(self, runtime, functions_version, is_linux=False):
runtimes = [r for r in self.stacks if r.linux == is_linux and r.name == runtime]
# sort runtimes by end of life date
runtimes.sort(key=lambda r: r.end_of_life_date or
datetime.datetime.min.replace(tzinfo=datetime.timezone.utc), reverse=True)
Expand Down

0 comments on commit 1ee9981

Please sign in to comment.