You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
proxysql/plugins/mysqlx/include/mysqlx_config_store.h

75 lines
2.0 KiB

#ifndef PROXYSQL_MYSQLX_CONFIG_STORE_H
#define PROXYSQL_MYSQLX_CONFIG_STORE_H
#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
class SQLite3DB;
enum class MysqlxBackendAuthMode : uint8_t {
mapped = 0,
service_account = 1,
pass_through = 2
};
MysqlxBackendAuthMode mysqlx_backend_auth_mode_from_string(const std::string& value);
struct MysqlxResolvedIdentity {
std::string username {};
int default_hostgroup { 0 };
int max_connections { 0 };
bool x_enabled { false };
bool require_tls { false };
std::string allowed_auth_methods {};
std::string default_route {};
std::string policy_profile {};
MysqlxBackendAuthMode backend_auth_mode { MysqlxBackendAuthMode::mapped };
std::string backend_username {};
std::string backend_password {};
std::string attributes {};
};
struct MysqlxRoute {
std::string name {};
std::string bind {};
int destination_hostgroup { 0 };
int fallback_hostgroup { -1 };
std::string strategy { "first_available" };
bool active { true };
std::string attributes {};
};
struct MysqlxBackendEndpoint {
std::string hostname {};
int mysql_port { 0 };
int mysqlx_port { 33060 };
bool use_ssl { false };
std::string attributes {};
};
class MysqlxConfigStore {
public:
MysqlxConfigStore() = default;
MysqlxConfigStore(const MysqlxConfigStore&) = delete;
MysqlxConfigStore& operator=(const MysqlxConfigStore&) = delete;
~MysqlxConfigStore() = default;
bool load_from_runtime(SQLite3DB& db, std::string& err);
std::optional<MysqlxResolvedIdentity> resolve_identity(const std::string& username) const;
MysqlxBackendEndpoint pick_endpoint(const std::string& route_name) const;
uint64_t topology_generation() const;
void bump_topology_generation();
private:
std::unordered_map<std::string, MysqlxResolvedIdentity> identities_ {};
std::unordered_map<std::string, MysqlxRoute> routes_ {};
std::unordered_map<int, std::vector<MysqlxBackendEndpoint>> hostgroup_endpoints_ {};
uint64_t topology_generation_ { 0 };
};
#endif /* PROXYSQL_MYSQLX_CONFIG_STORE_H */