Unverified Commit 50a8bf5c authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

[breaking] Remove gRPC `settings` service (#2411)

* Removed setting service

* Updated docs

* Update mkdocs configuration
parent 0e5f6294
...@@ -237,13 +237,11 @@ tasks: ...@@ -237,13 +237,11 @@ tasks:
desc: Compile protobuf definitions desc: Compile protobuf definitions
cmds: cmds:
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/commands/v1/*.proto' - '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/commands/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/settings/v1/*.proto'
protoc:docs: protoc:docs:
desc: Generate docs for protobuf definitions desc: Generate docs for protobuf definitions
cmds: cmds:
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto' - '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
docs:include-configuration-json-schema: docs:include-configuration-json-schema:
desc: Copy configuration JSON schema to make it available in documentation desc: Copy configuration JSON schema to make it available in documentation
......
...@@ -29,7 +29,6 @@ import ( ...@@ -29,7 +29,6 @@ import (
"time" "time"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
) )
...@@ -63,8 +62,6 @@ func main() { ...@@ -63,8 +62,6 @@ func main() {
// Create an instance of the gRPC clients. // Create an instance of the gRPC clients.
client := rpc.NewArduinoCoreServiceClient(conn) client := rpc.NewArduinoCoreServiceClient(conn)
settingsClient := settings.NewSettingsServiceClient(conn)
// Now we can call various methods of the API... // Now we can call various methods of the API...
// `Version` can be called without any setup or init procedure. // `Version` can be called without any setup or init procedure.
...@@ -76,39 +73,39 @@ func main() { ...@@ -76,39 +73,39 @@ func main() {
// Use SetValue to configure the arduino-cli directories. // Use SetValue to configure the arduino-cli directories.
log.Println("calling SetValue") log.Println("calling SetValue")
callSetValue(settingsClient) callSetValue(client)
// List all the settings. // List all settings
log.Println("calling GetAll()") log.Println("calling SettingsGetAll()")
callGetAll(settingsClient) callGetAll(client)
// Merge applies multiple settings values at once. // Merge applies multiple settings values at once.
log.Println("calling Merge()") log.Println("calling SettingsMerge()")
callMerge(settingsClient, `{"foo": {"value": "bar"}, "daemon":{"port":"422"}, "board_manager": {"additional_urls":["https://example.com"]}}`) callMerge(client, `{"foo": {"value": "bar"}, "daemon":{"port":"422"}, "board_manager": {"additional_urls":["https://example.com"]}}`)
log.Println("calling GetAll()") log.Println("calling SettingsGetAll()")
callGetAll(settingsClient) callGetAll(client)
log.Println("calling Merge()") log.Println("calling SettingsMerge()")
callMerge(settingsClient, `{"foo": {} }`) callMerge(client, `{"foo": {} }`)
log.Println("calling GetAll()") log.Println("calling SettingsGetAll()")
callGetAll(settingsClient) callGetAll(client)
log.Println("calling Merge()") log.Println("calling SettingsMerge()")
callMerge(settingsClient, `{"foo": "bar" }`) callMerge(client, `{"foo": "bar" }`)
// Get the value of the foo key. // Get the value of the foo key.
log.Println("calling GetValue(foo)") log.Println("calling SettingsGetValue(foo)")
callGetValue(settingsClient) callGetValue(client)
// List all the settings. // List all settings
log.Println("calling GetAll()") log.Println("calling SettingsGetAll()")
callGetAll(settingsClient) callGetAll(client)
// Write settings to file. // Write settings to file.
log.Println("calling Write()") log.Println("calling Write()")
callWrite(settingsClient) callWrite(client)
// Before we can do anything with the CLI, an "instance" must be created. // Before we can do anything with the CLI, an "instance" must be created.
// We keep a reference to the created instance because we will need it to // We keep a reference to the created instance because we will need it to
...@@ -121,7 +118,7 @@ func main() { ...@@ -121,7 +118,7 @@ func main() {
// We set up the proxy and then run the update to verify that the proxy settings are currently used // We set up the proxy and then run the update to verify that the proxy settings are currently used
log.Println("calling setProxy") log.Println("calling setProxy")
callSetProxy(settingsClient) callSetProxy(client)
// With a brand new instance, the first operation should always be updating // With a brand new instance, the first operation should always be updating
// the index. // the index.
...@@ -247,22 +244,21 @@ func callVersion(client rpc.ArduinoCoreServiceClient) { ...@@ -247,22 +244,21 @@ func callVersion(client rpc.ArduinoCoreServiceClient) {
log.Printf("arduino-cli version: %v", versionResp.GetVersion()) log.Printf("arduino-cli version: %v", versionResp.GetVersion())
} }
func callSetValue(client settings.SettingsServiceClient) { func callSetValue(client rpc.ArduinoCoreServiceClient) {
_, err := client.SetValue(context.Background(), _, err := client.SettingsSetValue(context.Background(),
&settings.SetValueRequest{ &rpc.SettingsSetValueRequest{
Key: "directories", Key: "directories",
JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`, JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`,
}) })
if err != nil { if err != nil {
log.Fatalf("Error setting settings value: %s", err) log.Fatalf("Error setting settings value: %s", err)
} }
} }
func callSetProxy(client settings.SettingsServiceClient) { func callSetProxy(client rpc.ArduinoCoreServiceClient) {
_, err := client.SetValue(context.Background(), _, err := client.SettingsSetValue(context.Background(),
&settings.SetValueRequest{ &rpc.SettingsSetValueRequest{
Key: "network.proxy", Key: "network.proxy",
JsonData: `"http://localhost:3128"`, JsonData: `"http://localhost:3128"`,
}) })
...@@ -272,9 +268,9 @@ func callSetProxy(client settings.SettingsServiceClient) { ...@@ -272,9 +268,9 @@ func callSetProxy(client settings.SettingsServiceClient) {
} }
} }
func callUnsetProxy(client settings.SettingsServiceClient) { func callUnsetProxy(client rpc.ArduinoCoreServiceClient) {
_, err := client.SetValue(context.Background(), _, err := client.SettingsSetValue(context.Background(),
&settings.SetValueRequest{ &rpc.SettingsSetValueRequest{
Key: "network.proxy", Key: "network.proxy",
JsonData: `""`, JsonData: `""`,
}) })
...@@ -284,9 +280,9 @@ func callUnsetProxy(client settings.SettingsServiceClient) { ...@@ -284,9 +280,9 @@ func callUnsetProxy(client settings.SettingsServiceClient) {
} }
} }
func callMerge(client settings.SettingsServiceClient, jsonData string) { func callMerge(client rpc.ArduinoCoreServiceClient, jsonData string) {
_, err := client.Merge(context.Background(), _, err := client.SettingsMerge(context.Background(),
&settings.MergeRequest{ &rpc.SettingsMergeRequest{
JsonData: jsonData, JsonData: jsonData,
}) })
...@@ -295,9 +291,9 @@ func callMerge(client settings.SettingsServiceClient, jsonData string) { ...@@ -295,9 +291,9 @@ func callMerge(client settings.SettingsServiceClient, jsonData string) {
} }
} }
func callGetValue(client settings.SettingsServiceClient) { func callGetValue(client rpc.ArduinoCoreServiceClient) {
getValueResp, err := client.GetValue(context.Background(), getValueResp, err := client.SettingsGetValue(context.Background(),
&settings.GetValueRequest{ &rpc.SettingsGetValueRequest{
Key: "foo", Key: "foo",
}) })
...@@ -308,8 +304,8 @@ func callGetValue(client settings.SettingsServiceClient) { ...@@ -308,8 +304,8 @@ func callGetValue(client settings.SettingsServiceClient) {
log.Printf("Value: %s: %s", getValueResp.GetKey(), getValueResp.GetJsonData()) log.Printf("Value: %s: %s", getValueResp.GetKey(), getValueResp.GetJsonData())
} }
func callGetAll(client settings.SettingsServiceClient) { func callGetAll(client rpc.ArduinoCoreServiceClient) {
getAllResp, err := client.GetAll(context.Background(), &settings.GetAllRequest{}) getAllResp, err := client.SettingsGetAll(context.Background(), &rpc.SettingsGetAllRequest{})
if err != nil { if err != nil {
log.Fatalf("Error getting settings: %s", err) log.Fatalf("Error getting settings: %s", err)
...@@ -318,10 +314,10 @@ func callGetAll(client settings.SettingsServiceClient) { ...@@ -318,10 +314,10 @@ func callGetAll(client settings.SettingsServiceClient) {
log.Printf("Settings: %s", getAllResp.GetJsonData()) log.Printf("Settings: %s", getAllResp.GetJsonData())
} }
func callWrite(client settings.SettingsServiceClient) { func callWrite(client rpc.ArduinoCoreServiceClient) {
_, err := client.Write(context.Background(), _, err := client.SettingsWrite(context.Background(),
&settings.WriteRequest{ &rpc.SettingsWriteRequest{
FilePath: path.Join(dataDir, "written-settings.yml"), FilePath: path.Join(dataDir, "written-rpc.Settingsyml"),
}) })
if err != nil { if err != nil {
......
...@@ -23,20 +23,15 @@ import ( ...@@ -23,20 +23,15 @@ import (
"strings" "strings"
"github.com/arduino/arduino-cli/configuration" "github.com/arduino/arduino-cli/configuration"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
) )
// SettingsService implements the `Settings` service // SettingsGetAll returns a message with a string field containing all the settings
type SettingsService struct {
rpc.UnimplementedSettingsServiceServer
}
// GetAll returns a message with a string field containing all the settings
// currently in use, marshalled in JSON format. // currently in use, marshalled in JSON format.
func (s *SettingsService) GetAll(ctx context.Context, req *rpc.GetAllRequest) (*rpc.GetAllResponse, error) { func (s *ArduinoCoreServerImpl) SettingsGetAll(ctx context.Context, req *rpc.SettingsGetAllRequest) (*rpc.SettingsGetAllResponse, error) {
b, err := json.Marshal(configuration.Settings.AllSettings()) b, err := json.Marshal(configuration.Settings.AllSettings())
if err == nil { if err == nil {
return &rpc.GetAllResponse{ return &rpc.SettingsGetAllResponse{
JsonData: string(b), JsonData: string(b),
}, nil }, nil
} }
...@@ -72,8 +67,8 @@ func mapper(toMap map[string]interface{}) map[string]interface{} { ...@@ -72,8 +67,8 @@ func mapper(toMap map[string]interface{}) map[string]interface{} {
return res return res
} }
// Merge applies multiple settings values at once. // SettingsMerge applies multiple settings values at once.
func (s *SettingsService) Merge(ctx context.Context, req *rpc.MergeRequest) (*rpc.MergeResponse, error) { func (s *ArduinoCoreServerImpl) SettingsMerge(ctx context.Context, req *rpc.SettingsMergeRequest) (*rpc.SettingsMergeResponse, error) {
var toMerge map[string]interface{} var toMerge map[string]interface{}
if err := json.Unmarshal([]byte(req.GetJsonData()), &toMerge); err != nil { if err := json.Unmarshal([]byte(req.GetJsonData()), &toMerge); err != nil {
return nil, err return nil, err
...@@ -88,13 +83,13 @@ func (s *SettingsService) Merge(ctx context.Context, req *rpc.MergeRequest) (*rp ...@@ -88,13 +83,13 @@ func (s *SettingsService) Merge(ctx context.Context, req *rpc.MergeRequest) (*rp
configuration.Settings.Set(k, v) configuration.Settings.Set(k, v)
} }
return &rpc.MergeResponse{}, nil return &rpc.SettingsMergeResponse{}, nil
} }
// GetValue returns a settings value given its key. If the key is not present // SettingsGetValue returns a settings value given its key. If the key is not present
// an error will be returned, so that we distinguish empty settings from missing // an error will be returned, so that we distinguish empty settings from missing
// ones. // ones.
func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest) (*rpc.GetValueResponse, error) { func (s *ArduinoCoreServerImpl) SettingsGetValue(ctx context.Context, req *rpc.SettingsGetValueRequest) (*rpc.SettingsGetValueResponse, error) {
key := req.GetKey() key := req.GetKey()
// Check if settings key actually existing, we don't use Viper.InConfig() // Check if settings key actually existing, we don't use Viper.InConfig()
...@@ -112,7 +107,7 @@ func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest ...@@ -112,7 +107,7 @@ func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest
} }
b, err := json.Marshal(configuration.Settings.Get(key)) b, err := json.Marshal(configuration.Settings.Get(key))
value := &rpc.GetValueResponse{} value := &rpc.SettingsGetValueResponse{}
if err == nil { if err == nil {
value.Key = key value.Key = key
value.JsonData = string(b) value.JsonData = string(b)
...@@ -121,8 +116,8 @@ func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest ...@@ -121,8 +116,8 @@ func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest
return value, err return value, err
} }
// SetValue updates or set a value for a certain key. // SettingsSetValue updates or set a value for a certain key.
func (s *SettingsService) SetValue(ctx context.Context, val *rpc.SetValueRequest) (*rpc.SetValueResponse, error) { func (s *ArduinoCoreServerImpl) SettingsSetValue(ctx context.Context, val *rpc.SettingsSetValueRequest) (*rpc.SettingsSetValueResponse, error) {
key := val.GetKey() key := val.GetKey()
var value interface{} var value interface{}
...@@ -131,22 +126,22 @@ func (s *SettingsService) SetValue(ctx context.Context, val *rpc.SetValueRequest ...@@ -131,22 +126,22 @@ func (s *SettingsService) SetValue(ctx context.Context, val *rpc.SetValueRequest
configuration.Settings.Set(key, value) configuration.Settings.Set(key, value)
} }
return &rpc.SetValueResponse{}, err return &rpc.SettingsSetValueResponse{}, err
} }
// Write to file set in request the settings currently stored in memory. // SettingsWrite to file set in request the settings currently stored in memory.
// We don't have a Read() function, that's not necessary since we only want one config file to be used // We don't have a Read() function, that's not necessary since we only want one config file to be used
// and that's picked up when the CLI is run as daemon, either using the default path or a custom one // and that's picked up when the CLI is run as daemon, either using the default path or a custom one
// set with the --config-file flag. // set with the --config-file flag.
func (s *SettingsService) Write(ctx context.Context, req *rpc.WriteRequest) (*rpc.WriteResponse, error) { func (s *ArduinoCoreServerImpl) SettingsWrite(ctx context.Context, req *rpc.SettingsWriteRequest) (*rpc.SettingsWriteResponse, error) {
if err := configuration.Settings.WriteConfigAs(req.FilePath); err != nil { if err := configuration.Settings.WriteConfigAs(req.FilePath); err != nil {
return nil, err return nil, err
} }
return &rpc.WriteResponse{}, nil return &rpc.SettingsWriteResponse{}, nil
} }
// Delete removes a key from the config file // SettingsDelete removes a key from the config file
func (s *SettingsService) Delete(ctx context.Context, req *rpc.DeleteRequest) (*rpc.DeleteResponse, error) { func (s *ArduinoCoreServerImpl) SettingsDelete(ctx context.Context, req *rpc.SettingsDeleteRequest) (*rpc.SettingsDeleteResponse, error) {
toDelete := req.GetKey() toDelete := req.GetKey()
// Check if settings key actually existing, we don't use Viper.InConfig() // Check if settings key actually existing, we don't use Viper.InConfig()
...@@ -175,5 +170,5 @@ func (s *SettingsService) Delete(ctx context.Context, req *rpc.DeleteRequest) (* ...@@ -175,5 +170,5 @@ func (s *SettingsService) Delete(ctx context.Context, req *rpc.DeleteRequest) (*
updatedSettings.SetConfigFile(configPath) updatedSettings.SetConfigFile(configPath)
configuration.Settings = updatedSettings configuration.Settings = updatedSettings
return &rpc.DeleteResponse{}, nil return &rpc.SettingsDeleteResponse{}, nil
} }
...@@ -22,12 +22,12 @@ import ( ...@@ -22,12 +22,12 @@ import (
"testing" "testing"
"github.com/arduino/arduino-cli/configuration" "github.com/arduino/arduino-cli/configuration"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var svc = SettingsService{} var svc = ArduinoCoreServerImpl{}
func init() { func init() {
configuration.Settings = configuration.Init(filepath.Join("testdata", "arduino-cli.yaml")) configuration.Settings = configuration.Init(filepath.Join("testdata", "arduino-cli.yaml"))
...@@ -38,7 +38,7 @@ func reset() { ...@@ -38,7 +38,7 @@ func reset() {
} }
func TestGetAll(t *testing.T) { func TestGetAll(t *testing.T) {
resp, err := svc.GetAll(context.Background(), &rpc.GetAllRequest{}) resp, err := svc.SettingsGetAll(context.Background(), &rpc.SettingsGetAllRequest{})
require.Nil(t, err) require.Nil(t, err)
content, err := json.Marshal(configuration.Settings.AllSettings()) content, err := json.Marshal(configuration.Settings.AllSettings())
...@@ -54,7 +54,7 @@ func TestMerge(t *testing.T) { ...@@ -54,7 +54,7 @@ func TestMerge(t *testing.T) {
require.Equal(t, false, configuration.Settings.GetBool("sketch.always_export_binaries")) require.Equal(t, false, configuration.Settings.GetBool("sketch.always_export_binaries"))
bulkSettings := `{"foo": "bar", "daemon":{"port":"420"}, "sketch": {"always_export_binaries": "true"}}` bulkSettings := `{"foo": "bar", "daemon":{"port":"420"}, "sketch": {"always_export_binaries": "true"}}`
res, err := svc.Merge(context.Background(), &rpc.MergeRequest{JsonData: bulkSettings}) res, err := svc.SettingsMerge(context.Background(), &rpc.SettingsMergeRequest{JsonData: bulkSettings})
require.NotNil(t, res) require.NotNil(t, res)
require.NoError(t, err) require.NoError(t, err)
...@@ -63,7 +63,7 @@ func TestMerge(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestMerge(t *testing.T) {
require.Equal(t, true, configuration.Settings.GetBool("sketch.always_export_binaries")) require.Equal(t, true, configuration.Settings.GetBool("sketch.always_export_binaries"))
bulkSettings = `{"foo":"", "daemon": {}, "sketch": {"always_export_binaries": "false"}}` bulkSettings = `{"foo":"", "daemon": {}, "sketch": {"always_export_binaries": "false"}}`
res, err = svc.Merge(context.Background(), &rpc.MergeRequest{JsonData: bulkSettings}) res, err = svc.SettingsMerge(context.Background(), &rpc.SettingsMergeRequest{JsonData: bulkSettings})
require.NotNil(t, res) require.NotNil(t, res)
require.NoError(t, err) require.NoError(t, err)
...@@ -72,7 +72,7 @@ func TestMerge(t *testing.T) { ...@@ -72,7 +72,7 @@ func TestMerge(t *testing.T) {
require.Equal(t, false, configuration.Settings.GetBool("sketch.always_export_binaries")) require.Equal(t, false, configuration.Settings.GetBool("sketch.always_export_binaries"))
bulkSettings = `{"daemon": {"port":""}}` bulkSettings = `{"daemon": {"port":""}}`
res, err = svc.Merge(context.Background(), &rpc.MergeRequest{JsonData: bulkSettings}) res, err = svc.SettingsMerge(context.Background(), &rpc.SettingsMergeRequest{JsonData: bulkSettings})
require.NotNil(t, res) require.NotNil(t, res)
require.NoError(t, err) require.NoError(t, err)
...@@ -85,60 +85,60 @@ func TestMerge(t *testing.T) { ...@@ -85,60 +85,60 @@ func TestMerge(t *testing.T) {
} }
func TestGetValue(t *testing.T) { func TestGetValue(t *testing.T) {
key := &rpc.GetValueRequest{Key: "daemon"} key := &rpc.SettingsGetValueRequest{Key: "daemon"}
resp, err := svc.GetValue(context.Background(), key) resp, err := svc.SettingsGetValue(context.Background(), key)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, `{"port":"50051"}`, resp.GetJsonData()) require.Equal(t, `{"port":"50051"}`, resp.GetJsonData())
key = &rpc.GetValueRequest{Key: "daemon.port"} key = &rpc.SettingsGetValueRequest{Key: "daemon.port"}
resp, err = svc.GetValue(context.Background(), key) resp, err = svc.SettingsGetValue(context.Background(), key)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, `"50051"`, resp.GetJsonData()) require.Equal(t, `"50051"`, resp.GetJsonData())
} }
func TestGetMergedValue(t *testing.T) { func TestGetMergedValue(t *testing.T) {
// Verifies value is not set // Verifies value is not set
key := &rpc.GetValueRequest{Key: "foo"} key := &rpc.SettingsGetValueRequest{Key: "foo"}
res, err := svc.GetValue(context.Background(), key) res, err := svc.SettingsGetValue(context.Background(), key)
require.Nil(t, res) require.Nil(t, res)
require.Error(t, err, "Error getting settings value") require.Error(t, err, "Error getting settings value")
// Merge value // Merge value
bulkSettings := `{"foo": "bar"}` bulkSettings := `{"foo": "bar"}`
_, err = svc.Merge(context.Background(), &rpc.MergeRequest{JsonData: bulkSettings}) _, err = svc.SettingsMerge(context.Background(), &rpc.SettingsMergeRequest{JsonData: bulkSettings})
require.NoError(t, err) require.NoError(t, err)
// Verifies value is correctly returned // Verifies value is correctly returned
key = &rpc.GetValueRequest{Key: "foo"} key = &rpc.SettingsGetValueRequest{Key: "foo"}
res, err = svc.GetValue(context.Background(), key) res, err = svc.SettingsGetValue(context.Background(), key)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, `"bar"`, res.GetJsonData()) require.Equal(t, `"bar"`, res.GetJsonData())
} }
func TestGetValueNotFound(t *testing.T) { func TestGetValueNotFound(t *testing.T) {
key := &rpc.GetValueRequest{Key: "DOESNTEXIST"} key := &rpc.SettingsGetValueRequest{Key: "DOESNTEXIST"}
_, err := svc.GetValue(context.Background(), key) _, err := svc.SettingsGetValue(context.Background(), key)
require.NotNil(t, err) require.NotNil(t, err)
require.Equal(t, `key not found in settings`, err.Error()) require.Equal(t, `key not found in settings`, err.Error())
} }
func TestSetValue(t *testing.T) { func TestSetValue(t *testing.T) {
val := &rpc.SetValueRequest{ val := &rpc.SettingsSetValueRequest{
Key: "foo", Key: "foo",
JsonData: `"bar"`, JsonData: `"bar"`,
} }
_, err := svc.SetValue(context.Background(), val) _, err := svc.SettingsSetValue(context.Background(), val)
require.Nil(t, err) require.Nil(t, err)
require.Equal(t, "bar", configuration.Settings.GetString("foo")) require.Equal(t, "bar", configuration.Settings.GetString("foo"))
} }
func TestWrite(t *testing.T) { func TestWrite(t *testing.T) {
// Writes some settings // Writes some settings
val := &rpc.SetValueRequest{ val := &rpc.SettingsSetValueRequest{
Key: "foo", Key: "foo",
JsonData: `"bar"`, JsonData: `"bar"`,
} }
_, err := svc.SetValue(context.Background(), val) _, err := svc.SettingsSetValue(context.Background(), val)
require.NoError(t, err) require.NoError(t, err)
tempDir := paths.TempDir() tempDir := paths.TempDir()
...@@ -150,7 +150,7 @@ func TestWrite(t *testing.T) { ...@@ -150,7 +150,7 @@ func TestWrite(t *testing.T) {
configFile := testFolder.Join("arduino-cli.yml") configFile := testFolder.Join("arduino-cli.yml")
require.True(t, configFile.NotExist()) require.True(t, configFile.NotExist())
_, err = svc.Write(context.Background(), &rpc.WriteRequest{ _, err = svc.SettingsWrite(context.Background(), &rpc.SettingsWriteRequest{
FilePath: configFile.String(), FilePath: configFile.String(),
}) })
require.NoError(t, err) require.NoError(t, err)
...@@ -161,16 +161,16 @@ func TestWrite(t *testing.T) { ...@@ -161,16 +161,16 @@ func TestWrite(t *testing.T) {
} }
func TestDelete(t *testing.T) { func TestDelete(t *testing.T) {
_, err := svc.Delete(context.Background(), &rpc.DeleteRequest{ _, err := svc.SettingsDelete(context.Background(), &rpc.SettingsDeleteRequest{
Key: "doesnotexist", Key: "doesnotexist",
}) })
require.Error(t, err) require.Error(t, err)
_, err = svc.Delete(context.Background(), &rpc.DeleteRequest{ _, err = svc.SettingsDelete(context.Background(), &rpc.SettingsDeleteRequest{
Key: "network", Key: "network",
}) })
require.NoError(t, err) require.NoError(t, err)
_, err = svc.GetValue(context.Background(), &rpc.GetValueRequest{Key: "network"}) _, err = svc.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"})
require.Error(t, err) require.Error(t, err)
} }
...@@ -4,6 +4,27 @@ Here you can find a list of migration guides to handle breaking changes between ...@@ -4,6 +4,27 @@ Here you can find a list of migration guides to handle breaking changes between
## 0.36.0 ## 0.36.0
### gRPC service `cc.arduino.cli.settings.v1` has been removed, and all RPC calls have been migrated to `cc.arduino.cli.commands.v1`
The service `cc.arduino.cli.settings.v1` no longer exists and all existing RPC calls have been moved to the
`cc.arduino.cli.commands.v1` service adding a `Settings` prefix to the names of all messages. The existing RPC calls:
- `rpc GetAll(GetAllRequest) returns (GetAllResponse)`
- `rpc Merge(MergeRequest) returns (MergeResponse)`
- `rpc GetValue(GetValueRequest) returns (GetValueResponse)`
- `rpc SetValue(SetValueRequest) returns (SetValueResponse)`
- `rpc Write(WriteRequest) returns (WriteResponse)`
- `rpc Delete(DeleteRequest) returns (DeleteResponse)`
are now renamed to:
- `rpc SettingsGetAll(SettingsGetAllRequest) returns (SettingsGetAllResponse)`
- `rpc SettingsMerge(SettingsMergeRequest) returns (SettingsMergeResponse)`
- `rpc SettingsGetValue(SettingsGetValueRequest) returns (SettingsGetValueResponse)`
- `rpc SettingsSetValue(SettingsSetValueRequest) returns (SettingsSetValueResponse)`
- `rpc SettingsWrite(SettingsWriteRequest) returns (SettingsWriteResponse)`
- `rpc SettingsDelete(SettingsDeleteRequest) returns (SettingsDeleteResponse)`
### gRPC `cc.arduino.cli.commands.v1.LibrarySearchRequest` message has been changed. ### gRPC `cc.arduino.cli.commands.v1.LibrarySearchRequest` message has been changed.
The `query` field has been removed, use `search_args` instead. The `query` field has been removed, use `search_args` instead.
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
"github.com/arduino/arduino-cli/commands/daemon" "github.com/arduino/arduino-cli/commands/daemon"
"github.com/arduino/arduino-cli/configuration" "github.com/arduino/arduino-cli/configuration"
"github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
...@@ -47,12 +47,12 @@ func runDeleteCommand(cmd *cobra.Command, args []string) { ...@@ -47,12 +47,12 @@ func runDeleteCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino-cli config delete`") logrus.Info("Executing `arduino-cli config delete`")
toDelete := args[0] toDelete := args[0]
svc := daemon.SettingsService{} svc := daemon.ArduinoCoreServerImpl{}
_, err := svc.Delete(cmd.Context(), &settings.DeleteRequest{Key: toDelete}) _, err := svc.SettingsDelete(cmd.Context(), &rpc.SettingsDeleteRequest{Key: toDelete})
if err != nil { if err != nil {
feedback.Fatal(tr("Cannot delete the key %[1]s: %[2]v", toDelete, err), feedback.ErrGeneric) feedback.Fatal(tr("Cannot delete the key %[1]s: %[2]v", toDelete, err), feedback.ErrGeneric)
} }
_, err = svc.Write(cmd.Context(), &settings.WriteRequest{FilePath: configuration.Settings.ConfigFileUsed()}) _, err = svc.SettingsWrite(cmd.Context(), &rpc.SettingsWriteRequest{FilePath: configuration.Settings.ConfigFileUsed()})
if err != nil { if err != nil {
feedback.Fatal(tr("Cannot write the file %[1]s: %[2]v", configuration.Settings.ConfigFileUsed(), err), feedback.ErrGeneric) feedback.Fatal(tr("Cannot write the file %[1]s: %[2]v", configuration.Settings.ConfigFileUsed(), err), feedback.ErrGeneric)
} }
......
...@@ -29,7 +29,6 @@ import ( ...@@ -29,7 +29,6 @@ import (
"github.com/arduino/arduino-cli/i18n" "github.com/arduino/arduino-cli/i18n"
"github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/cli/feedback"
srv_commands "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" srv_commands "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
srv_settings "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
"github.com/arduino/arduino-cli/version" "github.com/arduino/arduino-cli/version"
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
...@@ -107,9 +106,6 @@ func runDaemonCommand(cmd *cobra.Command, args []string) { ...@@ -107,9 +106,6 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
VersionString: version.VersionInfo.VersionString, VersionString: version.VersionInfo.VersionString,
}) })
// Register the settings service
srv_settings.RegisterSettingsServiceServer(s, &daemon.SettingsService{})
if !daemonize { if !daemonize {
// When parent process ends terminate also the daemon // When parent process ends terminate also the daemon
go feedback.ExitWhenParentProcessEnds() go feedback.ExitWhenParentProcessEnds()
......
...@@ -31,7 +31,6 @@ import ( ...@@ -31,7 +31,6 @@ import (
"github.com/arduino/arduino-cli/executils" "github.com/arduino/arduino-cli/executils"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -70,20 +69,19 @@ func CreateArduinoCLIWithEnvironment(t *testing.T) (*Environment, *ArduinoCLI) { ...@@ -70,20 +69,19 @@ func CreateArduinoCLIWithEnvironment(t *testing.T) (*Environment, *ArduinoCLI) {
// ArduinoCLI is an Arduino CLI client. // ArduinoCLI is an Arduino CLI client.
type ArduinoCLI struct { type ArduinoCLI struct {
path *paths.Path path *paths.Path
t *require.Assertions t *require.Assertions
proc *executils.Process proc *executils.Process
stdIn io.WriteCloser stdIn io.WriteCloser
cliEnvVars map[string]string cliEnvVars map[string]string
cliConfigPath *paths.Path cliConfigPath *paths.Path
stagingDir *paths.Path stagingDir *paths.Path
dataDir *paths.Path dataDir *paths.Path
sketchbookDir *paths.Path sketchbookDir *paths.Path
workingDir *paths.Path workingDir *paths.Path
daemonAddr string daemonAddr string
daemonConn *grpc.ClientConn daemonConn *grpc.ClientConn
daemonClient commands.ArduinoCoreServiceClient daemonClient commands.ArduinoCoreServiceClient
daemonSettingsClient settings.SettingsServiceClient
} }
// ArduinoCLIConfig is the configuration of the ArduinoCLI client // ArduinoCLIConfig is the configuration of the ArduinoCLI client
...@@ -386,7 +384,6 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string { ...@@ -386,7 +384,6 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string {
cli.t.NoError(err) cli.t.NoError(err)
cli.daemonConn = conn cli.daemonConn = conn
cli.daemonClient = commands.NewArduinoCoreServiceClient(conn) cli.daemonClient = commands.NewArduinoCoreServiceClient(conn)
cli.daemonSettingsClient = settings.NewSettingsServiceClient(conn)
return cli.daemonAddr return cli.daemonAddr
} }
...@@ -418,12 +415,12 @@ func (cli *ArduinoCLI) Create() *ArduinoCLIInstance { ...@@ -418,12 +415,12 @@ func (cli *ArduinoCLI) Create() *ArduinoCLIInstance {
// SetValue calls the "SetValue" gRPC method. // SetValue calls the "SetValue" gRPC method.
func (cli *ArduinoCLI) SetValue(key, jsonData string) error { func (cli *ArduinoCLI) SetValue(key, jsonData string) error {
req := &settings.SetValueRequest{ req := &commands.SettingsSetValueRequest{
Key: key, Key: key,
JsonData: jsonData, JsonData: jsonData,
} }
logCallf(">>> SetValue(%+v)\n", req) logCallf(">>> SetValue(%+v)\n", req)
_, err := cli.daemonSettingsClient.SetValue(context.Background(), req) _, err := cli.daemonClient.SettingsSetValue(context.Background(), req)
return err return err
} }
......
...@@ -100,7 +100,6 @@ nav: ...@@ -100,7 +100,6 @@ nav:
- version: commands/arduino-cli_version.md - version: commands/arduino-cli_version.md
- gRPC reference: - gRPC reference:
- commands: rpc/commands.md - commands: rpc/commands.md
- settings: rpc/settings.md
- configuration.md - configuration.md
- Integration options: integration-options.md - Integration options: integration-options.md
- sketch-build-process.md - sketch-build-process.md
......
...@@ -5,6 +5,3 @@ lint: ...@@ -5,6 +5,3 @@ lint:
ignore_only: ignore_only:
ENUM_ZERO_VALUE_SUFFIX: ENUM_ZERO_VALUE_SUFFIX:
- cc/arduino/cli/commands/v1/lib.proto - cc/arduino/cli/commands/v1/lib.proto
- cc/arduino/cli/monitor/v1/monitor.proto
RPC_REQUEST_STANDARD_NAME:
- cc/arduino/cli/debug/v1/debug.proto
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -29,6 +29,7 @@ import "cc/arduino/cli/commands/v1/debug.proto"; ...@@ -29,6 +29,7 @@ import "cc/arduino/cli/commands/v1/debug.proto";
import "cc/arduino/cli/commands/v1/monitor.proto"; import "cc/arduino/cli/commands/v1/monitor.proto";
import "cc/arduino/cli/commands/v1/upload.proto"; import "cc/arduino/cli/commands/v1/upload.proto";
import "cc/arduino/cli/commands/v1/lib.proto"; import "cc/arduino/cli/commands/v1/lib.proto";
import "cc/arduino/cli/commands/v1/settings.proto";
// The main Arduino Platform service API // The main Arduino Platform service API
service ArduinoCoreService { service ArduinoCoreService {
...@@ -182,6 +183,26 @@ service ArduinoCoreService { ...@@ -182,6 +183,26 @@ service ArduinoCoreService {
rpc Debug(stream DebugRequest) returns (stream DebugResponse) {} rpc Debug(stream DebugRequest) returns (stream DebugResponse) {}
rpc GetDebugConfig(GetDebugConfigRequest) returns (GetDebugConfigResponse) {} rpc GetDebugConfig(GetDebugConfigRequest) returns (GetDebugConfigResponse) {}
// List all the settings.
rpc SettingsGetAll(SettingsGetAllRequest) returns (SettingsGetAllResponse);
// Set multiple settings values at once.
rpc SettingsMerge(SettingsMergeRequest) returns (SettingsMergeResponse);
// Get the value of a specific setting.
rpc SettingsGetValue(SettingsGetValueRequest)
returns (SettingsGetValueResponse);
// Set the value of a specific setting.
rpc SettingsSetValue(SettingsSetValueRequest)
returns (SettingsSetValueResponse);
// Writes to file settings currently stored in memory
rpc SettingsWrite(SettingsWriteRequest) returns (SettingsWriteResponse);
// Deletes an entry and rewrites the file settings
rpc SettingsDelete(SettingsDeleteRequest) returns (SettingsDeleteResponse);
} }
message CreateRequest {} message CreateRequest {}
......
...@@ -15,77 +15,55 @@ ...@@ -15,77 +15,55 @@
syntax = "proto3"; syntax = "proto3";
package cc.arduino.cli.settings.v1; package cc.arduino.cli.commands.v1;
option go_package = "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1;settings"; option go_package = "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1;commands";
// The SettingsService provides an interface to Arduino CLI configuration message SettingsGetAllResponse {
// options
service SettingsService {
// List all the settings.
rpc GetAll(GetAllRequest) returns (GetAllResponse);
// Set multiple settings values at once.
rpc Merge(MergeRequest) returns (MergeResponse);
// Get the value of a specific setting.
rpc GetValue(GetValueRequest) returns (GetValueResponse);
// Set the value of a specific setting.
rpc SetValue(SetValueRequest) returns (SetValueResponse);
// Writes to file settings currently stored in memory
rpc Write(WriteRequest) returns (WriteResponse);
// Deletes an entry and rewrites the file settings
rpc Delete(DeleteRequest) returns (DeleteResponse);
}
message GetAllResponse {
// The settings, in JSON format. // The settings, in JSON format.
string json_data = 1; string json_data = 1;
} }
message MergeRequest { message SettingsMergeRequest {
// The settings, in JSON format. // The settings, in JSON format.
string json_data = 1; string json_data = 1;
} }
message GetValueResponse { message SettingsGetValueResponse {
// The key of the setting. // The key of the setting.
string key = 1; string key = 1;
// The setting, in JSON format. // The setting, in JSON format.
string json_data = 2; string json_data = 2;
} }
message SetValueRequest { message SettingsSetValueRequest {
// The key of the setting. // The key of the setting.
string key = 1; string key = 1;
// The setting, in JSON format. // The setting, in JSON format.
string json_data = 2; string json_data = 2;
} }
message GetAllRequest {} message SettingsGetAllRequest {}
message GetValueRequest { message SettingsGetValueRequest {
// The key of the setting. // The key of the setting.
string key = 1; string key = 1;
} }
message MergeResponse {} message SettingsMergeResponse {}
message SetValueResponse {} message SettingsSetValueResponse {}
message WriteRequest { message SettingsWriteRequest {
// Path to settings file (e.g. /path/to/arduino-cli.yaml) // Path to settings file (e.g. /path/to/arduino-cli.yaml)
string file_path = 1; string file_path = 1;
} }
message WriteResponse {} message SettingsWriteResponse {}
message DeleteRequest { message SettingsDeleteRequest {
// The key of the setting to delete. // The key of the setting to delete.
string key = 1; string key = 1;
} }
message DeleteResponse {} message SettingsDeleteResponse {}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment