std::string http_auth::generate_signature(const swarm::http_request &request, const std::string &key) { const auto &url = request.url(); const auto &query = url.query(); const auto &original_headers = request.headers().all(); std::vector<swarm::headers_entry> headers; for (auto it = original_headers.begin(); it != original_headers.end(); ++it) { std::string name = to_lower(it->first); if (name.compare(0, 6, "x-ell-") == 0) { headers.emplace_back(std::move(name), it->second); } } std::sort(headers.begin(), headers.end()); std::vector<std::pair<std::string, std::string> > query_items; for (size_t i = 0; i < query.count(); ++i) { const auto &item = query.item(i); query_items.emplace_back(to_lower(item.first), item.second); } std::sort(query_items.begin(), query_items.end()); swarm::url result_url; result_url.set_path(url.path()); for (auto it = query_items.begin(); it != query_items.end(); ++it) { result_url.query().add_item(it->first, it->second); } std::string text = request.method(); text += '\n'; text += result_url.to_string(); text += '\n'; for (auto it = headers.begin(); it != headers.end(); ++it) { text += it->first; text += ':'; text += it->second; text += '\n'; } check_hash(key); check_hash(text); dnet_raw_id signature; char signature_str[DNET_ID_SIZE * 2 + 1]; dnet_digest_auth_transform_raw(text.c_str(), text.size(), key.c_str(), key.size(), signature.id, DNET_ID_SIZE); dnet_dump_id_len_raw(signature.id, DNET_ID_SIZE, signature_str); return signature_str; }
elliptics::session extract_key(const swarm::http_request &request, const rift::bucket_meta_raw &meta, elliptics::key &key) const { const auto &query = request.url().query(); if (auto name = query.item_value("name")) { key = *name; } else if (auto sid = query.item_value("id")) { struct dnet_id id; memset(&id, 0, sizeof(struct dnet_id)); dnet_parse_numeric_id(sid->c_str(), id.id); key = id; } elliptics::session session = m_elliptics.session(); if (meta.groups.size() && meta.key.size()) { session.set_namespace(meta.key.c_str(), meta.key.size()); session.set_groups(meta.groups); } session.transform(key); return session; }
bool query_ok(const swarm::http_request &request) const { const auto &query = request.url().query(); if (auto name = query.item_value("name")) { return true; } else if (auto sid = query.item_value("id")) { if (m_noauth_allowed) return true; } return false; }
void process(const swarm::http_request &request, const boost::asio::const_buffer &buffer, const rift::continue_handler_t &continue_handler) const { auto ns = request.url().query().item_value("namespace"); if (!ns || !m_bucket) { auto verdict = swarm::http_response::bad_request; if (m_noauth_allowed || !m_bucket) verdict = swarm::http_response::ok; rift::bucket_meta_raw meta; continue_handler(request, buffer, meta, verdict); } else { m_bucket->check(*ns, request, buffer, continue_handler); } }
virtual void on_request(const swarm::http_request &req, const boost::asio::const_buffer &buffer) { using namespace std::placeholders; (void) buffer; ioremap::swarm::url url(req.url()); ioremap::swarm::url_query query(url.query()); if (auto text = query.item_value("text")) { ioremap::wookie::operators op(server()->get_storage()); shared_find_t fobj = op.find(*text); } else { send_reply(ioremap::swarm::url_fetcher::response::bad_request); } }
virtual void on_request(const swarm::http_request &req, const boost::asio::const_buffer &buffer) { const swarm::url_query &query_list = req.url().query(); ioremap::elliptics::session sess = this->server()->elliptics()->session(); auto base_index = query_list.item_value("base_index"); auto name = query_list.item_value("name"); if (!base_index || !name) { this->send_reply(ioremap::swarm::http_response::bad_request); return; } m_base_index = *base_index; m_doc.data.assign(boost::asio::buffer_cast<const char*>(buffer), boost::asio::buffer_size(buffer)); m_doc.key = *name; sess.write_data(m_doc.key, std::move(storage::pack_document(m_doc)), 0) .connect(std::bind(&on_upload<T>::on_write_finished_update_index, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2)); }
ioremap::swarm::http_response::status_type elliptics_base::process(const swarm::http_request &request, ioremap::elliptics::key &key, ioremap::elliptics::session &session) const { const auto &query = request.url().query(); if (auto name = query.item_value("name")) { key = *name; } else if (auto sid = query.item_value("id")) { struct dnet_id id; memset(&id, 0, sizeof(struct dnet_id)); dnet_parse_numeric_id(sid->c_str(), id.id); key = id; } else { return ioremap::swarm::http_response::bad_request; } session.transform(key); (void) session; return ioremap::swarm::http_response::ok; }