diff --git a/commands/daemon/settings.go b/commands/daemon/settings.go index 4a524638f23..60b7169fc87 100644 --- a/commands/daemon/settings.go +++ b/commands/daemon/settings.go @@ -144,3 +144,36 @@ func (s *SettingsService) Write(ctx context.Context, req *rpc.WriteRequest) (*rp } return &rpc.WriteResponse{}, nil } + +// Delete removes a key from the config file +func (s *SettingsService) Delete(ctx context.Context, req *rpc.DeleteRequest) (*rpc.DeleteResponse, error) { + toDelete := req.GetKey() + + // Check if settings key actually existing, we don't use Viper.InConfig() + // since that doesn't check for keys formatted like daemon.port or those set + // with Viper.Set(). This way we check for all existing settings for sure. + keyExists := false + keys := []string{} + for _, k := range configuration.Settings.AllKeys() { + if !strings.HasPrefix(k, toDelete) { + keys = append(keys, k) + continue + } + keyExists = true + } + + if !keyExists { + return nil, errors.New(tr("key not found in settings")) + } + + // Override current settings to delete the key + updatedSettings := configuration.Init("") + for _, k := range keys { + updatedSettings.Set(k, configuration.Settings.Get(k)) + } + configPath := configuration.Settings.ConfigFileUsed() + updatedSettings.SetConfigFile(configPath) + configuration.Settings = updatedSettings + + return &rpc.DeleteResponse{}, nil +} diff --git a/commands/daemon/settings_test.go b/commands/daemon/settings_test.go index 49634f33d95..b95c7fe2446 100644 --- a/commands/daemon/settings_test.go +++ b/commands/daemon/settings_test.go @@ -142,7 +142,9 @@ func TestWrite(t *testing.T) { require.NoError(t, err) tempDir := paths.TempDir() - testFolder, _ := tempDir.MkTempDir("testdata") + testFolder, err := tempDir.MkTempDir("testdata") + require.NoError(t, err) + defer testFolder.RemoveAll() // Verifies config files doesn't exist configFile := testFolder.Join("arduino-cli.yml") @@ -157,3 +159,18 @@ func TestWrite(t *testing.T) { // We don't verify the content since we expect config library, Viper, to work require.True(t, configFile.Exist()) } + +func TestDelete(t *testing.T) { + _, err := svc.Delete(context.Background(), &rpc.DeleteRequest{ + Key: "doesnotexist", + }) + require.Error(t, err) + + _, err = svc.Delete(context.Background(), &rpc.DeleteRequest{ + Key: "network", + }) + require.NoError(t, err) + + _, err = svc.GetValue(context.Background(), &rpc.GetValueRequest{Key: "network"}) + require.Error(t, err) +} diff --git a/commands/daemon/testdata/arduino-cli.yml b/commands/daemon/testdata/arduino-cli.yml index 61fb5f655eb..b13cb0b6749 100644 --- a/commands/daemon/testdata/arduino-cli.yml +++ b/commands/daemon/testdata/arduino-cli.yml @@ -14,3 +14,6 @@ logging: file: "" format: text level: info + +network: + proxy: "123" diff --git a/internal/cli/config/delete.go b/internal/cli/config/delete.go index 6e3cf58d6f1..794a513a858 100644 --- a/internal/cli/config/delete.go +++ b/internal/cli/config/delete.go @@ -17,13 +17,13 @@ package config import ( "os" - "strings" + "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" "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/spf13/viper" ) func initDeleteCommand() *cobra.Command { @@ -47,26 +47,13 @@ func runDeleteCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino-cli config delete`") toDelete := args[0] - keys := []string{} - exists := false - for _, v := range configuration.Settings.AllKeys() { - if !strings.HasPrefix(v, toDelete) { - keys = append(keys, v) - continue - } - exists = true + svc := daemon.SettingsService{} + _, err := svc.Delete(cmd.Context(), &settings.DeleteRequest{Key: toDelete}) + if err != nil { + feedback.Fatal(tr("Cannot delete the key %[1]s: %[2]v", toDelete, err), feedback.ErrGeneric) } - - if !exists { - feedback.Fatal(tr("Settings key doesn't exist"), feedback.ErrGeneric) - } - - updatedSettings := viper.New() - for _, k := range keys { - updatedSettings.Set(k, configuration.Settings.Get(k)) - } - - if err := updatedSettings.WriteConfigAs(configuration.Settings.ConfigFileUsed()); err != nil { - feedback.Fatal(tr("Can't write config file: %v", err), feedback.ErrGeneric) + _, err = svc.Write(cmd.Context(), &settings.WriteRequest{FilePath: configuration.Settings.ConfigFileUsed()}) + if err != nil { + feedback.Fatal(tr("Cannot write the file %[1]s: %[2]v", configuration.Settings.ConfigFileUsed(), err), feedback.ErrGeneric) } } diff --git a/internal/integrationtest/config/config_test.go b/internal/integrationtest/config/config_test.go index ab098960498..ed3360efb67 100644 --- a/internal/integrationtest/config/config_test.go +++ b/internal/integrationtest/config/config_test.go @@ -302,7 +302,7 @@ func TestAddRemoveSetDeleteOnUnexistingKey(t *testing.T) { _, stderr, err = cli.Run("config", "delete", "some.key", "--config-file", "arduino-cli.yaml") require.Error(t, err) - require.Contains(t, string(stderr), "Settings key doesn't exist") + require.Contains(t, string(stderr), "Cannot delete the key some.key: key not found in settings\n") } func TestAddSingleArgument(t *testing.T) { diff --git a/rpc/cc/arduino/cli/settings/v1/settings.pb.go b/rpc/cc/arduino/cli/settings/v1/settings.pb.go index 9ef1e7ca4e5..6bbf4cece43 100644 --- a/rpc/cc/arduino/cli/settings/v1/settings.pb.go +++ b/rpc/cc/arduino/cli/settings/v1/settings.pb.go @@ -493,6 +493,92 @@ func (*WriteResponse) Descriptor() ([]byte, []int) { return file_cc_arduino_cli_settings_v1_settings_proto_rawDescGZIP(), []int{9} } +type DeleteRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key of the setting to delete. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *DeleteRequest) Reset() { + *x = DeleteRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cc_arduino_cli_settings_v1_settings_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteRequest) ProtoMessage() {} + +func (x *DeleteRequest) ProtoReflect() protoreflect.Message { + mi := &file_cc_arduino_cli_settings_v1_settings_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeleteRequest.ProtoReflect.Descriptor instead. +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return file_cc_arduino_cli_settings_v1_settings_proto_rawDescGZIP(), []int{10} +} + +func (x *DeleteRequest) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +type DeleteResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *DeleteResponse) Reset() { + *x = DeleteResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_cc_arduino_cli_settings_v1_settings_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteResponse) ProtoMessage() {} + +func (x *DeleteResponse) ProtoReflect() protoreflect.Message { + mi := &file_cc_arduino_cli_settings_v1_settings_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeleteResponse.ProtoReflect.Descriptor instead. +func (*DeleteResponse) Descriptor() ([]byte, []int) { + return file_cc_arduino_cli_settings_v1_settings_proto_rawDescGZIP(), []int{11} +} + var File_cc_arduino_cli_settings_v1_settings_proto protoreflect.FileDescriptor var file_cc_arduino_cli_settings_v1_settings_proto_rawDesc = []byte{ @@ -524,44 +610,53 @@ var file_cc_arduino_cli_settings_v1_settings_proto_rawDesc = []byte{ 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x22, 0x0f, 0x0a, 0x0d, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x32, 0xfc, 0x03, 0x0a, 0x0f, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5f, 0x0a, 0x06, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x12, - 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, + 0x65, 0x22, 0x21, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xdd, 0x04, 0x0a, 0x0f, 0x53, 0x65, 0x74, 0x74, 0x69, + 0x6e, 0x67, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5f, 0x0a, 0x06, 0x47, 0x65, + 0x74, 0x41, 0x6c, 0x6c, 0x12, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, + 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x2a, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, - 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x63, 0x2e, - 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, - 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x05, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x12, - 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, - 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x72, - 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, - 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, - 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, - 0x12, 0x2b, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, - 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, - 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, - 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, - 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x61, - 0x6c, 0x75, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x08, 0x53, - 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, - 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, - 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, + 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x05, 0x4d, + 0x65, 0x72, 0x67, 0x65, 0x12, 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, - 0x31, 0x2e, 0x53, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x05, 0x57, 0x72, 0x69, 0x74, 0x65, 0x12, 0x28, 0x2e, 0x63, 0x63, - 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, - 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, + 0x31, 0x2e, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, + 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, + 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x72, 0x67, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x08, 0x47, 0x65, 0x74, + 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, - 0x76, 0x31, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 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, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2f, 0x76, - 0x31, 0x3b, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, + 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x65, 0x0a, 0x08, 0x53, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x2b, 0x2e, 0x63, + 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, + 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x63, 0x2e, 0x61, + 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, + 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x05, 0x57, 0x72, 0x69, 0x74, 0x65, + 0x12, 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, + 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x57, 0x72, + 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x63, 0x63, 0x2e, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, + 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, + 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, + 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x63, 0x2e, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x73, 0x65, 0x74, 0x74, + 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 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, 0x73, 0x65, 0x74, 0x74, + 0x69, 0x6e, 0x67, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -576,7 +671,7 @@ func file_cc_arduino_cli_settings_v1_settings_proto_rawDescGZIP() []byte { return file_cc_arduino_cli_settings_v1_settings_proto_rawDescData } -var file_cc_arduino_cli_settings_v1_settings_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_cc_arduino_cli_settings_v1_settings_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_cc_arduino_cli_settings_v1_settings_proto_goTypes = []interface{}{ (*GetAllResponse)(nil), // 0: cc.arduino.cli.settings.v1.GetAllResponse (*MergeRequest)(nil), // 1: cc.arduino.cli.settings.v1.MergeRequest @@ -588,23 +683,27 @@ var file_cc_arduino_cli_settings_v1_settings_proto_goTypes = []interface{}{ (*SetValueResponse)(nil), // 7: cc.arduino.cli.settings.v1.SetValueResponse (*WriteRequest)(nil), // 8: cc.arduino.cli.settings.v1.WriteRequest (*WriteResponse)(nil), // 9: cc.arduino.cli.settings.v1.WriteResponse + (*DeleteRequest)(nil), // 10: cc.arduino.cli.settings.v1.DeleteRequest + (*DeleteResponse)(nil), // 11: cc.arduino.cli.settings.v1.DeleteResponse } var file_cc_arduino_cli_settings_v1_settings_proto_depIdxs = []int32{ - 4, // 0: cc.arduino.cli.settings.v1.SettingsService.GetAll:input_type -> cc.arduino.cli.settings.v1.GetAllRequest - 1, // 1: cc.arduino.cli.settings.v1.SettingsService.Merge:input_type -> cc.arduino.cli.settings.v1.MergeRequest - 5, // 2: cc.arduino.cli.settings.v1.SettingsService.GetValue:input_type -> cc.arduino.cli.settings.v1.GetValueRequest - 3, // 3: cc.arduino.cli.settings.v1.SettingsService.SetValue:input_type -> cc.arduino.cli.settings.v1.SetValueRequest - 8, // 4: cc.arduino.cli.settings.v1.SettingsService.Write:input_type -> cc.arduino.cli.settings.v1.WriteRequest - 0, // 5: cc.arduino.cli.settings.v1.SettingsService.GetAll:output_type -> cc.arduino.cli.settings.v1.GetAllResponse - 6, // 6: cc.arduino.cli.settings.v1.SettingsService.Merge:output_type -> cc.arduino.cli.settings.v1.MergeResponse - 2, // 7: cc.arduino.cli.settings.v1.SettingsService.GetValue:output_type -> cc.arduino.cli.settings.v1.GetValueResponse - 7, // 8: cc.arduino.cli.settings.v1.SettingsService.SetValue:output_type -> cc.arduino.cli.settings.v1.SetValueResponse - 9, // 9: cc.arduino.cli.settings.v1.SettingsService.Write:output_type -> cc.arduino.cli.settings.v1.WriteResponse - 5, // [5:10] is the sub-list for method output_type - 0, // [0:5] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 4, // 0: cc.arduino.cli.settings.v1.SettingsService.GetAll:input_type -> cc.arduino.cli.settings.v1.GetAllRequest + 1, // 1: cc.arduino.cli.settings.v1.SettingsService.Merge:input_type -> cc.arduino.cli.settings.v1.MergeRequest + 5, // 2: cc.arduino.cli.settings.v1.SettingsService.GetValue:input_type -> cc.arduino.cli.settings.v1.GetValueRequest + 3, // 3: cc.arduino.cli.settings.v1.SettingsService.SetValue:input_type -> cc.arduino.cli.settings.v1.SetValueRequest + 8, // 4: cc.arduino.cli.settings.v1.SettingsService.Write:input_type -> cc.arduino.cli.settings.v1.WriteRequest + 10, // 5: cc.arduino.cli.settings.v1.SettingsService.Delete:input_type -> cc.arduino.cli.settings.v1.DeleteRequest + 0, // 6: cc.arduino.cli.settings.v1.SettingsService.GetAll:output_type -> cc.arduino.cli.settings.v1.GetAllResponse + 6, // 7: cc.arduino.cli.settings.v1.SettingsService.Merge:output_type -> cc.arduino.cli.settings.v1.MergeResponse + 2, // 8: cc.arduino.cli.settings.v1.SettingsService.GetValue:output_type -> cc.arduino.cli.settings.v1.GetValueResponse + 7, // 9: cc.arduino.cli.settings.v1.SettingsService.SetValue:output_type -> cc.arduino.cli.settings.v1.SetValueResponse + 9, // 10: cc.arduino.cli.settings.v1.SettingsService.Write:output_type -> cc.arduino.cli.settings.v1.WriteResponse + 11, // 11: cc.arduino.cli.settings.v1.SettingsService.Delete:output_type -> cc.arduino.cli.settings.v1.DeleteResponse + 6, // [6:12] is the sub-list for method output_type + 0, // [0:6] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_cc_arduino_cli_settings_v1_settings_proto_init() } @@ -733,6 +832,30 @@ func file_cc_arduino_cli_settings_v1_settings_proto_init() { return nil } } + file_cc_arduino_cli_settings_v1_settings_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cc_arduino_cli_settings_v1_settings_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -740,7 +863,7 @@ func file_cc_arduino_cli_settings_v1_settings_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_cc_arduino_cli_settings_v1_settings_proto_rawDesc, NumEnums: 0, - NumMessages: 10, + NumMessages: 12, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/cc/arduino/cli/settings/v1/settings.proto b/rpc/cc/arduino/cli/settings/v1/settings.proto index 859931d9684..c05bfbef533 100644 --- a/rpc/cc/arduino/cli/settings/v1/settings.proto +++ b/rpc/cc/arduino/cli/settings/v1/settings.proto @@ -36,6 +36,9 @@ service SettingsService { // 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 { @@ -78,4 +81,11 @@ message WriteRequest { string file_path = 1; } -message WriteResponse {} \ No newline at end of file +message WriteResponse {} + +message DeleteRequest { + // The key of the setting to delete. + string key = 1; +} + +message DeleteResponse {} diff --git a/rpc/cc/arduino/cli/settings/v1/settings_grpc.pb.go b/rpc/cc/arduino/cli/settings/v1/settings_grpc.pb.go index 24b5372663c..2d59ca1f8bb 100644 --- a/rpc/cc/arduino/cli/settings/v1/settings_grpc.pb.go +++ b/rpc/cc/arduino/cli/settings/v1/settings_grpc.pb.go @@ -39,6 +39,7 @@ const ( SettingsService_GetValue_FullMethodName = "/cc.arduino.cli.settings.v1.SettingsService/GetValue" SettingsService_SetValue_FullMethodName = "/cc.arduino.cli.settings.v1.SettingsService/SetValue" SettingsService_Write_FullMethodName = "/cc.arduino.cli.settings.v1.SettingsService/Write" + SettingsService_Delete_FullMethodName = "/cc.arduino.cli.settings.v1.SettingsService/Delete" ) // SettingsServiceClient is the client API for SettingsService service. @@ -55,6 +56,8 @@ type SettingsServiceClient interface { SetValue(ctx context.Context, in *SetValueRequest, opts ...grpc.CallOption) (*SetValueResponse, error) // Writes to file settings currently stored in memory Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) + // Deletes an entry and rewrites the file settings + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) } type settingsServiceClient struct { @@ -110,6 +113,15 @@ func (c *settingsServiceClient) Write(ctx context.Context, in *WriteRequest, opt return out, nil } +func (c *settingsServiceClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, SettingsService_Delete_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // SettingsServiceServer is the server API for SettingsService service. // All implementations must embed UnimplementedSettingsServiceServer // for forward compatibility @@ -124,6 +136,8 @@ type SettingsServiceServer interface { SetValue(context.Context, *SetValueRequest) (*SetValueResponse, error) // Writes to file settings currently stored in memory Write(context.Context, *WriteRequest) (*WriteResponse, error) + // Deletes an entry and rewrites the file settings + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) mustEmbedUnimplementedSettingsServiceServer() } @@ -146,6 +160,9 @@ func (UnimplementedSettingsServiceServer) SetValue(context.Context, *SetValueReq func (UnimplementedSettingsServiceServer) Write(context.Context, *WriteRequest) (*WriteResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") } +func (UnimplementedSettingsServiceServer) Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} func (UnimplementedSettingsServiceServer) mustEmbedUnimplementedSettingsServiceServer() {} // UnsafeSettingsServiceServer may be embedded to opt out of forward compatibility for this service. @@ -249,6 +266,24 @@ func _SettingsService_Write_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _SettingsService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SettingsServiceServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SettingsService_Delete_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SettingsServiceServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + // SettingsService_ServiceDesc is the grpc.ServiceDesc for SettingsService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -276,6 +311,10 @@ var SettingsService_ServiceDesc = grpc.ServiceDesc{ MethodName: "Write", Handler: _SettingsService_Write_Handler, }, + { + MethodName: "Delete", + Handler: _SettingsService_Delete_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "cc/arduino/cli/settings/v1/settings.proto",