Skip to content

Commit

Permalink
[Feature] Add http GET method to get the enterprise license content (v…
Browse files Browse the repository at this point in the history
…esoft-inc#671)

* Add http method to get the enterprise license content

* Add http method to get the enterprise license content

* Update cmakelist to fix compiling

Co-authored-by: jimingquan <mingquan.ji@vesoft.com>
  • Loading branch information
Aiee and nevermore3 authored Mar 16, 2022
1 parent 08788fd commit d3a6b6c
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/codec/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(CODEC_TEST_LIBS
$<TARGET_OBJECTS:drainer_thrift_obj>
$<TARGET_OBJECTS:meta_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:file_based_cluster_id_man_obj>
Expand Down
1 change: 1 addition & 0 deletions src/common/http/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nebula_add_test(
OBJECTS
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
Expand Down
2 changes: 2 additions & 0 deletions src/common/id/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ nebula_add_executable(
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:expression_obj>
$<TARGET_OBJECTS:encryption_obj>
LIBRARIES
follybenchmark
boost_regex
Expand Down Expand Up @@ -72,6 +73,7 @@ nebula_add_test(
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:expression_obj>
$<TARGET_OBJECTS:encryption_obj>
LIBRARIES
gtest
gtest_main
Expand Down
1 change: 1 addition & 0 deletions src/drainer/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(drainer_test_deps
$<TARGET_OBJECTS:drainer_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:stats_obj>
Expand Down
1 change: 1 addition & 0 deletions src/graph/executor/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

SET(EXEC_QUERY_TEST_OBJS
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:expression_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:process_obj>
Expand Down
1 change: 1 addition & 0 deletions src/graph/planner/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ nebula_add_test(
$<TARGET_OBJECTS:thrift_obj>
$<TARGET_OBJECTS:meta_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:time_obj>
Expand Down
1 change: 1 addition & 0 deletions src/kvstore/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(KVSTORE_TEST_LIBS
$<TARGET_OBJECTS:meta_obj>
$<TARGET_OBJECTS:meta_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:meta_thrift_obj>
Expand Down
1 change: 1 addition & 0 deletions src/meta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ set(meta_test_deps
$<TARGET_OBJECTS:meta_client_obj>
$<TARGET_OBJECTS:file_based_cluster_id_man_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:raftex_thrift_obj>
Expand Down
1 change: 1 addition & 0 deletions src/storage/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(storage_test_deps
$<TARGET_OBJECTS:log_str_list_iterator_obj>
$<TARGET_OBJECTS:codec_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:storage_thrift_obj>
Expand Down
1 change: 1 addition & 0 deletions src/webservice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nebula_add_library(
GetStatsHandler.cpp
Router.cpp
StatusHandler.cpp
GetLicenseHandler.cpp
)

set_target_properties(ws_obj PROPERTIES COMPILE_FLAGS "-Wno-error=format-security")
Expand Down
72 changes: 72 additions & 0 deletions src/webservice/GetLicenseHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Copyright (c) 2022 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include "webservice/GetLicenseHandler.h"

#include <proxygen/httpserver/RequestHandler.h>
#include <proxygen/httpserver/ResponseBuilder.h>
#include <proxygen/lib/http/ProxygenErrorEnum.h>

#include "common/encryption/License.h"

namespace nebula {

using proxygen::HTTPMessage;
using proxygen::HTTPMethod;
using proxygen::ProxygenError;
using proxygen::ResponseBuilder;
using proxygen::UpgradeProtocol;

void GetLicenseHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
if (headers->getMethod().value() != HTTPMethod::GET) {
// Unsupported method
err_ = HttpCode::E_UNSUPPORTED_METHOD;
return;
}
}

void GetLicenseHandler::onBody(std::unique_ptr<folly::IOBuf>) noexcept {
// Do nothing, we only support GET
}

void GetLicenseHandler::onEOM() noexcept {
switch (err_) {
case HttpCode::E_UNSUPPORTED_METHOD:
ResponseBuilder(downstream_)
.status(WebServiceUtils::to(HttpStatusCode::METHOD_NOT_ALLOWED),
WebServiceUtils::toString(HttpStatusCode::METHOD_NOT_ALLOWED))
.sendWithEOM();
return;
default:
break;
}

folly::dynamic vals = getLicense();
ResponseBuilder(downstream_)
.status(WebServiceUtils::to(HttpStatusCode::OK),
WebServiceUtils::toString(HttpStatusCode::OK))
.body(folly::toJson(vals))
.sendWithEOM();
}

void GetLicenseHandler::onUpgrade(UpgradeProtocol) noexcept {
// Do nothing
}

void GetLicenseHandler::requestComplete() noexcept {
delete this;
}

void GetLicenseHandler::onError(ProxygenError error) noexcept {
LOG(ERROR) << "Web service StorageHttpHandler got error: " << proxygen::getErrorString(error);
}

const folly::dynamic GetLicenseHandler::getLicense() const {
auto licenseIns = encryption::License::getInstance();
auto licenseContent = licenseIns->getContent();
return licenseContent;
}

} // namespace nebula
43 changes: 43 additions & 0 deletions src/webservice/GetLicenseHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright (c) 2022 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#ifndef WEBSERVICE_GETLICENSEHANDLER_H_
#define WEBSERVICE_GETLICENSEHANDLER_H_

#include <folly/dynamic.h>
#include <proxygen/httpserver/RequestHandler.h>

#include "common/base/Base.h"
#include "webservice/Common.h"

namespace nebula {

class GetLicenseHandler : public proxygen::RequestHandler {
public:
GetLicenseHandler() = default;

void onRequest(std::unique_ptr<proxygen::HTTPMessage> headers) noexcept override;

void onBody(std::unique_ptr<folly::IOBuf> body) noexcept override;

void onEOM() noexcept override;

void onUpgrade(proxygen::UpgradeProtocol proto) noexcept override;

void requestComplete() noexcept override;

void onError(proxygen::ProxygenError err) noexcept override;

protected:
const folly::dynamic getLicense() const;

protected:
HttpCode err_{HttpCode::SUCCEEDED};
bool returnJson_{false};
std::vector<std::string> statNames_;
};

} // namespace nebula
#endif // WEBSERVICE_GETLICENSEHANDLER_H_
6 changes: 6 additions & 0 deletions src/webservice/WebService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "common/thread/NamedThread.h"
#include "webservice/GetFlagsHandler.h"
#include "webservice/GetLicenseHandler.h"
#include "webservice/GetStatsHandler.h"
#include "webservice/NotFoundHandler.h"
#include "webservice/Router.h"
Expand Down Expand Up @@ -86,6 +87,11 @@ Status WebService::start(uint16_t httpPort) {
DCHECK(params.empty());
return new StatusHandler();
});
// License
router().get("/license").handler([](web::PathParams&& params) {
DCHECK(params.empty());
return new GetLicenseHandler();
});

started_ = true;

Expand Down
75 changes: 31 additions & 44 deletions src/webservice/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
#
# This source code is licensed under Apache 2.0 License.

set(ws_test_deps
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:version_obj>
$<TARGET_OBJECTS:wkt_wkb_io_obj>
$<TARGET_OBJECTS:encryption_obj>
)

nebula_add_test(
NAME
flags_access_test
SOURCES
FlagsAccessTest.cpp
OBJECTS
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:version_obj>
$<TARGET_OBJECTS:wkt_wkb_io_obj>
${ws_test_deps}
LIBRARIES
${PROXYGEN_LIBRARIES}
gtest
Expand All @@ -31,17 +36,7 @@ nebula_add_test(
SOURCES
StatsReaderTest.cpp
OBJECTS
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:version_obj>
$<TARGET_OBJECTS:wkt_wkb_io_obj>
${ws_test_deps}
LIBRARIES
${PROXYGEN_LIBRARIES}
gtest
Expand All @@ -54,17 +49,7 @@ nebula_add_test(
SOURCES
RouterTest.cpp
OBJECTS
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:version_obj>
$<TARGET_OBJECTS:wkt_wkb_io_obj>
${ws_test_deps}
LIBRARIES
${PROXYGEN_LIBRARIES}
gtest
Expand All @@ -76,17 +61,19 @@ nebula_add_test(
SOURCES
StatusHandlerTest.cpp
OBJECTS
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:version_obj>
$<TARGET_OBJECTS:wkt_wkb_io_obj>
${ws_test_deps}
LIBRARIES
${PROXYGEN_LIBRARIES}
gtest
)

nebula_add_test(
NAME
http_license_test
SOURCES
LicenseHandlerTest.cpp
OBJECTS
${ws_test_deps}
LIBRARIES
${PROXYGEN_LIBRARIES}
gtest
Expand Down
Loading

0 comments on commit d3a6b6c

Please sign in to comment.