@@ -30,6 +30,7 @@ import (
30
30
"path/filepath"
31
31
"runtime"
32
32
33
+ "github.com/arduino/arduino-create-agent/utilities"
33
34
"github.com/arduino/arduino-create-agent/v2/pkgs"
34
35
"github.com/arduino/go-paths-helper"
35
36
"github.com/blang/semver"
@@ -98,17 +99,33 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
98
99
return t .writeMap ()
99
100
}
100
101
}
102
+ return t .download (pack , correctTool .Name , correctTool .Version , correctSystem .URL , correctSystem .Checksum )
103
+ }
104
+
105
+ // DowloadUsingURL will download the tool from the specified URL if it is signed and can be verified.
106
+ // If no URL is specified, it will follow the standard download procedure.
107
+ func (t * Tools ) DownloadFromURL (pack , name , version , behaviour , URL , signature , checksum string ) error {
108
+ if URL != "" && signature != "" && checksum != "" {
109
+ err := utilities .VerifyInput (URL , signature )
110
+ if err != nil {
111
+ return err
112
+ }
113
+ return t .download (pack , name , version , URL , checksum )
114
+ }
115
+ return t .Download (pack , name , version , behaviour )
116
+ }
101
117
118
+ func (t * Tools ) download (pack , name , version , url , checksum256 string ) error {
102
119
// Download the tool
103
- t .logger ("Downloading tool " + name + " from " + correctSystem . URL )
104
- resp , err := http .Get (correctSystem . URL )
120
+ t .logger ("Downloading tool " + name + " from " + url )
121
+ resp , err := http .Get (url )
105
122
if err != nil {
106
123
return err
107
124
}
108
125
defer resp .Body .Close ()
109
126
110
127
// Read the body
111
- body , err = io .ReadAll (resp .Body )
128
+ body , err : = io .ReadAll (resp .Body )
112
129
if err != nil {
113
130
return err
114
131
}
@@ -117,7 +134,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
117
134
checksum := sha256 .Sum256 (body )
118
135
checkSumString := "SHA-256:" + hex .EncodeToString (checksum [:sha256 .Size ])
119
136
120
- if checkSumString != correctSystem . Checksum {
137
+ if checkSumString != checksum256 {
121
138
return errors .New ("checksum doesn't match" )
122
139
}
123
140
@@ -140,7 +157,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
140
157
return fmt .Errorf ("extracting archive: %s" , err )
141
158
}
142
159
143
- location := t .directory .Join (pack , correctTool . Name , correctTool . Version )
160
+ location := t .directory .Join (pack , name , version )
144
161
err = location .RemoveAll ()
145
162
if err != nil {
146
163
return err
@@ -172,7 +189,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
172
189
t .logger ("Updating map with location " + location .String ())
173
190
174
191
t .setMapValue (name , location .String ())
175
- t .setMapValue (name + "-" + correctTool . Version , location .String ())
192
+ t .setMapValue (name + "-" + version , location .String ())
176
193
return t .writeMap ()
177
194
}
178
195
0 commit comments