Skip to content

Commit

Permalink
fix(amazon): support long AMI ID patterns in image lookup (#2381)
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Feb 21, 2018
1 parent 4c124a1 commit 66f3407
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class AmazonNamedImageLookupController {
private static final int MIN_NAME_FILTER = 3
private static final String EXCEPTION_REASON = 'Minimum of ' + MIN_NAME_FILTER + ' characters required to filter namedImages'

private static final AMI_GLOB_PATTERN = /^ami-([a-f0-9]{8}|[a-f0-9]{17})$/

private final Cache cacheView

@Autowired
Expand All @@ -69,7 +71,7 @@ class AmazonNamedImageLookupController {
List<NamedImage> list(LookupOptions lookupOptions, HttpServletRequest request) {
validateLookupOptions(lookupOptions)
String glob = lookupOptions.q?.trim()
def isAmi = glob ==~ /^ami-[a-z0-9]{8}$/
def isAmi = glob ==~ AMI_GLOB_PATTERN

// Wrap in '*' if there are no glob-style characters in the query string
if (!isAmi && !glob.contains('*') && !glob.contains('?') && !glob.contains('[') && !glob.contains('\\')) {
Expand Down Expand Up @@ -189,7 +191,7 @@ class AmazonNamedImageLookupController {
}

String glob = lookupOptions.q?.trim()
def isAmi = glob ==~ /^ami-[a-z0-9]{8}$/
def isAmi = glob ==~ AMI_GLOB_PATTERN
if (glob == "ami" || (!isAmi && glob.startsWith("ami-"))) {
throw new InvalidRequestException("Searches by AMI id must be an exact match (ami-xxxxxxxx)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class AmazonNamedImageLookupControllerSpec extends Specification {
notThrown(InvalidRequestException)

where:
query << ["ami_", "ami-12345678", "sami", "ami_12345678"]
query << ["ami_", "ami-12345678", "sami", "ami_12345678", "ami-1234567890abcdef0"]
}

private HttpServletRequest httpServletRequest(Map<String, String> tagFilters) {
Expand Down

0 comments on commit 66f3407

Please sign in to comment.