ORE Studio 0.0.4
Loading...
Searching...
No Matches
connection_manager.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_CONNECTIONS_SERVICE_CONNECTION_MANAGER_HPP
21#define ORES_CONNECTIONS_SERVICE_CONNECTION_MANAGER_HPP
22
23#include <string>
24#include <vector>
25#include <optional>
26#include <filesystem>
27#include <boost/uuid/uuid.hpp>
28#include "ores.connections/domain/folder.hpp"
29#include "ores.connections/domain/tag.hpp"
30#include "ores.connections/domain/server_environment.hpp"
31#include "ores.connections/domain/environment_tag.hpp"
32#include "ores.connections/repository/sqlite_context.hpp"
33#include "ores.connections/repository/folder_repository.hpp"
34#include "ores.connections/repository/tag_repository.hpp"
35#include "ores.connections/repository/server_environment_repository.hpp"
36#include "ores.connections/repository/environment_tag_repository.hpp"
37
38namespace ores::connections::service {
39
48class connection_manager final {
49public:
55 connection_manager(const std::filesystem::path& db_path,
56 const std::string& master_password);
57
58 // Folder operations
59 void create_folder(const domain::folder& folder);
60 void update_folder(const domain::folder& folder);
61 void delete_folder(const boost::uuids::uuid& id);
62 std::vector<domain::folder> get_all_folders();
63 std::optional<domain::folder> get_folder(const boost::uuids::uuid& id);
64 std::vector<domain::folder> get_root_folders();
65 std::vector<domain::folder> get_child_folders(const boost::uuids::uuid& parent_id);
66
67 // Tag operations
68 void create_tag(const domain::tag& tag);
69 void update_tag(const domain::tag& tag);
70 void delete_tag(const boost::uuids::uuid& id);
71 std::vector<domain::tag> get_all_tags();
72 std::optional<domain::tag> get_tag(const boost::uuids::uuid& id);
73 std::optional<domain::tag> get_tag_by_name(const std::string& name);
74
75 // Server environment operations (passwords are encrypted/decrypted automatically)
76 void create_environment(domain::server_environment env, const std::string& password);
77 void update_environment(domain::server_environment env, const std::optional<std::string>& password);
78 void delete_environment(const boost::uuids::uuid& id);
79 std::vector<domain::server_environment> get_all_environments();
80 std::optional<domain::server_environment> get_environment(const boost::uuids::uuid& id);
81 std::vector<domain::server_environment> get_environments_in_folder(
82 const std::optional<boost::uuids::uuid>& folder_id);
83
87 std::string get_password(const boost::uuids::uuid& environment_id);
88
89 // Environment-tag operations
90 void add_tag_to_environment(const boost::uuids::uuid& environment_id,
91 const boost::uuids::uuid& tag_id);
92 void remove_tag_from_environment(const boost::uuids::uuid& environment_id,
93 const boost::uuids::uuid& tag_id);
94 std::vector<domain::tag> get_tags_for_environment(const boost::uuids::uuid& environment_id);
95 std::vector<domain::server_environment> get_environments_with_tag(
96 const boost::uuids::uuid& tag_id);
97
105
111 void change_master_password(const std::string& new_password);
112
119 void purge();
120
121private:
124 repository::tag_repository tag_repo_;
125 repository::server_environment_repository env_repo_;
126 repository::environment_tag_repository env_tag_repo_;
127 std::string master_password_;
128};
129
130}
131
132#endif
Represents a folder for organizing server connections hierarchically.
Definition folder.hpp:35
Represents a server connection/environment configuration.
Definition server_environment.hpp:39
Represents a tag for categorizing server connections.
Definition tag.hpp:35
Repository for managing folders in the SQLite database.
Definition folder_repository.hpp:34
SQLite database context for connection management.
Definition sqlite_context.hpp:36
High-level service for managing server connections.
Definition connection_manager.hpp:48
void change_master_password(const std::string &new_password)
Change the master password.
Definition connection_manager.cpp:214
bool verify_master_password()
Verify if the master password is correct.
Definition connection_manager.cpp:203
void purge()
Delete all data from the database.
Definition connection_manager.cpp:230
std::string get_password(const boost::uuids::uuid &environment_id)
Get decrypted password for an environment.
Definition connection_manager.cpp:143
Utilities for reading environment variables.
Definition environment.hpp:31