forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add http GET method to get the enterprise license content (v…
…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
1 parent
08788fd
commit d3a6b6c
Showing
15 changed files
with
240 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.