Skip to content

Commit

Permalink
snapshot/downloader: fix fetching snapshot URI (#1791) (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 6, 2022
1 parent 8c2fcfc commit 867c3db
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 867c3db

Please sign in to comment.