20#ifndef ORES_DATABASE_CONTEXT_HPP
21#define ORES_DATABASE_CONTEXT_HPP
25#include <sqlgen/postgres.hpp>
26#include <boost/uuid/uuid.hpp>
27#include "ores.database/domain/tenant_aware_pool.hpp"
28#include "ores.utility/uuid/tenant_id.hpp"
30namespace ores::database {
49 using connection_type = sqlgen::postgres::Connection;
58 std::string
actor =
"",
73 std::string
actor =
"",
90 const sqlgen::postgres::Credentials&
credentials()
const {
return credentials_; }
102 std::optional<boost::uuids::uuid>
party_id()
const {
119 const std::string&
actor()
const {
return connection_pool_.
actor(); }
143 const std::vector<std::string>&
roles()
const {
return roles_; }
153 copy.roles_ = std::move(
roles);
163 std::string
actor)
const {
177 std::string
actor)
const {
185 connection_pool_type connection_pool_;
186 sqlgen::postgres::Credentials credentials_;
187 std::string service_account_;
188 std::vector<std::string> roles_;
Context for the operations on a postgres database.
Definition context.hpp:47
const std::string & service_account() const
Gets the service account for this context.
Definition context.hpp:128
connection_pool_type & connection_pool()
Gets the tenant-aware connection pool.
Definition context.hpp:85
std::optional< boost::uuids::uuid > party_id() const
Gets the party ID for this context, if set.
Definition context.hpp:102
const sqlgen::postgres::Credentials & credentials() const
Gets the credentials for this context.
Definition context.hpp:90
context(sqlgen::ConnectionPool< connection_type > connection_pool, sqlgen::postgres::Credentials credentials, utility::uuid::tenant_id tenant_id, std::string actor="", std::string service_account="")
Constructs a tenant-only context.
Definition context.hpp:55
const std::vector< boost::uuids::uuid > & visible_party_ids() const
Gets the visible party IDs for this context.
Definition context.hpp:109
const std::vector< std::string > & roles() const
Gets the permission codes carried in this context.
Definition context.hpp:143
context with_party(utility::uuid::tenant_id tenant_id, boost::uuids::uuid party_id, std::vector< boost::uuids::uuid > visible_party_ids, std::string actor) const
Creates a new context with tenant and party isolation.
Definition context.hpp:173
const std::string & actor() const
Gets the current actor (end-user) for this context.
Definition context.hpp:119
const utility::uuid::tenant_id & tenant_id() const
Gets the tenant ID for this context.
Definition context.hpp:95
const sqlgen::ConnectionPool< connection_type > & underlying_pool() const
Gets the underlying raw connection pool.
Definition context.hpp:133
context with_roles(std::vector< std::string > roles) const
Returns a copy of this context with the given permission codes.
Definition context.hpp:151
context with_tenant(utility::uuid::tenant_id tenant_id, std::string actor) const
Creates a new context with a different tenant ID (no party).
Definition context.hpp:162
context(sqlgen::ConnectionPool< connection_type > connection_pool, sqlgen::postgres::Credentials credentials, utility::uuid::tenant_id tenant_id, boost::uuids::uuid party_id, std::vector< boost::uuids::uuid > visible_party_ids, std::string actor="", std::string service_account="")
Constructs a tenant-and-party-aware context.
Definition context.hpp:68
const sqlgen::ConnectionPool< Connection > & underlying_pool() const
Gets the underlying connection pool.
Definition tenant_aware_pool.hpp:283
std::optional< boost::uuids::uuid > party_id() const
Gets the current party ID, if set.
Definition tenant_aware_pool.hpp:261
const std::vector< boost::uuids::uuid > & visible_party_ids() const
Gets the visible party IDs.
Definition tenant_aware_pool.hpp:266
const std::string & actor() const
Gets the current actor (username), if set.
Definition tenant_aware_pool.hpp:273
const utility::uuid::tenant_id & tenant_id() const
Gets the current tenant ID.
Definition tenant_aware_pool.hpp:256
A strongly-typed wrapper around a UUID representing a tenant identifier.
Definition tenant_id.hpp:66