Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings handlers #2352

Merged
merged 254 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 245 commits
Commits
Show all changes
254 commits
Select commit Hold shift + click to select a range
c7c9c67
[settings] Replicate `keys` logic in std handler
ricab Oct 26, 2021
1686081
[settings] Slight class and header reorganization
ricab Oct 26, 2021
f512f9f
[test] Start moving/adapting tests to handler
ricab Nov 5, 2021
ead2299
[settings] Fix file name for persistent settings
ricab Oct 27, 2021
0615b54
[test] Move and adapt more tests to handler
ricab Nov 11, 2021
a871809
[test] Continue moving/adapting tests to handler
ricab Oct 28, 2021
cb16003
[test] Check persistent settings defaults
ricab Oct 28, 2021
89f50e1
[test] Split InvalidSettingsException in two
ricab Oct 28, 2021
0bacb9a
[settings] Rename InvalidSettingsException
ricab Oct 28, 2021
49a282b
[test] Refactor common bits out of handler tests
ricab Nov 11, 2021
9606c13
[test] Check handling of unknown settings key
ricab Oct 28, 2021
709da9b
[test] Check that handler writes to given filename
ricab Oct 28, 2021
b296c13
[client] Register handler for client settings
ricab Nov 2, 2021
7e7de2f
[client] Register tmp handler for daemon settings
ricab Nov 2, 2021
7fa9c22
[client] Derive path for client settings
ricab Nov 2, 2021
870dd1a
[client] Derive path for daemon settings (temp)
ricab Nov 2, 2021
7602e87
[client] Preserve info in comment
ricab Nov 2, 2021
8574b64
[test] Start testing clients' registered handlers
ricab Nov 2, 2021
dbce607
[test] Extract MockQSettings into own header
ricab Nov 3, 2021
4715757
[test] Check default settings in client handler
ricab Nov 3, 2021
e85e087
[platform] Move extra settings to singleton
ricab Nov 4, 2021
937a156
[test] Check platform extras in client handler
ricab Nov 4, 2021
c2601ff
[test] Filename in clients' persistent handler
ricab Nov 4, 2021
192e98b
[daemon] Repurpose files for generic settings init
ricab Nov 4, 2021
7ee1b5b
[daemon] Move settings init to daemon namespace
ricab Nov 4, 2021
3ad1428
[daemon] Register persistent handler for daemon
ricab Nov 4, 2021
2fa2814
[test] Generalize test file for client/daemon
ricab Nov 4, 2021
8caf9c4
[test] Factor out grabbing of registered handler
ricab Nov 4, 2021
a84b78b
[platform] Move daemon config home to singleton
ricab Nov 4, 2021
0f00726
[test] Filename in daemon's persistent handler
ricab Nov 4, 2021
1041bf1
[daemon] Fix duplicated setting defaults
ricab Nov 4, 2021
6b1ff83
[platform] Move a couple of defaults to singleton
ricab Nov 4, 2021
cf150d2
[test] Check default settings in daemon handler
ricab Nov 4, 2021
7aad342
[test] Check platform extras in daemon handler
ricab Nov 5, 2021
a2ddfb7
[test] Remove outdated settings tests
ricab Nov 5, 2021
ee2d78d
[settings] Add a PersistentSetting class
ricab Nov 5, 2021
a5c62f8
[settings] Add a BasicPersistentSetting class
ricab Nov 5, 2021
06d7c87
[settings] Replace defaults w/ PersistentSettings
ricab Nov 5, 2021
f0206a1
[settings] Fix users of PersistentSettingsHandler
ricab Nov 5, 2021
b433e37
[settings] Move new types to their own files
ricab Nov 5, 2021
e6ce85f
[settings] Move settings headers to own folder
ricab Nov 5, 2021
e505811
[settings] Remove obsolete `utils::get_driver_str`
ricab Nov 6, 2021
8fbb5aa
[settings] Move to own lib
ricab Nov 6, 2021
eda3bb3
[settings] Link client code against settings lib
ricab Nov 6, 2021
044faba
[settings] Rename PersistentSetting types
ricab Nov 6, 2021
74fd930
[settings] Add a DynamicSettingSpec
ricab Nov 6, 2021
c38bcc0
[settings] Add a BoolSettingSpec
ricab Nov 6, 2021
d92309c
[daemon] Register setting interpreters
ricab Nov 6, 2021
95bbb4e
[settings] Receive setting set in handler's ctor
ricab Nov 16, 2021
f4f0cea
[platform] Replace `extra_settings_defaults`
ricab Nov 6, 2021
01f8cd3
[platform] Update caller code to use new functions
ricab Nov 6, 2021
4eee251
[test] Fix tests to use new platform functions
ricab Nov 6, 2021
4bc4a75
[test] Replace snake_case with camelCase in tests
ricab Nov 8, 2021
646b5ce
[test] Delete misplaced comment
ricab Nov 8, 2021
290dba1
[test] Start moving setting-specific tests
ricab Nov 8, 2021
df5f478
[test] Start testing setting specs.
ricab Nov 8, 2021
9972888
[test] Add a couple setting-spec tests
ricab Nov 8, 2021
37ed002
[test] Add setting-spec tests for good bool reprs
ricab Nov 8, 2021
8bca284
[test] Add setting-spec tests for bad bool reprs
ricab Nov 8, 2021
8cb62fc
[settings] Reject bad defaults in BoolSettingSpec
ricab Nov 8, 2021
0e25a27
[settings] Fix comment
ricab Nov 8, 2021
bf709f2
[test] Avoid bad bool defaults in tests
ricab Nov 8, 2021
6f4352f
[test] Drop superseded settings tests
ricab Nov 8, 2021
dc61895
[settings] Interpret default in DynamicSettingSpec
ricab Nov 8, 2021
e886aad
[test] Extract common mock-platform setup
ricab Nov 8, 2021
4178de8
[test] Fix test names
ricab Nov 8, 2021
997da75
[test] Drop superfluous expect cardinalities
ricab Nov 8, 2021
f6c3a06
[test] Add test for client autostart setting
ricab Nov 8, 2021
8de29c5
[settings] Fix handler to set interpreted value!
ricab Nov 8, 2021
5e18337
[test] Persistent handler sets interpreted value
ricab Nov 8, 2021
2cffa03
[test] Add tests for petenv setting
ricab Nov 8, 2021
011d8bf
[test] Prune obsolete stuff from settings fixture
ricab Nov 8, 2021
f9f7688
[test] Add test for daemon mounts setting
ricab Nov 8, 2021
1f70277
[test] Add test for bridged interface setting
ricab Nov 8, 2021
1f82c7a
[settings] Plug interpreter in persistent handler
ricab Nov 9, 2021
bec0d61
[test] Interpreter throws in persistent handler
ricab Nov 9, 2021
e2e5fe2
[settings] Plug handlers in Settings
ricab Nov 12, 2021
72365b0
[test] Overhaul MockSettings
ricab Nov 9, 2021
b8c4e20
[test] Adapt settings tests to new MockSettings
ricab Nov 9, 2021
63696e1
[test] Fix some client tests
ricab Nov 9, 2021
e869bcd
[test] Fix more client tests
ricab Nov 9, 2021
2827206
[test] Fix test name
ricab Nov 9, 2021
ae867ec
[test] Replace client tests for specific settings
ricab Nov 9, 2021
5591a19
[test] Adapt registered handler tests
ricab Nov 9, 2021
e674b81
[test] Adapt platform tests to new MockSettings
ricab Nov 10, 2021
69a94f4
[test] Adapt formatter tests to new MockSettings
ricab Nov 10, 2021
a87fbea
[test] Adapt UbuntuImageHost tests to MockSettings
ricab Nov 10, 2021
c422aa7
[test] Homogenize injections for UbuntuImageHost
ricab Nov 10, 2021
470194c
[test] Adapt SimpleStreamsManifest tests
ricab Nov 10, 2021
ea51189
[test] Adapt Daemon tests to new MockSettings
ricab Nov 10, 2021
b65af1b
[test] Homogenize injections in Daemon tests
ricab Nov 10, 2021
8b45e86
[client] Introduce a RemoteSettingsHandler class
ricab Nov 11, 2021
ea0d0e3
[cli] Remove useless `parse_args` virtual method
ricab Nov 11, 2021
ec949f6
[client] Implement RemoteSettingsHandler::get
ricab Nov 12, 2021
0e9af37
[client] Register RemoteSettingsHandler
ricab Nov 12, 2021
2e860fd
[client] Throw on failure to fetch daemon setting
ricab Nov 12, 2021
d94cda0
[client] Add a RemoteSettingsException
ricab Nov 12, 2021
bcaa732
[client] Throw and handle RemoteSettingsExceptions
ricab Nov 12, 2021
38a153d
[client] Rework RemoteSettingException
ricab Nov 12, 2021
0cb2604
[client] Simplify RemoteGet
ricab Nov 12, 2021
397efed
[client] Extract an InternalCmd base class
ricab Nov 12, 2021
6673e19
[client] Drop unnecessary members from RemoteGet
ricab Nov 12, 2021
add36dd
[client] Drop unnecessary capture
ricab Nov 12, 2021
a35187e
[client] Simplify RemoteSettingsException
ricab Nov 15, 2021
d4c747c
[client] Mark RemoteSettingsExcption ctor explicit
ricab Nov 15, 2021
c4c5758
[daemon] Add `set` RPC
ricab Nov 15, 2021
78d6dda
[client] Implement RemoteSettingsHandler::set
ricab Nov 15, 2021
f3a3c78
[client] Remove scaffolding for daemon settings
ricab Nov 15, 2021
66c8755
[client] Don't throw when RemoteSet succeeds
ricab Nov 15, 2021
92f9cfb
[client] Fix missing value in set request
ricab Nov 15, 2021
9ffe9db
[daemon] Implement `Daemon::set`
ricab Nov 15, 2021
d2b926a
[settings] Assert handlers and specs aren't null
ricab Nov 15, 2021
87faf63
[settings] Rename var to avoid confusion w/ specs
ricab Nov 15, 2021
f6bc24c
[settings] Drop a few TODOs
ricab Nov 15, 2021
dba8730
[settings] Move constants to multipass namespace
ricab Nov 19, 2021
6e4e3c8
[settings] Mark a few exception ctors explicit
ricab Nov 15, 2021
24586f4
[test] Remove obsolete includes in tests
ricab Nov 16, 2021
cc119ed
[test] Rework test and drop TODO
ricab Nov 16, 2021
3711994
[test] Fix move of universal reference in lambda
ricab Nov 16, 2021
4c530da
[settings] Fix param type in SettingSpec ctors
ricab Nov 16, 2021
39b51dd
[test] Update TODOs
ricab Nov 16, 2021
ccfe4b3
[settings] Fix formatting
ricab Nov 16, 2021
b497808
[settings] Document SettingsHandlers methods
ricab Nov 16, 2021
944ffeb
[settings] Rename a few things
ricab Nov 16, 2021
d702234
[rpc] Add `keys` RPC
ricab Nov 16, 2021
d24c60a
[client] Implement `RemoteSettingsHandler::keys`
ricab Nov 16, 2021
2492239
[util] Generalize callable_traits
ricab Nov 16, 2021
1b8c111
[client] Extract on_failure from remote cmds
ricab Nov 16, 2021
a383658
[client] Extract on_success from remote cmds
ricab Nov 16, 2021
76267df
[client] Remove optional from RemoteGet::got
ricab Nov 16, 2021
63ee4e4
[client] Move RemoteGet::got out
ricab Nov 16, 2021
18a3044
[daemon] Implement keys RPC
ricab Nov 17, 2021
0d73b71
[client] Don't fail keys when daemon not around
ricab Nov 17, 2021
d3c501e
[daemon] Remove a couple of TODOs
ricab Nov 17, 2021
bf33395
[settings] Update docs for `SettingsHandler::keys`
ricab Nov 17, 2021
6de5d57
[settings] Reorder handler methods, match Settings
ricab Nov 17, 2021
6302074
[settings] Update docs for `Settings::keys`
ricab Nov 17, 2021
6f1ce9e
[settings] Document Settings::get and set
ricab Nov 17, 2021
a4765c9
[client] Fix wrong return code on failure
ricab Nov 17, 2021
554bffe
[settings] Support unregistering handlers
ricab Nov 18, 2021
98ba144
[client] Unregister RemoteSettingsHandler
ricab Nov 18, 2021
115fb53
[settings] Make `SettingsHandler::set` non-const
ricab Nov 23, 2021
cb257fc
[client] Rename exception: RemoteHandlerException
ricab Nov 23, 2021
b03d9a8
[doc] Remove redundant comments
ricab Nov 23, 2021
0e11638
Merge branch 'main' into settings-handlers-draft
ricab Jan 18, 2022
1b0ab35
[doc] Update copyright notices
ricab Jan 19, 2022
e7457b8
Merge branch 'main' into settings-handlers-draft
ricab Jan 21, 2022
6a88d3c
[todos] Drop obsolete TODO
ricab Jan 24, 2022
1efdaee
[test] Verify handler argument in matcher
ricab Jan 24, 2022
453b5b2
[test] Factor out grabbing of persistent handler
ricab Jan 24, 2022
fbf5f69
[tests] Factor out common bits
ricab Jan 25, 2022
712d8ec
[tests] Check platform settings override defaults
ricab Jan 25, 2022
26cb38a
[tests] Verify isolation of client/daemon settings
ricab Jan 25, 2022
65bdcc5
[test] Extract check for unknown keys
ricab Jan 25, 2022
14a3bd0
[todos] Update platform TODOs and reorder funcs
ricab Jan 28, 2022
c94929d
[format] Fix formatting
ricab Jan 28, 2022
2d710e4
Merge branch 'main' into settings-handlers
ricab Jan 31, 2022
dfc8c6f
[settings] Make default petenv constant public
ricab Jan 31, 2022
4b21f57
[settings] Add missing includes
ricab Jan 31, 2022
bcd69e0
[tests] Expect winterm-setting reads
ricab Feb 2, 2022
30618d1
[tests] Prevent EINVAL from failing tests on win
ricab Feb 1, 2022
1e30ed4
[cmake] Add client dependency on scope_guard
ricab Feb 8, 2022
80d341c
[linux] Test no client or daemon extra settings
ricab Feb 9, 2022
9c8df66
[settings] Fix var use after move
ricab Feb 9, 2022
08e91c5
[settings] Fix no-op move
ricab Feb 9, 2022
a9e4749
[settings] Fix move on returns
ricab Feb 9, 2022
716c28d
[settings] Receive setting value by copy in spec
ricab Feb 9, 2022
8e4173e
[todos] Drop obsolete TODOs
ricab Feb 9, 2022
353c1f7
Merge branch 'main' into settings-handlers
ricab Feb 10, 2022
cefc4d7
[test] Check that client registers remote handler
ricab Feb 11, 2022
01b034e
[test] Check verbosity honored in remote handler
ricab Feb 11, 2022
9c93c00
[test] Cover other verbosities in handler test
ricab Feb 11, 2022
910e891
[test] Do remote-handler tests w/ and without cmds
ricab Feb 11, 2022
db39041
[tests] Fix coverage misses of newly mocked funcs
ricab Feb 11, 2022
2470753
[test] Check client unregisters remote handler
ricab Feb 15, 2022
c3eaf04
Merge branch 'main' into settings-handlers
ricab Feb 17, 2022
05381d8
[test] Check client handles RemoteHandlerException
ricab Feb 17, 2022
33b532d
[test] Check that daemon handles set requests
ricab Feb 18, 2022
6335f62
[test] Check that `Daemon::set` sets
ricab Feb 18, 2022
f4c5082
[test] Check `Daemon::set` handles unrecognized
ricab Feb 18, 2022
e29cf2d
[test] Check remaining `Daemon::set` exceptions
ricab Feb 23, 2022
95229f3
Merge branch 'main' into settings-handlers
ricab Feb 24, 2022
7edc11e
[test] Check Settings delegates keys() on handlers
ricab Feb 24, 2022
44a621f
[test] Reset Settings singleton after tests
ricab Feb 24, 2022
753bbb3
[test] Check Settings returns all handler's keys
ricab Feb 24, 2022
3c440d3
[test] Use forwarding references in reduce lambda
ricab Feb 24, 2022
fd78252
[test] Check `Settings::get` on unrecognized key
ricab Feb 25, 2022
ffe4aeb
[test] Check `Settings::get` hit on first handler
ricab Feb 25, 2022
59bf473
[test] Check `Settings::get` hit on inner handler
ricab Feb 25, 2022
e674591
[test] Refactor `Settings::get` tests
ricab Feb 25, 2022
1b4b055
[test] Test `Settings::get` multiple keys/handlers
ricab Feb 25, 2022
5456985
[test] Get rid of extra if branch in test
ricab Feb 25, 2022
ae3925b
[test] Further refactor mixed settings test
ricab Feb 25, 2022
8d8ba7d
[test] Add unknown key to mixed Settings::get test
ricab Feb 25, 2022
e3dfa22
[test] Prefix settings test names w/ tested method
ricab Feb 28, 2022
15eba0b
[test] Check `Settings::set` on unrecognized key
ricab Feb 28, 2022
f47e38f
[test] Replace needless mock arrays with loop vars
ricab Feb 28, 2022
005d64c
[test] Check `Settings::set` delegates on handlers
ricab Feb 28, 2022
ae88b10
[test] Check `Settings::set` w/ multiple handlers
ricab Feb 28, 2022
ec3dc61
[test] Test `Settings::set` multiple keys/handlers
ricab Feb 28, 2022
f2bf5a6
[test] Check that `set` throws other exceptions
ricab Feb 28, 2022
19b33a1
[test] Slight variable refactorings
ricab Feb 28, 2022
c5ffa5f
[test] Test keys RPC
ricab Mar 1, 2022
bda5cb4
[test] Check that daemon returns settings keys
ricab Mar 1, 2022
9c4cf96
[test] Check that `Daemon::keys` reports exception
ricab Mar 1, 2022
e5ffc95
[test] Homogenize `MockSettings` mock declarations
ricab Mar 1, 2022
2c8efa4
[test] Test `PersistentSettingsHandler::keys`
ricab Mar 1, 2022
72498f1
Merge branch 'main' into settings-handlers
ricab Mar 3, 2022
40c4115
[client] Complete `rpc_channel` removal from cmds
ricab Mar 2, 2022
12fd8f5
[client] Complete replacing StubInterface in cmds
ricab Mar 2, 2022
754d2ec
[test] Add a mock RPC Stub
ricab Mar 3, 2022
39a03ce
[test] Start testing `RemoteSettingsHandler`
ricab Mar 2, 2022
09a385c
[test] Remote handler gives empty keys by default
ricab Mar 3, 2022
4896548
[test] Move `MockClientReader` to header
ricab Mar 3, 2022
e26bbf8
[test] Extract common remote-handler-test bits
ricab Mar 3, 2022
74ec51d
[test] Drop relax strictness of mock_client_reader
ricab Mar 3, 2022
7825163
[test] Further simplify remote handler test
ricab Mar 3, 2022
7d733f8
[doc] Add comment explaining testing choice
ricab Mar 3, 2022
79a2b3c
[test] Check remote-keys request honors verbosity
ricab Mar 3, 2022
43b5346
[test] Check verbosity honored in get and set too
ricab Mar 3, 2022
3418027
[client] Fix attempting to move from const capture
ricab Mar 3, 2022
f45bb54
[test] Check remote handler returns remote keys
ricab Mar 3, 2022
f0d51e7
[test] Check placeholder key when remote not found
ricab Mar 7, 2022
fa589f5
[test] Check throw on other remote keys error
ricab Mar 7, 2022
4c8a1ce
[test] Extract repeated ptr transfer boilerplate
ricab Mar 7, 2022
5fb804b
[test] Verify other exception data on remote keys
ricab Mar 7, 2022
ab0ac07
[test] Extract mock-client-reader making
ricab Mar 7, 2022
e4cb153
[test] Add a couple of tests for remote get
ricab Mar 7, 2022
29ee813
[test] Rename tests slightly
ricab Mar 7, 2022
61a7d39
[test] Verify that remote get refused on wrong key
ricab Mar 7, 2022
db44a3b
[test] Verify that remote set throws on wrong key
ricab Mar 7, 2022
274140d
[test] Verify contents of remote-setting request
ricab Mar 7, 2022
fe9aa7b
Merge branch 'main' into settings-handlers
ricab Mar 7, 2022
504fcdf
[test] Verify get throws on other remote error
ricab Mar 7, 2022
d7617fb
[test] Verify set throws on other remote error
ricab Mar 7, 2022
a2eb13f
[doc] Delete obsolete TODOs
ricab Mar 7, 2022
4a30c9e
[test] Fix formatting
ricab Mar 8, 2022
f516881
[test] Add missing includes
ricab Mar 8, 2022
e89ce48
[test] Drop constexpr from initializer_list const
ricab Mar 9, 2022
f28730b
[test] Fix comparison of std and c strings on win
ricab Mar 9, 2022
c6ad110
[doc] Add TODO to move prompters into settings
ricab Mar 15, 2022
45efcab
[networks] Revert wrong constant name
ricab Mar 28, 2022
d214952
[settings] Rename `{Dynamic,Custom}SettingSpec`
ricab Mar 28, 2022
f5d890e
Merge branch 'main' into settings-handlers
ricab Mar 29, 2022
7e5c3fb
[tests] Fix bad file ordering in cmake declaration
ricab Apr 4, 2022
3c69c8f
Merge branch 'main' into settings-handlers
ricab Apr 6, 2022
a02b0b4
[settings] Improve error messages
ricab Apr 6, 2022
47688d9
[daemon] Add TODOs on settings monitoring
ricab Apr 6, 2022
4ed6ae7
[daemon] Fix password resetting
ricab Apr 7, 2022
481e96b
[tests] Check custom password handler
ricab Apr 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions include/multipass/callable_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,41 @@
#define MULTIPASS_CALLABLE_TRAITS_H

