From 41470628024fe9ffd0bac3344e8334b2c2f74b6b Mon Sep 17 00:00:00 2001 From: Tom Carrio Date: Fri, 20 Jul 2018 18:09:48 -0400 Subject: [PATCH] Internally handling most_recent logic. --- builder/openstack/image_query.go | 8 +++----- builder/openstack/step_source_image_info.go | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/builder/openstack/image_query.go b/builder/openstack/image_query.go index b07e77510..1d16f6cc3 100644 --- a/builder/openstack/image_query.go +++ b/builder/openstack/image_query.go @@ -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 diff --git a/builder/openstack/step_source_image_info.go b/builder/openstack/step_source_image_info.go index 641eab1d9..029993e6c 100644 --- a/builder/openstack/step_source_image_info.go +++ b/builder/openstack/step_source_image_info.go @@ -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)