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:
desc: Compile protobuf definitions
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/settings/v1/*.proto'
protoc:docs:
desc: Generate docs for protobuf definitions
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,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
docs:include-configuration-json-schema:
desc: Copy configuration JSON schema to make it available in documentation
......
......@@ -29,7 +29,6 @@ import (
"time"
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/credentials/insecure"
)
......@@ -63,8 +62,6 @@ func main() {
// Create an instance of the gRPC clients.
client := rpc.NewArduinoCoreServiceClient(conn)
settingsClient := settings.NewSettingsServiceClient(conn)
// Now we can call various methods of the API...
// `Version` can be called without any setup or init procedure.
......@@ -76,39 +73,39 @@ func main() {
// Use SetValue to configure the arduino-cli directories.
log.Println("calling SetValue")
callSetValue(settingsClient)
callSetValue(client)
// List all the settings.
log.Println("calling GetAll()")
callGetAll(settingsClient)
// List all settings
log.Println("calling SettingsGetAll()")
callGetAll(client)
// Merge applies multiple settings values at once.
log.Println("calling Merge()")
callMerge(settingsClient, `{"foo": {"value": "bar"}, "daemon":{"port":"422"}, "board_manager": {"additional_urls":["https://example.com"]}}`)
log.Println("calling SettingsMerge()")
callMerge(client, `{"foo": {"value": "bar"}, "daemon":{"port":"422"}, "board_manager": {"additional_urls":["https://example.com"]}}`)
log.Println("calling GetAll()")
callGetAll(settingsClient)
log.Println("calling SettingsGetAll()")
callGetAll(client)
log.Println("calling Merge()")
callMerge(settingsClient, `{"foo": {} }`)
log.Println("calling SettingsMerge()")
callMerge(client, `{"foo": {} }`)
log.Println("calling GetAll()")
callGetAll(settingsClient)
log.Println("calling SettingsGetAll()")
callGetAll(client)
log.Println("calling Merge()")
callMerge(settingsClient, `{"foo": "bar" }`)
log.Println("calling SettingsMerge()")
callMerge(client, `{"foo": "bar" }`)
// Get the value of the foo key.
log.Println("calling GetValue(foo)")
callGetValue(settingsClient)
log.Println("calling SettingsGetValue(foo)")
callGetValue(client)
// List all the settings.
log.Println("calling GetAll()")
callGetAll(settingsClient)
// List all settings
log.Println("calling SettingsGetAll()")
callGetAll(client)
// Write settings to file.
log.Println("calling Write()")
callWrite(settingsClient)
callWrite(client)
// 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
......@@ -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
log.Println("calling setProxy")
callSetProxy(settingsClient)
callSetProxy(client)
// With a brand new instance, the first operation should always be updating
// the index.
......@@ -247,22 +244,21 @@ func callVersion(client rpc.ArduinoCoreServiceClient) {
log.Printf("arduino-cli version: %v", versionResp.GetVersion())
}
func callSetValue(client settings.SettingsServiceClient) {
_, err := client.SetValue(context.Background(),
&settings.SetValueRequest{
func callSetValue(client rpc.ArduinoCoreServiceClient) {
_, err := client.SettingsSetValue(context.Background(),
&rpc.SettingsSetValueRequest{
Key: "directories",
JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`,
})
if err != nil {
log.Fatalf("Error setting settings value: %s", err)
}
}
func callSetProxy(client settings.SettingsServiceClient) {
_, err := client.SetValue(context.Background(),
&settings.SetValueRequest{
func callSetProxy(client rpc.ArduinoCoreServiceClient) {
_, err := client.SettingsSetValue(context.Background(),
&rpc.SettingsSetValueRequest{
Key: "network.proxy",
JsonData: `"http://localhost:3128"`,
})
......@@ -272,9 +268,9 @@ func callSetProxy(client settings.SettingsServiceClient) {
}
}
func callUnsetProxy(client settings.SettingsServiceClient) {
_, err := client.SetValue(context.Background(),
&settings.SetValueRequest{
func callUnsetProxy(client rpc.ArduinoCoreServiceClient) {
_, err := client.SettingsSetValue(context.Background(),
&rpc.SettingsSetValueRequest{
Key: "network.proxy",
JsonData: `""`,
})
......@@ -284,9 +280,9 @@ func callUnsetProxy(client settings.SettingsServiceClient) {
}
}
func callMerge(client settings.SettingsServiceClient, jsonData string) {
_, err := client.Merge(context.Background(),
&settings.MergeRequest{
func callMerge(client rpc.ArduinoCoreServiceClient, jsonData string) {
_, err := client.SettingsMerge(context.Background(),
&rpc.SettingsMergeRequest{
JsonData: jsonData,
})
......@@ -295,9 +291,9 @@ func callMerge(client settings.SettingsServiceClient, jsonData string) {
}
}
func callGetValue(client settings.SettingsServiceClient) {
getValueResp, err := client.GetValue(context.Background(),
&settings.GetValueRequest{
func callGetValue(client rpc.ArduinoCoreServiceClient) {
getValueResp, err := client.SettingsGetValue(context.Background(),
&rpc.SettingsGetValueRequest{
Key: "foo",
})
......@@ -308,8 +304,8 @@ func callGetValue(client settings.SettingsServiceClient) {
log.Printf("Value: %s: %s", getValueResp.GetKey(), getValueResp.GetJsonData())
}
func callGetAll(client settings.SettingsServiceClient) {
getAllResp, err := client.GetAll(context.Background(), &settings.GetAllRequest{})
func callGetAll(client rpc.ArduinoCoreServiceClient) {
getAllResp, err := client.SettingsGetAll(context.Background(), &rpc.SettingsGetAllRequest{})
if err != nil {
log.Fatalf("Error getting settings: %s", err)
......@@ -318,10 +314,10 @@ func callGetAll(client settings.SettingsServiceClient) {
log.Printf("Settings: %s", getAllResp.GetJsonData())
}
func callWrite(client settings.SettingsServiceClient) {
_, err := client.Write(context.Background(),
&settings.WriteRequest{
FilePath: path.Join(dataDir, "written-settings.yml"),
func callWrite(client rpc.ArduinoCoreServiceClient) {
_, err := client.SettingsWrite(context.Background(),
&rpc.SettingsWriteRequest{
FilePath: path.Join(dataDir, "written-rpc.Settingsyml"),
})
if err != nil {
......
......@@ -23,20 +23,15 @@ import (
"strings"
"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
type SettingsService struct {
rpc.UnimplementedSettingsServiceServer
}
// GetAll returns a message with a string field containing all the settings
// SettingsGetAll returns a message with a string field containing all the settings
// 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())
if err == nil {
return &rpc.GetAllResponse{
return &rpc.SettingsGetAllResponse{
JsonData: string(b),
}, nil
}
......@@ -72,8 +67,8 @@ func mapper(toMap map[string]interface{}) map[string]interface{} {
return res
}
// Merge applies multiple settings values at once.
func (s *SettingsService) Merge(ctx context.Context, req *rpc.MergeRequest) (*rpc.MergeResponse, error) {
// SettingsMerge applies multiple settings values at once.
func (s *ArduinoCoreServerImpl) SettingsMerge(ctx context.Context, req *rpc.SettingsMergeRequest) (*rpc.SettingsMergeResponse, error) {
var toMerge map[string]interface{}
if err := json.Unmarshal([]byte(req.GetJsonData()), &toMerge); err != nil {
return nil, err
......@@ -88,13 +83,13 @@ func (s *SettingsService) Merge(ctx context.Context, req *rpc.MergeRequest) (*rp
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
// 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()
// 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
}
b, err := json.Marshal(configuration.Settings.Get(key))
value := &rpc.GetValueResponse{}
value := &rpc.SettingsGetValueResponse{}
if err == nil {
value.Key = key
value.JsonData = string(b)
......@@ -121,8 +116,8 @@ func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest
return value, err
}
// SetValue updates or set a value for a certain key.
func (s *SettingsService) SetValue(ctx context.Context, val *rpc.SetValueRequest) (*rpc.SetValueResponse, error) {
// SettingsSetValue updates or set a value for a certain key.
func (s *ArduinoCoreServerImpl) SettingsSetValue(ctx context.Context, val *rpc.SettingsSetValueRequest) (*rpc.SettingsSetValueResponse, error) {
key := val.GetKey()
var value interface{}
......@@ -131,22 +126,22 @@ func (s *SettingsService) SetValue(ctx context.Context, val *rpc.SetValueRequest
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
// 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.
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 {
return nil, err
}
return &rpc.WriteResponse{}, nil
return &rpc.SettingsWriteResponse{}, nil
}
// Delete removes a key from the config file
func (s *SettingsService) Delete(ctx context.Context, req *rpc.DeleteRequest) (*rpc.DeleteResponse, error) {
// SettingsDelete removes a key from the config file
func (s *ArduinoCoreServerImpl) SettingsDelete(ctx context.Context, req *rpc.SettingsDeleteRequest) (*rpc.SettingsDeleteResponse, error) {
toDelete := req.GetKey()
// 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) (*
updatedSettings.SetConfigFile(configPath)
configuration.Settings = updatedSettings
return &rpc.DeleteResponse{}, nil
return &rpc.SettingsDeleteResponse{}, nil
}
......@@ -22,12 +22,12 @@ import (
"testing"
"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/stretchr/testify/require"
)
var svc = SettingsService{}
var svc = ArduinoCoreServerImpl{}
func init() {
configuration.Settings = configuration.Init(filepath.Join("testdata", "arduino-cli.yaml"))
......@@ -38,7 +38,7 @@ func reset() {
}
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)
content, err := json.Marshal(configuration.Settings.AllSettings())
......@@ -54,7 +54,7 @@ func TestMerge(t *testing.T) {
require.Equal(t, false, configuration.Settings.GetBool("sketch.always_export_binaries"))
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.NoError(t, err)
......@@ -63,7 +63,7 @@ func TestMerge(t *testing.T) {
require.Equal(t, true, configuration.Settings.GetBool("sketch.always_export_binaries"))
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.NoError(t, err)
......@@ -72,7 +72,7 @@ func TestMerge(t *testing.T) {
require.Equal(t, false, configuration.Settings.GetBool("sketch.always_export_binaries"))
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.NoError(t, err)
......@@ -85,60 +85,60 @@ func TestMerge(t *testing.T) {
}
func TestGetValue(t *testing.T) {
key := &rpc.GetValueRequest{Key: "daemon"}
resp, err := svc.GetValue(context.Background(), key)
key := &rpc.SettingsGetValueRequest{Key: "daemon"}
resp, err := svc.SettingsGetValue(context.Background(), key)
require.NoError(t, err)
require.Equal(t, `{"port":"50051"}`, resp.GetJsonData())
key = &rpc.GetValueRequest{Key: "daemon.port"}
resp, err = svc.GetValue(context.Background(), key)
key = &rpc.SettingsGetValueRequest{Key: "daemon.port"}
resp, err = svc.SettingsGetValue(context.Background(), key)
require.NoError(t, err)
require.Equal(t, `"50051"`, resp.GetJsonData())
}
func TestGetMergedValue(t *testing.T) {
// Verifies value is not set
key := &rpc.GetValueRequest{Key: "foo"}
res, err := svc.GetValue(context.Background(), key)
key := &rpc.SettingsGetValueRequest{Key: "foo"}
res, err := svc.SettingsGetValue(context.Background(), key)
require.Nil(t, res)
require.Error(t, err, "Error getting settings value")
// Merge value
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)
// Verifies value is correctly returned
key = &rpc.GetValueRequest{Key: "foo"}
res, err = svc.GetValue(context.Background(), key)
key = &rpc.SettingsGetValueRequest{Key: "foo"}
res, err = svc.SettingsGetValue(context.Background(), key)
require.NoError(t, err)
require.Equal(t, `"bar"`, res.GetJsonData())
}
func TestGetValueNotFound(t *testing.T) {
key := &rpc.GetValueRequest{Key: "DOESNTEXIST"}
_, err := svc.GetValue(context.Background(), key)
key := &rpc.SettingsGetValueRequest{Key: "DOESNTEXIST"}
_, err := svc.SettingsGetValue(context.Background(), key)
require.NotNil(t, err)
require.Equal(t, `key not found in settings`, err.Error())
}
func TestSetValue(t *testing.T) {
val := &rpc.SetValueRequest{
val := &rpc.SettingsSetValueRequest{
Key: "foo",
JsonData: `"bar"`,
}
_, err := svc.SetValue(context.Background(), val)
_, err := svc.SettingsSetValue(context.Background(), val)
require.Nil(t, err)
require.Equal(t, "bar", configuration.Settings.GetString("foo"))
}
func TestWrite(t *testing.T) {
// Writes some settings
val := &rpc.SetValueRequest{
val := &rpc.SettingsSetValueRequest{
Key: "foo",
JsonData: `"bar"`,
}
_, err := svc.SetValue(context.Background(), val)
_, err := svc.SettingsSetValue(context.Background(), val)
require.NoError(t, err)
tempDir := paths.TempDir()
......@@ -150,7 +150,7 @@ func TestWrite(t *testing.T) {
configFile := testFolder.Join("arduino-cli.yml")
require.True(t, configFile.NotExist())
_, err = svc.Write(context.Background(), &rpc.WriteRequest{
_, err = svc.SettingsWrite(context.Background(), &rpc.SettingsWriteRequest{
FilePath: configFile.String(),
})
require.NoError(t, err)
......@@ -161,16 +161,16 @@ func TestWrite(t *testing.T) {
}
func TestDelete(t *testing.T) {
_, err := svc.Delete(context.Background(), &rpc.DeleteRequest{
_, err := svc.SettingsDelete(context.Background(), &rpc.SettingsDeleteRequest{
Key: "doesnotexist",
})
require.Error(t, err)
_, err = svc.Delete(context.Background(), &rpc.DeleteRequest{
_, err = svc.SettingsDelete(context.Background(), &rpc.SettingsDeleteRequest{
Key: "network",
})
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)
}
......@@ -4,6 +4,27 @@ Here you can find a list of migration guides to handle breaking changes between
## 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.
The `query` field has been removed, use `search_args` instead.
......
......@@ -21,7 +21,7 @@ import (
"github.com/arduino/arduino-cli/commands/daemon"
"github.com/arduino/arduino-cli/configuration"
"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/spf13/cobra"
)
......@@ -47,12 +47,12 @@ func runDeleteCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino-cli config delete`")
toDelete := args[0]
svc := daemon.SettingsService{}
_, err := svc.Delete(cmd.Context(), &settings.DeleteRequest{Key: toDelete})
svc := daemon.ArduinoCoreServerImpl{}
_, err := svc.SettingsDelete(cmd.Context(), &rpc.SettingsDeleteRequest{Key: toDelete})
if err != nil {
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 {
feedback.Fatal(tr("Cannot write the file %[1]s: %[2]v", configuration.Settings.ConfigFileUsed(), err), feedback.ErrGeneric)
}
......
......@@ -29,7 +29,6 @@ import (
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/arduino-cli/internal/cli/feedback"
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/go-paths-helper"
"github.com/sirupsen/logrus"
......@@ -107,9 +106,6 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
VersionString: version.VersionInfo.VersionString,
})
// Register the settings service
srv_settings.RegisterSettingsServiceServer(s, &daemon.SettingsService{})
if !daemonize {
// When parent process ends terminate also the daemon
go feedback.ExitWhenParentProcessEnds()
......
......@@ -31,7 +31,6 @@ import (
"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/settings/v1"
"github.com/arduino/go-paths-helper"
"github.com/fatih/color"
"github.com/stretchr/testify/require"
......@@ -70,20 +69,19 @@ func CreateArduinoCLIWithEnvironment(t *testing.T) (*Environment, *ArduinoCLI) {
// ArduinoCLI is an Arduino CLI client.
type ArduinoCLI struct {
path *paths.Path
t *require.Assertions
proc *executils.Process
stdIn io.WriteCloser
cliEnvVars map[string]string
cliConfigPath *paths.Path
stagingDir *paths.Path
dataDir *paths.Path
sketchbookDir *paths.Path
workingDir *paths.Path
daemonAddr string
daemonConn *grpc.ClientConn
daemonClient commands.ArduinoCoreServiceClient
daemonSettingsClient settings.SettingsServiceClient
path *paths.Path
t *require.Assertions
proc *executils.Process
stdIn io.WriteCloser
cliEnvVars map[string]string
cliConfigPath *paths.Path
stagingDir *paths.Path
dataDir *paths.Path
sketchbookDir *paths.Path
workingDir *paths.Path
daemonAddr string
daemonConn *grpc.ClientConn
daemonClient commands.ArduinoCoreServiceClient
}
// ArduinoCLIConfig is the configuration of the ArduinoCLI client
......@@ -386,7 +384,6 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string {
cli.t.NoError(err)
cli.daemonConn = conn
cli.daemonClient = commands.NewArduinoCoreServiceClient(conn)
cli.daemonSettingsClient = settings.NewSettingsServiceClient(conn)
return cli.daemonAddr
}
......@@ -418,12 +415,12 @@ func (cli *ArduinoCLI) Create() *ArduinoCLIInstance {
// SetValue calls the "SetValue" gRPC method.
func (cli *ArduinoCLI) SetValue(key, jsonData string) error {
req := &settings.SetValueRequest{
req := &commands.SettingsSetValueRequest{
Key: key,
JsonData: jsonData,
}
logCallf(">>> SetValue(%+v)\n", req)
_, err := cli.daemonSettingsClient.SetValue(context.Background(), req)
_, err := cli.daemonClient.SettingsSetValue(context.Background(), req)
return err
}
......
......@@ -100,7 +100,6 @@ nav:
- version: commands/arduino-cli_version.md
- gRPC reference:
- commands: rpc/commands.md
- settings: rpc/settings.md
- configuration.md
- Integration options: integration-options.md
- sketch-build-process.md
......
......@@ -5,6 +5,3 @@ lint:
ignore_only:
ENUM_ZERO_VALUE_SUFFIX:
- 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";
import "cc/arduino/cli/commands/v1/monitor.proto";
import "cc/arduino/cli/commands/v1/upload.proto";
import "cc/arduino/cli/commands/v1/lib.proto";
import "cc/arduino/cli/commands/v1/settings.proto";
// The main Arduino Platform service API
service ArduinoCoreService {
......@@ -182,6 +183,26 @@ service ArduinoCoreService {
rpc Debug(stream DebugRequest) returns (stream DebugResponse) {}
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 {}
......
......@@ -15,77 +15,55 @@
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
// 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 {
message SettingsGetAllResponse {
// The settings, in JSON format.
string json_data = 1;
}
message MergeRequest {
message SettingsMergeRequest {
// The settings, in JSON format.
string json_data = 1;
}
message GetValueResponse {
message SettingsGetValueResponse {
// The key of the setting.
string key = 1;
// The setting, in JSON format.
string json_data = 2;
}
message SetValueRequest {
message SettingsSetValueRequest {
// The key of the setting.
string key = 1;
// The setting, in JSON format.
string json_data = 2;
}
message GetAllRequest {}
message SettingsGetAllRequest {}
message GetValueRequest {
message SettingsGetValueRequest {
// The key of the setting.
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)
string file_path = 1;
}
message WriteResponse {}
message SettingsWriteResponse {}
message DeleteRequest {
message SettingsDeleteRequest {
// The key of the setting to delete.
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