#include <tuple>
#include <type_traits>

namespace multipass
{
// For lambdas, look at it's functor operator
// For lambdas, look at their function operator
// For functors, look at their function-call operator
template <typename T>
struct callable_traits
: public callable_traits<decltype(&std::remove_reference<T>::type::operator())>
struct callable_traits : public callable_traits<decltype(&T::operator())>
{
};

// Deal with references and pointers
template <typename T>
struct callable_traits<T&> : public callable_traits<T>
{
};

template <typename T>
struct callable_traits<T*> : public callable_traits<T>
{
};

// Deal with member functions
template <typename ClassType, typename ReturnType, typename... Args>
struct callable_traits<ReturnType (ClassType::*)(Args...) const>
struct callable_traits<ReturnType (ClassType::*)(Args...) const> : public callable_traits<ReturnType(Args...)>
{
};

template <typename ClassType, typename ReturnType, typename... Args>
struct callable_traits<ReturnType (ClassType::*)(Args...)> : public callable_traits<ReturnType(Args...)>
{
};

// Finally, the most basic function type, where all others will drain
template <typename ReturnType, typename... Args>
struct callable_traits<ReturnType(Args...)>
{
using return_type = ReturnType;
static constexpr std::size_t num_args = sizeof...(Args);
Expand Down
2 changes: 2 additions & 0 deletions include/multipass/cli/client_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ std::string update_notice(const multipass::UpdateInfo& update_info);

namespace client
{
QString persistent_settings_filename();
void register_global_settings_handlers();
std::shared_ptr<grpc::Channel> make_channel(const std::string& server_address, CertProvider* cert_provider);
std::string get_server_address();
std::unique_ptr<SSLCertProvider> get_cert_provider();
Expand Down
2 changes: 0 additions & 2 deletions include/multipass/cli/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ class Command : private DisabledCopyMove
std::ostream& cerr;

private:
virtual ParseCode parse_args(ArgParser* parser) = 0;

template <typename SuccessCallable, typename FailureCallable>
void check_return_callables(SuccessCallable&& on_success, FailureCallable&& on_failure)
{
Expand Down
2 changes: 1 addition & 1 deletion include/multipass/cli/format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <multipass/constants.h>
#include <multipass/rpc/multipass.grpc.pb.h>
#include <multipass/settings.h>
#include <multipass/settings/settings.h>

#include <fmt/format.h>

Expand Down
6 changes: 5 additions & 1 deletion include/multipass/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ constexpr auto driver_env_var = "MULTIPASS_VM_DRIVER";
constexpr auto winterm_profile_guid =
"{aaaa9e6d-1e09-4be6-b76c-82b4ba1885fb}"; // identifies the primary Multipass profile in Windows Terminal

constexpr auto settings_extension = ".conf";
constexpr auto daemon_settings_root = "local";
constexpr auto petenv_key = "client.primary-name"; // This will eventually be moved to some dynamic settings schema
constexpr auto driver_key = "local.driver"; // idem
constexpr auto passphrase_key = "local.passphrase"; // idem
constexpr auto bridged_interface_key = "local.bridged-network"; // idem
constexpr auto bridged_network_name = "bridged";
constexpr auto mounts_key = "local.privileged-mounts"; // idem
constexpr auto autostart_key = "client.gui.autostart"; // idem
constexpr auto winterm_key = "client.apps.windows-terminal.profiles"; // idem
constexpr auto hotkey_key = "client.gui.hotkey"; // idem

constexpr auto bridged_interface_default = "bridged";
ricab marked this conversation as resolved.
Show resolved Hide resolved
constexpr auto petenv_default = "primary";
constexpr auto hotkey_default = "Ctrl+Alt+U"; // idem; translates to Cmd+Opt+U on macOS

constexpr auto timeout_exit_code = 5;
Expand Down
14 changes: 9 additions & 5 deletions include/multipass/exceptions/settings_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace multipass
class SettingsException : public std::runtime_error
{
public:
SettingsException(const std::string& msg) : runtime_error{msg}
explicit SettingsException(const std::string& msg) : runtime_error{msg}
{
}
};
Expand All @@ -44,15 +44,19 @@ class PersistentSettingsException : public SettingsException
}
};

class InvalidSettingsException : public SettingsException
class UnrecognizedSettingException : public SettingsException
{
public:
InvalidSettingsException(const QString& key)
explicit UnrecognizedSettingException(const QString& key)
: SettingsException{fmt::format("Unrecognized settings key: '{}'", key)}
{
}
};

InvalidSettingsException(const QString& key, const QString& val, const QString& why)
class InvalidSettingException : public SettingsException
{
public:
InvalidSettingException(const QString& key, const QString& val, const QString& why)
: SettingsException{fmt::format("Invalid setting '{}={}': {}", key, val, why)}
{
}
Expand All @@ -62,7 +66,7 @@ template <typename T>
class UnsupportedSettingValueType : public SettingsException
{
public:
UnsupportedSettingValueType(const QString& key)
explicit UnsupportedSettingValueType(const QString& key)
: SettingsException{fmt::format("Invalid value type for key {}. Type hint: {}", key, typeid(T).name())}
{
}
Expand Down
12 changes: 6 additions & 6 deletions include/multipass/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <multipass/network_interface_info.h>
#include <multipass/process/process.h>
#include <multipass/process/process_spec.h>
#include <multipass/settings/setting_spec.h>
#include <multipass/singleton.h>
#include <multipass/sshfs_server_config.h>
#include <multipass/update_prompt.h>
Expand Down Expand Up @@ -66,21 +67,20 @@ class Platform : public Singleton<Platform>
virtual void remove_alias_script(const std::string& alias) const;
virtual std::string alias_path_message() const;
virtual void set_server_socket_restrictions(const std::string& server_address, const bool restricted) const;
virtual QString daemon_config_home() const; // temporary
virtual SettingSpec::Set extra_daemon_settings() const;
virtual SettingSpec::Set extra_client_settings() const;
virtual QString default_driver() const;
virtual QString default_privileged_mounts() const;
};

std::map<QString, QString> extra_settings_defaults();

QString interpret_setting(const QString& key, const QString& val);
void sync_winterm_profiles();

QString autostart_test_data(); // returns a platform-specific string, for testing purposes
void setup_gui_autostart_prerequisites();

std::string default_server_address();
QString default_driver();
QString default_privileged_mounts();

QString daemon_config_home(); // temporary

VirtualMachineFactory::UPtr vm_backend(const Path& data_dir);
logging::Logger::UPtr make_logger(logging::Level level);
Expand Down
81 changes: 0 additions & 81 deletions include/multipass/settings.h

This file was deleted.

39 changes: 39 additions & 0 deletions include/multipass/settings/basic_setting_spec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2021-2022 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef MULTIPASS_BASIC_SETTING_SPEC_H
#define MULTIPASS_BASIC_SETTING_SPEC_H

#include "setting_spec.h"

namespace multipass
{
class BasicSettingSpec : public SettingSpec
{
public:
BasicSettingSpec(QString key, QString default_);
Saviq marked this conversation as resolved.
Show resolved Hide resolved
QString get_key() const override;
QString get_default() const override;
QString interpret(QString val) const override;

protected:
QString key;
QString default_;
};
} // namespace multipass

#endif // MULTIPASS_BASIC_SETTING_SPEC_H
38 changes: 38 additions & 0 deletions include/multipass/settings/bool_setting_spec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021-2022 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef MULTIPASS_BOOL_SETTING_SPEC_H
#define MULTIPASS_BOOL_SETTING_SPEC_H

#include "basic_setting_spec.h"

#include <utility>

namespace multipass
{
class BoolSettingSpec : public BasicSettingSpec
{
public:
BoolSettingSpec(QString key, QString default_);
QString interpret(QString val) const override;

private:
BoolSettingSpec(std::pair<QString, QString> params);
};
} // namespace multipass

#endif // MULTIPASS_BOOL_SETTING_SPEC_H
38 changes: 38 additions & 0 deletions include/multipass/settings/dynamic_setting_spec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021-2022 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef MULTIPASS_DYNAMIC_SETTING_SPEC_H
#define MULTIPASS_DYNAMIC_SETTING_SPEC_H

#include "basic_setting_spec.h"

#include <functional>

namespace multipass
{
class DynamicSettingSpec : public multipass::BasicSettingSpec
Saviq marked this conversation as resolved.
Show resolved Hide resolved
{
public:
DynamicSettingSpec(QString key, QString default_, std::function<QString(QString)> interpreter);
QString interpret(QString val) const override;

protected:
std::function<QString(const QString&)> interpreter;
};
} // namespace multipass

#endif // MULTIPASS_DYNAMIC_SETTING_SPEC_H
Loading