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