@@ -10,7 +10,6 @@ import (
1010 "fmt"
1111 "log/slog"
1212 "os"
13- "path"
1413 "path/filepath"
1514 "regexp"
1615 "strconv"
@@ -107,51 +106,11 @@ func CheckPRVersion(version string, fallbackVersion string) string {
107106 return version
108107}
109108
110- // FetchElasticArtifact fetches an artifact from the right repository, returning binary name, path and error
111- func FetchElasticArtifact (ctx context.Context , artifact string , version string , os string , arch string , extension string , isDocker bool , xpack bool ) (string , string , error ) {
112- useCISnapshots := GithubCommitSha1 != ""
113-
114- return FetchElasticArtifactForSnapshots (ctx , useCISnapshots , artifact , version , os , arch , extension , isDocker , xpack )
115- }
116-
117- // FetchElasticArtifactForSnapshots fetches an artifact from the right repository, returning binary name, path and error
118- func FetchElasticArtifactForSnapshots (ctx context.Context , useCISnapshots bool , artifact string , version string , os string , arch string , extension string , isDocker bool , xpack bool ) (string , string , error ) {
119- binaryName := buildArtifactName (artifact , version , os , arch , extension , isDocker )
120- binaryPath , err := FetchProjectBinaryForSnapshots (ctx , useCISnapshots , artifact , binaryName , artifact , version , timeoutFactor , xpack , "" , false )
121- if err != nil {
122- logger .Error ("Could not download the binary for the Elastic artifact" ,
123- slog .String ("artifact" , artifact ),
124- slog .String ("version" , version ),
125- slog .String ("os" , os ),
126- slog .String ("arch" , arch ),
127- slog .String ("extension" , extension ),
128- slog .String ("error" , err .Error ()),
129- )
130- return "" , "" , err
131- }
132-
133- return binaryName , binaryPath , nil
134- }
135-
136109// GetCommitVersion returns a version including the version and the git commit, if it exists
137110func GetCommitVersion (version string ) string {
138111 return newElasticVersion (version ).HashedVersion
139112}
140113
141- // GetElasticArtifactURL returns the URL of a released artifact, which its full name is defined in the first argument,
142- // from Elastic's artifact repository, building the JSON path query based on the full name
143- // It also returns the URL of the sha512 file of the released artifact.
144- // i.e. GetElasticArtifactURL("elastic-agent-$VERSION-$ARCH.deb", "elastic-agent", "$VERSION")
145- // i.e. GetElasticArtifactURL("elastic-agent-$VERSION-x86_64.rpm", "elastic-agent","$VERSION")
146- // i.e. GetElasticArtifactURL("elastic-agent-$VERSION-linux-$ARCH.tar.gz", "elastic-agent","$VERSION")
147- func GetElasticArtifactURL (artifactName string , artifact string , version string ) (string , string , error ) {
148- resolver := NewArtifactURLResolver (artifactName , artifact , version )
149- if resolver == nil {
150- return "" , "" , errors .New ("nil resolver returned" )
151- }
152- return resolver .Resolve ()
153- }
154-
155114// GetElasticArtifactVersion returns the current version:
156115// 1. Elastic's artifact repository, building the JSON path query based
157116// If the version is a SNAPSHOT including a commit, then it will directly use the version without checking the artifacts API
@@ -354,11 +313,19 @@ func FetchProjectBinaryForSnapshots(ctx context.Context, useCISnapshots bool, pr
354313 return "" , fmt .Errorf ("⚠️ Beats local path usage is deprecated and not used to fetch the binaries. Please use the packaging job to generate the artifacts to be consumed by these tests" )
355314 }
356315
316+ if downloadPath == "" {
317+ return "" , errors .New ("downloadPath cannot be empty" )
318+ }
319+
357320 handleDownload := func (URL string ) (string , error ) {
358321 name := artifactName
322+ if strings .HasSuffix (URL , ".sha512" ) {
323+ name = fmt .Sprintf ("%s.sha512" , name )
324+ }
325+ downloadFilePath := filepath .Join (downloadPath , name )
359326 downloadRequest := downloadRequest {
360- DownloadPath : downloadPath ,
361- URL : URL ,
327+ TargetPath : downloadFilePath ,
328+ URL : URL ,
362329 }
363330 span , _ := apm .StartSpanOptions (ctx , "Fetching Project binary" , "project.url.fetch-binary" , apm.SpanOptions {
364331 Parent : apm .SpanFromContext (ctx ).TraceContext (),
@@ -379,28 +346,14 @@ func FetchProjectBinaryForSnapshots(ctx context.Context, useCISnapshots bool, pr
379346
380347 err := downloadFile (& downloadRequest )
381348 if err != nil {
382- return downloadRequest .UnsanitizedFilePath , err
383- }
384-
385- if strings .HasSuffix (URL , ".sha512" ) {
386- name = fmt .Sprintf ("%s.sha512" , name )
387- }
388- // use artifact name as file name to avoid having URL params in the name
389- sanitizedFilePath := filepath .Join (path .Dir (downloadRequest .UnsanitizedFilePath ), name )
390- err = os .Rename (downloadRequest .UnsanitizedFilePath , sanitizedFilePath )
391- if err != nil {
392- logger .Warn ("Could not sanitize downloaded file name. Keeping old name" ,
393- slog .String ("fileName" , downloadRequest .UnsanitizedFilePath ),
394- slog .String ("sanitizedFileName" , sanitizedFilePath ),
395- )
396- sanitizedFilePath = downloadRequest .UnsanitizedFilePath
349+ return "" , err
397350 }
398351
399352 binariesMutex .Lock ()
400- binariesCache [URL ] = sanitizedFilePath
353+ binariesCache [URL ] = downloadFilePath
401354 binariesMutex .Unlock ()
402355
403- return sanitizedFilePath , nil
356+ return downloadFilePath , nil
404357 }
405358
406359 var downloadURL , downloadShaURL string
0 commit comments