Skip to content

Add utility method for parsing dual-stack and fips URIs #4612

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ShelbyZ
Copy link
Contributor

@ShelbyZ ShelbyZ commented May 1, 2025

Summary

Add a utility method to ecs-agent utils package to allow parsing a URI (string) and check if it matches ipv4, dual-stack regex patterns and if it is a FIPS endpoint.

Implementation details

Using 2 separate patterns for regex (ipv4/dual-stack) check if the supplied URI (string) matches either pattern. If it matches either pattern also check if the URI is a FIPS endpoint

Testing

make test and local debugging

New tests cover the changes: yes

Description for the changelog

Add utility method for parsing dual-stack and fips URIs

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions?
N/A

Does this PR include the addition of new environment variables in the README?
N/A

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

// 123456789.dkr.ecr.cn-north-1.amazonaws.com.cn/
// 98765432.dkr.starport.us-west-2.amazonaws.com/
// 98765432.dkr.starport-fips.us-west-2.amazonaws.com/
ECRImagePattern = regexp.MustCompile(`(^[a-zA-Z0-9][a-zA-Z0-9-_]*)\.dkr\.((ecr|starport)(` + FIPSKeyword + `)?)\.([\w\-_]+)\.([\w\.\-]+).*`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's check with team but i think starport is for Gamma so we might not want to expose it here. We will continue getting endpoint overrides for Gamma so it might not be necessary to check it there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

foundFips := (matchedPattern || matchedDualstackPattern) && strings.Contains(uri, FIPSKeyword)

logger.Info(fmt.Sprintf("URI: %s, Matched Pattern: %t, Matched Dualstack Pattern: %t, IsFIPS: %t", uri, matchedPattern, matchedDualstackPattern, foundFips))
return matchedPattern, matchedDualstackPattern, foundFips
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering what are the benefits of having three return outputs
vs (isDualStackPattern, isFipsPattern)

I might be wrong but image URI validation is done somewhere elses already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants