Update QueryServer to use AuthenticatedMarketDataRelayBase
This commit is contained in:
1 parent
ad8e803a8c
commit
ba4b6aa1ff
3 files changed
+21
-19
No files matched your search
@@ -387,7 +387,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
struct MDRelayServer : bts::co2::MarketDataRelayBase {
|
||||
struct MDRelayServer : bts::co2::AuthenticatedMarketDataRelayBase {
|
||||
const QueryServerImpl& _db;
|
||||
utils::Dispatcher& _threadpool;
|
||||
std::shared_ptr<std::unordered_map<uint32_t,Entitlements>> _entitlements;
|
||||
@@ -396,7 +396,7 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase {
|
||||
#endif
|
||||
|
||||
MDRelayServer(const QueryServerImpl& db, utils::Dispatcher& threadpool, bts::api::ServiceContext ctx, metrics::MetricsContainer& stats) :
|
||||
bts::co2::MarketDataRelayBase(ctx),
|
||||
bts::co2::AuthenticatedMarketDataRelayBase(ctx),
|
||||
_db(db), _threadpool(threadpool), _entitlements()
|
||||
#ifndef _WIN32
|
||||
, _time(std::make_shared<metrics::HistogramMetric<5>>("spark_qserver_response_time_ms", std::array<double,5>({ 5.0, 10.0, 20.0, 50.0, 100.0 }))),
|
||||
@@ -412,6 +412,7 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase {
|
||||
void update_entitlements(std::shared_ptr<std::unordered_map<uint32_t, Entitlements>>& entitlements) {
|
||||
_entitlements = entitlements;
|
||||
}
|
||||
|
||||
static const Entitlements* get_entitlements(uint32_t user_id, std::shared_ptr<std::unordered_map<uint32_t,Entitlements>>& entitlements) {
|
||||
if (entitlements) {
|
||||
auto iter = entitlements->find(user_id);
|
||||
@@ -422,7 +423,7 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual void requestmd(const MDRequest& request, const std::function<void(const MDReply&)>& reply) override {
|
||||
virtual void requestmd(const api::AuthToken& token, const MDRequest& request, const std::function<void(const MDReply&)>& reply) override {
|
||||
TimeStamp start = TimeStamp::now();
|
||||
_threadpool.post([=]() {
|
||||
google::protobuf::Arena arena;
|
||||
@@ -432,13 +433,12 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase {
|
||||
auto ents = _entitlements;
|
||||
const Entitlements* user_entitlement = nullptr;
|
||||
bool bypass_entitlement = false;
|
||||
if (api::auth::decode_token(request.token(), &payload)) {
|
||||
if (api::auth::decode_token(token, &payload)) {
|
||||
bypass_entitlement = payload.wheel();
|
||||
if (!bypass_entitlement) {
|
||||
user_entitlement = get_entitlements(payload.id(), ents);
|
||||
}
|
||||
}
|
||||
// Temporarily bypass all entitlements
|
||||
_db.query(request, preply, user_entitlement, bypass_entitlement);
|
||||
reply(*preply);
|
||||
#ifndef _WIN32
|
||||
@@ -449,7 +449,7 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase {
|
||||
});
|
||||
}
|
||||
|
||||
virtual void request_products(const api::VoidMessage&, const std::function<void(const ProductListReply&)>& reply) override {
|
||||
virtual void request_products(const api::AuthToken&, const api::VoidMessage&, const std::function<void(const ProductListReply&)>& reply) override {
|
||||
ProductListReply list;
|
||||
std::set<UserSymbol> syms;
|
||||
get_system_md_symbols(syms);
|
||||
@@ -463,7 +463,7 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase {
|
||||
reply(list);
|
||||
}
|
||||
|
||||
virtual void request_names(const api::VoidMessage&, const std::function<void(const ExpirationNameListReply&)>& reply) override {
|
||||
virtual void request_names(const api::AuthToken&, const api::VoidMessage&, const std::function<void(const ExpirationNameListReply&)>& reply) override {
|
||||
_threadpool.post([=]() {
|
||||
google::protobuf::Arena arena;
|
||||
ExpirationNameListReply* preply = google::protobuf::Arena::CreateMessage<ExpirationNameListReply>(&arena);
|
||||
|
||||
Reference in new issue
Block a user