Internally handling most_recent logic.
This commit is contained in:
parent
2d5d1890d4
commit
4147062802
|
@ -8,8 +8,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
mostRecentSortDir = "desc"
|
||||
mostRecentSortKey = "created_at"
|
||||
mostRecentSort = "created_at:desc"
|
||||
)
|
||||
|
||||
var validFields = map[string]string{
|
||||
|
@ -99,9 +98,8 @@ func buildImageFilters(input map[string]interface{}, listOpts *images.ListOpts)
|
|||
// See https://developer.openstack.org/api-ref/image/v2/
|
||||
func applyMostRecent(listOpts *images.ListOpts) {
|
||||
// Sort isn't supported through our API so there should be no existing values.
|
||||
// Overwriting .Sort is okay.
|
||||
listOpts.SortKey = mostRecentSortKey
|
||||
listOpts.SortDir = mostRecentSortDir
|
||||
// Overwriting ListOpts.Sort is okay.
|
||||
listOpts.Sort = mostRecentSort
|
||||
listOpts.Limit = 1
|
||||
|
||||
return
|
||||
|
|
|
@ -72,6 +72,10 @@ func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) m
|
|||
*image = i[0]
|
||||
return true, nil
|
||||
default:
|
||||
if s.ImageFilters.MostRecent {
|
||||
*image = i[0]
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf(
|
||||
"Your query returned more than one result. Please try a more specific search, or set most_recent to true. Search filters: %v",
|
||||
params)
|
||||
|
|
Loading…
Reference in New Issue