2023-08-19 00:23:15 +08:00
|
|
|
// Copyright 2023 Memgraph Ltd.
|
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
#pragma once
|
|
|
|
|
2023-09-20 19:13:54 +08:00
|
|
|
#include "audit/log.hpp"
|
|
|
|
#include "auth/auth.hpp"
|
2023-08-19 00:23:15 +08:00
|
|
|
#include "communication/v2/server.hpp"
|
|
|
|
#include "communication/v2/session.hpp"
|
2023-09-20 19:13:54 +08:00
|
|
|
#include "dbms/database.hpp"
|
|
|
|
#include "query/interpreter.hpp"
|
2023-08-19 00:23:15 +08:00
|
|
|
|
|
|
|
namespace memgraph::glue {
|
|
|
|
|
|
|
|
class SessionHL final : public memgraph::communication::bolt::Session<memgraph::communication::v2::InputStream,
|
|
|
|
memgraph::communication::v2::OutputStream> {
|
|
|
|
public:
|
2023-09-20 19:13:54 +08:00
|
|
|
SessionHL(memgraph::query::InterpreterContext *interpreter_context,
|
2023-11-22 21:05:02 +08:00
|
|
|
memgraph::communication::v2::ServerEndpoint endpoint,
|
2023-09-20 19:13:54 +08:00
|
|
|
memgraph::communication::v2::InputStream *input_stream,
|
|
|
|
memgraph::communication::v2::OutputStream *output_stream,
|
|
|
|
memgraph::utils::Synchronized<memgraph::auth::Auth, memgraph::utils::WritePrioritizedRWLock> *auth
|
2023-08-19 00:23:15 +08:00
|
|
|
#ifdef MG_ENTERPRISE
|
2023-09-20 19:13:54 +08:00
|
|
|
,
|
|
|
|
memgraph::audit::Log *audit_log
|
2023-08-19 00:23:15 +08:00
|
|
|
#endif
|
2023-09-20 19:13:54 +08:00
|
|
|
);
|
2023-08-19 00:23:15 +08:00
|
|
|
|
|
|
|
~SessionHL() override;
|
|
|
|
|
|
|
|
SessionHL(const SessionHL &) = delete;
|
|
|
|
SessionHL &operator=(const SessionHL &) = delete;
|
|
|
|
SessionHL(SessionHL &&) = delete;
|
|
|
|
SessionHL &operator=(SessionHL &&) = delete;
|
|
|
|
|
|
|
|
void Configure(const std::map<std::string, memgraph::communication::bolt::Value> &run_time_info) override;
|
|
|
|
|
|
|
|
using TEncoder = memgraph::communication::bolt::Encoder<
|
|
|
|
memgraph::communication::bolt::ChunkedEncoderBuffer<memgraph::communication::v2::OutputStream>>;
|
|
|
|
|
|
|
|
void BeginTransaction(const std::map<std::string, memgraph::communication::bolt::Value> &extra) override;
|
|
|
|
|
|
|
|
void CommitTransaction() override;
|
|
|
|
|
|
|
|
void RollbackTransaction() override;
|
|
|
|
|
|
|
|
std::pair<std::vector<std::string>, std::optional<int>> Interpret(
|
|
|
|
const std::string &query, const std::map<std::string, memgraph::communication::bolt::Value> ¶ms,
|
|
|
|
const std::map<std::string, memgraph::communication::bolt::Value> &extra) override;
|
|
|
|
|
|
|
|
std::map<std::string, memgraph::communication::bolt::Value> Pull(TEncoder *encoder, std::optional<int> n,
|
|
|
|
std::optional<int> qid) override;
|
|
|
|
|
|
|
|
std::map<std::string, memgraph::communication::bolt::Value> Discard(std::optional<int> n,
|
|
|
|
std::optional<int> qid) override;
|
|
|
|
|
|
|
|
void Abort() override;
|
|
|
|
|
|
|
|
// Called during Init
|
|
|
|
bool Authenticate(const std::string &username, const std::string &password) override;
|
|
|
|
|
|
|
|
std::optional<std::string> GetServerNameForInit() override;
|
|
|
|
|
2023-10-05 22:58:39 +08:00
|
|
|
std::string GetCurrentDB() const override;
|
2023-08-19 00:23:15 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<std::string, memgraph::communication::bolt::Value> DecodeSummary(
|
|
|
|
const std::map<std::string, memgraph::query::TypedValue> &summary);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the user's default database
|
|
|
|
*
|
|
|
|
* @return std::string
|
|
|
|
*/
|
|
|
|
std::string GetDefaultDB();
|
|
|
|
|
|
|
|
memgraph::query::InterpreterContext *interpreter_context_;
|
2023-09-20 19:13:54 +08:00
|
|
|
memgraph::query::Interpreter interpreter_;
|
2023-08-19 00:23:15 +08:00
|
|
|
std::optional<memgraph::auth::User> user_;
|
|
|
|
#ifdef MG_ENTERPRISE
|
|
|
|
memgraph::audit::Log *audit_log_;
|
|
|
|
bool in_explicit_db_{false}; //!< If true, the user has defined the database to use via metadata
|
|
|
|
#endif
|
2023-09-20 19:13:54 +08:00
|
|
|
memgraph::utils::Synchronized<memgraph::auth::Auth, memgraph::utils::WritePrioritizedRWLock> *auth_;
|
2023-08-19 00:23:15 +08:00
|
|
|
memgraph::communication::v2::ServerEndpoint endpoint_;
|
2023-09-20 19:13:54 +08:00
|
|
|
std::optional<std::string> implicit_db_;
|
2023-08-19 00:23:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace memgraph::glue
|