From 867c3dbad3f689fbd655b026aefe7bb841192c18 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:59:25 -0500 Subject: [PATCH] snapshot/downloader: fix fetching snapshot URI (#1791) (#1887) --- .../artifact/download/snapshot/downloader.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/pkg/agent/application/upgrade/artifact/download/snapshot/downloader.go b/internal/pkg/agent/application/upgrade/artifact/download/snapshot/downloader.go index 2a09c65e522..f36dee46eb9 100644 --- a/internal/pkg/agent/application/upgrade/artifact/download/snapshot/downloader.go +++ b/internal/pkg/agent/application/upgrade/artifact/download/snapshot/downloader.go @@ -130,12 +130,18 @@ func snapshotURI(versionOverride string, config *artifact.Config) (string, error return "", fmt.Errorf("uri is not a string") } + // Because we're iterating over a map from the API response, + // the order is random and some elements there do not contain the + // `/beats/elastic-agent/` substring, so we need to go through the + // whole map before returning an error. + // + // One of the elements that might be there and do not contain this + // substring is the `elastic-agent-shipper`, whose URL is something like: + // https://snapshots.elastic.co/8.7.0-d050210c/downloads/elastic-agent-shipper/elastic-agent-shipper-8.7.0-SNAPSHOT-linux-x86_64.tar.gz index := strings.Index(uri, "/beats/elastic-agent/") - if index == -1 { - return "", fmt.Errorf("not an agent uri: '%s'", uri) + if index != -1 { + return uri[:index], nil } - - return uri[:index], nil } return "", fmt.Errorf("uri not detected")