Skip to content

Commit 88a0f5a

Browse files
committed
remove go.rice and use go:embed
1 parent cdb666c commit 88a0f5a

File tree

6 files changed

+19
-61
lines changed

6 files changed

+19
-61
lines changed

cli/globals/globals.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@
1818

1919
package globals
2020

21-
import "github.com/arduino/go-paths-helper"
21+
import (
22+
"embed"
23+
24+
"github.com/arduino/go-paths-helper"
25+
)
2226

2327
var (
2428
PackageIndexGZURL = "https://downloads.arduino.cc/packages/package_index.json.gz"
2529
ModuleFirmwareIndexGZURL = "https://downloads.arduino.cc/arduino-fwuploader/boards/module_firmware_index.json.gz"
2630
FwUploaderPath = paths.TempDir().Join("fwuploader")
2731
)
32+
33+
//go:embed keys/*
34+
var Keys embed.FS

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/arduino/arduino-cli v0.0.0-20210603144340-aef5a54882fa
77
github.com/arduino/go-paths-helper v1.6.0
88
github.com/arduino/go-properties-orderedmap v1.3.0
9-
github.com/cmaglie/go.rice v1.0.3
109
github.com/mattn/go-colorable v0.1.8
1110
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
1211
github.com/sirupsen/logrus v1.8.1
@@ -18,6 +17,7 @@ require (
1817
)
1918

2019
require (
20+
github.com/cmaglie/go.rice v1.0.3 // indirect
2121
github.com/codeclysm/extract/v3 v3.0.2 // indirect
2222
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
2323
github.com/creack/goselect v0.1.2 // indirect

indexes/download/download.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/arduino/arduino-fwuploader/cli/globals"
3939
"github.com/arduino/arduino-fwuploader/indexes/firmwareindex"
4040
"github.com/arduino/go-paths-helper"
41-
rice "github.com/cmaglie/go.rice"
4241
"github.com/sirupsen/logrus"
4342
"go.bug.st/downloader/v2"
4443
)
@@ -316,15 +315,12 @@ func verifyPackageIndex(indexPath, signaturePath *paths.Path) (bool, error) {
316315

317316
// verifyModuleFirmwareIndex verify if the signature is valid for the provided module firmware index
318317
func verifyModuleFirmwareIndex(indexPath, signaturePath *paths.Path) (bool, error) {
319-
keysBox, err := rice.FindBox("gpg_keys")
318+
arduinoKeyringFile, err := globals.Keys.Open("keys/module_firmware_index_public.gpg.key")
320319
if err != nil {
321320
return false, fmt.Errorf("could not find bundled signature keys: %s", err)
322321
}
323-
key, err := keysBox.Open("module_firmware_index_public.gpg.key")
324-
if err != nil {
325-
return false, fmt.Errorf("could not find bundled signature keys: %s", err)
326-
}
327-
valid, _, err := security.VerifySignature(indexPath, signaturePath, key)
322+
defer arduinoKeyringFile.Close()
323+
valid, _, err := security.VerifySignature(indexPath, signaturePath, arduinoKeyringFile)
328324
if err != nil {
329325
return valid, nil
330326
}

indexes/download/rice-box.go

-44
This file was deleted.

indexes/firmwareindex/firmwareindex.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ package firmwareindex
2020

2121
import (
2222
"encoding/json"
23+
"fmt"
2324
"runtime"
2425

2526
"github.com/arduino/arduino-cli/arduino/security"
27+
"github.com/arduino/arduino-fwuploader/cli/globals"
2628
"github.com/arduino/go-paths-helper"
27-
rice "github.com/cmaglie/go.rice"
2829
"github.com/sirupsen/logrus"
2930
semver "go.bug.st/relaxed-semver"
3031
)
@@ -81,15 +82,13 @@ func LoadIndex(jsonIndexFile *paths.Path) (*Index, error) {
8182
}
8283

8384
jsonSignatureFile := jsonIndexFile.Parent().Join(jsonIndexFile.Base() + ".sig")
84-
keysBox, err := rice.FindBox("gpg_keys")
85+
arduinoKeyringFile, err := globals.Keys.Open("keys/module_firmware_index_public.gpg.key")
8586
if err != nil {
86-
return nil, err
87-
}
88-
key, err := keysBox.Open("module_firmware_index_public.gpg.key")
89-
if err != nil {
90-
return nil, err
87+
return nil, fmt.Errorf("could not find bundled signature keys: %s", err)
88+
9189
}
92-
trusted, _, err := security.VerifySignature(jsonIndexFile, jsonSignatureFile, key)
90+
defer arduinoKeyringFile.Close()
91+
trusted, _, err := security.VerifySignature(jsonIndexFile, jsonSignatureFile, arduinoKeyringFile)
9392
if err != nil {
9493
logrus.
9594
WithField("index", jsonIndexFile).

0 commit comments

Comments
 (0)