@@ -48,7 +48,7 @@ func (s *arduinoCoreServerImpl) BoardIdentify(ctx context.Context, req *rpc.Boar
48
48
defer release()
49
49
50
50
props := properties.NewFromHashmap(req.GetProperties())
51
-
res, err := identify(pme, props, s.settings, !req.GetUseCloudApiForUnknownBoardDetection())
51
+
res, err := identify(ctx, pme, props, s.settings, !req.GetUseCloudApiForUnknownBoardDetection())
52
52
if err != nil {
53
53
return nil, err
54
54
}
@@ -58,7 +58,7 @@ func (s *arduinoCoreServerImpl) BoardIdentify(ctx context.Context, req *rpc.Boar
58
58
}
59
59
60
60
// identify returns a list of boards checking first the installed platforms or the Cloud API
61
-
func identify(pme *packagemanager.Explorer, properties *properties.Map, settings *configuration.Settings, skipCloudAPI bool) ([]*rpc.BoardListItem, error) {
61
+
func identify(ctx context.Context, pme *packagemanager.Explorer, properties *properties.Map, settings *configuration.Settings, skipCloudAPI bool) ([]*rpc.BoardListItem, error) {
62
62
if properties == nil {
63
63
return nil, nil
64
64
}
@@ -90,7 +90,7 @@ func identify(pme *packagemanager.Explorer, properties *properties.Map, settings
90
90
// if installed cores didn't recognize the board, try querying
91
91
// the builder API if the board is a USB device port
92
92
if len(boards) == 0 && !skipCloudAPI && !settings.SkipCloudApiForBoardDetection() {
93
-
items, err := identifyViaCloudAPI(properties, settings)
93
+
items, err := identifyViaCloudAPI(ctx, properties, settings)
94
94
if err != nil {
95
95
// this is bad, but keep going
96
96
logrus.WithError(err).Debug("Error querying builder API")
@@ -119,22 +119,22 @@ func identify(pme *packagemanager.Explorer, properties *properties.Map, settings
119
119
return boards, nil
120
120
}
121
121
122
-
func identifyViaCloudAPI(props *properties.Map, settings *configuration.Settings) ([]*rpc.BoardListItem, error) {
122
+
func identifyViaCloudAPI(ctx context.Context, props *properties.Map, settings *configuration.Settings) ([]*rpc.BoardListItem, error) {
123
123
// If the port is not USB do not try identification via cloud
124
124
if !props.ContainsKey("vid") || !props.ContainsKey("pid") {
125
125
return nil, nil
126
126
}
127
127
128
128
logrus.Debug("Querying builder API for board identification...")
129
-
return cachedAPIByVidPid(props.Get("vid"), props.Get("pid"), settings)
129
+
return cachedAPIByVidPid(ctx, props.Get("vid"), props.Get("pid"), settings)
130
130
}
131
131
132
132
var (
133
133
vidPidURL = "https://builder.arduino.cc/v3/boards/byVidPid"
134
134
validVidPid = regexp.MustCompile(`0[xX][a-fA-F\d]{4}`)
135
135
)
136
136
137
-
func cachedAPIByVidPid(vid, pid string, settings *configuration.Settings) ([]*rpc.BoardListItem, error) {
137
+
func cachedAPIByVidPid(ctx context.Context, vid, pid string, settings *configuration.Settings) ([]*rpc.BoardListItem, error) {
138
138
var resp []*rpc.BoardListItem
139
139
140
140
cacheKey := fmt.Sprintf("cache.builder-api.v3/boards/byvid/pid/%s/%s", vid, pid)
@@ -148,7 +148,7 @@ func cachedAPIByVidPid(vid, pid string, settings *configuration.Settings) ([]*rp
148
148
}
149
149
}
150
150
151
-
resp, err := apiByVidPid(vid, pid, settings) // Perform API requrest
151
+
resp, err := apiByVidPid(ctx, vid, pid, settings) // Perform API requrest
152
152
153
153
if err == nil {
154
154
if cachedResp, err := json.Marshal(resp); err == nil {
@@ -160,7 +160,7 @@ func cachedAPIByVidPid(vid, pid string, settings *configuration.Settings) ([]*rp
160
160
return resp, err
161
161
}
162
162
163
-
func apiByVidPid(vid, pid string, settings *configuration.Settings) ([]*rpc.BoardListItem, error) {
163
+
func apiByVidPid(ctx context.Context, vid, pid string, settings *configuration.Settings) ([]*rpc.BoardListItem, error) {
164
164
// ensure vid and pid are valid before hitting the API
165
165
if !validVidPid.MatchString(vid) {
166
166
return nil, errors.New(i18n.Tr("Invalid vid value: '%s'", vid))
@@ -173,7 +173,7 @@ func apiByVidPid(vid, pid string, settings *configuration.Settings) ([]*rpc.Boar
173
173
req, _ := http.NewRequest("GET", url, nil)
174
174
req.Header.Set("Content-Type", "application/json")
175
175
176
-
httpClient, err := settings.NewHttpClient()
176
+
httpClient, err := settings.NewHttpClient(ctx)
177
177
if err != nil {
178
178
return nil, fmt.Errorf("%s: %w", i18n.Tr("failed to initialize http client"), err)
179
179
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4