ORE Studio 0.0.4
Loading...
Searching...
No Matches
authorization_protocol.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_ACCOUNTS_MESSAGING_AUTHORIZATION_PROTOCOL_HPP
21#define ORES_ACCOUNTS_MESSAGING_AUTHORIZATION_PROTOCOL_HPP
22
23#include <span>
24#include <iosfwd>
25#include <vector>
26#include <expected>
27#include <boost/uuid/uuid.hpp>
28#include "ores.comms/messaging/message_types.hpp"
29#include "ores.accounts/domain/role.hpp"
30#include "ores.accounts/domain/permission.hpp"
31
32namespace ores::accounts::messaging {
33
34// ============================================================================
35// List Roles
36// ============================================================================
37
41struct list_roles_request final {
47 std::vector<std::byte> serialize() const;
48
52 static std::expected<list_roles_request, comms::messaging::error_code>
53 deserialize(std::span<const std::byte> data);
54};
55
56std::ostream& operator<<(std::ostream& s, const list_roles_request& v);
57
61struct list_roles_response final {
62 std::vector<domain::role> roles;
63
85 std::vector<std::byte> serialize() const;
86
90 static std::expected<list_roles_response, comms::messaging::error_code>
91 deserialize(std::span<const std::byte> data);
92};
93
94std::ostream& operator<<(std::ostream& s, const list_roles_response& v);
95
96// ============================================================================
97// List Permissions
98// ============================================================================
99
109 std::vector<std::byte> serialize() const;
110
114 static std::expected<list_permissions_request, comms::messaging::error_code>
115 deserialize(std::span<const std::byte> data);
116};
117
118std::ostream& operator<<(std::ostream& s, const list_permissions_request& v);
119
124 std::vector<domain::permission> permissions;
125
138 std::vector<std::byte> serialize() const;
139
143 static std::expected<list_permissions_response, comms::messaging::error_code>
144 deserialize(std::span<const std::byte> data);
145};
146
147std::ostream& operator<<(std::ostream& s, const list_permissions_response& v);
148
149// ============================================================================
150// Assign Role
151// ============================================================================
152
159 boost::uuids::uuid account_id;
160 boost::uuids::uuid role_id;
161
169 std::vector<std::byte> serialize() const;
170
174 static std::expected<assign_role_request, comms::messaging::error_code>
175 deserialize(std::span<const std::byte> data);
176};
177
178std::ostream& operator<<(std::ostream& s, const assign_role_request& v);
179
184 bool success = false;
185 std::string error_message;
186
195 std::vector<std::byte> serialize() const;
196
200 static std::expected<assign_role_response, comms::messaging::error_code>
201 deserialize(std::span<const std::byte> data);
202};
203
204std::ostream& operator<<(std::ostream& s, const assign_role_response& v);
205
206// ============================================================================
207// Revoke Role
208// ============================================================================
209
216 boost::uuids::uuid account_id;
217 boost::uuids::uuid role_id;
218
226 std::vector<std::byte> serialize() const;
227
231 static std::expected<revoke_role_request, comms::messaging::error_code>
232 deserialize(std::span<const std::byte> data);
233};
234
235std::ostream& operator<<(std::ostream& s, const revoke_role_request& v);
236
241 bool success = false;
242 std::string error_message;
243
252 std::vector<std::byte> serialize() const;
253
257 static std::expected<revoke_role_response, comms::messaging::error_code>
258 deserialize(std::span<const std::byte> data);
259};
260
261std::ostream& operator<<(std::ostream& s, const revoke_role_response& v);
262
263// ============================================================================
264// Get Account Roles
265// ============================================================================
266
271 boost::uuids::uuid account_id;
272
279 std::vector<std::byte> serialize() const;
280
284 static std::expected<get_account_roles_request, comms::messaging::error_code>
285 deserialize(std::span<const std::byte> data);
286};
287
288std::ostream& operator<<(std::ostream& s, const get_account_roles_request& v);
289
294 std::vector<domain::role> roles;
295
301 std::vector<std::byte> serialize() const;
302
306 static std::expected<get_account_roles_response, comms::messaging::error_code>
307 deserialize(std::span<const std::byte> data);
308};
309
310std::ostream& operator<<(std::ostream& s, const get_account_roles_response& v);
311
312// ============================================================================
313// Get Account Permissions
314// ============================================================================
315
320 boost::uuids::uuid account_id;
321
328 std::vector<std::byte> serialize() const;
329
333 static std::expected<get_account_permissions_request, comms::messaging::error_code>
334 deserialize(std::span<const std::byte> data);
335};
336
337std::ostream& operator<<(std::ostream& s, const get_account_permissions_request& v);
338
343 std::vector<std::string> permission_codes;
344
354 std::vector<std::byte> serialize() const;
355
359 static std::expected<get_account_permissions_response, comms::messaging::error_code>
360 deserialize(std::span<const std::byte> data);
361};
362
363std::ostream& operator<<(std::ostream& s, const get_account_permissions_response& v);
364
365}
366
367#endif
Request to list all roles in the system.
Definition authorization_protocol.hpp:41
static std::expected< list_roles_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition authorization_protocol.cpp:108
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition authorization_protocol.cpp:103
Response containing all roles.
Definition authorization_protocol.hpp:61
static std::expected< list_roles_response, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition authorization_protocol.cpp:127
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition authorization_protocol.cpp:117
Request to list all permissions in the system.
Definition authorization_protocol.hpp:103
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition authorization_protocol.cpp:153
static std::expected< list_permissions_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition authorization_protocol.cpp:158
Response containing all permissions.
Definition authorization_protocol.hpp:123
static std::expected< list_permissions_response, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition authorization_protocol.cpp:179
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition authorization_protocol.cpp:167
Request to assign a role to an account.
Definition authorization_protocol.hpp:158
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition authorization_protocol.cpp:217
static std::expected< assign_role_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition authorization_protocol.cpp:225
Response indicating whether role assignment succeeded.
Definition authorization_protocol.hpp:183
static std::expected< assign_role_response, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition authorization_protocol.cpp:252
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition authorization_protocol.cpp:244
Request to revoke a role from an account.
Definition authorization_protocol.hpp:215
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition authorization_protocol.cpp:275
static std::expected< revoke_role_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition authorization_protocol.cpp:283
Response indicating whether role revocation succeeded.
Definition authorization_protocol.hpp:240
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition authorization_protocol.cpp:302
static std::expected< revoke_role_response, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition authorization_protocol.cpp:310
Request to get all roles assigned to an account.
Definition authorization_protocol.hpp:270
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition authorization_protocol.cpp:333
static std::expected< get_account_roles_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition authorization_protocol.cpp:340
Response containing roles assigned to an account.
Definition authorization_protocol.hpp:293
static std::expected< get_account_roles_response, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition authorization_protocol.cpp:365
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition authorization_protocol.cpp:355
Request to get effective permissions for an account.
Definition authorization_protocol.hpp:319
static std::expected< get_account_permissions_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition authorization_protocol.cpp:398
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition authorization_protocol.cpp:391
Response containing effective permissions for an account.
Definition authorization_protocol.hpp:342
static std::expected< get_account_permissions_response, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition authorization_protocol.cpp:424
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition authorization_protocol.cpp:413