From 43dd782cf2cf16f583d7dd7de07517122bdad1ca Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Thu, 28 Nov 2024 15:43:01 +0100 Subject: [PATCH 1/8] settings: add `connection_timeout` --- internal/cli/configuration/defaults.go | 1 + internal/cli/configuration/network.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/internal/cli/configuration/defaults.go b/internal/cli/configuration/defaults.go index 40f8b472cdb..3e6c3ed8d5a 100644 --- a/internal/cli/configuration/defaults.go +++ b/internal/cli/configuration/defaults.go @@ -71,6 +71,7 @@ func SetDefaults(settings *Settings) { // network settings setKeyTypeSchema("network.proxy", "") setKeyTypeSchema("network.user_agent_ext", "") + setKeyTypeSchema("network.connection_timeout", 0) // locale setKeyTypeSchema("locale", "") diff --git a/internal/cli/configuration/network.go b/internal/cli/configuration/network.go index 2c8a8047ce5..eb5032670b7 100644 --- a/internal/cli/configuration/network.go +++ b/internal/cli/configuration/network.go @@ -22,6 +22,7 @@ import ( "net/url" "os" "runtime" + "time" "github.com/arduino/arduino-cli/commands/cmderrors" "github.com/arduino/arduino-cli/internal/i18n" @@ -58,6 +59,11 @@ func (settings *Settings) ExtraUserAgent() string { return settings.GetString("network.user_agent_ext") } +func (settings *Settings) ConnectionTimeout() time.Duration { + timeout := settings.GetInt("network.connection_timeout") + return time.Duration(timeout) * time.Second +} + // NetworkProxy returns the proxy configuration (mainly used by HTTP clients) func (settings *Settings) NetworkProxy() (*url.URL, error) { if proxyConfig, ok, _ := settings.GetStringOk("network.proxy"); !ok { @@ -82,6 +88,7 @@ func (settings *Settings) NewHttpClient() (*http.Client, error) { }, userAgent: settings.UserAgent(), }, + Timeout: settings.ConnectionTimeout(), }, nil } From 2278bbc3bd6ce119502343169a2c1dd274e38daf Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Thu, 28 Nov 2024 17:13:12 +0100 Subject: [PATCH 2/8] add test --- internal/cli/configuration/network_test.go | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/internal/cli/configuration/network_test.go b/internal/cli/configuration/network_test.go index 6c8a7def80d..d4a9af384bc 100644 --- a/internal/cli/configuration/network_test.go +++ b/internal/cli/configuration/network_test.go @@ -21,6 +21,7 @@ import ( "net/http" "net/http/httptest" "testing" + "time" "github.com/arduino/arduino-cli/internal/cli/configuration" "github.com/stretchr/testify/require" @@ -68,3 +69,41 @@ func TestProxy(t *testing.T) { require.NoError(t, err) require.Equal(t, http.StatusNoContent, response.StatusCode) } + +func TestConnectionTimeout(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + time.Sleep(5 * time.Second) + w.WriteHeader(http.StatusNoContent) + })) + defer ts.Close() + + doRequest := func(timeout int) (*http.Response, time.Duration, error) { + settings := configuration.NewSettings() + settings.Set("network.proxy", ts.URL) + if timeout != 0 { + settings.Set("network.connection_timeout", 2) + } + client, err := settings.NewHttpClient() + require.NoError(t, err) + + request, err := http.NewRequest("GET", "http://arduino.cc", nil) + require.NoError(t, err) + + start := time.Now() + resp, err := client.Do(request) + duration := time.Since(start) + + return resp, duration, err + } + + // Using default timeout (0), will wait indefinitely (in our case up to 5s) + response, elapsed, err := doRequest(0) + require.NoError(t, err) + require.Equal(t, http.StatusNoContent, response.StatusCode) + require.True(t, elapsed.Seconds() >= 4 && elapsed.Seconds() <= 6) // Adding some tolerance just in case... + + // Setting a timeout of 1 seconds, will drop the connection after 1s + _, elapsed, err = doRequest(1) + require.Error(t, err) + require.True(t, elapsed.Seconds() >= 0.5 && elapsed.Seconds() <= 3) // Adding some tolerance just in case... +} From 3802b09b2df8cca1dcf4db559b9f25f15664fa27 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Thu, 28 Nov 2024 17:17:41 +0100 Subject: [PATCH 3/8] add docs --- docs/configuration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/configuration.md b/docs/configuration.md index 921554d4ceb..05abe7aa3ec 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -45,6 +45,7 @@ [time.ParseDuration()](https://pkg.go.dev/time#ParseDuration), defaults to `720h` (30 days). - `network` - configuration options related to the network connection. - `proxy` - URL of the proxy server. + - `connection_timeout` - connection timeout in seconds, defaults to `0` which will wait indefinitely. ### Default directories From 88e37717cc11c5252ca431044d79875c77681291 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 10 Dec 2024 16:45:04 +0100 Subject: [PATCH 4/8] Added gRPC flag to ignore Cloud API detection in BoardList* operations --- commands/service_board_list.go | 8 +- commands/service_board_list_test.go | 2 +- rpc/cc/arduino/cli/commands/v1/board.pb.go | 174 ++++++++++++--------- rpc/cc/arduino/cli/commands/v1/board.proto | 6 + 4 files changed, 113 insertions(+), 77 deletions(-) diff --git a/commands/service_board_list.go b/commands/service_board_list.go index 2b124c29f37..8f90e544748 100644 --- a/commands/service_board_list.go +++ b/commands/service_board_list.go @@ -139,7 +139,7 @@ func identifyViaCloudAPI(props *properties.Map, settings *configuration.Settings } // identify returns a list of boards checking first the installed platforms or the Cloud API -func identify(pme *packagemanager.Explorer, port *discovery.Port, settings *configuration.Settings) ([]*rpc.BoardListItem, error) { +func identify(pme *packagemanager.Explorer, port *discovery.Port, settings *configuration.Settings, skipCloudAPI bool) ([]*rpc.BoardListItem, error) { boards := []*rpc.BoardListItem{} if port.Properties == nil { return boards, nil @@ -170,7 +170,7 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port, settings *conf // if installed cores didn't recognize the board, try querying // the builder API if the board is a USB device port - if len(boards) == 0 { + if len(boards) == 0 && !skipCloudAPI { items, err := identifyViaCloudAPI(port.Properties, settings) if err != nil { // this is bad, but keep going @@ -225,7 +225,7 @@ func (s *arduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis ports := []*rpc.DetectedPort{} for _, port := range dm.List() { - boards, err := identify(pme, port, s.settings) + boards, err := identify(pme, port, s.settings, req.GetSkipCloudApiForBoardDetection()) if err != nil { warnings = append(warnings, err.Error()) } @@ -298,7 +298,7 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s boardsError := "" if event.Type == "add" { - boards, err := identify(pme, event.Port, s.settings) + boards, err := identify(pme, event.Port, s.settings, req.GetSkipCloudApiForBoardDetection()) if err != nil { boardsError = err.Error() } diff --git a/commands/service_board_list_test.go b/commands/service_board_list_test.go index 6fb1366d111..f9fe2ca8ba5 100644 --- a/commands/service_board_list_test.go +++ b/commands/service_board_list_test.go @@ -157,7 +157,7 @@ func TestBoardIdentifySorting(t *testing.T) { defer release() settings := configuration.NewSettings() - res, err := identify(pme, &discovery.Port{Properties: idPrefs}, settings) + res, err := identify(pme, &discovery.Port{Properties: idPrefs}, settings, true) require.NoError(t, err) require.NotNil(t, res) require.Len(t, res, 4) diff --git a/rpc/cc/arduino/cli/commands/v1/board.pb.go b/rpc/cc/arduino/cli/commands/v1/board.pb.go index 3bc667e8192..229a9d7243d 100644 --- a/rpc/cc/arduino/cli/commands/v1/board.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/board.pb.go @@ -874,6 +874,9 @@ type BoardListRequest struct { // The fully qualified board name of the board you want information about // (e.g., `arduino:avr:uno`). Fqbn string `protobuf:"bytes,3,opt,name=fqbn,proto3" json:"fqbn,omitempty"` + // If set to true, when a board cannot be identified using the installed + // platforms, the cloud API will not be called to detect the board. + SkipCloudApiForBoardDetection bool `protobuf:"varint,4,opt,name=skip_cloud_api_for_board_detection,json=skipCloudApiForBoardDetection,proto3" json:"skip_cloud_api_for_board_detection,omitempty"` } func (x *BoardListRequest) Reset() { @@ -929,6 +932,13 @@ func (x *BoardListRequest) GetFqbn() string { return "" } +func (x *BoardListRequest) GetSkipCloudApiForBoardDetection() bool { + if x != nil { + return x.SkipCloudApiForBoardDetection + } + return false +} + type BoardListResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1164,6 +1174,9 @@ type BoardListWatchRequest struct { // Arduino Core Service instance from the `Init` response. Instance *Instance `protobuf:"bytes,1,opt,name=instance,proto3" json:"instance,omitempty"` + // If set to true, when a board cannot be identified using the installed + // platforms, the cloud API will not be called to detect the board. + SkipCloudApiForBoardDetection bool `protobuf:"varint,2,opt,name=skip_cloud_api_for_board_detection,json=skipCloudApiForBoardDetection,proto3" json:"skip_cloud_api_for_board_detection,omitempty"` } func (x *BoardListWatchRequest) Reset() { @@ -1205,6 +1218,13 @@ func (x *BoardListWatchRequest) GetInstance() *Instance { return nil } +func (x *BoardListWatchRequest) GetSkipCloudApiForBoardDetection() bool { + if x != nil { + return x.SkipCloudApiForBoardDetection + } + return false +} + type BoardListWatchResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1608,7 +1628,7 @@ var file_cc_arduino_cli_commands_v1_board_proto_rawDesc = []byte{ 0x65, 0x5f, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x73, 0x65, 0x6c, - 0x65, 0x63, 0x74, 0x65, 0x64, 0x22, 0x82, 0x01, 0x0a, 0x10, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, + 0x65, 0x63, 0x74, 0x65, 0x64, 0x22, 0xcd, 0x01, 0x0a, 0x10, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, @@ -1616,86 +1636,96 @@ var file_cc_arduino_cli_commands_v1_board_proto_rawDesc = []byte{ 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x22, 0x6f, 0x0a, 0x11, 0x42, 0x6f, - 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x3e, 0x0a, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, - 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, - 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x74, 0x65, - 0x63, 0x74, 0x65, 0x64, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x12, - 0x1a, 0x0a, 0x08, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x08, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x22, 0x98, 0x01, 0x0a, 0x0c, - 0x44, 0x65, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x52, 0x0a, 0x0f, - 0x6d, 0x61, 0x74, 0x63, 0x68, 0x69, 0x6e, 0x67, 0x5f, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, - 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, - 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x74, 0x65, 0x6d, - 0x52, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x69, 0x6e, 0x67, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x73, - 0x12, 0x34, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, - 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, - 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6f, 0x72, 0x74, - 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x22, 0xac, 0x01, 0x0a, 0x13, 0x42, 0x6f, 0x61, 0x72, 0x64, - 0x4c, 0x69, 0x73, 0x74, 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, - 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, - 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, - 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, - 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x41, 0x72, 0x67, - 0x73, 0x12, 0x32, 0x0a, 0x15, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x68, 0x69, 0x64, - 0x64, 0x65, 0x6e, 0x5f, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x13, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x48, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x42, - 0x6f, 0x61, 0x72, 0x64, 0x73, 0x22, 0x59, 0x0a, 0x14, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, - 0x73, 0x74, 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, - 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, - 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, - 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64, - 0x4c, 0x69, 0x73, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, - 0x22, 0x59, 0x0a, 0x15, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x57, 0x61, 0x74, - 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, - 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x22, 0x8b, 0x01, 0x0a, 0x16, - 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, - 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, - 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x3c, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, - 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, - 0x2e, 0x44, 0x65, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x04, 0x70, - 0x6f, 0x72, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x96, 0x01, 0x0a, 0x0d, 0x42, 0x6f, - 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, - 0x71, 0x62, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x73, 0x5f, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x48, 0x69, 0x64, 0x64, 0x65, 0x6e, - 0x12, 0x40, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, - 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, - 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, - 0x72, 0x6d, 0x22, 0xab, 0x01, 0x0a, 0x12, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x53, 0x65, 0x61, 0x72, - 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x12, 0x49, 0x0a, 0x22, 0x73, 0x6b, + 0x69, 0x70, 0x5f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x5f, 0x61, 0x70, 0x69, 0x5f, 0x66, 0x6f, 0x72, + 0x5f, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x5f, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1d, 0x73, 0x6b, 0x69, 0x70, 0x43, 0x6c, 0x6f, 0x75, + 0x64, 0x41, 0x70, 0x69, 0x46, 0x6f, 0x72, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x44, 0x65, 0x74, 0x65, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x6f, 0x0a, 0x11, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, + 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x05, 0x70, 0x6f, + 0x72, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, + 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, 0x50, + 0x6f, 0x72, 0x74, 0x52, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x77, 0x61, + 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x77, 0x61, + 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x22, 0x98, 0x01, 0x0a, 0x0c, 0x44, 0x65, 0x74, 0x65, 0x63, + 0x74, 0x65, 0x64, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x52, 0x0a, 0x0f, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x69, 0x6e, 0x67, 0x5f, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, + 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, + 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x0e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x69, 0x6e, 0x67, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x12, 0x34, 0x0a, 0x04, 0x70, + 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x63, 0x63, 0x2e, 0x61, + 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x04, 0x70, 0x6f, 0x72, + 0x74, 0x22, 0xac, 0x01, 0x0a, 0x13, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x41, + 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, - 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x41, 0x72, 0x67, 0x73, 0x12, 0x32, 0x0a, 0x15, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x5f, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x13, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x48, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x73, - 0x22, 0x58, 0x0a, 0x13, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, + 0x22, 0x59, 0x0a, 0x14, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x6c, 0x6c, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x06, 0x62, 0x6f, 0x61, 0x72, + 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, + 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, + 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x49, + 0x74, 0x65, 0x6d, 0x52, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x22, 0xa4, 0x01, 0x0a, 0x15, + 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, - 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x74, - 0x65, 0x6d, 0x52, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x42, 0x48, 0x5a, 0x46, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, - 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, - 0x2f, 0x63, 0x63, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x63, 0x6c, 0x69, 0x2f, - 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, - 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, + 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x49, 0x0a, 0x22, 0x73, 0x6b, 0x69, 0x70, 0x5f, + 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x5f, 0x61, 0x70, 0x69, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x62, 0x6f, + 0x61, 0x72, 0x64, 0x5f, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x1d, 0x73, 0x6b, 0x69, 0x70, 0x43, 0x6c, 0x6f, 0x75, 0x64, 0x41, 0x70, + 0x69, 0x46, 0x6f, 0x72, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x44, 0x65, 0x74, 0x65, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x22, 0x8b, 0x01, 0x0a, 0x16, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, + 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1d, 0x0a, + 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x3c, 0x0a, 0x04, + 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x63, 0x2e, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, + 0x50, 0x6f, 0x72, 0x74, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x22, 0x96, 0x01, 0x0a, 0x0d, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x74, + 0x65, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x73, + 0x5f, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, + 0x73, 0x48, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x12, 0x40, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, + 0x6f, 0x72, 0x6d, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, + 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x52, + 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x22, 0xab, 0x01, 0x0a, 0x12, 0x42, 0x6f, + 0x61, 0x72, 0x64, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, + 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, + 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x61, 0x72, 0x67, + 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x41, + 0x72, 0x67, 0x73, 0x12, 0x32, 0x0a, 0x15, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x68, + 0x69, 0x64, 0x64, 0x65, 0x6e, 0x5f, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x13, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x48, 0x69, 0x64, 0x64, 0x65, + 0x6e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x22, 0x58, 0x0a, 0x13, 0x42, 0x6f, 0x61, 0x72, 0x64, + 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, + 0x0a, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, + 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, + 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x72, + 0x64, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, + 0x73, 0x42, 0x48, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, + 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x63, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, + 0x6e, 0x6f, 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, + 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/rpc/cc/arduino/cli/commands/v1/board.proto b/rpc/cc/arduino/cli/commands/v1/board.proto index 27be0f19d01..01d8145acdc 100644 --- a/rpc/cc/arduino/cli/commands/v1/board.proto +++ b/rpc/cc/arduino/cli/commands/v1/board.proto @@ -162,6 +162,9 @@ message BoardListRequest { // The fully qualified board name of the board you want information about // (e.g., `arduino:avr:uno`). string fqbn = 3; + // If set to true, when a board cannot be identified using the installed + // platforms, the cloud API will not be called to detect the board. + bool skip_cloud_api_for_board_detection = 4; } message BoardListResponse { @@ -195,6 +198,9 @@ message BoardListAllResponse { message BoardListWatchRequest { // Arduino Core Service instance from the `Init` response. Instance instance = 1; + // If set to true, when a board cannot be identified using the installed + // platforms, the cloud API will not be called to detect the board. + bool skip_cloud_api_for_board_detection = 2; } message BoardListWatchResponse { From a1da0d8066d42e31e2323deda833b5dfcadeebc0 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 10 Dec 2024 16:52:57 +0100 Subject: [PATCH 5/8] Set default duration to 60 seconds --- docs/configuration.md | 3 ++- internal/cli/configuration/defaults.go | 2 +- internal/cli/configuration/network.go | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 05abe7aa3ec..376c4aa5d2b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -45,7 +45,8 @@ [time.ParseDuration()](https://pkg.go.dev/time#ParseDuration), defaults to `720h` (30 days). - `network` - configuration options related to the network connection. - `proxy` - URL of the proxy server. - - `connection_timeout` - connection timeout in seconds, defaults to `0` which will wait indefinitely. + - `connection_timeout` - network connection timeout, the value format must be a valid input for + [time.ParseDuration()](https://pkg.go.dev/time#ParseDuration), defaults to `60s` (60 seconds). `0` means it will wait indefinitely. ### Default directories diff --git a/internal/cli/configuration/defaults.go b/internal/cli/configuration/defaults.go index 3e6c3ed8d5a..8e8f28fdcf5 100644 --- a/internal/cli/configuration/defaults.go +++ b/internal/cli/configuration/defaults.go @@ -71,7 +71,7 @@ func SetDefaults(settings *Settings) { // network settings setKeyTypeSchema("network.proxy", "") setKeyTypeSchema("network.user_agent_ext", "") - setKeyTypeSchema("network.connection_timeout", 0) + setDefaultValueAndKeyTypeSchema("network.connection_timeout", (time.Second * 60).String()) // locale setKeyTypeSchema("locale", "") diff --git a/internal/cli/configuration/network.go b/internal/cli/configuration/network.go index eb5032670b7..aae125bc0ed 100644 --- a/internal/cli/configuration/network.go +++ b/internal/cli/configuration/network.go @@ -59,9 +59,12 @@ func (settings *Settings) ExtraUserAgent() string { return settings.GetString("network.user_agent_ext") } +// ConnectionTimeout returns the network connection timeout func (settings *Settings) ConnectionTimeout() time.Duration { - timeout := settings.GetInt("network.connection_timeout") - return time.Duration(timeout) * time.Second + if timeout, ok, _ := settings.GetDurationOk("network.connection_timeout"); ok { + return timeout + } + return settings.Defaults.GetDuration("network.connection_timeout") } // NetworkProxy returns the proxy configuration (mainly used by HTTP clients) From b36819ee785807417b752a9881d3183fef632404 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 10 Dec 2024 17:18:02 +0100 Subject: [PATCH 6/8] Updated JSON schema for configuration --- .../configuration/configuration.schema.json | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/internal/cli/configuration/configuration.schema.json b/internal/cli/configuration/configuration.schema.json index 2f696904972..82173c0d96d 100644 --- a/internal/cli/configuration/configuration.schema.json +++ b/internal/cli/configuration/configuration.schema.json @@ -38,16 +38,8 @@ }, "ttl": { "description": "cache expiration time of build folders. If the cache is hit by a compilation the corresponding build files lifetime is renewed. The value format must be a valid input for time.ParseDuration(), defaults to `720h` (30 days)", - "oneOf": [ - { - "type": "integer", - "minimum": 0 - }, - { - "type": "string", - "pattern": "^\\+?([0-9]?\\.?[0-9]+(([nuµm]?s)|m|h))+$" - } - ] + "type": "string", + "pattern": "^[+-]?(([0-9]+(\\.[0-9]*)?|(\\.[0-9]+))(ns|us|µs|μs|ms|s|m|h))+$" } }, "type": "object" @@ -146,6 +138,25 @@ }, "type": "object" }, + "network": { + "description": "settings related to network connections.", + "type": "object", + "properties": { + "proxy": { + "description": "proxy settings for network connections.", + "type": "string" + }, + "user_agent_ext": { + "description": "extra string to append to the user agent string in HTTP requests.", + "type": "string" + }, + "connection_timeout": { + "description": "timeout for network connections, defaults to '30s'", + "type": "string", + "pattern": "^[+-]?(([0-9]+(\\.[0-9]*)?|(\\.[0-9]+))(ns|us|µs|μs|ms|s|m|h))+$" + } + } + }, "output": { "description": "settings related to text output.", "properties": { From ab8c35775e1031c23bd891874005916cd8680084 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 10 Dec 2024 18:11:30 +0100 Subject: [PATCH 7/8] Added option to disable call to Arduino Cloud API for board detection --- commands/service_board_list.go | 2 +- docs/configuration.md | 5 ++++- internal/cli/configuration/configuration.schema.json | 10 ++++++++++ internal/cli/configuration/defaults.go | 2 ++ internal/cli/configuration/network.go | 5 +++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/commands/service_board_list.go b/commands/service_board_list.go index 8f90e544748..a7ba7da0676 100644 --- a/commands/service_board_list.go +++ b/commands/service_board_list.go @@ -170,7 +170,7 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port, settings *conf // if installed cores didn't recognize the board, try querying // the builder API if the board is a USB device port - if len(boards) == 0 && !skipCloudAPI { + if len(boards) == 0 && !skipCloudAPI && !settings.SkipCloudApiForBoardDetection() { items, err := identifyViaCloudAPI(port.Properties, settings) if err != nil { // this is bad, but keep going diff --git a/docs/configuration.md b/docs/configuration.md index 376c4aa5d2b..c069638328f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -46,7 +46,10 @@ - `network` - configuration options related to the network connection. - `proxy` - URL of the proxy server. - `connection_timeout` - network connection timeout, the value format must be a valid input for - [time.ParseDuration()](https://pkg.go.dev/time#ParseDuration), defaults to `60s` (60 seconds). `0` means it will wait indefinitely. + [time.ParseDuration()](https://pkg.go.dev/time#ParseDuration), defaults to `60s` (60 seconds). `0` means it will + wait indefinitely. + - `cloud_api.skip_board_detection_calls` - if set to `true` it will make the Arduino CLI skip network calls to Arduino + Cloud API to help detection of an unknown board. ### Default directories diff --git a/internal/cli/configuration/configuration.schema.json b/internal/cli/configuration/configuration.schema.json index 82173c0d96d..4d129e5efd8 100644 --- a/internal/cli/configuration/configuration.schema.json +++ b/internal/cli/configuration/configuration.schema.json @@ -154,6 +154,16 @@ "description": "timeout for network connections, defaults to '30s'", "type": "string", "pattern": "^[+-]?(([0-9]+(\\.[0-9]*)?|(\\.[0-9]+))(ns|us|µs|μs|ms|s|m|h))+$" + }, + "cloud_api": { + "description": "settings related to the Arduino Cloud API.", + "type": "object", + "properties": { + "skip_board_detection_calls": { + "description": "do not call the Arduino Cloud API to detect an unknown board", + "type": "boolean" + } + } } } }, diff --git a/internal/cli/configuration/defaults.go b/internal/cli/configuration/defaults.go index 8e8f28fdcf5..6e46e2a1564 100644 --- a/internal/cli/configuration/defaults.go +++ b/internal/cli/configuration/defaults.go @@ -72,6 +72,8 @@ func SetDefaults(settings *Settings) { setKeyTypeSchema("network.proxy", "") setKeyTypeSchema("network.user_agent_ext", "") setDefaultValueAndKeyTypeSchema("network.connection_timeout", (time.Second * 60).String()) + // network: Arduino Cloud API settings + setKeyTypeSchema("network.cloud_api.skip_board_detection_calls", false) // locale setKeyTypeSchema("locale", "") diff --git a/internal/cli/configuration/network.go b/internal/cli/configuration/network.go index aae125bc0ed..c570d0a3b82 100644 --- a/internal/cli/configuration/network.go +++ b/internal/cli/configuration/network.go @@ -67,6 +67,11 @@ func (settings *Settings) ConnectionTimeout() time.Duration { return settings.Defaults.GetDuration("network.connection_timeout") } +// SkipCloudApiForBoardDetection returns whether the cloud API should be ignored for board detection +func (settings *Settings) SkipCloudApiForBoardDetection() bool { + return settings.GetBool("network.cloud_api.skip_board_detection_calls") +} + // NetworkProxy returns the proxy configuration (mainly used by HTTP clients) func (settings *Settings) NetworkProxy() (*url.URL, error) { if proxyConfig, ok, _ := settings.GetStringOk("network.proxy"); !ok { From ff3735f7f561abb58f4c8ec18eb418af2aeae7e9 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 11 Dec 2024 11:59:49 +0100 Subject: [PATCH 8/8] Adjusted unit-tests --- commands/service_settings_test.go | 67 +++++++++++++++++++++- internal/cli/configuration/network_test.go | 4 +- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/commands/service_settings_test.go b/commands/service_settings_test.go index 89f7b11c3f7..24959962f38 100644 --- a/commands/service_settings_test.go +++ b/commands/service_settings_test.go @@ -224,12 +224,73 @@ func TestDelete(t *testing.T) { srv := NewArduinoCoreServer() loadConfig(t, srv, paths.New("testdata", "arduino-cli.yml")) - _, err := srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"}) + // Check loaded config + resp, err := srv.ConfigurationSave(context.Background(), &rpc.ConfigurationSaveRequest{ + SettingsFormat: "yaml", + }) + require.NoError(t, err) + require.YAMLEq(t, ` +board_manager: + additional_urls: + - http://foobar.com + - http://example.com + +daemon: + port: "50051" + +directories: + data: /home/massi/.arduino15 + downloads: /home/massi/.arduino15/staging + +logging: + file: "" + format: text + level: info + +network: + proxy: "123" +`, resp.GetEncodedSettings()) + + // Check default and setted values + res, err := srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"}) + require.NoError(t, err) + require.Equal(t, `{"proxy":"123"}`, res.GetEncodedValue()) + // Maybe should be like this? + // require.Equal(t, `{"proxy":"123","connection_timeout":"1m0s"}`, res.GetEncodedValue()) + res, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network.connection_timeout"}) + require.Equal(t, `"1m0s"`, res.GetEncodedValue()) // default value require.NoError(t, err) + // Run deletion _, err = srv.SettingsSetValue(context.Background(), &rpc.SettingsSetValueRequest{Key: "network", EncodedValue: ""}) require.NoError(t, err) + resp, err = srv.ConfigurationSave(context.Background(), &rpc.ConfigurationSaveRequest{ + SettingsFormat: "yaml", + }) + require.NoError(t, err) + require.YAMLEq(t, ` +board_manager: + additional_urls: + - http://foobar.com + - http://example.com - _, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"}) - require.Error(t, err) +daemon: + port: "50051" + +directories: + data: /home/massi/.arduino15 + downloads: /home/massi/.arduino15/staging + +logging: + file: "" + format: text + level: info +`, resp.GetEncodedSettings()) + // Check default and setted values + res, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"}) + require.NoError(t, err) + require.Equal(t, `{"connection_timeout":"1m0s"}`, res.GetEncodedValue()) + res, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network.connection_timeout"}) + require.Equal(t, `"1m0s"`, res.GetEncodedValue()) // default value + require.NoError(t, err) } diff --git a/internal/cli/configuration/network_test.go b/internal/cli/configuration/network_test.go index d4a9af384bc..68cc84fdd59 100644 --- a/internal/cli/configuration/network_test.go +++ b/internal/cli/configuration/network_test.go @@ -79,9 +79,9 @@ func TestConnectionTimeout(t *testing.T) { doRequest := func(timeout int) (*http.Response, time.Duration, error) { settings := configuration.NewSettings() - settings.Set("network.proxy", ts.URL) + require.NoError(t, settings.Set("network.proxy", ts.URL)) if timeout != 0 { - settings.Set("network.connection_timeout", 2) + require.NoError(t, settings.Set("network.connection_timeout", "2s")) } client, err := settings.NewHttpClient() require.NoError(t, err)