id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
20,881
|
yaml_node_utils.h
|
canonical_multipass/include/multipass/yaml_node_utils.h
|
/*
* Copyright (C) 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_YAML_NODE_UTILS_H
#define MULTIPASS_YAML_NODE_UTILS_H
#include <yaml-cpp/yaml.h>
#include <string>
#include <vector>
namespace multipass
{
struct NetworkInterface;
namespace utils
{
// yaml helpers
std::string emit_yaml(const YAML::Node& node);
std::string emit_cloud_config(const YAML::Node& node);
// when file_content is non-empty, make_cloud_init_meta_config constructs the node based on the string and replaces
// the original name occurrences with the input name
YAML::Node make_cloud_init_meta_config(const std::string& name, const std::string& file_content = std::string{});
// load the file_content to construct the node and overwrite the instance-id, when the new_instance_id is provided, then
// it is used, if not, then there will be a generated new instance id to be used
YAML::Node make_cloud_init_meta_config_with_id_tweak(const std::string& file_content,
const std::string& new_instance_id = std::string());
// when file_content is non-empty, make_cloud_init_network_config constructs the node based on the string and replaces
// the default mac address and extra interfaces
YAML::Node make_cloud_init_network_config(const std::string& default_mac_addr,
const std::vector<NetworkInterface>& extra_interfaces,
const std::string& file_content = std::string{});
// adds one extra interface to the network_config_file_content baseline, it creates the default address node
// together with the extra interface node when it is empty,
YAML::Node add_extra_interface_to_network_config(const std::string& default_mac_addr,
const NetworkInterface& extra_interface,
const std::string& network_config_file_content);
// the make_cloud_init_network_config and add_extra_interface_to_network_config functions are adapted to generate the
// new format network-config file (having default interface present and having dhcp-identifier: mac on every network
// interface). At the same time, it also needs to take care of the pre-existed file, meaning that the generated file
// from the old file should have the new format.
} // namespace utils
} // namespace multipass
#endif // MULTIPASS_YAML_NODE_UTILS_H
| 2,990
|
C++
|
.h
| 53
| 50.622642
| 120
| 0.717013
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,882
|
dart_ffi.h
|
canonical_multipass/include/multipass/dart_ffi.h
|
#ifndef MULTIPASS_DART_FFI_H
#define MULTIPASS_DART_FFI_H
// clang-format off
extern "C"
{
// clang-format on
const char* multipass_version();
char* generate_petname();
char* get_server_address();
struct KeyCertificatePair
{
const char* pem_cert;
const char* pem_priv_key;
};
struct KeyCertificatePair get_cert_pair();
enum SettingResult
{
Ok,
KeyNotFound,
InvalidValue,
UnexpectedError,
};
char* settings_file();
enum SettingResult get_setting(char* key, char** output);
enum SettingResult set_setting(char* key, char* value, char** output);
int uid();
int gid();
int default_id();
long long memory_in_bytes(char* value);
const char* human_readable_memory(long long bytes);
long long get_total_disk_size();
char* default_mount_target(char* source);
}
#endif // MULTIPASS_DART_FFI_H
| 824
|
C++
|
.h
| 34
| 22.029412
| 70
| 0.751617
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,883
|
json_utils.h
|
canonical_multipass/include/multipass/json_utils.h
|
/*
* Copyright (C) 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_JSON_UTILS_H
#define MULTIPASS_JSON_UTILS_H
#include "singleton.h"
#include <multipass/network_interface.h>
#include <QJsonArray>
#include <QJsonObject>
#include <QString>
#include <optional>
#include <string>
#include <vector>
#define MP_JSONUTILS multipass::JsonUtils::instance()
namespace multipass
{
struct VMSpecs;
class JsonUtils : public Singleton<JsonUtils>
{
public:
explicit JsonUtils(const Singleton<JsonUtils>::PrivatePass&) noexcept;
virtual void write_json(const QJsonObject& root, QString file_name) const; // transactional; creates parent dirs
virtual std::string json_to_string(const QJsonObject& root) const;
virtual QJsonValue update_cloud_init_instance_id(const QJsonValue& cloud_init_instance_id_value,
const std::string& src_vm_name,
const std::string& dest_vm_name) const;
virtual QJsonValue update_unique_identifiers_of_metadata(const QJsonValue& metadata_value,
const multipass::VMSpecs& src_specs,
const multipass::VMSpecs& dest_specs,
const std::string& src_vm_name,
const std::string& dest_vm_name) const;
virtual QJsonArray extra_interfaces_to_json_array(const std::vector<NetworkInterface>& extra_interfaces) const;
virtual std::optional<std::vector<NetworkInterface>> read_extra_interfaces(const QJsonObject& record) const;
};
} // namespace multipass
#endif // MULTIPASS_JSON_UTILS_H
| 2,348
|
C++
|
.h
| 49
| 38.734694
| 116
| 0.662156
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,884
|
ssl_cert_provider.h
|
canonical_multipass/include/multipass/ssl_cert_provider.h
|
/*
* Copyright (C) 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_SSL_CERT_PROVIDER_H
#define MULTIPASS_SSL_CERT_PROVIDER_H
#include <multipass/cert_provider.h>
#include <multipass/path.h>
#include <string>
namespace multipass
{
class SSLCertProvider : public CertProvider
{
public:
struct KeyCertificatePair
{
std::string pem_cert;
std::string pem_priv_key;
};
explicit SSLCertProvider(const Path& data_dir);
SSLCertProvider(const Path& data_dir, const std::string& server_name);
std::string PEM_certificate() const override;
std::string PEM_signing_key() const override;
private:
KeyCertificatePair key_cert_pair;
};
} // namespace multipass
#endif // MULTIPASS_SSL_CERT_PROVIDER_H
| 1,318
|
C++
|
.h
| 40
| 30.225
| 74
| 0.751572
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,885
|
vm_status_monitor.h
|
canonical_multipass/include/multipass/vm_status_monitor.h
|
/*
* Copyright (C) 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_VM_STATUS_MONITOR_H
#define MULTIPASS_VM_STATUS_MONITOR_H
#include "disabled_copy_move.h"
#include "virtual_machine.h"
#include <string>
#include <QJsonObject>
namespace multipass
{
class VMStatusMonitor : private DisabledCopyMove
{
public:
virtual ~VMStatusMonitor() = default;
virtual void on_resume() = 0;
virtual void on_shutdown() = 0;
virtual void on_suspend() = 0;
virtual void on_restart(const std::string& name) = 0;
virtual void persist_state_for(const std::string& name, const VirtualMachine::State& state) = 0;
virtual void update_metadata_for(const std::string& name, const QJsonObject& metadata) = 0;
virtual QJsonObject retrieve_metadata_for(const std::string& name) = 0;
protected:
VMStatusMonitor() = default;
};
}
#endif // MULTIPASS_VM_STATUS_MONITOR_H
| 1,460
|
C++
|
.h
| 40
| 34.075
| 100
| 0.749646
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,886
|
cert_store.h
|
canonical_multipass/include/multipass/cert_store.h
|
/*
* Copyright (C) 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_CERT_STORE_H
#define MULTIPASS_CERT_STORE_H
#include "disabled_copy_move.h"
#include <string>
namespace multipass
{
class CertStore : private DisabledCopyMove
{
public:
virtual ~CertStore() = default;
virtual void add_cert(const std::string& pem_cert) = 0;
virtual std::string PEM_cert_chain() const = 0;
virtual bool verify_cert(const std::string& pem_cert) = 0;
virtual bool empty() = 0;
protected:
CertStore() = default;
};
} // namespace multipass
#endif // MULTIPASS_CERT_STORE_H
| 1,160
|
C++
|
.h
| 35
| 30.885714
| 72
| 0.74375
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,887
|
alias_definition.h
|
canonical_multipass/include/multipass/alias_definition.h
|
/*
* Copyright (C) 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_ALIAS_DEFINITION_H
#define MULTIPASS_ALIAS_DEFINITION_H
#include <string>
#include <unordered_map>
namespace multipass
{
struct AliasDefinition
{
std::string instance;
std::string command;
std::string working_directory;
};
inline bool operator==(const AliasDefinition& a, const AliasDefinition& b)
{
return (a.instance == b.instance && a.command == b.command);
}
typedef typename std::unordered_map<std::string, AliasDefinition> AliasContext;
} // namespace multipass
#endif // MULTIPASS_ALIAS_DEFINITION_H
| 1,175
|
C++
|
.h
| 35
| 31.514286
| 79
| 0.763668
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,888
|
recursive_dir_iterator.h
|
canonical_multipass/include/multipass/recursive_dir_iterator.h
|
/*
* Copyright (C) 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 RECURSIVE_DIR_ITERATOR_H
#define RECURSIVE_DIR_ITERATOR_H
#include <filesystem>
#include <optional>
namespace multipass
{
namespace fs = std::filesystem;
// this is just a thin wrapper around std::filesystem::directory_entry, used for mocking purposes
class DirectoryEntry
{
public:
DirectoryEntry() = default;
DirectoryEntry(const DirectoryEntry&) = default;
DirectoryEntry(DirectoryEntry&&) = default;
explicit DirectoryEntry(const fs::directory_entry& _entry) : entry{_entry}
{
}
DirectoryEntry& operator=(const DirectoryEntry&) = default;
DirectoryEntry& operator=(DirectoryEntry&&) noexcept = default;
virtual ~DirectoryEntry() = default;
virtual void assign(const fs::path& path)
{
entry.assign(path);
}
virtual void assign(const fs::path& path, std::error_code& err)
{
entry.assign(path, err);
}
virtual void replace_filename(const fs::path& path)
{
entry.replace_filename(path);
}
virtual void replace_filename(const fs::path& path, std::error_code& err)
{
entry.replace_filename(path, err);
}
virtual void refresh()
{
entry.refresh();
}
virtual void refresh(std::error_code& err) noexcept
{
entry.refresh(err);
}
virtual const fs::path& path() const noexcept
{
return entry.path();
}
virtual bool exists() const
{
return entry.exists();
}
virtual bool exists(std::error_code& err) const noexcept
{
return entry.exists(err);
}
virtual bool is_block_file() const
{
return entry.is_block_file();
}
virtual bool is_block_file(std::error_code& err) const noexcept
{
return entry.is_block_file(err);
}
virtual bool is_character_file() const
{
return entry.is_character_file();
}
virtual bool is_character_file(std::error_code& err) const noexcept
{
return entry.is_character_file(err);
}
virtual bool is_directory() const
{
return entry.is_directory();
}
virtual bool is_directory(std::error_code& err) const noexcept
{
return entry.is_directory(err);
}
virtual bool is_fifo() const
{
return entry.is_fifo();
}
virtual bool is_fifo(std::error_code& err) const noexcept
{
return entry.is_fifo(err);
}
virtual bool is_other() const
{
return entry.is_other();
}
virtual bool is_other(std::error_code& err) const noexcept
{
return entry.is_other(err);
}
virtual bool is_regular_file() const
{
return entry.is_regular_file();
}
virtual bool is_regular_file(std::error_code& err) const noexcept
{
return entry.is_regular_file(err);
}
virtual bool is_socket() const
{
return entry.is_socket();
}
virtual bool is_socket(std::error_code& err) const noexcept
{
return entry.is_socket(err);
}
virtual bool is_symlink() const
{
return entry.is_symlink();
}
virtual bool is_symlink(std::error_code& err) const noexcept
{
return entry.is_symlink(err);
}
virtual uintmax_t file_size() const
{
return entry.file_size();
}
virtual uintmax_t file_size(std::error_code& err) const noexcept
{
return entry.file_size(err);
}
virtual uintmax_t hard_link_count() const
{
return entry.hard_link_count();
}
virtual uintmax_t hard_link_count(std::error_code& err) const noexcept
{
return entry.hard_link_count(err);
}
virtual fs::file_time_type last_write_time() const
{
return entry.last_write_time();
}
virtual fs::file_time_type last_write_time(std::error_code& err) const noexcept
{
return entry.last_write_time(err);
}
virtual fs::file_status status() const
{
return entry.status();
}
virtual fs::file_status status(std::error_code& err) const noexcept
{
return entry.status(err);
}
virtual fs::file_status symlink_status() const
{
return entry.symlink_status();
}
virtual fs::file_status symlink_status(std::error_code& err) const noexcept
{
return entry.symlink_status(err);
}
virtual bool operator==(const DirectoryEntry& rhs) const noexcept
{
return entry == rhs.entry;
}
private:
fs::directory_entry entry;
};
// wrapper class around std::filesystem::recursive_directory_iterator used for mocking purposes
class RecursiveDirIterator
{
public:
RecursiveDirIterator() = default;
RecursiveDirIterator(const fs::path& path, std::error_code& err) : iter{path, err}
{
}
virtual bool hasNext()
{
return iter != fs::end(iter);
}
virtual const DirectoryEntry& next()
{
return current = DirectoryEntry{*iter++};
}
virtual ~RecursiveDirIterator() = default;
private:
fs::recursive_directory_iterator iter;
DirectoryEntry current;
};
// wrapper class around std::filesystem::directory_iterator used for mocking purposes
class DirIterator
{
public:
DirIterator() = default;
DirIterator(const fs::path& path, std::error_code& err) : self{path / "."}, parent{path / ".."}, iter{path, err}
{
}
virtual bool hasNext()
{
return iter != fs::end(iter);
}
virtual const DirectoryEntry& next()
{
if (self)
{
const fs::directory_entry entry{*self};
self.reset();
return current = DirectoryEntry{entry};
}
if (parent)
{
const fs::directory_entry entry{*parent};
parent.reset();
return current = DirectoryEntry{entry};
}
return current = DirectoryEntry{*iter++};
}
virtual ~DirIterator() = default;
private:
std::optional<fs::path> self;
std::optional<fs::path> parent;
fs::directory_iterator iter;
DirectoryEntry current;
};
} // namespace multipass
#endif // RECURSIVE_DIR_ITERATOR_H
| 6,764
|
C++
|
.h
| 241
| 22.522822
| 116
| 0.650224
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,889
|
fetch_type.h
|
canonical_multipass/include/multipass/fetch_type.h
|
/*
* Copyright (C) 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/>.
*
* Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
*
*/
#ifndef MULTIPASS_FETCH_TYPE_H
#define MULTIPASS_FETCH_TYPE_H
namespace multipass
{
enum class FetchType
{
ImageOnly
};
}
#endif //MULTIPASS_FETCH_TYPE_H
| 854
|
C++
|
.h
| 28
| 28.714286
| 72
| 0.763636
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,890
|
timer.h
|
canonical_multipass/include/multipass/timer.h
|
/*
* Copyright (C) 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_TIMER_H
#define MULTIPASS_TIMER_H
#include "disabled_copy_move.h"
#include "singleton.h"
#include <chrono>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <thread>
namespace multipass::utils
{
enum class TimerState : int
{
Stopped,
Running,
Paused
};
class Timer : private DisabledCopyMove
{
public:
Timer(std::chrono::milliseconds, std::function<void()>); /* NB: callback runs on the timeout thread. */
~Timer();
public:
void start();
void pause();
void resume();
void stop();
private:
void main();
const std::chrono::milliseconds timeout;
const std::function<void()> callback;
TimerState current_state;
std::thread t;
std::condition_variable cv;
std::mutex cv_m;
};
#define MP_TIMER_SYNC_FUNCS multipass::utils::TimerSyncFuncs::instance()
class TimerSyncFuncs : public Singleton<TimerSyncFuncs>
{
public:
TimerSyncFuncs(const Singleton<TimerSyncFuncs>::PrivatePass&) noexcept;
virtual void notify_all(std::condition_variable& cv) const;
virtual void wait(std::condition_variable& cv, std::unique_lock<std::mutex>& lock, std::function<bool()>) const;
virtual bool wait_for(std::condition_variable& cv, std::unique_lock<std::mutex>& lock,
const std::chrono::duration<int, std::milli>& rel_time, std::function<bool()>) const;
};
} // namespace multipass::utils
#endif // MULTIPASS_TIMER_H
| 2,082
|
C++
|
.h
| 64
| 29.453125
| 116
| 0.72682
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,891
|
delayed_shutdown_timer.h
|
canonical_multipass/include/multipass/delayed_shutdown_timer.h
|
/*
* Copyright (C) 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_DELAYED_SHUTDOWN_TIMER_H
#define MULTIPASS_DELAYED_SHUTDOWN_TIMER_H
#include <multipass/disabled_copy_move.h>
#include <multipass/virtual_machine.h>
#include <QObject>
#include <QTimer>
#include <chrono>
#include <functional>
#include <string>
namespace multipass
{
class DelayedShutdownTimer : public QObject, private DisabledCopyMove
{
Q_OBJECT
public:
using StopMounts = std::function<void(const std::string&)>;
DelayedShutdownTimer(VirtualMachine* virtual_machine, const StopMounts& stop_mounts);
~DelayedShutdownTimer();
void start(const std::chrono::milliseconds delay);
std::chrono::seconds get_time_remaining();
signals:
void finished();
private:
void shutdown_instance();
QTimer shutdown_timer;
VirtualMachine* virtual_machine;
const StopMounts stop_mounts;
std::chrono::milliseconds time_remaining;
};
} // namespace multipass
#endif // MULTIPASS_DELAYED_SHUTDOWN_TIMER_H
| 1,586
|
C++
|
.h
| 47
| 31.191489
| 89
| 0.767168
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,892
|
id_mappings.h
|
canonical_multipass/include/multipass/id_mappings.h
|
/*
* Copyright (C) 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_ID_MAPPINGS_H
#define MULTIPASS_ID_MAPPINGS_H
#include <multipass/format.h>
#include <multipass/logging/log.h>
#include <algorithm>
#include <iterator>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
namespace mpl = multipass::logging;
namespace multipass
{
using id_mappings = std::vector<std::pair<int, int>>;
inline auto unique_id_mappings(id_mappings& xid_mappings)
{
std::unordered_map<int, std::unordered_set<int>> dup_id_map;
std::unordered_map<int, std::unordered_set<int>> dup_rev_id_map;
for (auto it = xid_mappings.begin(); it != xid_mappings.end();)
{
bool duplicate =
dup_id_map.find(it->first) != dup_id_map.end() || dup_rev_id_map.find(it->second) != dup_rev_id_map.end();
dup_id_map[it->first].insert(it->second);
dup_rev_id_map[it->second].insert(it->first);
if (duplicate)
{
mpl::log(mpl::Level::debug,
"id_mappings",
fmt::format("Dropping repeated mapping {}:{}", it->first, it->second));
it = xid_mappings.erase(it);
}
else
{
++it;
}
}
auto filter_non_repeating = [](auto& map) {
for (auto it = map.begin(); it != map.end();)
{
if (it->second.size() <= 1)
it = map.erase(it);
else
++it;
}
};
filter_non_repeating(dup_id_map);
filter_non_repeating(dup_rev_id_map);
return std::make_pair(dup_id_map, dup_rev_id_map);
}
} // namespace multipass
#endif // MULTIPASS_ID_MAPPINGS_H
| 2,291
|
C++
|
.h
| 68
| 28.132353
| 118
| 0.636199
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,893
|
private_pass_provider.h
|
canonical_multipass/include/multipass/private_pass_provider.h
|
/*
* Copyright (C) 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_PRIVATE_PASS_PROVIDER_H
#define MULTIPASS_PRIVATE_PASS_PROVIDER_H
namespace multipass
{
/*
* Helper class for classes that want to make a function publicly visible but
* only callable privately and by friends. To use, inherit (publicly) using the
* CRTP idiom. Then require a PrivatePass in the intended function, and provide
* the only `pass` attribute privately to friends. Friends can then call the
* method using the pass.
*/
template <typename T>
class PrivatePassProvider
{
public:
virtual ~PrivatePassProvider() = default;
class PrivatePass
{
private:
constexpr PrivatePass() = default;
friend class PrivatePassProvider<T>;
};
private:
static constexpr const PrivatePass pass{}; // token to prove friendship
friend T;
};
} // namespace multipass
template <typename T>
constexpr const typename multipass::PrivatePassProvider<T>::PrivatePass multipass::PrivatePassProvider<T>::pass;
#endif // MULTIPASS_PRIVATE_PASS_PROVIDER_H
| 1,634
|
C++
|
.h
| 46
| 32.978261
| 112
| 0.76359
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,894
|
top_catch_all.h
|
canonical_multipass/include/multipass/top_catch_all.h
|
/*
* Copyright (C) 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_TOP_CATCH_ALL_H
#define MULTIPASS_TOP_CATCH_ALL_H
#include <multipass/format.h>
#include <multipass/logging/log.h>
#include <functional>
#include <type_traits>
namespace multipass
{
namespace detail
{
void error(const multipass::logging::CString& log_category,
const std::exception& e); // not noexcept because logging isn't
void error(const multipass::logging::CString& log_category); // not noexcept because logging isn't
} // namespace detail
/**
* Call a non-void function within a try-catch, catching and logging anything that it throws.
*
* @tparam T The type of the value that is used to initialize the return value when an exception is caught
* @tparam Fun The type of the callable f. It must be callable and return non-void.
* @tparam Args The types of f's arguments
* @param log_category The category to use when logging exceptions
* @param fallback_return The value to return value when an exception is caught
* @param f The non-void function to protect with a catch-all
* @param args The arguments to pass to the function f
* @return The result of f when no exception is thrown, fallback_return otherwise
* @note This function will call `terminate()` if logging itself throws (all bets are off at that point). That
* corresponds to the usual `noexcept` guarantees (no exception or program terminated).
*/
template <typename T, typename Fun, typename... Args> // Fun needs to return non-void
auto top_catch_all(const logging::CString& log_category, T&& fallback_return, Fun&& f, Args&&... args) noexcept
-> std::invoke_result_t<Fun, Args...>; // logging can throw, but we want to std::terminate in that case
/**
* Call a void function within a try-catch, catching and logging anything that it throws.
*
* @tparam Fun The type of the callable f. It must be callable and return void.
* @tparam Args The types of f's arguments
* @param log_category The category to use when logging exceptions
* @param f The non-void function to protect with a catch-all
* @param args The arguments to pass to the function f
* @note This function will call `terminate()` if logging itself throws (all bets are off at that point). That
* corresponds to the usual `noexcept` guarantees (no exception or program terminated).
*/
template <typename Fun, typename... Args> // Fun needs to return void
void top_catch_all(const logging::CString& log_category, Fun&& f,
Args&&... args) noexcept; // logging can throw, but we want to std::terminate in that case
} // namespace multipass
inline void multipass::detail::error(const multipass::logging::CString& log_category, const std::exception& e)
{
namespace mpl = multipass::logging;
mpl::log(mpl::Level::error, log_category, fmt::format("Caught an unhandled exception: {}", e.what()));
}
inline void multipass::detail::error(const multipass::logging::CString& log_category)
{
namespace mpl = multipass::logging;
mpl::log(mpl::Level::error, log_category, "Caught an unknown exception");
}
template <typename T, typename Fun, typename... Args>
inline auto multipass::top_catch_all(const logging::CString& log_category, T&& fallback_return, Fun&& f,
Args&&... args) noexcept -> std::invoke_result_t<Fun, Args...>
{
try
{
return std::invoke(std::forward<Fun>(f), std::forward<Args>(args)...);
}
catch (const std::exception& e)
{
detail::error(log_category, e);
}
catch (...)
{
detail::error(log_category);
}
return std::forward<decltype(fallback_return)>(fallback_return);
}
template <typename Fun, typename... Args>
inline void multipass::top_catch_all(const logging::CString& log_category, Fun&& f, Args&&... args) noexcept
{
try
{
std::invoke(std::forward<Fun>(f), std::forward<Args>(args)...);
}
catch (const std::exception& e)
{
detail::error(log_category, e);
}
catch (...)
{
detail::error(log_category);
}
}
#endif // MULTIPASS_TOP_CATCH_ALL_H
| 4,697
|
C++
|
.h
| 107
| 40.457944
| 111
| 0.711228
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,895
|
snap_utils.h
|
canonical_multipass/include/multipass/snap_utils.h
|
/*
* Copyright (C) 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_SNAP_UTILS_H
#define MULTIPASS_SNAP_UTILS_H
#include <QByteArray>
namespace multipass
{
namespace utils
{
bool in_multipass_snap();
QByteArray snap_dir();
QByteArray snap_common_dir();
QByteArray snap_real_home_dir();
QByteArray snap_user_common_dir();
} // namespace utils
} // namespace multipass
#endif // MULTIPASS_SNAP_UTILS_H
| 982
|
C++
|
.h
| 31
| 30.064516
| 72
| 0.767687
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,896
|
cloud_init_iso.h
|
canonical_multipass/include/multipass/cloud_init_iso.h
|
/*
* Copyright (C) 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/>.
*
* Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
*
*/
#ifndef MULTIPASS_CLOUD_INIT_ISO_H
#define MULTIPASS_CLOUD_INIT_ISO_H
#include <multipass/path.h>
#include <filesystem>
#include <string>
#include <vector>
#include <multipass/singleton.h>
#define MP_CLOUD_INIT_FILE_OPS multipass::CloudInitFileOps::instance()
namespace multipass
{
class CloudInitIso
{
public:
void add_file(const std::string& name, const std::string& data);
bool contains(const std::string& name) const;
const std::string& at(const std::string& name) const;
std::string& at(const std::string& name);
std::string& operator[](const std::string& name);
bool erase(const std::string& name);
void write_to(const Path& path);
void read_from(const std::filesystem::path& path);
friend bool operator==(const CloudInitIso& lhs, const CloudInitIso& rhs)
{
return lhs.files == rhs.files;
}
private:
struct FileEntry
{
friend bool operator==(const FileEntry& lhs, const FileEntry& rhs)
{
return std::tie(lhs.name, lhs.data) == std::tie(rhs.name, rhs.data);
}
std::string name;
std::string data;
};
std::vector<FileEntry> files;
};
struct NetworkInterface;
class CloudInitFileOps : public Singleton<CloudInitFileOps>
{
public:
CloudInitFileOps(const Singleton<CloudInitFileOps>::PrivatePass&) noexcept;
virtual void update_cloud_init_with_new_extra_interfaces_and_new_id(
const std::string& default_mac_addr,
const std::vector<NetworkInterface>& extra_interfaces,
const std::string& new_instance_id,
const std::filesystem::path& cloud_init_path) const;
virtual void update_cloned_cloud_init_unique_identifiers(const std::string& default_mac_addr,
const std::vector<NetworkInterface>& extra_interfaces,
const std::string& new_hostname,
const std::filesystem::path& cloud_init_path) const;
virtual void add_extra_interface_to_cloud_init(const std::string& default_mac_addr,
const NetworkInterface& extra_interfaces,
const std::filesystem::path& cloud_init_path) const;
virtual std::string get_instance_id_from_cloud_init(const std::filesystem::path& cloud_init_path) const;
};
} // namespace multipass
#endif // MULTIPASS_CLOUD_INIT_ISO_H
| 3,207
|
C++
|
.h
| 76
| 34.789474
| 115
| 0.665811
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,897
|
url_downloader.h
|
canonical_multipass/include/multipass/url_downloader.h
|
/*
* Copyright (C) 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_URL_DOWNLOADER_H
#define MULTIPASS_URL_DOWNLOADER_H
#include "disabled_copy_move.h"
#include "path.h"
#include "progress_monitor.h"
#include "singleton.h"
#include <QByteArray>
#include <QDateTime>
#include <QNetworkAccessManager>
#include <atomic>
#include <chrono>
#define MP_NETMGRFACTORY multipass::NetworkManagerFactory::instance()
class QUrl;
class QString;
namespace multipass
{
class NetworkManagerFactory : public Singleton<NetworkManagerFactory>
{
public:
NetworkManagerFactory(const Singleton<NetworkManagerFactory>::PrivatePass&) noexcept;
virtual std::unique_ptr<QNetworkAccessManager> make_network_manager(const Path& cache_dir_path) const;
};
class URLDownloader : private DisabledCopyMove
{
public:
URLDownloader(std::chrono::milliseconds timeout);
URLDownloader(const Path& cache_dir, std::chrono::milliseconds timeout);
virtual ~URLDownloader() = default;
virtual void download_to(const QUrl& url, const QString& file_name, int64_t size, const int download_type,
const ProgressMonitor& monitor);
virtual QByteArray download(const QUrl& url);
virtual QByteArray download(const QUrl& url, const bool is_force_update_from_network);
virtual QDateTime last_modified(const QUrl& url);
virtual void abort_all_downloads();
protected:
std::atomic_bool abort_downloads{false};
private:
const Path cache_dir_path;
std::chrono::milliseconds timeout;
};
} // namespace multipass
#endif // MULTIPASS_URL_DOWNLOADER_H
| 2,158
|
C++
|
.h
| 58
| 34.37931
| 110
| 0.769378
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,898
|
ip_address.h
|
canonical_multipass/include/multipass/ip_address.h
|
/*
* Copyright (C) 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/>.
*
* Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
*
*/
#ifndef MULTIPASS_IP_ADDRESS_H
#define MULTIPASS_IP_ADDRESS_H
#include <array>
#include <cstdint>
#include <string>
namespace multipass
{
struct IPAddress
{
IPAddress(std::array<uint8_t, 4> octets);
IPAddress(const std::string& ip_string);
explicit IPAddress(uint32_t value);
IPAddress(const IPAddress& other) = default;
std::string as_string() const;
uint32_t as_uint32() const;
bool operator==(const IPAddress& other) const;
bool operator!=(const IPAddress& other) const;
bool operator<(const IPAddress& other) const;
bool operator<=(const IPAddress& other) const;
bool operator>(const IPAddress& other) const;
bool operator>=(const IPAddress& other) const;
IPAddress operator+(int value) const;
std::array<uint8_t, 4> octets;
};
}
#endif // MULTIPASS_IP_ADDRESS_H
| 1,525
|
C++
|
.h
| 44
| 31.840909
| 72
| 0.740163
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,899
|
vm_image_host.h
|
canonical_multipass/include/multipass/vm_image_host.h
|
/*
* Copyright (C) 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_VM_IMAGE_HOST_H
#define MULTIPASS_VM_IMAGE_HOST_H
#include "disabled_copy_move.h"
#include "vm_image_info.h"
#include <functional>
#include <optional>
#include <string>
#include <utility>
#include <vector>
namespace multipass
{
class Query;
class VMImage;
class VMImageHost : private DisabledCopyMove
{
public:
using Action = std::function<void(const std::string&, const VMImageInfo&)>;
virtual ~VMImageHost() = default;
virtual std::optional<VMImageInfo> info_for(const Query& query) = 0;
virtual std::vector<std::pair<std::string, VMImageInfo>> all_info_for(const Query& query) = 0;
virtual VMImageInfo info_for_full_hash(const std::string& full_hash) = 0;
virtual std::vector<VMImageInfo> all_images_for(const std::string& remote_name, const bool allow_unsupported) = 0;
virtual void for_each_entry_do(const Action& action) = 0;
virtual std::vector<std::string> supported_remotes() = 0;
virtual void update_manifests(const bool is_force_update_from_network) = 0;
protected:
VMImageHost() = default;
};
} // namespace multipass
#endif // MULTIPASS_VM_IMAGE_HOST_H
| 1,758
|
C++
|
.h
| 46
| 35.891304
| 118
| 0.749121
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,900
|
simple_streams_manifest.h
|
canonical_multipass/include/multipass/simple_streams_manifest.h
|
/*
* Copyright (C) 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/>.
*
* Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
*
*/
#ifndef MULTIPASS_SIMPLE_STREAMS_MANIFEST_H
#define MULTIPASS_SIMPLE_STREAMS_MANIFEST_H
#include "disabled_copy_move.h"
#include "vm_image_info.h"
#include <QByteArray>
#include <QMap>
#include <QString>
#include <memory>
#include <optional>
#include <vector>
namespace multipass
{
struct SimpleStreamsManifest
{
static std::unique_ptr<SimpleStreamsManifest>
fromJson(const QByteArray& json, const std::optional<QByteArray>& json_from_mirror, const QString& host_url);
const QString updated_at;
const std::vector<VMImageInfo> products;
const QMap<QString, const VMImageInfo*> image_records;
SimpleStreamsManifest(const QString& updated_at, std::vector<VMImageInfo>&& images);
};
} // namespace multipass
#endif // MULTIPASS_SIMPLE_STREAMS_MANIFEST_H
| 1,477
|
C++
|
.h
| 41
| 33.829268
| 113
| 0.771008
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,901
|
throw_on_error.h
|
canonical_multipass/include/multipass/ssh/throw_on_error.h
|
/*
* Copyright (C) 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_SSH_THROW_ON_ERROR_H
#define MULTIPASS_SSH_THROW_ON_ERROR_H
#include <libssh/libssh.h>
#include <fmt/format.h>
#include <multipass/exceptions/ssh_exception.h>
#include <string>
#include <type_traits>
namespace multipass
{
namespace SSH
{
template <typename Handle, typename Callable, typename... Args>
void throw_on_error(Handle&& h, ssh_session session, const char* error_msg, Callable&& f, Args&&... args)
{
const auto ret = f(h.get(), std::forward<Args>(args)...);
if (ret != SSH_OK)
{
throw SSHException(fmt::format("{}: '{}'", error_msg, ssh_get_error(session)));
}
}
template <typename Handle, typename Callable, typename... Args>
void throw_on_error(Handle&& h, const char* error_msg, Callable&& f, Args&&... args)
{
// Ensure that the handle type is appropriate for ssh_get_error
using HandleType = typename std::remove_reference<Handle>::type;
using HandlePointerType = decltype(std::declval<HandleType>().get());
static_assert(std::is_same<ssh_session, HandlePointerType>::value, "ssh_get_error needs an ssh_session");
throw_on_error(h, h.get(), error_msg, f, std::forward<Args>(args)...);
}
} // namespace SSH
} // namespace multipass
#endif // MULTIPASS_SSH_THROW_ON_ERROR_H
| 1,885
|
C++
|
.h
| 48
| 36.875
| 109
| 0.724986
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,902
|
ssh_key_provider.h
|
canonical_multipass/include/multipass/ssh/ssh_key_provider.h
|
/*
* Copyright (C) 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/>.
*
* Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
*
*/
#ifndef MULTIPASS_SSH_KEY_PROVIDER_H
#define MULTIPASS_SSH_KEY_PROVIDER_H
#include <multipass/disabled_copy_move.h>
#include <libssh/libssh.h>
#include <string>
namespace multipass
{
class SSHKeyProvider : private DisabledCopyMove
{
public:
virtual ~SSHKeyProvider() = default;
virtual std::string private_key_as_base64() const = 0;
virtual std::string public_key_as_base64() const = 0;
virtual ssh_key private_key() const = 0;
protected:
SSHKeyProvider() = default;
};
}
#endif // MULTIPASS_SSH_KEY_PROVIDER_H
| 1,232
|
C++
|
.h
| 37
| 31.135135
| 72
| 0.755257
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,903
|
ssh_process.h
|
canonical_multipass/include/multipass/ssh/ssh_process.h
|
/*
* Copyright (C) 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_SSH_PROCESS_H
#define MULTIPASS_SSH_PROCESS_H
#include <libssh/libssh.h>
#include <chrono>
#include <exception>
#include <memory>
#include <mutex>
#include <string>
#include <variant>
namespace multipass
{
class SSHProcess
{
public:
using ChannelUPtr = std::unique_ptr<ssh_channel_struct, void (*)(ssh_channel)>;
SSHProcess(ssh_session ssh_session, const std::string& cmd, std::unique_lock<std::mutex> session_lock);
// just being explicit (unique_ptr member already caused these to be deleted)
SSHProcess(const SSHProcess&) = delete;
SSHProcess& operator=(const SSHProcess&) = delete;
// we should be able to move just fine though
SSHProcess(SSHProcess&&) = default;
SSHProcess& operator=(SSHProcess&&) = default;
~SSHProcess() = default; // releases session lock
// Attempt to verify process completion within the given timeout. For this to return true, two conditions are
// necessary:
// a) the process did indeed finish;
// b) its exit code is read over ssh within the timeout.
//
// Note, in particular, that a false return does not guarantee that the process is still running. It may be just
// that the exit code was not made available to us in a timely manner.
//
// This method caches the exit code if we find it, but it keeps the SSHSession locked.
bool exit_recognized(std::chrono::milliseconds timeout = std::chrono::milliseconds(10)); // keeps session lock
int exit_code(std::chrono::milliseconds timeout = std::chrono::seconds(5)); // releases session lock
std::string read_std_output();
std::string read_std_error();
private:
enum class StreamType
{
out,
err
};
void rethrow_if_saved() const;
void read_exit_code(std::chrono::milliseconds timeout, bool save_exception);
std::string read_stream(StreamType type, int timeout = -1);
ssh_channel release_channel(); // releases the lock on the session; callers are on their own to ensure thread safety
std::unique_lock<std::mutex> session_lock; // do not attempt to re-lock, as this is moved from
ssh_session session;
std::string cmd;
ChannelUPtr channel;
std::variant<std::monostate, int, std::exception_ptr> exit_result;
friend class SftpServer;
};
} // namespace multipass
#endif // MULTIPASS_SSH_PROCESS_H
| 3,008
|
C++
|
.h
| 71
| 38.760563
| 120
| 0.720835
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,904
|
ssh_session.h
|
canonical_multipass/include/multipass/ssh/ssh_session.h
|
/*
* Copyright (C) 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_SSH_H
#define MULTIPASS_SSH_H
#include <multipass/ssh/ssh_process.h>
#include <libssh/libssh.h>
#include <chrono>
#include <memory>
#include <mutex>
#include <string>
namespace multipass
{
class SSHKeyProvider;
class SSHSession
{
public:
SSHSession(const std::string& host,
int port,
const std::string& ssh_username,
const SSHKeyProvider& key_provider,
const std::chrono::milliseconds timeout = std::chrono::seconds(20));
// just being explicit (unique_ptr member already caused these to be deleted)
SSHSession(const SSHSession&) = delete;
SSHSession& operator=(const SSHSession&) = delete;
// we should be able to move just fine though, but we need to lock
SSHSession(SSHSession&&);
SSHSession& operator=(SSHSession&&);
~SSHSession();
SSHProcess exec(const std::string& cmd, bool whisper = false); /* locks the session until the process is destroyed
or exit_code is called! */
[[nodiscard]] bool is_connected() const;
operator ssh_session(); // careful, not thread safe
void force_shutdown(); // careful, not thread safe
private:
SSHSession(SSHSession&&, std::unique_lock<std::mutex> lock);
void set_option(ssh_options_e type, const void* value);
std::unique_ptr<ssh_session_struct, void (*)(ssh_session)> session;
mutable std::mutex mut;
};
} // namespace multipass
#endif // MULTIPASS_SSH_H
| 2,148
|
C++
|
.h
| 55
| 34.018182
| 118
| 0.694231
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,905
|
sftp_dir_iterator.h
|
canonical_multipass/include/multipass/ssh/sftp_dir_iterator.h
|
/*
* Copyright (C) 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_SFTP_DIR_ITERATOR_H
#define MULTIPASS_SFTP_DIR_ITERATOR_H
#include <libssh/sftp.h>
#include <filesystem>
#include <functional>
#include <memory>
#include <stack>
#include <vector>
namespace multipass
{
namespace fs = std::filesystem;
using SFTPAttributesUPtr = std::unique_ptr<sftp_attributes_struct, std::function<void(sftp_attributes)>>;
using SFTPDirUPtr = std::unique_ptr<sftp_dir_struct, std::function<int(sftp_dir)>>;
class SFTPDirIterator
{
public:
SFTPDirIterator() = default;
SFTPDirIterator(sftp_session sftp, const fs::path& path);
virtual bool hasNext() const;
virtual SFTPAttributesUPtr next();
virtual ~SFTPDirIterator() = default;
private:
sftp_session sftp;
std::stack<SFTPDirUPtr, std::vector<SFTPDirUPtr>> dirs;
SFTPAttributesUPtr next_attr;
void push_dir(const std::string& path);
};
} // namespace multipass
#endif
| 1,527
|
C++
|
.h
| 45
| 31.577778
| 105
| 0.759511
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,906
|
ssh_client.h
|
canonical_multipass/include/multipass/ssh/ssh_client.h
|
/*
* Copyright (C) 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_SSH_CLIENT_H
#define MULTIPASS_SSH_CLIENT_H
#include <multipass/console.h>
#include <multipass/ssh/ssh_session.h>
#include <libssh/libssh.h>
#include <functional>
#include <memory>
#include <string>
#include <vector>
namespace multipass
{
using SSHSessionUPtr = std::unique_ptr<SSHSession>;
class SSHClient
{
public:
using ChannelUPtr = std::unique_ptr<ssh_channel_struct, void (*)(ssh_channel)>;
using ConsoleCreator = std::function<Console::UPtr(ssh_channel_struct*)>;
SSHClient(const std::string& host, int port, const std::string& username, const std::string& priv_key_blob,
ConsoleCreator console_creator);
SSHClient(SSHSessionUPtr ssh_session, ConsoleCreator console_creator);
int exec(const std::vector<std::string>& args);
int exec(const std::vector<std::vector<std::string>>& args_list);
void connect();
private:
void handle_ssh_events();
int exec_string(const std::string& cmd_line);
SSHSessionUPtr ssh_session;
ChannelUPtr channel;
Console::UPtr console;
};
} // namespace multipass
#endif // MULTIPASS_SSH_CLIENT_H
| 1,745
|
C++
|
.h
| 48
| 33.541667
| 111
| 0.746295
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,907
|
sftp_client.h
|
canonical_multipass/include/multipass/ssh/sftp_client.h
|
/*
* Copyright (C) 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_SFTP_CLIENT_H
#define MULTIPASS_SFTP_CLIENT_H
#include "ssh_session.h"
#include <libssh/sftp.h>
#include <filesystem>
#include <functional>
#include <iostream>
#include <QFlags>
namespace multipass
{
namespace fs = std::filesystem;
using SSHSessionUPtr = std::unique_ptr<SSHSession>;
using SFTPSessionUPtr = std::unique_ptr<sftp_session_struct, std::function<void(sftp_session)>>;
SFTPSessionUPtr make_sftp_session(ssh_session session);
class SFTPClient
{
public:
enum class Flag
{
Recursive = 1,
MakeParent = 2,
};
Q_DECLARE_FLAGS(Flags, Flag)
SFTPClient() = default;
SFTPClient(const std::string& host, int port, const std::string& username, const std::string& priv_key_blob);
SFTPClient(SSHSessionUPtr ssh_session);
virtual bool is_remote_dir(const fs::path& path);
virtual bool push(const fs::path& source_path, const fs::path& target_path, Flags flags = {});
virtual bool pull(const fs::path& source_path, const fs::path& target_path, Flags flags = {});
virtual void from_cin(std::istream& cin, const fs::path& target_path, bool make_parent);
virtual void to_cout(const fs::path& source_path, std::ostream& cout);
virtual ~SFTPClient() = default;
private:
void push_file(const fs::path& source_path, const fs::path& target_path);
void pull_file(const fs::path& source_path, const fs::path& target_path);
bool push_dir(const fs::path& source_path, const fs::path& target_path);
bool pull_dir(const fs::path& source_path, const fs::path& target_path);
void do_push_file(std::istream& source, const fs::path& target_path);
void do_pull_file(const fs::path& source_path, std::ostream& target);
SSHSessionUPtr ssh_session;
SFTPSessionUPtr sftp;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(SFTPClient::Flags)
} // namespace multipass
#endif // MULTIPASS_SFTP_CLIENT_H
| 2,517
|
C++
|
.h
| 61
| 38.131148
| 113
| 0.732487
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,908
|
sftp_utils.h
|
canonical_multipass/include/multipass/ssh/sftp_utils.h
|
/*
* Copyright (C) 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_SFTP_UTILS_H
#define MULTIPASS_SFTP_UTILS_H
#include "sftp_client.h"
#include "sftp_dir_iterator.h"
#include <multipass/format.h>
#include <multipass/singleton.h>
#define MP_SFTP_UNIQUE_PTR(open, close) \
template <typename... Args> \
auto mp_##open(Args&&... args) \
{ \
return std::unique_ptr<std::remove_pointer_t<decltype(std::function{open})::result_type>, \
decltype(std::function{close})>{open(std::forward<Args>(args)...), close}; \
}
namespace multipass
{
struct SFTPError : public std::runtime_error
{
template <typename... Args>
explicit SFTPError(const char* fmt, Args&&... args) : runtime_error(fmt::format(fmt, std::forward<Args>(args)...))
{
}
};
MP_SFTP_UNIQUE_PTR(sftp_new, sftp_free)
MP_SFTP_UNIQUE_PTR(sftp_open, sftp_close)
MP_SFTP_UNIQUE_PTR(sftp_stat, sftp_attributes_free)
MP_SFTP_UNIQUE_PTR(sftp_lstat, sftp_attributes_free)
MP_SFTP_UNIQUE_PTR(sftp_opendir, sftp_closedir)
MP_SFTP_UNIQUE_PTR(sftp_readdir, sftp_attributes_free)
MP_SFTP_UNIQUE_PTR(sftp_readlink, free)
#define MP_SFTPUTILS multipass::SFTPUtils::instance()
struct SFTPUtils : public Singleton<SFTPUtils>
{
SFTPUtils(const Singleton<SFTPUtils>::PrivatePass&) noexcept;
virtual fs::path get_local_file_target(const fs::path& source_path, const fs::path& target_path, bool make_parent);
virtual fs::path get_remote_file_target(sftp_session sftp, const fs::path& source_path, const fs::path& target_path,
bool make_parent);
virtual fs::path get_local_dir_target(const fs::path& source_path, const fs::path& target_path, bool make_parent);
virtual fs::path get_remote_dir_target(sftp_session sftp, const fs::path& source_path, const fs::path& target_path,
bool make_parent);
virtual void mkdir_recursive(sftp_session sftp, const fs::path& path);
virtual std::unique_ptr<SFTPDirIterator> make_SFTPDirIterator(sftp_session sftp, const fs::path& path);
virtual std::unique_ptr<SFTPClient> make_SFTPClient(const std::string& host, int port, const std::string& username,
const std::string& priv_key_blob);
};
} // namespace multipass
#endif
| 3,319
|
C++
|
.h
| 62
| 48.16129
| 120
| 0.611642
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,909
|
openssh_key_provider.h
|
canonical_multipass/include/multipass/ssh/openssh_key_provider.h
|
/*
* Copyright (C) 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_OPENSSH_KEY_PROVIDER_H
#define MULTIPASS_OPENSSH_KEY_PROVIDER_H
#include <multipass/path.h>
#include <multipass/ssh/ssh_key_provider.h>
#include <QDir>
#include <memory>
namespace multipass
{
class OpenSSHKeyProvider : public SSHKeyProvider
{
public:
struct KeyDeleter
{
void operator()(ssh_key key);
};
using KeyUPtr = std::unique_ptr<ssh_key_struct, KeyDeleter>;
OpenSSHKeyProvider(const Path& cache_dir);
std::string private_key_as_base64() const override;
std::string public_key_as_base64() const override;
ssh_key private_key() const override;
private:
QDir ssh_key_dir;
KeyUPtr priv_key;
};
}
#endif // MULTIPASS_OPENSSH_KEY_PROVIDER_H
| 1,342
|
C++
|
.h
| 42
| 29.309524
| 72
| 0.748068
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,910
|
simple_process_spec.h
|
canonical_multipass/include/multipass/process/simple_process_spec.h
|
/*
* Copyright (C) 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 SIMPLE_PROCESS_SPEC_H
#define SIMPLE_PROCESS_SPEC_H
#include <memory>
#include <multipass/process/process_spec.h>
namespace multipass
{
std::unique_ptr<ProcessSpec> simple_process_spec(const QString& cmd, const QStringList& args = QStringList());
}
#endif // SIMPLE_PROCESS_SPEC_H
| 920
|
C++
|
.h
| 25
| 35.08
| 110
| 0.766816
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,911
|
qemuimg_process_spec.h
|
canonical_multipass/include/multipass/process/qemuimg_process_spec.h
|
/*
* Copyright (C) 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_QEMUIMG_PROCESS_SPEC_H
#define MULTIPASS_QEMUIMG_PROCESS_SPEC_H
#include <multipass/process/process_spec.h>
#include <QString>
#include <QStringList>
namespace multipass
{
class QemuImgProcessSpec : public ProcessSpec
{
public:
explicit QemuImgProcessSpec(const QStringList& args, const QString& source_image, const QString& target_image = {});
QString program() const override;
QStringList arguments() const override;
QString apparmor_profile() const override;
private:
const QStringList args;
const QString source_image;
const QString target_image;
};
} // namespace multipass
#endif // MULTIPASS_QEMUIMG_PROCESS_SPEC_H
| 1,306
|
C++
|
.h
| 37
| 32.864865
| 120
| 0.771247
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,912
|
process.h
|
canonical_multipass/include/multipass/process/process.h
|
/*
* Copyright (C) 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_PROCESS_H
#define MULTIPASS_PROCESS_H
#include <QProcessEnvironment>
#include <QStringList>
#include <memory>
#include <optional>
namespace multipass
{
/***
* ProcessState - encapsulates info on an process
*
* Possible states this encapsulates are:
* +--------------------------------+------------------------+-----------+--------------------------+
* | state | completed_successfully | exit_code | error |
* +--------------------------------+------------------------+-----------+--------------------------+
* | running | false | N/A | N/A. |
* | normal exit (returns 0) | true | set | N/A. |
* | normal exit (returns non-zero) | false | set | N/A. |
* | failed to start | false | N/A | FailedToStart |
* | crash exit | false | N/A | Crashed |
* | timeout | false | N/A | Timedout (still running) |
* +--------------------------------+------------------------+-----------+--------------------------+
*/
struct ProcessState
{
bool completed_successfully() const // if process stopped successfully with exit code 0
{
return !error && exit_code && *exit_code == 0;
}
QString failure_message() const
{
if (error)
{
return error->message;
}
if (exit_code && *exit_code != 0)
{
return QString("Process returned exit code: %1").arg(*exit_code);
}
return QString();
}
std::optional<int> exit_code; // only set if process stops successfully. Can be set even if success() is false
struct Error
{
QProcess::ProcessError state; // FailedToStart, Crashed, Timedout only options
QString message; // human-readable error message
};
std::optional<Error> error;
};
class Process : public QObject
{
Q_OBJECT
public:
using UPtr = std::unique_ptr<Process>;
virtual ~Process() = default;
virtual QString program() const = 0;
virtual QStringList arguments() const = 0;
virtual QString working_directory() const = 0;
virtual QProcessEnvironment process_environment() const = 0;
virtual qint64 process_id() const = 0;
virtual void start() = 0;
virtual void terminate() = 0;
virtual void kill() = 0;
virtual bool wait_for_started(int msecs = 30000) = 0;
virtual bool wait_for_finished(int msecs = 30000) = 0;
virtual bool wait_for_ready_read(int msecs = 30000) = 0;
virtual bool running() const = 0;
virtual ProcessState process_state() const = 0;
virtual QString error_string() const = 0;
virtual QByteArray read_all_standard_output() = 0;
virtual QByteArray read_all_standard_error() = 0;
virtual qint64 write(const QByteArray& data) = 0;
virtual void close_write_channel() = 0;
virtual void set_process_channel_mode(QProcess::ProcessChannelMode mode) = 0;
virtual ProcessState execute(const int timeout = 30000) = 0;
signals:
void started();
void finished(multipass::ProcessState process_state);
void state_changed(QProcess::ProcessState state); // not running, starting, running
void error_occurred(QProcess::ProcessError error,
QString error_string); // FailedToStart (file not found / resource error) Crashed,
// Timedout, ReadError, WriteError, UnknownError
void ready_read_standard_output();
void ready_read_standard_error();
protected:
virtual void setup_child_process() = 0;
};
} // namespace multipass
Q_DECLARE_METATYPE(multipass::ProcessState)
#endif // MULTIPASS_PROCESS_H
| 4,554
|
C++
|
.h
| 106
| 38.292453
| 114
| 0.578947
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,913
|
process_spec.h
|
canonical_multipass/include/multipass/process/process_spec.h
|
/*
* Copyright (C) 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_PROCESS_SPEC_H
#define MULTIPASS_PROCESS_SPEC_H
#include <QProcessEnvironment>
#include <QString>
#include <multipass/logging/level.h>
namespace multipass
{
class ProcessSpec
{
public:
ProcessSpec() = default;
virtual ~ProcessSpec() = default;
virtual QString program() const = 0;
virtual QStringList arguments() const;
virtual QProcessEnvironment environment() const;
virtual QString working_directory() const;
virtual logging::Level error_log_level() const;
virtual QString apparmor_profile() const = 0;
const QString apparmor_profile_name() const;
virtual QString identifier() const;
};
} // namespace multipass
#endif // MULTIPASS_PROCESS_SPEC_H
| 1,346
|
C++
|
.h
| 39
| 31.846154
| 72
| 0.758674
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,914
|
basic_process.h
|
canonical_multipass/include/multipass/process/basic_process.h
|
/*
* Copyright (C) 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_PROCESS_H
#define MULTIPASS_BASIC_PROCESS_H
#include <multipass/process/process.h>
#include <multipass/process/process_spec.h>
#include <memory>
namespace multipass
{
class CustomQProcess;
// BasicProcess implements the Process interface without using any platform-specifics.
class BasicProcess : public Process
{
Q_OBJECT
public:
BasicProcess(std::shared_ptr<ProcessSpec> spec);
virtual ~BasicProcess();
QString program() const override;
QStringList arguments() const override;
QString working_directory() const override;
QProcessEnvironment process_environment() const override;
virtual qint64 process_id() const override;
void start() override;
void terminate() override;
void kill() override;
bool wait_for_started(int msecs = 30000) override;
bool wait_for_finished(int msecs = 30000) override;
bool wait_for_ready_read(int msecs = 30000) override;
bool running() const override;
ProcessState process_state() const override;
QString error_string() const override;
QByteArray read_all_standard_output() override;
QByteArray read_all_standard_error() override;
qint64 write(const QByteArray& data) override;
void close_write_channel() override;
void set_process_channel_mode(QProcess::ProcessChannelMode mode) override;
ProcessState execute(const int timeout = 30000) override;
protected:
const std::shared_ptr<ProcessSpec> process_spec;
void setup_child_process() override;
class CustomQProcess : public QProcess
{
public:
CustomQProcess(BasicProcess* p);
};
CustomQProcess process; // ease testing
private:
void handle_started();
void run_and_wait_until_finished(const int timeout);
qint64 pid = 0;
};
} // namespace multipass
#endif // MULTIPASS_BASIC_PROCESS_H
| 2,480
|
C++
|
.h
| 67
| 33.402985
| 86
| 0.753865
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,915
|
sshfs_mount_handler.h
|
canonical_multipass/include/multipass/sshfs_mount/sshfs_mount_handler.h
|
/*
* Copyright (C) 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_SSHFS_MOUNT_HANDLER_H
#define MULTIPASS_SSHFS_MOUNT_HANDLER_H
#include <multipass/mount_handler.h>
#include <multipass/process/process.h>
#include <multipass/qt_delete_later_unique_ptr.h>
#include <multipass/sshfs_server_config.h>
namespace multipass
{
class SSHFSMountHandler : public MountHandler
{
public:
SSHFSMountHandler(VirtualMachine* vm,
const SSHKeyProvider* ssh_key_provider,
const std::string& target,
VMMount mount_spec);
~SSHFSMountHandler() override;
void activate_impl(ServerVariant server, std::chrono::milliseconds timeout) override;
void deactivate_impl(bool force) override;
bool is_active() override;
private:
qt_delete_later_unique_ptr<Process> process;
SSHFSServerConfig config;
};
} // namespace multipass
#endif // MULTIPASS_SSHFS_MOUNT_HANDLER_H
| 1,517
|
C++
|
.h
| 41
| 33.219512
| 89
| 0.743032
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,916
|
settings_handler.h
|
canonical_multipass/include/multipass/settings/settings_handler.h
|
/*
* Copyright (C) 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_SETTINGS_HANDLER_H
#define MULTIPASS_SETTINGS_HANDLER_H
#include <multipass/disabled_copy_move.h>
#include <QString>
#include <set>
namespace multipass
{
class SettingsHandler : private DisabledCopyMove
{
public:
SettingsHandler() = default;
virtual ~SettingsHandler() = default;
/**
* Obtain the keys that this SettingsHandler handles.
* @return The set of keys that this SettingsHandler handles.
*/
virtual std::set<QString> keys() const = 0;
/**
* Get the value of the setting specified by @c key.
* @param key The key identifying the requested setting.
* @return A string representation of the value of the specified setting, according to this SettingsHandler's
* interpretation.
* @throws UnrecognizedSettingException When @c key does not identify a setting that this handler recognizes.
* @note Descendents are free to throw other exceptions as well.
*/
virtual QString get(const QString& key) const = 0;
/**
* Set the value of the setting specified by @c key to @val, according to this SettingsHandler's interpretation.
* @param key The key identifying the setting to modify.
* @param val A string representation of the value to assign to the setting. The actual value is derived according
* to this SettingsHandler's interpretation.
* @throws UnrecognizedSettingException When @c key does not identify a setting that this handler recognizes.
* @throws InvalidSettingException When @c val does not represent a valid value for the setting identified by
* @c key, according to this SettingHandler's interpretation.
* @note Descendents are free to throw other exceptions as well.
*/
virtual void set(const QString& key, const QString& val) = 0;
};
} // namespace multipass
#endif // MULTIPASS_SETTINGS_HANDLER_H
| 2,499
|
C++
|
.h
| 56
| 40.910714
| 118
| 0.743938
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,917
|
setting_spec.h
|
canonical_multipass/include/multipass/settings/setting_spec.h
|
/*
* Copyright (C) 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_SETTING_SPEC_H
#define MULTIPASS_SETTING_SPEC_H
#include <multipass/disabled_copy_move.h>
#include <QString>
#include <memory>
#include <set>
namespace multipass
{
class SettingSpec : private DisabledCopyMove
{
public:
virtual ~SettingSpec() = default;
virtual QString get_key() const = 0;
virtual QString get_default() const = 0;
virtual QString interpret(QString val) const = 0; // TODO: replace with marshall/unmarshall
public:
using UPtr = std::unique_ptr<SettingSpec>;
struct LessByKey
{
bool operator()(const SettingSpec& a, const SettingSpec& b) const;
bool operator()(const SettingSpec::UPtr& a, const SettingSpec::UPtr& b) const;
};
using Set = std::set<UPtr, LessByKey>; // would be nice to have gsl::not_null
};
} // namespace multipass
inline bool multipass::SettingSpec::LessByKey::operator()(const SettingSpec& a, const SettingSpec& b) const
{
return a.get_key() < b.get_key(); // compares lexicographically
}
inline bool multipass::SettingSpec::LessByKey::operator()(const SettingSpec::UPtr& a, const SettingSpec::UPtr& b) const
{
return a && b ? (*this)(*a, *b) : bool{b}; // nullptr is the lowest, otherwise lexicographical
}
#endif // MULTIPASS_SETTING_SPEC_H
| 1,896
|
C++
|
.h
| 50
| 35.18
| 119
| 0.735005
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,918
|
bool_setting_spec.h
|
canonical_multipass/include/multipass/settings/bool_setting_spec.h
|
/*
* Copyright (C) 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
| 1,078
|
C++
|
.h
| 32
| 31.65625
| 72
| 0.771154
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,919
|
custom_setting_spec.h
|
canonical_multipass/include/multipass/settings/custom_setting_spec.h
|
/*
* Copyright (C) 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_CUSTOM_SETTING_SPEC_H
#define MULTIPASS_CUSTOM_SETTING_SPEC_H
#include "basic_setting_spec.h"
#include <functional>
namespace multipass
{
class CustomSettingSpec : public multipass::BasicSettingSpec
{
public:
CustomSettingSpec(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_CUSTOM_SETTING_SPEC_H
| 1,148
|
C++
|
.h
| 32
| 33.84375
| 98
| 0.775676
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,920
|
persistent_settings_handler.h
|
canonical_multipass/include/multipass/settings/persistent_settings_handler.h
|
/*
* Copyright (C) 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_PERSISTENT_SETTINGS_HANDLER_H
#define MULTIPASS_PERSISTENT_SETTINGS_HANDLER_H
#include "setting_spec.h"
#include "settings_handler.h"
#include <map>
#include <mutex>
namespace multipass
{
class PersistentSettingsHandler : public SettingsHandler
{
public:
PersistentSettingsHandler(QString filename, SettingSpec::Set settings); // no nulls please
QString get(const QString& key) const override;
void set(const QString& key, const QString& val) override;
std::set<QString> keys() const override;
private:
const SettingSpec& get_setting(const QString& key) const; // throws on unknown key
private:
using SettingMap = std::map<QString, SettingSpec::UPtr>;
static SettingMap convert(SettingSpec::Set);
private:
QString filename;
SettingMap settings;
mutable std::mutex mutex;
};
} // namespace multipass
#endif // MULTIPASS_PERSISTENT_SETTINGS_HANDLER_H
| 1,543
|
C++
|
.h
| 43
| 33.418605
| 94
| 0.768097
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,921
|
settings.h
|
canonical_multipass/include/multipass/settings/settings.h
|
/*
* Copyright (C) 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_SETTINGS_H
#define MULTIPASS_SETTINGS_H
#include "settings_handler.h"
#include <multipass/exceptions/settings_exceptions.h>
#include <multipass/singleton.h>
#include <QString>
#include <QVariant>
#include <set>
#define MP_SETTINGS multipass::Settings::instance()
namespace multipass
{
class Settings : public Singleton<Settings>
{
public:
Settings(const Singleton<Settings>::PrivatePass&);
virtual SettingsHandler* register_handler(std::unique_ptr<SettingsHandler> handler); // no nulls please
virtual void unregister_handler(SettingsHandler* handler); // no-op if handler isn't registered
/**
* Obtain the keys that this Settings singleton knows about.
* @return The set of keys that this Settings singleton knows about.
*/
virtual std::set<QString> keys() const;
/**
* Get the value of the setting specified by @c key, as returned by the first registered handler that handles it.
* @param key The key identifying the requested setting.
* @return A string representation of the value of the specified setting, according to the corresponding
* SettingsHandler's interpretation.
* @throws UnrecognizedSettingException When @c key does not identify a setting that any registered handler
* recognizes.
* @note May also throw any other exceptions that occur when handling.
*/
virtual QString get(const QString& key) const;
/**
* Set the value of the setting specified by @c key to @val, according to the interpretation of first registered
* handler that handles the respective setting.
* @param key The key identifying the setting to modify.
* @param val A string representation of the value to assign to the setting. The actual value is derived according
* to the corresponding SettingsHandler's interpretation.
* @throws UnrecognizedSettingException When @c key does not identify a setting that any registered handler
* recognizes.
* @throws InvalidSettingException When @c val does not represent a valid value for the setting identified by
* @c key, according to the corresponding SettingHandler's interpretation.
* @note May also throw any other exceptions that occur when handling.
*/
virtual void set(const QString& key, const QString& val);
/**
* Obtain a setting as a certain type
* @tparam T The type to obtain the setting as
* @param key The key that identifies the setting
* @return The value that the setting converts to, when interpreted as type @p T. Follows the conversion rules used
* by @c QVariant.
* If the current @em value cannot be converted, a default @p T value is returned.
* @throws UnsupportedSettingValueType<T> If QVariant cannot convert from a @c QString to type @c T. Note that
* this is only thrown when the type itself can't be converted to. The actual value may still fail to convert, in
* which case a default @c T value is returned.
*/
template <typename T>
T get_as(const QString& key) const;
private:
std::vector<std::unique_ptr<SettingsHandler>> handlers;
};
} // namespace multipass
template <typename T>
T multipass::Settings::get_as(const QString& key) const
{
auto var = QVariant{get(key)};
if (var.canConvert<T>()) // Note: this only checks if the types themselves are convertible, not the values
return var.value<T>();
throw UnsupportedSettingValueType<T>(key);
}
#endif // MULTIPASS_SETTINGS_H
| 4,129
|
C++
|
.h
| 87
| 43.448276
| 119
| 0.740998
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,922
|
basic_setting_spec.h
|
canonical_multipass/include/multipass/settings/basic_setting_spec.h
|
/*
* Copyright (C) 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_);
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
| 1,116
|
C++
|
.h
| 34
| 30.529412
| 72
| 0.76416
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,923
|
return_codes.h
|
canonical_multipass/include/multipass/cli/return_codes.h
|
/*
* Copyright (C) Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RETURN_CODES_H
#define RETURN_CODES_H
namespace multipass
{
enum class ParseCode
{
Ok,
CommandLineError,
CommandFail,
HelpRequested
};
enum ReturnCode
{
Ok = 0,
CommandLineError = 1,
CommandFail = 2,
DaemonFail = 3,
Retry = 4
};
} // namespace multipass
#endif // RETURN_CODES_H
| 997
|
C++
|
.h
| 36
| 25.222222
| 80
| 0.743215
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,924
|
json_formatter.h
|
canonical_multipass/include/multipass/cli/json_formatter.h
|
/*
* Copyright (C) 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_JSON_FORMATTER
#define MULTIPASS_JSON_FORMATTER
#include <multipass/cli/formatter.h>
namespace multipass
{
class JsonFormatter final : public Formatter
{
public:
std::string format(const InfoReply& info) const override;
std::string format(const ListReply& list) const override;
std::string format(const NetworksReply& list) const override;
std::string format(const FindReply& list) const override;
std::string format(const VersionReply& list, const std::string& client_version) const override;
std::string format(const AliasDict& aliases) const override;
};
}
#endif // MULTIPASS_JSON_FORMATTER
| 1,268
|
C++
|
.h
| 33
| 36.151515
| 99
| 0.769481
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,925
|
csv_formatter.h
|
canonical_multipass/include/multipass/cli/csv_formatter.h
|
/*
* Copyright (C) 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_CSV_FORMATTER
#define MULTIPASS_CSV_FORMATTER
#include <multipass/cli/formatter.h>
namespace multipass
{
class CSVFormatter final : public Formatter
{
public:
std::string format(const InfoReply& info) const override;
std::string format(const ListReply& list) const override;
std::string format(const NetworksReply& list) const override;
std::string format(const FindReply& list) const override;
std::string format(const VersionReply& list, const std::string& client_version) const override;
std::string format(const AliasDict& aliases) const override;
};
}
#endif // MULTIPASS_CSV_FORMATTER
| 1,264
|
C++
|
.h
| 33
| 36.030303
| 99
| 0.76873
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,926
|
table_formatter.h
|
canonical_multipass/include/multipass/cli/table_formatter.h
|
/*
* Copyright (C) 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_TABLE_FORMATTER
#define MULTIPASS_TABLE_FORMATTER
#include <multipass/cli/formatter.h>
namespace multipass
{
class TableFormatter final : public Formatter
{
public:
std::string format(const InfoReply& info) const override;
std::string format(const ListReply& list) const override;
std::string format(const NetworksReply& list) const override;
std::string format(const FindReply& list) const override;
std::string format(const VersionReply& list, const std::string& client_version) const override;
std::string format(const AliasDict& aliases) const override;
};
}
#endif // MULTIPASS_TABLE_FORMATTER
| 1,272
|
C++
|
.h
| 33
| 36.272727
| 99
| 0.770227
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,927
|
argparser.h
|
canonical_multipass/include/multipass/cli/argparser.h
|
/*
* Copyright (C) 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 ARGPARSER_H
#define ARGPARSER_H
#include <multipass/cli/alias_dict.h>
#include <QtCore/QCommandLineOption>
#include <QtCore/QCommandLineParser>
#include "command.h"
namespace multipass
{
class ArgParser
{
// Note: We are using camelCase here for methods since this class mimics the QCommandLineParser class
public:
ArgParser(const QStringList& arguments, const std::vector<cmd::Command::UPtr>& commands, std::ostream& cout,
std::ostream& cerr);
void setApplicationDescription(const QString& description);
bool addOption(const QCommandLineOption& command_line_option);
bool addOptions(const QList<QCommandLineOption>& options);
void addPositionalArgument(const QString& name, const QString& description, const QString& syntax = QString());
ParseCode parse(const std::optional<AliasDict>& aliases = std::nullopt);
cmd::Command* chosenCommand() const;
cmd::Command* findCommand(const QString& command) const;
const std::vector<cmd::Command::UPtr>& getCommands() const;
bool isSet(const QString& option) const;
bool isSet(const QCommandLineOption& option) const;
QString value(const QCommandLineOption& option) const;
QString value(const QString& option) const;
QStringList values(const QCommandLineOption& option) const;
QStringList positionalArguments() const;
QStringList unknownOptionNames() const;
ParseCode commandParse(cmd::Command* command);
ReturnCode returnCodeFrom(ParseCode parse_code) const;
void forceCommandHelp();
void forceGeneralHelp();
void setVerbosityLevel(int verbosity);
int verbosityLevel() const;
bool containsArgument(const QString& argument) const;
QStringList allArguments() const
{
return arguments;
}
std::optional<AliasDefinition> executeAlias()
{
return execute_alias;
};
private:
QString generalHelpText();
QString helpText(cmd::Command* command);
ParseCode prepare_alias_execution(const QString& alias);
QStringList arguments;
const std::vector<cmd::Command::UPtr>& commands;
cmd::Command* chosen_command;
std::optional<AliasDefinition> execute_alias;
QCommandLineParser parser;
bool help_requested;
int verbosity_level{0};
std::ostream& cout;
std::ostream& cerr;
};
} // namespace multipass
#endif // ARGPARSER_H
| 3,002
|
C++
|
.h
| 76
| 35.381579
| 115
| 0.750861
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,928
|
format_utils.h
|
canonical_multipass/include/multipass/cli/format_utils.h
|
/*
* Copyright (C) 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_FORMAT_UTILS_H
#define MULTIPASS_FORMAT_UTILS_H
#include <multipass/constants.h>
#include <multipass/rpc/multipass.grpc.pb.h>
#include <multipass/settings/settings.h>
#include <fmt/format.h>
#include <google/protobuf/util/time_util.h>
#include <algorithm>
#include <string>
#define MP_FORMAT_UTILS multipass::FormatUtils::instance()
namespace multipass
{
class Formatter;
namespace format
{
static constexpr int col_buffer = 3;
std::string status_string_for(const InstanceStatus& status);
std::string image_string_for(const multipass::FindReply_AliasInfo& alias);
Formatter* formatter_for(const std::string& format);
template <typename Container>
Container sorted(const Container& items);
void filter_aliases(google::protobuf::RepeatedPtrField<multipass::FindReply_AliasInfo>& aliases);
// Computes the column width needed to display all the elements of a range [begin, end). get_width is a function
// which takes as input the element in the range and returns its width in columns.
static constexpr auto column_width =
[](const auto begin, const auto end, const auto get_width, int header_width, int minimum_width = 0) {
if (0 == std::distance(begin, end))
return std::max({header_width + col_buffer, minimum_width});
auto max_width = std::max_element(begin, end, [&get_width](auto& lhs, auto& rhs) {
return get_width(lhs) < get_width(rhs);
});
return std::max({get_width(*max_width) + col_buffer, header_width + col_buffer, minimum_width});
};
} // namespace format
class FormatUtils : public Singleton<FormatUtils>
{
public:
FormatUtils(const Singleton<FormatUtils>::PrivatePass&) noexcept;
virtual std::string convert_to_user_locale(const google::protobuf::Timestamp& timestamp) const;
};
} // namespace multipass
template <typename Container>
Container multipass::format::sorted(const Container& items)
{
if (items.empty())
return items;
auto ret = items;
const auto petenv_name = MP_SETTINGS.get(petenv_key).toStdString();
std::sort(std::begin(ret), std::end(ret), [&petenv_name](const auto& a, const auto& b) {
using T = std::decay_t<decltype(a)>;
using google::protobuf::util::TimeUtil;
// Put instances first when sorting info reply
if constexpr (std::is_same_v<T, multipass::DetailedInfoItem>)
{
if (a.has_instance_info() && b.has_snapshot_info())
return true;
else if (a.has_snapshot_info() && b.has_instance_info())
return false;
}
// Put petenv related entries first
if (a.name() == petenv_name && b.name() != petenv_name)
return true;
else if (b.name() == petenv_name && a.name() != petenv_name)
return false;
else
{
// Sort by timestamp when names are the same for snapshots
if constexpr (std::is_same_v<T, multipass::DetailedInfoItem>)
{
if (a.has_snapshot_info() && a.name() == b.name())
return TimeUtil::TimestampToNanoseconds(a.snapshot_info().fundamentals().creation_timestamp()) <
TimeUtil::TimestampToNanoseconds(b.snapshot_info().fundamentals().creation_timestamp());
}
else if constexpr (std::is_same_v<T, multipass::ListVMSnapshot>)
{
if (a.name() == b.name())
return TimeUtil::TimestampToNanoseconds(a.fundamentals().creation_timestamp()) <
TimeUtil::TimestampToNanoseconds(b.fundamentals().creation_timestamp());
}
// Lastly, sort by name
return a.name() < b.name();
}
});
return ret;
}
namespace fmt
{
template <>
struct formatter<multipass::FindReply_AliasInfo>
{
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
{
return ctx.begin();
}
template <typename FormatContext>
auto format(const multipass::FindReply_AliasInfo& a, FormatContext& ctx) const
{
return format_to(ctx.out(), "{}", a.alias());
}
};
} // namespace fmt
#endif // MULTIPASS_FORMAT_UTILS_H
| 4,841
|
C++
|
.h
| 119
| 34.638655
| 116
| 0.670143
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,929
|
alias_dict.h
|
canonical_multipass/include/multipass/cli/alias_dict.h
|
/*
* Copyright (C) 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_ALIAS_DICT_H
#define MULTIPASS_ALIAS_DICT_H
#include <multipass/alias_definition.h>
#include <multipass/terminal.h>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
class QJsonObject;
namespace multipass
{
static constexpr auto default_context_name = "default";
typedef std::pair<std::string, std::string> ContextAliasPair;
// The alias dictionary is basically a mapping between strings and contexts. The string represents the context name
// and the associated context is itself a map relating alias names to alias definitions.
class AliasDict
{
public:
typedef std::unordered_map<std::string, AliasContext> DictType;
typedef typename DictType::key_type key_type;
typedef typename DictType::mapped_type mapped_type;
typedef typename DictType::size_type size_type;
AliasDict(Terminal* term);
~AliasDict();
void set_active_context(const std::string& new_active_context);
std::string active_context_name() const;
const AliasContext& get_active_context() const;
bool add_alias(const std::string& alias, const AliasDefinition& command);
bool exists_alias(const std::string& alias) const;
bool is_alias_unique(const std::string& alias) const;
bool remove_alias(const std::string& alias);
bool remove_context(const std::string& context);
std::vector<ContextAliasPair> remove_aliases_for_instance(const std::string& instance);
std::optional<ContextAliasPair> get_context_and_alias(const std::string& alias) const;
std::optional<AliasDefinition> get_alias_from_current_context(const std::string& alias) const;
std::optional<AliasDefinition> get_alias(const std::string& alias) const;
DictType::iterator begin()
{
return aliases.begin();
}
DictType::iterator end()
{
return aliases.end();
}
DictType::const_iterator cbegin() const
{
return aliases.cbegin();
}
DictType::const_iterator cend() const
{
return aliases.cend();
}
bool empty() const
{
return (aliases.empty() || (aliases.size() == 1 && get_active_context().empty()));
}
size_type size() const
{
return aliases.size();
}
void clear()
{
if (!empty())
{
modified = true;
aliases.clear();
active_context = default_context_name;
aliases[default_context_name] = AliasContext();
}
}
QJsonObject to_json() const;
private:
void load_dict();
void save_dict();
void sanitize_contexts();
std::optional<AliasDefinition> get_alias_from_all_contexts(const std::string& alias) const;
std::string active_context;
DictType aliases;
bool modified = false;
std::string aliases_file;
std::ostream& cout;
std::ostream& cerr;
}; // class AliasDict
} // namespace multipass
#endif // MULTIPASS_ALIAS_DICT_H
| 3,545
|
C++
|
.h
| 101
| 30.663366
| 115
| 0.706876
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,930
|
command.h
|
canonical_multipass/include/multipass/cli/command.h
|
/*
* Copyright (C) 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_COMMAND_H
#define MULTIPASS_COMMAND_H
#include <multipass/callable_traits.h>
#include <multipass/cli/return_codes.h>
#include <multipass/disabled_copy_move.h>
#include <multipass/format.h>
#include <multipass/rpc/multipass.grpc.pb.h>
#include <multipass/terminal.h>
#include <multipass/utils.h>
#include <QLocalSocket>
#include <QString>
#include <grpc++/grpc++.h>
namespace multipass
{
class ArgParser;
namespace cmd
{
class Command : private DisabledCopyMove
{
public:
using UPtr = std::unique_ptr<Command>;
Command(Rpc::StubInterface& stub, std::ostream& cout, std::ostream& cerr) : stub{&stub}, cout{cout}, cerr{cerr}
{
}
Command(Rpc::StubInterface& stub, Terminal* term) : stub{&stub}, term{term}, cout{term->cout()}, cerr{term->cerr()}
{
}
virtual ~Command() = default;
virtual ReturnCode run(ArgParser* parser) = 0;
virtual std::string name() const = 0;
virtual std::vector<std::string> aliases() const
{
return {name()};
};
virtual QString short_help() const = 0;
virtual QString description() const = 0;
protected:
template <typename RpcFunc, typename Request, typename SuccessCallable, typename FailureCallable,
typename StreamingCallback>
ReturnCode dispatch(RpcFunc&& rpc_func, const Request& request, SuccessCallable&& on_success,
FailureCallable&& on_failure, StreamingCallback&& streaming_callback)
{
check_return_callables(on_success, on_failure);
using Arg0Type = typename multipass::callable_traits<SuccessCallable>::template arg<0>::type;
using ReplyType = typename std::remove_reference<Arg0Type>::type;
ReplyType reply;
auto handle_failure = adapt_failure_handler(on_failure, reply);
auto rpc_method = std::bind(rpc_func, stub, std::placeholders::_1);
grpc::ClientContext context;
std::unique_ptr<grpc::ClientReaderWriterInterface<Request, ReplyType>> client = rpc_method(&context);
client->Write(request);
while (client->Read(&reply))
{
streaming_callback(reply, client.get());
}
auto status = client->Finish();
if (status.ok())
{
return on_success(reply);
}
else if (status.error_code() != grpc::StatusCode::UNAVAILABLE)
{
return handle_failure(status);
}
else
{
auto socket_address{context.peer()};
const auto tokens = multipass::utils::split(context.peer(), ":");
if (tokens[0] == "unix")
{
socket_address = tokens[1];
QLocalSocket multipassd_socket;
multipassd_socket.connectToServer(QString::fromStdString(socket_address));
if (!multipassd_socket.waitForConnected() &&
multipassd_socket.error() == QLocalSocket::SocketAccessError)
{
grpc::Status denied_status{
grpc::StatusCode::PERMISSION_DENIED, "multipass socket access denied",
fmt::format("Please check that you have read/write permissions to '{}'", socket_address)};
return handle_failure(denied_status);
}
}
grpc::Status access_error_status{
grpc::StatusCode::NOT_FOUND, "cannot connect to the multipass socket",
fmt::format("Please ensure multipassd is running and '{}' is accessible", socket_address)};
return handle_failure(access_error_status);
}
}
template <typename RpcFunc, typename Request, typename SuccessCallable, typename FailureCallable>
ReturnCode dispatch(RpcFunc&& rpc_func, const Request& request, SuccessCallable&& on_success,
FailureCallable&& on_failure)
{
using Arg0Type = typename multipass::callable_traits<SuccessCallable>::template arg<0>::type;
using ReplyType = typename std::remove_reference<Arg0Type>::type;
return dispatch(rpc_func, request, on_success, on_failure,
[this](ReplyType& reply, grpc::ClientReaderWriterInterface<Request, ReplyType>* client) {
if (!reply.log_line().empty())
{
cerr << reply.log_line();
}
});
}
Rpc::StubInterface* stub;
Terminal* term;
std::ostream& cout;
std::ostream& cerr;
private:
template <typename SuccessCallable, typename FailureCallable>
void check_return_callables(SuccessCallable&& on_success, FailureCallable&& on_failure)
{
using SuccessCallableTraits = multipass::callable_traits<SuccessCallable>;
using FailureCallableTraits = multipass::callable_traits<FailureCallable>;
using SuccessCallableArg0Type = std::remove_reference_t<typename SuccessCallableTraits::template arg<0>::type>;
using FailureCallableArg0Type = std::remove_reference_t<typename FailureCallableTraits::template arg<0>::type>;
static_assert(std::is_same<typename SuccessCallableTraits::return_type, ReturnCode>::value);
static_assert(std::is_same<typename FailureCallableTraits::return_type, ReturnCode>::value);
static_assert(SuccessCallableTraits::num_args == 1);
static_assert(std::is_base_of_v<google::protobuf::Message, SuccessCallableArg0Type>,
"`on_success` should receive a Message");
if constexpr (FailureCallableTraits::num_args != 1)
{
static_assert(FailureCallableTraits::num_args == 2, "`on_failure` needs to take either 1 or 2 parameters");
using FailureCallableArg1Type =
std::remove_reference_t<typename FailureCallableTraits::template arg<1>::type>;
static_assert(std::is_same_v<SuccessCallableArg0Type, FailureCallableArg1Type>,
"`on_success` and `on_failure` should handle the same reply types");
}
static_assert(std::is_same<FailureCallableArg0Type, grpc::Status>::value);
}
template <typename FailureCallable, typename Reply>
auto adapt_failure_handler(FailureCallable& on_failure, Reply& reply) // lvalue refs ensure args' lifetime continues
{
return [&on_failure, &reply](grpc::Status status) {
(void)reply; // suppress unhelpful warning in clang: https://bugs.llvm.org/show_bug.cgi?id=35450
if constexpr (multipass::callable_traits<FailureCallable>::num_args == 2)
return on_failure(status, reply);
else
return on_failure(status);
};
}
};
} // namespace cmd
} // namespace multipass
#endif // MULTIPASS_COMMAND_H
| 7,446
|
C++
|
.h
| 160
| 37.71875
| 120
| 0.653168
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,931
|
client_platform.h
|
canonical_multipass/include/multipass/cli/client_platform.h
|
/*
* Copyright (C) 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_CLIENT_PLATFORM_H
#define MULTIPASS_CLIENT_PLATFORM_H
#include <multipass/singleton.h>
#include <QString>
#include <string>
#include <utility>
#define MP_CLIENT_PLATFORM multipass::cli::platform::Platform::instance()
namespace multipass
{
const auto default_id = -1;
const auto no_id_info_available = -2;
class Terminal;
namespace cli
{
namespace platform
{
class Platform : public Singleton<Platform>
{
public:
Platform(const Singleton::PrivatePass&) noexcept;
virtual std::string get_password(Terminal* term) const;
virtual void enable_ansi_escape_chars() const;
};
void parse_transfer_entry(const QString& entry, QString& path, QString& instance_name);
int getuid();
int getgid();
void open_multipass_shell(const QString& instance_name); // precondition: requires a valid instance name
} // namespace platform
} // namespace cli
} // namespace multipass
inline multipass::cli::platform::Platform::Platform(const PrivatePass& pass) noexcept : Singleton(pass)
{
}
#endif // MULTIPASS_CLIENT_PLATFORM_H
| 1,673
|
C++
|
.h
| 50
| 31.68
| 104
| 0.773433
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,932
|
prompters.h
|
canonical_multipass/include/multipass/cli/prompters.h
|
/*
* Copyright (C) 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/>.
*
*/
#include <multipass/disabled_copy_move.h>
#include <multipass/terminal.h>
#include <string>
#include <vector>
#ifndef MULTIPASS_CLI_PROMPTERS_H
#define MULTIPASS_CLI_PROMPTERS_H
namespace multipass
{
class Prompter : private DisabledCopyMove
{
public:
explicit Prompter(Terminal*);
virtual ~Prompter() = default;
virtual std::string prompt(const std::string&) const = 0;
protected:
Prompter() = default;
};
class BasePrompter : public Prompter
{
public:
explicit BasePrompter(Terminal* term) : term(term){};
protected:
Terminal* term;
};
class PlainPrompter : public BasePrompter
{
public:
using BasePrompter::BasePrompter;
std::string prompt(const std::string&) const override;
};
class PassphrasePrompter : public PlainPrompter
{
public:
using PlainPrompter::PlainPrompter;
std::string prompt(const std::string& text = "Please enter passphrase") const override;
private:
class ScopedEcholessInput
{
public:
explicit ScopedEcholessInput(Terminal* term) : term(term)
{
term->set_cin_echo(false);
};
virtual ~ScopedEcholessInput()
{
term->set_cin_echo(true);
}
private:
Terminal* term;
};
};
class NewPassphrasePrompter : public PassphrasePrompter
{
public:
using PassphrasePrompter::PassphrasePrompter;
std::string prompt(const std::string& text = "Please re-enter passphrase") const override;
};
class BridgePrompter : private DisabledCopyMove
{
public:
explicit BridgePrompter(Terminal* term) : term(term){};
~BridgePrompter() = default;
bool bridge_prompt(const std::vector<std::string>& nets_need_bridging) const;
private:
BridgePrompter() = default;
Terminal* term;
};
} // namespace multipass
#endif // MULTIPASS_CLI_PROMPTERS_H
| 2,455
|
C++
|
.h
| 85
| 25.447059
| 94
| 0.73231
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,933
|
formatter.h
|
canonical_multipass/include/multipass/cli/formatter.h
|
/*
* Copyright (C) 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_FORMATTER_H
#define MULTIPASS_FORMATTER_H
#include <multipass/disabled_copy_move.h>
#include <multipass/rpc/multipass.grpc.pb.h>
#include <multipass/cli/alias_dict.h>
#include <multipass/cli/client_platform.h>
#include <string>
namespace multipass
{
constexpr auto default_id_str = "default";
class Formatter : private DisabledCopyMove
{
public:
virtual ~Formatter() = default;
virtual std::string format(const InfoReply& reply) const = 0;
virtual std::string format(const ListReply& reply) const = 0;
virtual std::string format(const NetworksReply& reply) const = 0;
virtual std::string format(const FindReply& reply) const = 0;
virtual std::string format(const VersionReply& reply, const std::string& client_version) const = 0;
virtual std::string format(const AliasDict& aliases) const = 0;
protected:
Formatter() = default;
template <class D>
std::map<typename D::key_type, typename D::mapped_type> sort_dict(const D& unsorted_dict) const
{
return std::map<typename D::key_type, typename D::mapped_type>(unsorted_dict.cbegin(), unsorted_dict.cend());
}
};
}
#endif // MULTIPASS_FORMATTER_H
| 1,804
|
C++
|
.h
| 46
| 36.5
| 117
| 0.745714
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,934
|
client_common.h
|
canonical_multipass/include/multipass/cli/client_common.h
|
/*
* Copyright (C) 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_CLIENT_COMMON_H
#define MULTIPASS_CLIENT_COMMON_H
#include <grpcpp/grpcpp.h>
#include <multipass/cert_provider.h>
#include <multipass/cli/client_platform.h>
#include <multipass/cli/return_codes.h>
#include <multipass/console.h>
#include <multipass/rpc/multipass.grpc.pb.h>
#include <multipass/ssl_cert_provider.h>
#include <memory>
#include <regex>
#include <string>
namespace multipass
{
const QString common_client_cert_dir{"/multipass-client-certificate"};
const QString client_cert_prefix{"multipass_cert"};
const QString cert_file_suffix{".pem"};
const QString key_file_suffix{"_key.pem"};
const QString client_cert_file{client_cert_prefix + cert_file_suffix};
const QString client_key_file{client_cert_prefix + key_file_suffix};
namespace logging
{
enum class Level : int; // Fwd decl
}
namespace cmd
{
multipass::ReturnCode standard_failure_handler_for(const std::string& command, std::ostream& cerr,
const grpc::Status& status,
const std::string& error_details = std::string());
bool update_available(const UpdateInfo& update_info);
std::string update_notice(const multipass::UpdateInfo& update_info);
template <typename Request, typename Reply>
void handle_password(grpc::ClientReaderWriterInterface<Request, Reply>* client, Terminal* term)
{
Request request;
request.set_password(MP_CLIENT_PLATFORM.get_password(term));
client->Write(request);
}
}
namespace client
{
QString persistent_settings_filename();
void register_global_settings_handlers();
std::shared_ptr<grpc::Channel> make_channel(const std::string& server_address, const CertProvider& cert_provider);
std::string get_server_address();
std::unique_ptr<SSLCertProvider> get_cert_provider();
void set_logger();
void set_logger(multipass::logging::Level verbosity); // full param qualification makes sure msvc is happy
void post_setup();
const std::regex yes_answer{"y|yes", std::regex::icase | std::regex::optimize};
const std::regex no_answer{"n|no", std::regex::icase | std::regex::optimize};
}
} // namespace multipass
#endif // MULTIPASS_CLIENT_COMMON_H
| 2,797
|
C++
|
.h
| 70
| 36.985714
| 114
| 0.747241
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,935
|
yaml_formatter.h
|
canonical_multipass/include/multipass/cli/yaml_formatter.h
|
/*
* Copyright (C) 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_YAML_FORMATTER
#define MULTIPASS_YAML_FORMATTER
#include <multipass/cli/formatter.h>
namespace multipass
{
class YamlFormatter final : public Formatter
{
public:
std::string format(const InfoReply& info) const override;
std::string format(const ListReply& list) const override;
std::string format(const NetworksReply& list) const override;
std::string format(const FindReply& list) const override;
std::string format(const VersionReply& list, const std::string& client_version) const override;
std::string format(const AliasDict& aliases) const override;
};
}
#endif // MULTIPASS_YAML_FORMATTER
| 1,268
|
C++
|
.h
| 33
| 36.151515
| 99
| 0.769481
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,936
|
level.h
|
canonical_multipass/include/multipass/logging/level.h
|
/*
* Copyright (C) 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_LEVEL_H
#define MULTIPASS_LEVEL_H
#include <multipass/logging/cstring.h>
namespace multipass
{
namespace logging
{
/**
* The level of a log entry, in decreasing order of severity.
*/
enum class Level : int
{
error = 0, /**< Indicates a failure that prevents the intended operation from being accomplished in its entirety.
If there is a corresponding CLI command, it should exit with an error code. */
warning = 1, /**< Indicates an event or fact that might not correspond to the users' intentions/desires/beliefs, or
a problem that is light enough that it does not prevent main goals from being accomplished.
If there is a corresponding CLI command, it should exit with a success code */
info = 2, /**< Indicates information that may be useful for the user to know, learn, etc. */
debug = 3, /**< Indicates information that is useful for developers and troubleshooting */
trace = 4 /**< Indicates information that may be helpful for debugging but which would clutter logs unreasonably
if enabled by default */
};
constexpr CString as_string(const Level& l) noexcept
{
switch (l)
{
case Level::debug:
return "debug";
case Level::error:
return "error";
case Level::info:
return "info";
case Level::warning:
return "warning";
case Level::trace:
return "trace";
}
return "unknown";
}
constexpr auto enum_type(Level e) noexcept
{
return static_cast<std::underlying_type_t<Level>>(e);
}
constexpr Level level_from(std::underlying_type_t<Level> in)
{
return static_cast<Level>(in);
}
constexpr bool operator<(Level a, Level b) noexcept
{
return enum_type(a) < enum_type(b);
}
constexpr bool operator>(Level a, Level b) noexcept
{
return enum_type(a) > enum_type(b);
}
constexpr bool operator<=(Level a, Level b) noexcept
{
return enum_type(a) <= enum_type(b);
}
constexpr bool operator>=(Level a, Level b) noexcept
{
return enum_type(a) >= enum_type(b);
}
} // namespace logging
} // namespace multipass
#endif // MULTIPASS_LEVEL_H
| 2,803
|
C++
|
.h
| 82
| 30.292683
| 119
| 0.69952
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,937
|
multiplexing_logger.h
|
canonical_multipass/include/multipass/logging/multiplexing_logger.h
|
/*
* Copyright (C) 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_MULTIPLEXING_LOGGER_H
#define MULTIPASS_MULTIPLEXING_LOGGER_H
#include "logger.h"
#include <memory>
#include <shared_mutex>
#include <vector>
namespace multipass
{
namespace logging
{
class MultiplexingLogger : public Logger
{
public:
explicit MultiplexingLogger(UPtr system_logger);
void log(Level level, CString category, CString message) const override;
void add_logger(const Logger* logger);
void remove_logger(const Logger* logger);
private:
UPtr system_logger;
mutable std::shared_timed_mutex mutex;
std::vector<const Logger*> loggers;
};
} // namespace logging
} // namespace multipass
#endif // MULTIPASS_MULTIPLEXING_LOGGER_H
| 1,315
|
C++
|
.h
| 41
| 29.878049
| 76
| 0.768139
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,938
|
cstring.h
|
canonical_multipass/include/multipass/logging/cstring.h
|
/*
* Copyright (C) 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_CSTRING_H
#define MULTIPASS_CSTRING_H
#include <string>
namespace multipass
{
namespace logging
{
class CString
{
public:
constexpr CString(const char* data) : data{data}
{
}
// Use this carefully, it depends on the lifetime of s
CString(const std::string& s) : data{s.c_str()}
{
}
const char* c_str() const
{
return data;
}
private:
const char* data;
};
} // namespace logging
} // namespace multipass
#endif // MULTIPASS_CSTRING_H
| 1,138
|
C++
|
.h
| 43
| 23.744186
| 72
| 0.721507
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,939
|
logger.h
|
canonical_multipass/include/multipass/logging/logger.h
|
/*
* Copyright (C) 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_LOGGER_H
#define MULTIPASS_LOGGER_H
#include <multipass/disabled_copy_move.h>
#include <multipass/logging/cstring.h>
#include <multipass/logging/level.h>
#include <QDateTime>
#include <memory>
#include <string>
namespace multipass
{
namespace logging
{
class Logger : private DisabledCopyMove
{
public:
using UPtr = std::unique_ptr<Logger>;
virtual ~Logger() = default;
virtual void log(Level level, CString category, CString message) const = 0;
Level get_logging_level()
{
return logging_level;
};
static std::string timestamp()
{
auto time = QDateTime::currentDateTime();
return time.toString(Qt::ISODateWithMs).toStdString();
};
protected:
Logger(Level logging_level) : logging_level{logging_level} {};
Logger() = default;
const Level logging_level{Level::error};
};
} // namespace logging
} // namespace multipass
#endif // MULTIPASS_LOGGER_H
| 1,573
|
C++
|
.h
| 51
| 27.980392
| 79
| 0.735799
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,940
|
client_logger.h
|
canonical_multipass/include/multipass/logging/client_logger.h
|
/*
* Copyright (C) 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_CLIENT_LOGGER_H
#define MULTIPASS_CLIENT_LOGGER_H
#include <multipass/logging/logger.h>
#include <multipass/logging/multiplexing_logger.h>
#include <multipass/rpc/multipass.grpc.pb.h>
#include <multipass/utils.h>
#include <fmt/format.h>
namespace multipass
{
namespace logging
{
template <typename T, typename U>
class ClientLogger : public Logger
{
public:
ClientLogger(Level level, MultiplexingLogger& mpx, grpc::ServerReaderWriterInterface<T, U>* server)
: logging_level{level}, server{server}, mpx_logger{mpx}
{
mpx_logger.add_logger(this);
}
~ClientLogger()
{
mpx_logger.remove_logger(this);
}
void log(Level level, CString category, CString message) const override
{
if (level <= logging_level && server != nullptr)
{
T reply;
reply.set_log_line(fmt::format("[{}] [{}] [{}] {}\n", timestamp(), as_string(level).c_str(),
category.c_str(), message.c_str()));
server->Write(reply);
}
}
private:
Level logging_level;
grpc::ServerReaderWriterInterface<T, U>* server;
MultiplexingLogger& mpx_logger;
};
} // namespace logging
} // namespace multipass
#endif // MULTIPASS_CLIENT_LOGGER_H
| 1,916
|
C++
|
.h
| 58
| 28.62069
| 104
| 0.690811
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,941
|
standard_logger.h
|
canonical_multipass/include/multipass/logging/standard_logger.h
|
/*
* Copyright (C) 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_STANDARD_LOGGER_H
#define MULTIPASS_STANDARD_LOGGER_H
#include <multipass/logging/logger.h>
namespace multipass
{
namespace logging
{
class StandardLogger : public Logger
{
public:
StandardLogger(Level level);
void log(Level level, CString category, CString message) const override;
};
} // namespace logging
} // namespace multipass
#endif // MULTIPASS_STANDARD_LOGGER_H
| 1,029
|
C++
|
.h
| 32
| 30.34375
| 76
| 0.772636
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,942
|
log.h
|
canonical_multipass/include/multipass/logging/log.h
|
/*
* Copyright (C) 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_LOG_H
#define MULTIPASS_LOG_H
#include <multipass/logging/cstring.h>
#include <multipass/logging/level.h>
#include <multipass/logging/logger.h>
namespace multipass
{
namespace logging
{
void log(Level level, CString category, CString message);
void set_logger(std::shared_ptr<Logger> logger);
Level get_logging_level();
Logger* get_logger(); // for tests, don't rely on it lasting
} // namespace logging
} // namespace multipass
#endif // MULTIPASS_LOG_H
| 1,104
|
C++
|
.h
| 32
| 32.9375
| 72
| 0.767072
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,943
|
image_vault_exceptions.h
|
canonical_multipass/include/multipass/exceptions/image_vault_exceptions.h
|
/*
* Copyright (C) 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_IMAGE_VAULT_EXCEPTIONS_H
#define MULTIPASS_IMAGE_VAULT_EXCEPTIONS_H
#include <stdexcept>
#include <multipass/format.h>
namespace multipass
{
class ImageNotFoundException : public std::runtime_error
{
public:
ImageNotFoundException(const std::string& image, const std::string& remote)
: runtime_error(fmt::format("Unable to find an image matching \"{}\" in remote \"{}\".", image, remote))
{
}
};
} // namespace multipass
#endif // MULTIPASS_IMAGE_VAULT_EXCEPTIONS_H
| 1,136
|
C++
|
.h
| 32
| 33.28125
| 112
| 0.75
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,944
|
sshfs_missing_error.h
|
canonical_multipass/include/multipass/exceptions/sshfs_missing_error.h
|
/*
* Copyright (C) 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_SSHFS_MISSING_ERROR_H
#define MULTIPASS_SSHFS_MISSING_ERROR_H
#include <stdexcept>
namespace multipass
{
class SSHFSMissingError : public std::runtime_error
{
public:
SSHFSMissingError() : runtime_error{"sshfs missing"}
{
}
};
}
#endif // MULTIPASS_SSHFS_MISSING_ERROR_H
| 933
|
C++
|
.h
| 30
| 29.066667
| 72
| 0.759733
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,945
|
virtual_machine_state_exceptions.h
|
canonical_multipass/include/multipass/exceptions/virtual_machine_state_exceptions.h
|
/*
* Copyright (C) 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_VIRTUAL_MACHINE_STATE_EXCEPTIONS_H
#define MULTIPASS_VIRTUAL_MACHINE_STATE_EXCEPTIONS_H
#include <stdexcept>
#include <string>
namespace multipass
{
class VMStateIdempotentException : public std::runtime_error
{
public:
explicit VMStateIdempotentException(const std::string& msg) : runtime_error{msg}
{
}
};
class VMStateInvalidException : public std::runtime_error
{
public:
explicit VMStateInvalidException(const std::string& msg) : runtime_error{msg}
{
}
};
} // namespace multipass
#endif // MULTIPASS_VIRTUAL_MACHINE_STATE_EXCEPTIONS_H
| 1,217
|
C++
|
.h
| 38
| 29.842105
| 84
| 0.768968
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,946
|
file_open_failed_exception.h
|
canonical_multipass/include/multipass/exceptions/file_open_failed_exception.h
|
/*
* Copyright (C) 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_FILE_OPEN_FAILED_EXCEPTION_H
#define MULTIPASS_FILE_OPEN_FAILED_EXCEPTION_H
#include <multipass/format.h>
#include <cerrno>
#include <cstring>
#include <stdexcept>
namespace multipass
{
class FileOpenFailedException : public std::runtime_error
{
public:
explicit FileOpenFailedException(const std::string& name)
: std::runtime_error(fmt::format("failed to open file '{}': {}({})", name, strerror(errno), errno))
{
}
};
} // namespace multipass
#endif // MULTIPASS_FILE_OPEN_FAILED_EXCEPTION_H
| 1,164
|
C++
|
.h
| 34
| 32.058824
| 107
| 0.751111
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,947
|
settings_exceptions.h
|
canonical_multipass/include/multipass/exceptions/settings_exceptions.h
|
/*
* Copyright (C) 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_SETTINGS_EXCEPTIONS_H
#define MULTIPASS_SETTINGS_EXCEPTIONS_H
#include <multipass/format.h>
#include <QString>
#include <stdexcept>
#include <string>
namespace multipass
{
class SettingsException : public std::runtime_error
{
public:
explicit SettingsException(const std::string& msg) : runtime_error{msg}
{
}
};
class PersistentSettingsException : public SettingsException
{
public:
PersistentSettingsException(const QString& attempted_operation, const QString& detail)
: SettingsException{fmt::format("Unable to {} settings: {}", attempted_operation, detail)}
{
}
};
class UnrecognizedSettingException : public SettingsException
{
public:
explicit UnrecognizedSettingException(const QString& key)
: SettingsException{fmt::format("Unrecognized settings key: '{}'", key)}
{
}
};
class InvalidSettingException : public SettingsException
{
public:
InvalidSettingException(const QString& key, const QString& val, const QString& why)
: SettingsException{fmt::format("Invalid setting '{}={}': {}", key, val, why)}
{
}
};
template <typename T>
class UnsupportedSettingValueType : public SettingsException
{
public:
explicit UnsupportedSettingValueType(const QString& key)
: SettingsException{fmt::format("Invalid value type for key {}. Type hint: {}", key, typeid(T).name())}
{
}
};
} // namespace multipass
#endif // MULTIPASS_SETTINGS_EXCEPTIONS_H
| 2,093
|
C++
|
.h
| 66
| 28.924242
| 111
| 0.748512
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,948
|
download_exception.h
|
canonical_multipass/include/multipass/exceptions/download_exception.h
|
/*
* Copyright (C) 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_DOWNLOAD_H
#define MULTIPASS_DOWNLOAD_H
#include <fmt/format.h>
#include "base_qexception.h"
namespace multipass
{
class DownloadException final : public BaseQException<DownloadException>
{
public:
DownloadException(const std::string& url, const std::string& cause)
: BaseQException{fmt::format("failed to download from '{}': {}", url, cause)}
{
}
};
} // namespace multipass
#endif // MULTIPASS_DOWNLOAD_H
| 1,077
|
C++
|
.h
| 32
| 31.4375
| 85
| 0.75024
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,949
|
clone_exceptions.h
|
canonical_multipass/include/multipass/exceptions/clone_exceptions.h
|
/*
* Copyright (C) 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_CLONE_EXCEPTIONS_H
#define MULTIPASS_CLONE_EXCEPTIONS_H
#include <stdexcept>
namespace multipass
{
class CloneInvalidNameException : public std::runtime_error
{
public:
using std::runtime_error::runtime_error;
};
} // namespace multipass
#endif // MULTIPASS_CLONE_EXCEPTIONS_H
| 931
|
C++
|
.h
| 28
| 31.428571
| 72
| 0.771969
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,950
|
autostart_setup_exception.h
|
canonical_multipass/include/multipass/exceptions/autostart_setup_exception.h
|
/*
* Copyright (C) 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_AUTOSTART_SETUP_EXCEPTION_H
#define MULTIPASS_AUTOSTART_SETUP_EXCEPTION_H
#include <stdexcept>
#include <string>
namespace multipass
{
class AutostartSetupException : public std::runtime_error
{
public:
AutostartSetupException(const std::string& why, const std::string& detail) : runtime_error(why), detail{detail}
{
}
const std::string& get_detail() const
{
return detail;
}
private:
std::string detail;
};
} // namespace multipass
#endif // MULTIPASS_AUTOSTART_SETUP_EXCEPTION_H
| 1,169
|
C++
|
.h
| 37
| 29.054054
| 115
| 0.751332
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,951
|
unsupported_remote_exception.h
|
canonical_multipass/include/multipass/exceptions/unsupported_remote_exception.h
|
/*
* Copyright (C) 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_UNSUPPORTED_REMOTE_EXCEPTION_H
#define MULTIPASS_UNSUPPORTED_REMOTE_EXCEPTION_H
#include <stdexcept>
namespace multipass
{
class UnsupportedRemoteException : public std::runtime_error
{
public:
explicit UnsupportedRemoteException(const std::string& message) : runtime_error(message)
{
}
};
} // namespace multipass
#endif // MULTIPASS_UNSUPPORTED_REMOTE_EXCEPTION_H
| 1,027
|
C++
|
.h
| 30
| 32.233333
| 92
| 0.774648
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,952
|
aborted_download_exception.h
|
canonical_multipass/include/multipass/exceptions/aborted_download_exception.h
|
/*
* Copyright (C) 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_ABORTED_DOWNLOAD_EXCEPTION
#define MULTIPASS_ABORTED_DOWNLOAD_EXCEPTION
#include "base_qexception.h"
namespace multipass
{
class AbortedDownloadException final : public BaseQException<AbortedDownloadException>
{
public:
using BaseQException::BaseQException;
};
} // namespace multipass
#endif // MULTIPASS_ABORTED_DOWNLOAD_EXCEPTION
| 986
|
C++
|
.h
| 28
| 33.428571
| 86
| 0.787435
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,953
|
base_qexception.h
|
canonical_multipass/include/multipass/exceptions/base_qexception.h
|
/*
* Copyright (C) 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_BASE_QEXCEPTION
#define MULTIPASS_BASE_QEXCEPTION
#include <QException>
#include <string>
namespace multipass
{
// CRTP template base class that is the boilerplate code of QException derived classes
// Derived classes should either be final or be themselves templated with the ultimate leaf type.
template <typename DerivedException>
class BaseQException : public QException
{
public:
BaseQException(const std::string& err) : error_string{err}
{
// TODO@C++20, use concepts instead of static_assert + type traits to apply the constraint.
static_assert(std::is_base_of_v<BaseQException, DerivedException>,
"DerivedException must be derived from BaseQException");
}
// TODO@C++23, use explicit object parameters instead of static_cast conversion to derive class, see
// https://devblogs.microsoft.com/cppblog/cpp23-deducing-this/ for more details
void raise() const override
{
throw static_cast<const DerivedException&>(*this);
}
BaseQException* clone() const override
{
return new DerivedException(static_cast<const DerivedException&>(*this));
}
const char* what() const noexcept override
{
return error_string.c_str();
}
private:
std::string error_string;
};
} // namespace multipass
#endif // MULTIPASS_BASE_QEXCEPTION
| 1,996
|
C++
|
.h
| 53
| 33.924528
| 104
| 0.738501
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,954
|
manifest_exceptions.h
|
canonical_multipass/include/multipass/exceptions/manifest_exceptions.h
|
/*
* Copyright (C) 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_MANIFEST_EXCEPTIONS_H
#define MULTIPASS_MANIFEST_EXCEPTIONS_H
#include <stdexcept>
namespace multipass
{
class GenericManifestException : public std::runtime_error
{
public:
GenericManifestException(const std::string& details) : runtime_error(details)
{
}
};
class EmptyManifestException : public GenericManifestException
{
public:
EmptyManifestException(const std::string& details) : GenericManifestException(details)
{
}
};
} // namespace multipass
#endif // MULTIPASS_MANIFEST_EXCEPTIONS_H
| 1,167
|
C++
|
.h
| 37
| 29.378378
| 90
| 0.773535
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,955
|
unsupported_image_exception.h
|
canonical_multipass/include/multipass/exceptions/unsupported_image_exception.h
|
/*
* Copyright (C) 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_UNSUPPORTED_IMAGE_EXCEPTION_H
#define MULTIPASS_UNSUPPORTED_IMAGE_EXCEPTION_H
#include <stdexcept>
#include <multipass/format.h>
namespace multipass
{
class UnsupportedImageException : public std::runtime_error
{
public:
UnsupportedImageException(const std::string& release)
: runtime_error(fmt::format("The {} release is no longer supported.", release))
{
}
};
} // namespace multipass
#endif // MULTIPASS_UNSUPPORTED_IMAGE_EXCEPTION_H
| 1,107
|
C++
|
.h
| 32
| 32.375
| 87
| 0.763772
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,956
|
blueprint_exceptions.h
|
canonical_multipass/include/multipass/exceptions/blueprint_exceptions.h
|
/*
* Copyright (C) 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_BLUEPRINT_EXCEPTIONS_H
#define MULTIPASS_BLUEPRINT_EXCEPTIONS_H
#include <multipass/format.h>
#include <stdexcept>
#include <string>
namespace multipass
{
class BlueprintMinimumException : public std::runtime_error
{
public:
BlueprintMinimumException(const std::string& type, const std::string& min_val)
: runtime_error(fmt::format("Requested {} is less than Blueprint minimum of {}", type, min_val))
{
}
};
class InvalidBlueprintException : public std::runtime_error
{
public:
using std::runtime_error::runtime_error;
};
class IncompatibleBlueprintException : public std::runtime_error
{
public:
using std::runtime_error::runtime_error;
};
} // namespace multipass
#endif // MULTIPASS_BLUEPRINT_EXCEPTIONS_H
| 1,389
|
C++
|
.h
| 43
| 30.162791
| 104
| 0.764179
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,957
|
create_image_exception.h
|
canonical_multipass/include/multipass/exceptions/create_image_exception.h
|
/*
* Copyright (C) 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_CREATE_IMAGE_EXCEPTION
#define MULTIPASS_CREATE_IMAGE_EXCEPTION
#include "base_qexception.h"
namespace multipass
{
class CreateImageException final : public BaseQException<CreateImageException>
{
public:
using BaseQException::BaseQException;
};
} // namespace multipass
#endif // MULTIPASS_CREATE_IMAGE_EXCEPTION
| 966
|
C++
|
.h
| 28
| 32.714286
| 78
| 0.782888
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,958
|
start_exception.h
|
canonical_multipass/include/multipass/exceptions/start_exception.h
|
/*
* Copyright (C) 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_START_EXCEPTION_H
#define MULTIPASS_START_EXCEPTION_H
#include <stdexcept>
#include <string>
namespace multipass
{
class StartException : public std::runtime_error
{
public:
StartException(const std::string& instance_name, const std::string& what)
: runtime_error(what), instance_name(instance_name)
{
}
std::string name() const
{
return instance_name;
}
private:
const std::string instance_name;
};
}
#endif // MULTIPASS_START_EXCEPTION_H
| 1,135
|
C++
|
.h
| 38
| 27.184211
| 77
| 0.741758
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,959
|
snapshot_exceptions.h
|
canonical_multipass/include/multipass/exceptions/snapshot_exceptions.h
|
/*
* Copyright (C) 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_SNAPSHOT_EXCEPTIONS_H
#define MULTIPASS_SNAPSHOT_EXCEPTIONS_H
#include <stdexcept>
#include <string>
#include <multipass/format.h>
namespace multipass
{
class SnapshotNameTakenException : public std::runtime_error
{
public:
SnapshotNameTakenException(const std::string& vm_name, const std::string& snapshot_name)
: std::runtime_error{fmt::format("Snapshot already exists: {}.{}", vm_name, snapshot_name)}
{
}
};
class NoSuchSnapshotException : public std::runtime_error
{
public:
NoSuchSnapshotException(const std::string& vm_name, const std::string& snapshot_name)
: std::runtime_error{fmt::format("No such snapshot: {}.{}", vm_name, snapshot_name)}
{
}
};
} // namespace multipass
#endif // MULTIPASS_SNAPSHOT_EXCEPTIONS_H
| 1,417
|
C++
|
.h
| 41
| 32.073171
| 99
| 0.746715
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,961
|
cli_exceptions.h
|
canonical_multipass/include/multipass/exceptions/cli_exceptions.h
|
/*
* Copyright (C) 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_CLI_EXCEPTIONS_H
#define MULTIPASS_CLI_EXCEPTIONS_H
#include <stdexcept>
namespace multipass
{
class PromptException : public std::runtime_error
{
public:
using std::runtime_error::runtime_error;
};
} // namespace multipass
#endif // MULTIPASS_CLI_EXCEPTIONS_H
| 916
|
C++
|
.h
| 28
| 30.857143
| 72
| 0.767837
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,962
|
cmd_exceptions.h
|
canonical_multipass/include/multipass/exceptions/cmd_exceptions.h
|
/*
* Copyright (C) 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_CMD_EXCEPTIONS_H
#define MULTIPASS_CMD_EXCEPTIONS_H
#include <stdexcept>
namespace multipass
{
class ValidationException : public std::runtime_error
{
public:
using std::runtime_error::runtime_error;
};
} // namespace multipass
#endif // MULTIPASS_CMD_EXCEPTIONS_H
| 920
|
C++
|
.h
| 28
| 31
| 72
| 0.768884
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,963
|
invalid_memory_size_exception.h
|
canonical_multipass/include/multipass/exceptions/invalid_memory_size_exception.h
|
/*
* Copyright (C) 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_INVALID_MEMORY_SIZE_EXCEPTION_H
#define MULTIPASS_INVALID_MEMORY_SIZE_EXCEPTION_H
#include <fmt/format.h>
#include <stdexcept>
#include <string>
namespace multipass
{
class InvalidMemorySizeException : public std::runtime_error
{
public:
InvalidMemorySizeException(const std::string& val)
: runtime_error(fmt::format("{} is not a valid memory size - need a non-negative integer (in base 10) "
"or a decimal followed by K, M, or G (e.g. 1234B, 42MiB, 0.5G)",
val))
{
}
};
} // namespace multipass
#endif // MULTIPASS_INVALID_MEMORY_SIZE_EXCEPTION_H
| 1,290
|
C++
|
.h
| 35
| 32.685714
| 111
| 0.707434
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,964
|
not_implemented_on_this_backend_exception.h
|
canonical_multipass/include/multipass/exceptions/not_implemented_on_this_backend_exception.h
|
/*
* Copyright (C) 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_NOT_IMPLEMENTED_ON_THIS_BACKEND_EXCEPTION_H
#define MULTIPASS_NOT_IMPLEMENTED_ON_THIS_BACKEND_EXCEPTION_H
#include <stdexcept>
#include <multipass/format.h>
namespace multipass
{
class NotImplementedOnThisBackendException : public std::runtime_error
{
public:
NotImplementedOnThisBackendException(const std::string& feature)
: runtime_error(fmt::format("The {} feature is not implemented on this backend.", feature))
{
}
};
} // namespace multipass
#endif // MULTIPASS_NOT_IMPLEMENTED_ON_THIS_BACKEND_EXCEPTION_H
| 1,184
|
C++
|
.h
| 32
| 34.75
| 99
| 0.769834
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,965
|
local_socket_connection_exception.h
|
canonical_multipass/include/multipass/exceptions/local_socket_connection_exception.h
|
/*
* Copyright (C) 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_LOCAL_SOCKET_CONNECTION_EXCEPTION_H
#define MULTIPASS_LOCAL_SOCKET_CONNECTION_EXCEPTION_H
#include <stdexcept>
namespace multipass
{
class LocalSocketConnectionException : public std::runtime_error
{
public:
LocalSocketConnectionException(const std::string& what) : runtime_error(what)
{
}
};
} // namespace multipass
#endif // MULTIPASS_HTTP_LOCAL_SOCKET_EXCEPTION_H
| 1,029
|
C++
|
.h
| 30
| 32.3
| 81
| 0.773092
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,966
|
internal_timeout_exception.h
|
canonical_multipass/include/multipass/exceptions/internal_timeout_exception.h
|
/*
* Copyright (C) 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_INTERNAL_TIMEOUT_EXCEPTION_H
#define MULTIPASS_INTERNAL_TIMEOUT_EXCEPTION_H
#include <chrono>
#include <stdexcept>
#include <string>
#include <multipass/format.h>
namespace multipass
{
class InternalTimeoutException : public std::runtime_error
{
public:
InternalTimeoutException(const std::string& action, std::chrono::milliseconds timeout)
: std::runtime_error{fmt::format("Could not {} within {}ms", action, timeout.count())}
{
}
};
} // namespace multipass
#endif // MULTIPASS_INTERNAL_TIMEOUT_EXCEPTION_H
| 1,182
|
C++
|
.h
| 34
| 32.529412
| 94
| 0.75986
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,967
|
http_local_socket_exception.h
|
canonical_multipass/include/multipass/exceptions/http_local_socket_exception.h
|
/*
* Copyright (C) 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_HTTP_LOCAL_SOCKET_EXCEPTION_H
#define MULTIPASS_HTTP_LOCAL_SOCKET_EXCEPTION_H
#include <stdexcept>
namespace multipass
{
class HttpLocalSocketException : public std::runtime_error
{
public:
HttpLocalSocketException(const std::string& what) : runtime_error(what)
{
}
};
} // namespace multipass
#endif // MULTIPASS_HTTP_LOCAL_SOCKET_EXCEPTION_H
| 1,005
|
C++
|
.h
| 30
| 31.5
| 75
| 0.76749
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,968
|
snap_environment_exception.h
|
canonical_multipass/include/multipass/exceptions/snap_environment_exception.h
|
/*
* Copyright (C) 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_SNAP_ENVIRONMENT_EXCEPTION_H
#define MULTIPASS_SNAP_ENVIRONMENT_EXCEPTION_H
#include <stdexcept>
#include <multipass/format.h>
namespace multipass
{
class SnapEnvironmentException : public std::runtime_error
{
public:
SnapEnvironmentException(const std::string& env_var)
: runtime_error(fmt::format("The \'{}\' environment variable is not set.", env_var))
{
}
SnapEnvironmentException(const std::string& env_var, const std::string& expected_value)
: runtime_error(fmt::format("The \'{}\' environment variable is not set to \'{}\'.", env_var, expected_value))
{
}
};
} // namespace multipass
#endif // MULTIPASS_SNAP_ENVIRONMENT_EXCEPTION_H
| 1,331
|
C++
|
.h
| 36
| 34.305556
| 118
| 0.74031
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,969
|
unsupported_alias_exception.h
|
canonical_multipass/include/multipass/exceptions/unsupported_alias_exception.h
|
/*
* Copyright (C) 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_UNSUPPORTED_ALIAS_EXCEPTION_H
#define MULTIPASS_UNSUPPORTED_ALIAS_EXCEPTION_H
#include <stdexcept>
namespace multipass
{
class UnsupportedAliasException : public std::runtime_error
{
public:
explicit UnsupportedAliasException(const std::string& message) : runtime_error(message)
{
}
};
} // namespace multipass
#endif // MULTIPASS_UNSUPPORTED_ALIAS_EXCEPTION_H
| 1,022
|
C++
|
.h
| 30
| 32.066667
| 91
| 0.773509
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,970
|
exitless_sshprocess_exceptions.h
|
canonical_multipass/include/multipass/exceptions/exitless_sshprocess_exceptions.h
|
/*
* Copyright (C) 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_EXITLESS_SSHPROCESS_EXCEPTIONS_H
#define MULTIPASS_EXITLESS_SSHPROCESS_EXCEPTIONS_H
#include "ssh_exception.h"
#include <fmt/format.h>
#include <chrono>
#include <string>
namespace multipass
{
class ExitlessSSHProcessException : public SSHException
{
protected:
ExitlessSSHProcessException(const std::string& command, const std::string& cause)
: SSHException{fmt::format("failed to obtain exit status for remote process '{}': {}", command, cause)}
{
}
};
class SSHProcessTimeoutException : public ExitlessSSHProcessException
{
public:
SSHProcessTimeoutException(const std::string& command, std::chrono::milliseconds timeout)
: ExitlessSSHProcessException{command, fmt::format("timed out after {} ms", timeout.count())}
{
}
};
class SSHProcessExitError : public ExitlessSSHProcessException
{
public:
SSHProcessExitError(const std::string& command, const std::string& error)
: ExitlessSSHProcessException{command, fmt::format("SSH error: {}", error)}
{
}
};
} // namespace multipass
#endif // MULTIPASS_EXITLESS_SSHPROCESS_EXCEPTIONS_H
| 1,748
|
C++
|
.h
| 50
| 32.3
| 111
| 0.759172
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,971
|
ssh_exception.h
|
canonical_multipass/include/multipass/exceptions/ssh_exception.h
|
/*
* Copyright (C) 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_SSH_EXCEPTION_H
#define MULTIPASS_SSH_EXCEPTION_H
#include <stdexcept>
#include <string>
namespace multipass
{
class SSHException : public std::runtime_error
{
public:
explicit SSHException(const std::string& what_arg) : runtime_error(what_arg)
{
}
};
class SSHExecFailure : public SSHException
{
public:
SSHExecFailure(const std::string& what_arg, int exit_code) : SSHException{what_arg}, ec{exit_code}
{
}
int exit_code() const
{
return ec;
}
private:
int ec;
};
} // namespace multipass
#endif // MULTIPASS_SSH_EXCEPTION_H
| 1,226
|
C++
|
.h
| 44
| 25.295455
| 102
| 0.737245
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,972
|
stub_logger.h
|
canonical_multipass/tests/stub_logger.h
|
/*
* Copyright (C) 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/>.
*
* Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
*
*/
#ifndef MULTIPASS_STUB_LOGGER_H
#define MULTIPASS_STUB_LOGGER_H
#include <multipass/logging/logger.h>
namespace multipass
{
namespace test
{
class StubLogger : public logging::Logger
{
void log(logging::Level, logging::CString, logging::CString) const
{
}
};
} // namespace test
} // namespace multipass
#endif // MULTIPASS_STUB_LOGGER_H
| 1,049
|
C++
|
.h
| 34
| 28.882353
| 72
| 0.757666
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,973
|
mock_cert_provider.h
|
canonical_multipass/tests/mock_cert_provider.h
|
/*
* Copyright (C) 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_MOCK_CERT_PROVIDER_H
#define MULTIPASS_MOCK_CERT_PROVIDER_H
#include <multipass/cert_provider.h>
using namespace testing;
namespace multipass::test
{
constexpr auto client_cert = "-----BEGIN CERTIFICATE-----\n"
"MIIBUjCB+AIBKjAKBggqhkjOPQQDAjA1MQswCQYDVQQGEwJDQTESMBAGA1UECgwJ\n"
"Q2Fub25pY2FsMRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMTgwNjIxMTM0MjI5WhcN\n"
"MTkwNjIxMTM0MjI5WjA1MQswCQYDVQQGEwJDQTESMBAGA1UECgwJQ2Fub25pY2Fs\n"
"MRIwEAYDVQQDDAlsb2NhbGhvc3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQA\n"
"FGNAqq7c5IMDeQ/cV4+EmogmkfpbTLSPfXgXVLHRsvL04xUAkqGpL+eyGFVE6dqa\n"
"J7sAPJJwlVj1xD0r5DX5MAoGCCqGSM49BAMCA0kAMEYCIQCvI0PYv9f201fbe4LP\n"
"BowTeYWSqMQtLNjvZgd++AAGhgIhALNPW+NRSKCXwadiIFgpbjPInLPqXPskLWSc\n"
"aXByaQyt\n"
"-----END CERTIFICATE-----\n";
constexpr auto client_key = "-----BEGIN PRIVATE KEY-----\n"
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgsSAz5ggzrLjai0I/\n"
"F0hYg5oG/shpXJiBQtJdBCG3lUShRANCAAQAFGNAqq7c5IMDeQ/cV4+Emogmkfpb\n"
"TLSPfXgXVLHRsvL04xUAkqGpL+eyGFVE6dqaJ7sAPJJwlVj1xD0r5DX5\n"
"-----END PRIVATE KEY-----\n";
constexpr auto daemon_cert = "-----BEGIN CERTIFICATE-----\n"
"MIIBUjCB+AIBKjAKBggqhkjOPQQDAjA1MQswCQYDVQQGEwJDQTESMBAGA1UECgwJ\n"
"Q2Fub25pY2FsMRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMTgwNjIxMTM0MjI5WhcN\n"
"MTkwNjIxMTM0MjI5WjA1MQswCQYDVQQGEwJDQTESMBAGA1UECgwJQ2Fub25pY2Fs\n"
"MRIwEAYDVQQDDAlsb2NhbGhvc3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQA\n"
"FGNAqq7c5IMDeQ/cV4+EmogmkfpbTLSPfXgXVLHRsvL04xUAkqGpL+eyGFVE6dqa\n"
"J7sAPJJwlVj1xD0r5DX5MAoGCCqGSM49BAMCA0kAMEYCIQCvI0PYv9f201fbe4LP\n"
"BowTeYWSqMQtLNjvZgd++AAGhgIhALNPW+NRSKCXwadiIFgpbjPInLPqXPskLWSc\n"
"aXByaQyt\n"
"-----END CERTIFICATE-----\n";
constexpr auto daemon_key = "-----BEGIN PRIVATE KEY-----\n"
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgsSAz5ggzrLjai0I/\n"
"F0hYg5oG/shpXJiBQtJdBCG3lUShRANCAAQAFGNAqq7c5IMDeQ/cV4+Emogmkfpb\n"
"TLSPfXgXVLHRsvL04xUAkqGpL+eyGFVE6dqaJ7sAPJJwlVj1xD0r5DX5\n"
"-----END PRIVATE KEY-----\n";
struct MockCertProvider : public CertProvider
{
MockCertProvider()
{
ON_CALL(*this, PEM_certificate).WillByDefault(Return(client_cert));
ON_CALL(*this, PEM_signing_key).WillByDefault(Return(client_key));
}
MOCK_METHOD(std::string, PEM_certificate, (), (override, const));
MOCK_METHOD(std::string, PEM_signing_key, (), (override, const));
};
} // namespace multipass::test
#endif // MULTIPASS_MOCK_CERT_PROVIDER_H
| 3,756
|
C++
|
.h
| 64
| 45.09375
| 97
| 0.649742
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,974
|
mock_vm_blueprint_provider.h
|
canonical_multipass/tests/mock_vm_blueprint_provider.h
|
/*
* Copyright (C) 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_MOCK_VM_BLUEPRINT_PROVIDER_H
#define MULTIPASS_MOCK_VM_BLUEPRINT_PROVIDER_H
#include "common.h"
#include <multipass/vm_blueprint_provider.h>
#include <multipass/vm_image_info.h>
namespace multipass
{
namespace test
{
class MockVMBlueprintProvider : public VMBlueprintProvider
{
public:
MockVMBlueprintProvider()
{
ON_CALL(*this, info_for(_)).WillByDefault([](const auto& blueprint_name) {
mp::VMImageInfo info;
info.aliases.append(QString::fromStdString(blueprint_name));
info.release_title = QString::fromStdString(fmt::format("This is the {} blueprint", blueprint_name));
return info;
});
};
MOCK_METHOD(Query, fetch_blueprint_for, (const std::string&, VirtualMachineDescription&, ClientLaunchData&),
(override));
MOCK_METHOD(Query, blueprint_from_file,
(const std::string&, const std::string&, VirtualMachineDescription&, ClientLaunchData&), (override));
MOCK_METHOD(std::optional<VMImageInfo>, info_for, (const std::string&), (override));
MOCK_METHOD(std::vector<VMImageInfo>, all_blueprints, (), (override));
MOCK_METHOD(std::string, name_from_blueprint, (const std::string&), (override));
MOCK_METHOD(int, blueprint_timeout, (const std::string&), (override));
};
} // namespace test
} // namespace multipass
#endif // MULTIPASS_MOCK_VM_BLUEPRINT_PROVIDER_H
| 2,048
|
C++
|
.h
| 49
| 37.653061
| 117
| 0.717369
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,975
|
stub_image_host.h
|
canonical_multipass/tests/stub_image_host.h
|
/*
* Copyright (C) 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_STUB_IMAGE_HOST_H
#define MULTIPASS_STUB_IMAGE_HOST_H
#include <multipass/vm_image.h>
#include <multipass/vm_image_host.h>
namespace multipass
{
namespace test
{
struct StubVMImageHost final : public multipass::VMImageHost
{
std::optional<multipass::VMImageInfo> info_for(const multipass::Query& query) override
{
return std::optional<multipass::VMImageInfo>{VMImageInfo{{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, -1, {}}};
};
std::vector<std::pair<std::string, multipass::VMImageInfo>> all_info_for(const multipass::Query& query) override
{
return {};
};
multipass::VMImageInfo info_for_full_hash(const std::string& full_hash) override
{
return {{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, -1, {}};
};
std::vector<multipass::VMImageInfo> all_images_for(const std::string& remote_name,
const bool allow_unsupported) override
{
return {};
};
void for_each_entry_do(const Action&) override
{
}
std::vector<std::string> supported_remotes() override
{
return {};
}
void update_manifests(const bool is_force_update_from_network) override
{
}
};
} // namespace test
} // namespace multipass
#endif // MULTIPASS_STUB_IMAGE_HOST_H
| 1,949
|
C++
|
.h
| 57
| 29.649123
| 116
| 0.661359
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,976
|
test_with_mocked_bin_path.h
|
canonical_multipass/tests/test_with_mocked_bin_path.h
|
/*
* Copyright (C) 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_TEST_WITH_MOCKED_BIN_PATH
#define MULTIPASS_TEST_WITH_MOCKED_BIN_PATH
#include "common.h"
#include "mock_environment_helpers.h"
namespace multipass
{
namespace test
{
struct TestWithMockedBinPath : public testing::Test
{
void SetUp() override;
void TearDown() override;
private:
std::unique_ptr<SetEnvScope> env;
};
} // namespace test
} // namespace multipass
#endif // MULTIPASS_TEST_WITH_MOCKED_BIN_PATH
| 1,069
|
C++
|
.h
| 34
| 29.529412
| 72
| 0.764306
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,977
|
mock_sftp.h
|
canonical_multipass/tests/mock_sftp.h
|
/*
* Copyright (C) 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_MOCK_SFTP_H
#define MULTIPASS_MOCK_SFTP_H
#include <premock.hpp>
#include <libssh/sftp.h>
DECL_MOCK(sftp_new);
DECL_MOCK(sftp_free);
DECL_MOCK(sftp_init);
DECL_MOCK(sftp_open);
DECL_MOCK(sftp_write);
DECL_MOCK(sftp_read);
DECL_MOCK(sftp_get_error);
DECL_MOCK(sftp_close);
DECL_MOCK(sftp_stat);
DECL_MOCK(sftp_lstat);
DECL_MOCK(sftp_opendir);
DECL_MOCK(sftp_readdir);
DECL_MOCK(sftp_readlink);
DECL_MOCK(sftp_mkdir);
DECL_MOCK(sftp_symlink);
DECL_MOCK(sftp_unlink);
DECL_MOCK(sftp_setstat);
DECL_MOCK(sftp_dir_eof);
DECL_MOCK(sftp_chmod);
#endif // MULTIPASS_MOCK_SFTP_H
| 1,221
|
C++
|
.h
| 40
| 29.025
| 72
| 0.764456
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,978
|
fake_alias_config.h
|
canonical_multipass/tests/fake_alias_config.h
|
/*
* Copyright (C) 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_FAKE_ALIAS_CONFIG_H
#define MULTIPASS_FAKE_ALIAS_CONFIG_H
#include <multipass/cli/alias_dict.h>
#include <multipass/constants.h>
#include "common.h"
#include "mock_standard_paths.h"
#include "stub_terminal.h"
#include "temp_dir.h"
namespace mp = multipass;
namespace mpt = multipass::test;
using namespace testing;
namespace
{
struct FakeAliasConfig
{
FakeAliasConfig()
{
EXPECT_CALL(mpt::MockStandardPaths::mock_instance(), writableLocation(_))
.WillRepeatedly(Return(fake_alias_dir.path()));
}
std::string db_filename()
{
const auto file_name = QStringLiteral("%1/%1_aliases.json").arg(mp::client_name);
return fake_alias_dir.filePath(file_name).toStdString();
}
void populate_db_file(const std::vector<std::pair<std::string, mp::AliasDefinition>>& aliases)
{
static std::stringstream trash_stream;
mpt::StubTerminal term(trash_stream, trash_stream, trash_stream);
mp::AliasDict writer(&term);
for (const auto& alias : aliases)
writer.add_alias(alias.first, alias.second);
}
mpt::TempDir fake_alias_dir;
};
} // namespace
#endif // MULTIPASS_FAKE_ALIAS_CONFIG_H
| 1,841
|
C++
|
.h
| 53
| 30.981132
| 98
| 0.718627
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,979
|
mock_file_ops.h
|
canonical_multipass/tests/mock_file_ops.h
|
/*
* Copyright (C) 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_MOCK_CONST_FILE_OPS_H
#define MULTIPASS_MOCK_CONST_FILE_OPS_H
#include "common.h"
#include "mock_singleton_helpers.h"
#include <multipass/file_ops.h>
namespace multipass::test
{
class MockFileOps : public FileOps
{
public:
using FileOps::FileOps;
// QDir mock methods
MOCK_METHOD(QDir, current, (), (const));
MOCK_METHOD(bool, exists, (const QDir&), (const, override));
MOCK_METHOD(bool, isReadable, (const QDir&), (const, override));
MOCK_METHOD(bool, mkpath, (const QDir&, const QString& dirName), (const, override));
MOCK_METHOD(bool, rmdir, (QDir&, const QString& dirName), (const, override));
// QFileInfo mock methods
MOCK_METHOD(bool, exists, (const QFileInfo&), (const, override));
MOCK_METHOD(bool, isDir, (const QFileInfo&), (const, override));
MOCK_METHOD(bool, isReadable, (const QFileInfo&), (const, override));
MOCK_METHOD(uint, ownerId, (const QFileInfo&), (const, override));
MOCK_METHOD(uint, groupId, (const QFileInfo&), (const, override));
// QFile mock methods
MOCK_METHOD(bool, exists, (const QFile&), (const, override));
MOCK_METHOD(bool, is_open, (const QFile&), (const, override));
MOCK_METHOD(bool, open, (QFileDevice&, QIODevice::OpenMode), (const, override));
MOCK_METHOD(QFileDevice::Permissions, permissions, (const QFile&), (const, override));
MOCK_METHOD(qint64, read, (QFile&, char*, qint64), (const, override));
MOCK_METHOD(QByteArray, read_all, (QFile&), (const, override));
MOCK_METHOD(QString, read_line, (QTextStream&), (const, override));
MOCK_METHOD(bool, remove, (QFile&), (const, override));
MOCK_METHOD(bool, rename, (QFile&, const QString& newName), (const, override));
MOCK_METHOD(bool, resize, (QFile&, qint64 sz), (const, override));
MOCK_METHOD(bool, seek, (QFile&, qint64 pos), (const, override));
MOCK_METHOD(bool, setPermissions, (QFile&, QFileDevice::Permissions), (const, override));
MOCK_METHOD(qint64, size, (QFile&), (const, override));
MOCK_METHOD(qint64, write, (QFile&, const char*, qint64), (const, override));
MOCK_METHOD(qint64, write, (QFileDevice&, const QByteArray&), (const, override));
MOCK_METHOD(bool, flush, (QFile & file), (const, override));
// QSaveFile mock methods
MOCK_METHOD(bool, commit, (QSaveFile&), (const, override));
// posix mock methods
MOCK_METHOD((std::unique_ptr<NamedFd>), open_fd, (const fs::path&, int, int), (const, override));
MOCK_METHOD(int, read, (int, void*, size_t), (const, override));
MOCK_METHOD(int, write, (int, const void*, size_t), (const, override));
MOCK_METHOD(off_t, lseek, (int, off_t, int), (const, override));
// Mock std methods
MOCK_METHOD(void, open, (std::fstream&, const char*, std::ios_base::openmode), (const, override));
MOCK_METHOD(bool, is_open, (const std::ifstream&), (const, override));
MOCK_METHOD(std::ifstream&, read, (std::ifstream&, char*, std::streamsize), (const, override));
MOCK_METHOD(std::unique_ptr<std::ostream>, open_write, (const fs::path& path, std::ios_base::openmode mode),
(override, const));
MOCK_METHOD(std::unique_ptr<std::istream>, open_read, (const fs::path& path, std::ios_base::openmode mode),
(override, const));
MOCK_METHOD(bool, exists, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(bool, is_directory, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(bool, create_directory, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(bool, create_directories, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(bool, remove, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(void, create_symlink, (const fs::path& to, const fs::path& path, std::error_code& err),
(override, const));
MOCK_METHOD(fs::path, read_symlink, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(void, permissions, (const fs::path& path, fs::perms perms, std::error_code& err), (override, const));
MOCK_METHOD(fs::file_status, status, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(fs::file_status, symlink_status, (const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(std::unique_ptr<multipass::RecursiveDirIterator>, recursive_dir_iterator,
(const fs::path& path, std::error_code& err), (override, const));
MOCK_METHOD(std::unique_ptr<multipass::DirIterator>,
dir_iterator,
(const fs::path& path, std::error_code& err),
(override, const));
MP_MOCK_SINGLETON_BOILERPLATE(MockFileOps, FileOps);
};
} // namespace multipass::test
#endif // MULTIPASS_MOCK_FILE_OPS_H
| 5,504
|
C++
|
.h
| 92
| 54.880435
| 117
| 0.678704
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,980
|
mock_status_monitor.h
|
canonical_multipass/tests/mock_status_monitor.h
|
/*
* Copyright (C) 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_MOCK_STATUS_MONITOR_H
#define MULTIPASS_MOCK_STATUS_MONITOR_H
#include "common.h"
#include <multipass/vm_status_monitor.h>
namespace multipass
{
namespace test
{
struct MockVMStatusMonitor : public VMStatusMonitor
{
MOCK_METHOD(void, on_resume, (), (override));
MOCK_METHOD(void, on_shutdown, (), (override));
MOCK_METHOD(void, on_suspend, (), (override));
MOCK_METHOD(void, on_restart, (const std::string&), (override));
MOCK_METHOD(void, persist_state_for, (const std::string&, const VirtualMachine::State&), (override));
MOCK_METHOD(void, update_metadata_for, (const std::string&, const QJsonObject&), (override));
MOCK_METHOD(QJsonObject, retrieve_metadata_for, (const std::string&), (override));
};
} // namespace test
} // namespace multipass
#endif // MULTIPASS_MOCK_STATUS_MONITOR_H
| 1,469
|
C++
|
.h
| 37
| 37.432432
| 105
| 0.740196
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
20,981
|
mock_platform.h
|
canonical_multipass/tests/mock_platform.h
|
/*
* Copyright (C) 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_MOCK_PLATFORM_H
#define MULTIPASS_MOCK_PLATFORM_H
#include "common.h"
#include "mock_singleton_helpers.h"
#include <multipass/platform.h>
namespace multipass::test
{
class MockPlatform : public platform::Platform
{
public:
MockPlatform(const PrivatePass& pass) : platform::Platform(pass)
{
EXPECT_CALL(*this, set_server_socket_restrictions)
.Times(testing::AnyNumber())
.WillRepeatedly(testing::Return());
};
MOCK_METHOD((std::map < std::string, NetworkInterfaceInfo) >, get_network_interfaces_info, (), (const, override));
MOCK_METHOD(QString, get_blueprints_url_override, (), (const, override));
MOCK_METHOD(bool, is_remote_supported, (const std::string&), (const, override));
MOCK_METHOD(bool, is_backend_supported, (const QString&), (const, override));
MOCK_METHOD(bool, is_alias_supported, (const std::string&, const std::string&), (const, override));
MOCK_METHOD(int, chmod, (const char*, unsigned int), (const, override));
MOCK_METHOD(int, chown, (const char*, unsigned int, unsigned int), (const, override));
MOCK_METHOD(bool, link, (const char*, const char*), (const, override));
MOCK_METHOD(bool, symlink, (const char*, const char*, bool), (const, override));
MOCK_METHOD(int, utime, (const char*, int, int), (const, override));
MOCK_METHOD(void, create_alias_script, (const std::string&, const AliasDefinition&), (const, override));
MOCK_METHOD(void, remove_alias_script, (const std::string&), (const, override));
MOCK_METHOD(void, set_server_socket_restrictions, (const std::string&, const bool), (const, override));
MOCK_METHOD(QString, multipass_storage_location, (), (const, override));
MOCK_METHOD(SettingSpec::Set, extra_daemon_settings, (), (const, override));
MOCK_METHOD(SettingSpec::Set, extra_client_settings, (), (const, override));
MOCK_METHOD(QString, daemon_config_home, (), (const, override));
MOCK_METHOD(QString, default_driver, (), (const, override));
MOCK_METHOD(QString, default_privileged_mounts, (), (const, override));
MOCK_METHOD(bool, is_image_url_supported, (), (const, override));
MOCK_METHOD(QString, get_username, (), (const, override));
MOCK_METHOD(std::string, bridge_nomenclature, (), (const, override));
MP_MOCK_SINGLETON_BOILERPLATE(MockPlatform, Platform);
};
} // namespace multipass::test
#endif // MULTIPASS_MOCK_PLATFORM_H
| 3,063
|
C++
|
.h
| 58
| 49.086207
| 118
| 0.710807
|
canonical/multipass
| 7,732
| 642
| 476
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.