Skip to content

Commit 50a8bf5

Browse files
authored
[breaking] Remove gRPC settings service (#2411)
* Removed setting service * Updated docs * Update mkdocs configuration
1 parent 0e5f629 commit 50a8bf5

File tree

17 files changed

+1899
-1958
lines changed

17 files changed

+1899
-1958
lines changed

Diff for: Taskfile.yml

-2
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,11 @@ tasks:
237237
desc: Compile protobuf definitions
238238
cmds:
239239
- '{{ 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'
240-
- '{{ 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'
241240

242241
protoc:docs:
243242
desc: Generate docs for protobuf definitions
244243
cmds:
245244
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
246-
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
247245

248246
docs:include-configuration-json-schema:
249247
desc: Copy configuration JSON schema to make it available in documentation

Diff for: client_example/main.go

+42-46
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"time"
3030

3131
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
32-
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
3332
"google.golang.org/grpc"
3433
"google.golang.org/grpc/credentials/insecure"
3534
)
@@ -63,8 +62,6 @@ func main() {
6362
// Create an instance of the gRPC clients.
6463
client := rpc.NewArduinoCoreServiceClient(conn)
6564

66-
settingsClient := settings.NewSettingsServiceClient(conn)
67-
6865
// Now we can call various methods of the API...
6966

7067
// `Version` can be called without any setup or init procedure.
@@ -76,39 +73,39 @@ func main() {
7673

7774
// Use SetValue to configure the arduino-cli directories.
7875
log.Println("calling SetValue")
79-
callSetValue(settingsClient)
76+
callSetValue(client)
8077

81-
// List all the settings.
82-
log.Println("calling GetAll()")
83-
callGetAll(settingsClient)
78+
// List all settings
79+
log.Println("calling SettingsGetAll()")
80+
callGetAll(client)
8481

8582
// Merge applies multiple settings values at once.
86-
log.Println("calling Merge()")
87-
callMerge(settingsClient, `{"foo": {"value": "bar"}, "daemon":{"port":"422"}, "board_manager": {"additional_urls":["https://example.com"]}}`)
83+
log.Println("calling SettingsMerge()")
84+
callMerge(client, `{"foo": {"value": "bar"}, "daemon":{"port":"422"}, "board_manager": {"additional_urls":["https://example.com"]}}`)
8885

89-
log.Println("calling GetAll()")
90-
callGetAll(settingsClient)
86+
log.Println("calling SettingsGetAll()")
87+
callGetAll(client)
9188

92-
log.Println("calling Merge()")
93-
callMerge(settingsClient, `{"foo": {} }`)
89+
log.Println("calling SettingsMerge()")
90+
callMerge(client, `{"foo": {} }`)
9491

95-
log.Println("calling GetAll()")
96-
callGetAll(settingsClient)
92+
log.Println("calling SettingsGetAll()")
93+
callGetAll(client)
9794

98-
log.Println("calling Merge()")
99-
callMerge(settingsClient, `{"foo": "bar" }`)
95+
log.Println("calling SettingsMerge()")
96+
callMerge(client, `{"foo": "bar" }`)
10097

10198
// Get the value of the foo key.
102-
log.Println("calling GetValue(foo)")
103-
callGetValue(settingsClient)
99+
log.Println("calling SettingsGetValue(foo)")
100+
callGetValue(client)
104101

105-
// List all the settings.
106-
log.Println("calling GetAll()")
107-
callGetAll(settingsClient)
102+
// List all settings
103+
log.Println("calling SettingsGetAll()")
104+
callGetAll(client)
108105

109106
// Write settings to file.
110107
log.Println("calling Write()")
111-
callWrite(settingsClient)
108+
callWrite(client)
112109

113110
// Before we can do anything with the CLI, an "instance" must be created.
114111
// We keep a reference to the created instance because we will need it to
@@ -121,7 +118,7 @@ func main() {
121118

122119
// We set up the proxy and then run the update to verify that the proxy settings are currently used
123120
log.Println("calling setProxy")
124-
callSetProxy(settingsClient)
121+
callSetProxy(client)
125122

126123
// With a brand new instance, the first operation should always be updating
127124
// the index.
@@ -247,22 +244,21 @@ func callVersion(client rpc.ArduinoCoreServiceClient) {
247244
log.Printf("arduino-cli version: %v", versionResp.GetVersion())
248245
}
249246

250-
func callSetValue(client settings.SettingsServiceClient) {
251-
_, err := client.SetValue(context.Background(),
252-
&settings.SetValueRequest{
247+
func callSetValue(client rpc.ArduinoCoreServiceClient) {
248+
_, err := client.SettingsSetValue(context.Background(),
249+
&rpc.SettingsSetValueRequest{
253250
Key: "directories",
254251
JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`,
255252
})
256253

257254
if err != nil {
258255
log.Fatalf("Error setting settings value: %s", err)
259-
260256
}
261257
}
262258

263-
func callSetProxy(client settings.SettingsServiceClient) {
264-
_, err := client.SetValue(context.Background(),
265-
&settings.SetValueRequest{
259+
func callSetProxy(client rpc.ArduinoCoreServiceClient) {
260+
_, err := client.SettingsSetValue(context.Background(),
261+
&rpc.SettingsSetValueRequest{
266262
Key: "network.proxy",
267263
JsonData: `"http://localhost:3128"`,
268264
})
@@ -272,9 +268,9 @@ func callSetProxy(client settings.SettingsServiceClient) {
272268
}
273269
}
274270

275-
func callUnsetProxy(client settings.SettingsServiceClient) {
276-
_, err := client.SetValue(context.Background(),
277-
&settings.SetValueRequest{
271+
func callUnsetProxy(client rpc.ArduinoCoreServiceClient) {
272+
_, err := client.SettingsSetValue(context.Background(),
273+
&rpc.SettingsSetValueRequest{
278274
Key: "network.proxy",
279275
JsonData: `""`,
280276
})
@@ -284,9 +280,9 @@ func callUnsetProxy(client settings.SettingsServiceClient) {
284280
}
285281
}
286282

287-
func callMerge(client settings.SettingsServiceClient, jsonData string) {
288-
_, err := client.Merge(context.Background(),
289-
&settings.MergeRequest{
283+
func callMerge(client rpc.ArduinoCoreServiceClient, jsonData string) {
284+
_, err := client.SettingsMerge(context.Background(),
285+
&rpc.SettingsMergeRequest{
290286
JsonData: jsonData,
291287
})
292288

@@ -295,9 +291,9 @@ func callMerge(client settings.SettingsServiceClient, jsonData string) {
295291
}
296292
}
297293

298-
func callGetValue(client settings.SettingsServiceClient) {
299-
getValueResp, err := client.GetValue(context.Background(),
300-
&settings.GetValueRequest{
294+
func callGetValue(client rpc.ArduinoCoreServiceClient) {
295+
getValueResp, err := client.SettingsGetValue(context.Background(),
296+
&rpc.SettingsGetValueRequest{
301297
Key: "foo",
302298
})
303299

@@ -308,8 +304,8 @@ func callGetValue(client settings.SettingsServiceClient) {
308304
log.Printf("Value: %s: %s", getValueResp.GetKey(), getValueResp.GetJsonData())
309305
}
310306

311-
func callGetAll(client settings.SettingsServiceClient) {
312-
getAllResp, err := client.GetAll(context.Background(), &settings.GetAllRequest{})
307+
func callGetAll(client rpc.ArduinoCoreServiceClient) {
308+
getAllResp, err := client.SettingsGetAll(context.Background(), &rpc.SettingsGetAllRequest{})
313309

314310
if err != nil {
315311
log.Fatalf("Error getting settings: %s", err)
@@ -318,10 +314,10 @@ func callGetAll(client settings.SettingsServiceClient) {
318314
log.Printf("Settings: %s", getAllResp.GetJsonData())
319315
}
320316

321-
func callWrite(client settings.SettingsServiceClient) {
322-
_, err := client.Write(context.Background(),
323-
&settings.WriteRequest{
324-
FilePath: path.Join(dataDir, "written-settings.yml"),
317+
func callWrite(client rpc.ArduinoCoreServiceClient) {
318+
_, err := client.SettingsWrite(context.Background(),
319+
&rpc.SettingsWriteRequest{
320+
FilePath: path.Join(dataDir, "written-rpc.Settingsyml"),
325321
})
326322

327323
if err != nil {

Diff for: commands/daemon/settings.go

+19-24
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,15 @@ import (
2323
"strings"
2424

2525
"github.com/arduino/arduino-cli/configuration"
26-
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
26+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2727
)
2828

29-
// SettingsService implements the `Settings` service
30-
type SettingsService struct {
31-
rpc.UnimplementedSettingsServiceServer
32-
}
33-
34-
// GetAll returns a message with a string field containing all the settings
29+
// SettingsGetAll returns a message with a string field containing all the settings
3530
// currently in use, marshalled in JSON format.
36-
func (s *SettingsService) GetAll(ctx context.Context, req *rpc.GetAllRequest) (*rpc.GetAllResponse, error) {
31+
func (s *ArduinoCoreServerImpl) SettingsGetAll(ctx context.Context, req *rpc.SettingsGetAllRequest) (*rpc.SettingsGetAllResponse, error) {
3732
b, err := json.Marshal(configuration.Settings.AllSettings())
3833
if err == nil {
39-
return &rpc.GetAllResponse{
34+
return &rpc.SettingsGetAllResponse{
4035
JsonData: string(b),
4136
}, nil
4237
}
@@ -72,8 +67,8 @@ func mapper(toMap map[string]interface{}) map[string]interface{} {
7267
return res
7368
}
7469

75-
// Merge applies multiple settings values at once.
76-
func (s *SettingsService) Merge(ctx context.Context, req *rpc.MergeRequest) (*rpc.MergeResponse, error) {
70+
// SettingsMerge applies multiple settings values at once.
71+
func (s *ArduinoCoreServerImpl) SettingsMerge(ctx context.Context, req *rpc.SettingsMergeRequest) (*rpc.SettingsMergeResponse, error) {
7772
var toMerge map[string]interface{}
7873
if err := json.Unmarshal([]byte(req.GetJsonData()), &toMerge); err != nil {
7974
return nil, err
@@ -88,13 +83,13 @@ func (s *SettingsService) Merge(ctx context.Context, req *rpc.MergeRequest) (*rp
8883
configuration.Settings.Set(k, v)
8984
}
9085

91-
return &rpc.MergeResponse{}, nil
86+
return &rpc.SettingsMergeResponse{}, nil
9287
}
9388

94-
// GetValue returns a settings value given its key. If the key is not present
89+
// SettingsGetValue returns a settings value given its key. If the key is not present
9590
// an error will be returned, so that we distinguish empty settings from missing
9691
// ones.
97-
func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest) (*rpc.GetValueResponse, error) {
92+
func (s *ArduinoCoreServerImpl) SettingsGetValue(ctx context.Context, req *rpc.SettingsGetValueRequest) (*rpc.SettingsGetValueResponse, error) {
9893
key := req.GetKey()
9994

10095
// 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
112107
}
113108

114109
b, err := json.Marshal(configuration.Settings.Get(key))
115-
value := &rpc.GetValueResponse{}
110+
value := &rpc.SettingsGetValueResponse{}
116111
if err == nil {
117112
value.Key = key
118113
value.JsonData = string(b)
@@ -121,8 +116,8 @@ func (s *SettingsService) GetValue(ctx context.Context, req *rpc.GetValueRequest
121116
return value, err
122117
}
123118

124-
// SetValue updates or set a value for a certain key.
125-
func (s *SettingsService) SetValue(ctx context.Context, val *rpc.SetValueRequest) (*rpc.SetValueResponse, error) {
119+
// SettingsSetValue updates or set a value for a certain key.
120+
func (s *ArduinoCoreServerImpl) SettingsSetValue(ctx context.Context, val *rpc.SettingsSetValueRequest) (*rpc.SettingsSetValueResponse, error) {
126121
key := val.GetKey()
127122
var value interface{}
128123

@@ -131,22 +126,22 @@ func (s *SettingsService) SetValue(ctx context.Context, val *rpc.SetValueRequest
131126
configuration.Settings.Set(key, value)
132127
}
133128

134-
return &rpc.SetValueResponse{}, err
129+
return &rpc.SettingsSetValueResponse{}, err
135130
}
136131

137-
// Write to file set in request the settings currently stored in memory.
132+
// SettingsWrite to file set in request the settings currently stored in memory.
138133
// We don't have a Read() function, that's not necessary since we only want one config file to be used
139134
// and that's picked up when the CLI is run as daemon, either using the default path or a custom one
140135
// set with the --config-file flag.
141-
func (s *SettingsService) Write(ctx context.Context, req *rpc.WriteRequest) (*rpc.WriteResponse, error) {
136+
func (s *ArduinoCoreServerImpl) SettingsWrite(ctx context.Context, req *rpc.SettingsWriteRequest) (*rpc.SettingsWriteResponse, error) {
142137
if err := configuration.Settings.WriteConfigAs(req.FilePath); err != nil {
143138
return nil, err
144139
}
145-
return &rpc.WriteResponse{}, nil
140+
return &rpc.SettingsWriteResponse{}, nil
146141
}
147142

148-
// Delete removes a key from the config file
149-
func (s *SettingsService) Delete(ctx context.Context, req *rpc.DeleteRequest) (*rpc.DeleteResponse, error) {
143+
// SettingsDelete removes a key from the config file
144+
func (s *ArduinoCoreServerImpl) SettingsDelete(ctx context.Context, req *rpc.SettingsDeleteRequest) (*rpc.SettingsDeleteResponse, error) {
150145
toDelete := req.GetKey()
151146

152147
// 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) (*
175170
updatedSettings.SetConfigFile(configPath)
176171
configuration.Settings = updatedSettings
177172

178-
return &rpc.DeleteResponse{}, nil
173+
return &rpc.SettingsDeleteResponse{}, nil
179174
}

0 commit comments

Comments
 (0)