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/connection.hpp"
31#include "ores.connections/domain/connection_tag.hpp"
32#include "ores.connections/domain/environment.hpp"
33#include "ores.connections/domain/environment_tag.hpp"
34#include "ores.connections/repository/sqlite_context.hpp"
35#include "ores.connections/repository/folder_repository.hpp"
36#include "ores.connections/repository/tag_repository.hpp"
37#include "ores.connections/repository/connection_repository.hpp"
38#include "ores.connections/repository/connection_tag_repository.hpp"
39#include "ores.connections/repository/environment_repository.hpp"
40#include "ores.connections/repository/environment_tag_repository.hpp"
41
42namespace ores::connections::service {
43
53class connection_manager final {
54public:
62 std::string host;
63 int port{0};
64 int http_port{8080};
65 std::string username;
66 std::string password;
67 std::string name;
68 std::string subject_prefix;
69 std::optional<boost::uuids::uuid> environment_id;
70 std::optional<std::string> environment_name;
71 };
72
78 connection_manager(const std::filesystem::path& db_path,
79 const std::string& master_password);
80
81 // Folder operations
82 void create_folder(const domain::folder& folder);
83 void update_folder(const domain::folder& folder);
84 void delete_folder(const boost::uuids::uuid& id);
85 std::vector<domain::folder> get_all_folders();
86 std::optional<domain::folder> get_folder(const boost::uuids::uuid& id);
87 std::vector<domain::folder> get_root_folders();
88 std::vector<domain::folder> get_child_folders(const boost::uuids::uuid& parent_id);
89
90 // Tag operations
91 void create_tag(const domain::tag& tag);
92 void update_tag(const domain::tag& tag);
93 void delete_tag(const boost::uuids::uuid& id);
94 std::vector<domain::tag> get_all_tags();
95 std::optional<domain::tag> get_tag(const boost::uuids::uuid& id);
96 std::optional<domain::tag> get_tag_by_name(const std::string& name);
97
98 // Environment operations (pure host/port, no credentials)
99 void create_environment(const domain::environment& env);
100 void update_environment(const domain::environment& env);
101 void delete_environment(const boost::uuids::uuid& id);
102 std::vector<domain::environment> get_all_environments();
103 std::optional<domain::environment> get_environment(const boost::uuids::uuid& id);
104 std::vector<domain::environment> get_environments_in_folder(
105 const std::optional<boost::uuids::uuid>& folder_id);
106
107 // Environment-tag operations
108 void add_tag_to_environment(const boost::uuids::uuid& environment_id,
109 const boost::uuids::uuid& tag_id);
110 void remove_tag_from_environment(const boost::uuids::uuid& environment_id,
111 const boost::uuids::uuid& tag_id);
112 std::vector<domain::tag> get_tags_for_environment(
113 const boost::uuids::uuid& environment_id);
114 std::vector<domain::environment> get_environments_with_tag(
115 const boost::uuids::uuid& tag_id);
116
117 // Connection operations (credentials, optional link to environment)
118 void create_connection(domain::connection conn, const std::string& password);
119 void update_connection(domain::connection conn,
120 const std::optional<std::string>& password);
121 void delete_connection(const boost::uuids::uuid& id);
122 std::vector<domain::connection> get_all_connections();
123 std::optional<domain::connection> get_connection(const boost::uuids::uuid& id);
124 std::vector<domain::connection> get_connections_in_folder(
125 const std::optional<boost::uuids::uuid>& folder_id);
126
130 std::string get_password(const boost::uuids::uuid& connection_id);
131
132 // Connection-tag operations
133 void add_tag_to_connection(const boost::uuids::uuid& connection_id,
134 const boost::uuids::uuid& tag_id);
135 void remove_tag_from_connection(const boost::uuids::uuid& connection_id,
136 const boost::uuids::uuid& tag_id);
137 std::vector<domain::tag> get_tags_for_connection(
138 const boost::uuids::uuid& connection_id);
139 std::vector<domain::connection> get_connections_with_tag(
140 const boost::uuids::uuid& tag_id);
141
148 resolved_connection resolve_connection(const boost::uuids::uuid& connection_id);
149
157
163 void change_master_password(const std::string& new_password);
164
171 void purge();
172
173private:
176 repository::tag_repository tag_repo_;
177 repository::connection_repository conn_repo_;
178 repository::connection_tag_repository conn_tag_repo_;
179 repository::environment_repository env_repo_;
180 repository::environment_tag_repository env_tag_repo_;
181 std::string master_password_;
182};
183
184}
185
186#endif
Represents a saved connection with credentials.
Definition connection.hpp:40
Represents a pure server environment (host + port only, no credentials).
Definition environment.hpp:39
Represents a folder for organizing server connections hierarchically.
Definition folder.hpp:35
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 and environments.
Definition connection_manager.hpp:53
resolved_connection resolve_connection(const boost::uuids::uuid &connection_id)
Resolve a connection to its full details for opening a login dialog.
Definition connection_manager.cpp:281
void change_master_password(const std::string &new_password)
Change the master password.
Definition connection_manager.cpp:328
bool verify_master_password()
Verify if the master password is correct.
Definition connection_manager.cpp:317
void purge()
Delete all data from the database.
Definition connection_manager.cpp:344
std::string get_password(const boost::uuids::uuid &connection_id)
Get decrypted password for a connection.
Definition connection_manager.cpp:220
Resolved connection details for opening a login dialog.
Definition connection_manager.hpp:61
std::string password
decrypted
Definition connection_manager.hpp:66
Utilities for reading environment variables.
Definition environment.hpp:31