@@ -48,7 +48,7 @@ func (s *arduinoCoreServerImpl) BoardIdentify(ctx context.Context, req *rpc.Boar
4848 defer release ()
4949
5050 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 ())
5252 if err != nil {
5353 return nil , err
5454 }
@@ -58,7 +58,7 @@ func (s *arduinoCoreServerImpl) BoardIdentify(ctx context.Context, req *rpc.Boar
5858}
5959
6060// 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 ) {
6262 if properties == nil {
6363 return nil , nil
6464 }
@@ -90,7 +90,7 @@ func identify(pme *packagemanager.Explorer, properties *properties.Map, settings
9090 // if installed cores didn't recognize the board, try querying
9191 // the builder API if the board is a USB device port
9292 if len (boards ) == 0 && ! skipCloudAPI && ! settings .SkipCloudApiForBoardDetection () {
93- items , err := identifyViaCloudAPI (properties , settings )
93+ items , err := identifyViaCloudAPI (ctx , properties , settings )
9494 if err != nil {
9595 // this is bad, but keep going
9696 logrus .WithError (err ).Debug ("Error querying builder API" )
@@ -119,22 +119,22 @@ func identify(pme *packagemanager.Explorer, properties *properties.Map, settings
119119 return boards , nil
120120}
121121
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 ) {
123123 // If the port is not USB do not try identification via cloud
124124 if ! props .ContainsKey ("vid" ) || ! props .ContainsKey ("pid" ) {
125125 return nil , nil
126126 }
127127
128128 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 )
130130}
131131
132132var (
133133 vidPidURL = "https://builder.arduino.cc/v3/boards/byVidPid"
134134 validVidPid = regexp .MustCompile (`0[xX][a-fA-F\d]{4}` )
135135)
136136
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 ) {
138138 var resp []* rpc.BoardListItem
139139
140140 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
148148 }
149149 }
150150
151- resp , err := apiByVidPid (vid , pid , settings ) // Perform API requrest
151+ resp , err := apiByVidPid (ctx , vid , pid , settings ) // Perform API requrest
152152
153153 if err == nil {
154154 if cachedResp , err := json .Marshal (resp ); err == nil {
@@ -160,7 +160,7 @@ func cachedAPIByVidPid(vid, pid string, settings *configuration.Settings) ([]*rp
160160 return resp , err
161161}
162162
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 ) {
164164 // ensure vid and pid are valid before hitting the API
165165 if ! validVidPid .MatchString (vid ) {
166166 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
173173 req , _ := http .NewRequest ("GET" , url , nil )
174174 req .Header .Set ("Content-Type" , "application/json" )
175175
176- httpClient , err := settings .NewHttpClient ()
176+ httpClient , err := settings .NewHttpClient (ctx )
177177 if err != nil {
178178 return nil , fmt .Errorf ("%s: %w" , i18n .Tr ("failed to initialize http client" ), err )
179179 }
0 commit comments