ORE Studio 0.0.4
Loading...
Searching...
No Matches
tenant_context.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_DATABASE_SERVICE_TENANT_CONTEXT_HPP
21#define ORES_DATABASE_SERVICE_TENANT_CONTEXT_HPP
22
23#include <string>
24#include "ores.database/domain/context.hpp"
25#include "ores.utility/uuid/tenant_id.hpp"
26
28
37class tenant_context final {
38public:
45 static constexpr const char* system_tenant_id =
46 "ffffffff-ffff-ffff-ffff-ffffffffffff";
47
48 tenant_context() = delete;
49
64 [[nodiscard]] static context with_tenant(const context& ctx,
65 const std::string& tenant);
66
76 [[nodiscard]] static context with_system_tenant(const context& ctx);
77
87 const std::string& code);
88
98 const std::string& hostname);
99
111 static std::string lookup_name(const context& ctx,
112 const utility::uuid::tenant_id& tenant_id);
113
120 static bool is_uuid(const std::string& str);
121};
122
123}
124
125#endif
Database service layer.
Definition ores.database.service.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
Manages tenant context for multi-tenant database operations.
Definition tenant_context.hpp:37
static context with_tenant(const context &ctx, const std::string &tenant)
Creates a new context with the specified tenant.
Definition tenant_context.cpp:173
static utility::uuid::tenant_id lookup_by_hostname(const context &ctx, const std::string &hostname)
Looks up a tenant ID by its hostname.
Definition tenant_context.cpp:74
static constexpr const char * system_tenant_id
The UUID of the system tenant (max UUID per RFC 9562).
Definition tenant_context.hpp:45
static bool is_uuid(const std::string &str)
Checks if a string is a valid UUID format.
Definition tenant_context.cpp:41
static utility::uuid::tenant_id lookup_by_code(const context &ctx, const std::string &code)
Looks up a tenant ID by its code.
Definition tenant_context.cpp:48
static context with_system_tenant(const context &ctx)
Creates a new context with the system tenant.
Definition tenant_context.cpp:190
static std::string lookup_name(const context &ctx, const utility::uuid::tenant_id &tenant_id)
Looks up a tenant name by its ID.
Definition tenant_context.cpp:100
A strongly-typed wrapper around a UUID representing a tenant identifier.
Definition tenant_id.hpp:66