Skip to content

Commit

Permalink
Merge pull request #255 from ajordens/image-filters
Browse files Browse the repository at this point in the history
Generically pass additional image query parameters to clouddriver
  • Loading branch information
ajordens authored Jul 11, 2016
2 parents 17e641c + 6589dc5 commit 5e22b13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ interface ClouddriverService {
@Query("q") String query,
@Query("region") String region,
@Query("account") String account,
@Query("count") Integer count)
@Query("count") Integer count,
@QueryMap Map additionalFilters)

@Headers("Accept: application/json")
@GET("/search")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
package com.netflix.spinnaker.gate.controllers

import com.netflix.spinnaker.gate.services.ImageService
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import javax.servlet.http.HttpServletRequest

@CompileStatic
@RequestMapping("/images")
@RestController
class ImageController {
Expand All @@ -46,7 +45,13 @@ class ImageController {
@RequestParam(value = "q", required = false) String query,
@RequestParam(value = "region", required = false) String region,
@RequestParam(value = "account", required = false) String account,
@RequestParam(value = "count", required = false) Integer count) {
imageService.search(provider, query, region, account, count)
@RequestParam(value = "count", required = false) Integer count,
HttpServletRequest httpServletRequest) {
def additionalFilters = httpServletRequest.getParameterNames().findAll { String parameterName ->
!["provider", "q", "region", "account", "count"].contains(parameterName.toLowerCase())
}.collectEntries { String parameterName ->
[parameterName, httpServletRequest.getParameter(parameterName)]
}
imageService.search(provider, query, region, account, count, additionalFilters)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class ImageService {
} execute()
}

List<Map> search(String provider, String query, String region, String account, Integer count) {
List<Map> search(String provider, String query, String region, String account, Integer count, Map<String, Object> additionalFilters) {
HystrixFactory.newListCommand(GROUP, "searchImages-${providerLookupService.providerForAccount(account)}") {
clouddriverService.findImages(provider, query, region, account, count)
clouddriverService.findImages(provider, query, region, account, count, additionalFilters)
} execute()
}
}

0 comments on commit 5e22b13

Please sign in to comment.