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

Add a fix for user validation. Still need to test #30563

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions src/azure-cli/azure/cli/command_modules/containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,15 @@ def _update_revision_env_secretrefs(containers, name):


def store_as_secret_and_return_secret_ref(secrets_list, registry_user, registry_server, registry_pass, update_existing_secret=False, disable_warnings=False):
def make_dns1123_compliant(name):
# Replace invalid characters with a hyphen and ensure lowercase
return re.sub(r'[^a-z0-9\-]', '-', name.lower())

if registry_pass.startswith("secretref:"):
# If user passed in registry password using a secret

registry_pass = registry_pass.split("secretref:")
if len(registry_pass) <= 1:
raise ValidationError("Invalid registry password secret. Value must be a non-empty value starting with \'secretref:\'.")
raise ValidationError("Invalid registry password secret. Value must be a non-empty value starting with 'secretref:'.")
registry_pass = registry_pass[1:]
registry_pass = ''.join(registry_pass)

Expand All @@ -526,9 +529,15 @@ def store_as_secret_and_return_secret_ref(secrets_list, registry_user, registry_
# If user passed in registry password
registry_server = registry_server.replace(':', '-')
if urlparse(registry_server).hostname is not None:
registry_secret_name = "{server}-{user}".format(server=urlparse(registry_server).hostname.replace('.', ''), user=registry_user.lower())
registry_secret_name = "{server}-{user}".format(
server=urlparse(registry_server).hostname.replace('.', ''),
user=make_dns1123_compliant(registry_user)
)
else:
registry_secret_name = "{server}-{user}".format(server=registry_server.replace('.', ''), user=registry_user.lower())
registry_secret_name = "{server}-{user}".format(
server=registry_server.replace('.', ''),
user=make_dns1123_compliant(registry_user)
)

for secret in secrets_list:
if secret['name'].lower() == registry_secret_name.lower():
Expand All @@ -548,7 +557,6 @@ def store_as_secret_and_return_secret_ref(secrets_list, registry_user, registry_

return registry_secret_name


def parse_list_of_strings(comma_separated_string):
comma_separated = comma_separated_string.split(',')
return [s.strip() for s in comma_separated]
Expand Down
Loading