mirror of https://gitee.com/bigwinds/arangodb
do allow input to /_api/aqlfunction choose between (#4603)
This commit is contained in:
parent
101a9893a4
commit
9d311aac65
|
@ -39,7 +39,6 @@ RestAqlUserFunctionsHandler::RestAqlUserFunctionsHandler(GeneralRequest* request
|
|||
: RestVocbaseBaseHandler(request, response) {}
|
||||
|
||||
RestStatus RestAqlUserFunctionsHandler::execute() {
|
||||
|
||||
auto const type = _request->requestType();
|
||||
|
||||
if (type == rest::RequestType::POST) {
|
||||
|
@ -78,8 +77,7 @@ RestStatus RestAqlUserFunctionsHandler::execute() {
|
|||
generateError(res);
|
||||
}
|
||||
return RestStatus::DONE;
|
||||
}
|
||||
else if (type == rest::RequestType::DELETE_REQ) {
|
||||
} else if (type == rest::RequestType::DELETE_REQ) {
|
||||
// JSF_delete_api_aqlfunction.md
|
||||
// DELETE /_api/aqlfunction/{name}
|
||||
std::vector<std::string> const& suffixes = _request->decodedSuffixes();
|
||||
|
@ -110,24 +108,31 @@ RestStatus RestAqlUserFunctionsHandler::execute() {
|
|||
generateError(res);
|
||||
}
|
||||
return RestStatus::DONE;
|
||||
} // DELETE
|
||||
else if (type == rest::RequestType::GET) {
|
||||
// DELETE
|
||||
} else if (type == rest::RequestType::GET) {
|
||||
// JSF_get_api_aqlfunction.md
|
||||
// GET /_api/aqlfunction - figure out parameters - function namespace
|
||||
std::string functionNamespace;
|
||||
std::vector<std::string> const& suffixes = _request->decodedSuffixes();
|
||||
|
||||
|
||||
if ((suffixes.size() != 1) || suffixes[0].empty() ) {
|
||||
extractStringParameter(StaticStrings::Prefix, functionNamespace);
|
||||
if (functionNamespace.empty()) {
|
||||
generateError(rest::ResponseCode::BAD, TRI_ERROR_HTTP_SUPERFLUOUS_SUFFICES,
|
||||
"superfluous suffix, expecting _api/aqlfunction/[<functionname or prefix>|?" +
|
||||
StaticStrings::Prefix + "=<functionname or prefix>]");
|
||||
return RestStatus::DONE;
|
||||
if (!suffixes.empty()) {
|
||||
if ((suffixes.size() != 1) || suffixes[0].empty() ) {
|
||||
extractStringParameter(StaticStrings::Prefix, functionNamespace);
|
||||
if (functionNamespace.empty()) {
|
||||
generateError(rest::ResponseCode::BAD, TRI_ERROR_HTTP_SUPERFLUOUS_SUFFICES,
|
||||
"superfluous suffix, expecting _api/aqlfunction/[<functionname or prefix>|?" +
|
||||
StaticStrings::Prefix + "=<functionname or prefix>]");
|
||||
return RestStatus::DONE;
|
||||
}
|
||||
} else {
|
||||
functionNamespace = suffixes[0];
|
||||
}
|
||||
} else {
|
||||
functionNamespace = suffixes[0];
|
||||
extractStringParameter(StaticStrings::Prefix, functionNamespace);
|
||||
if (functionNamespace.empty()) {
|
||||
// compatibility mode
|
||||
extractStringParameter(StaticStrings::Namespace, functionNamespace);
|
||||
}
|
||||
}
|
||||
|
||||
// internal get
|
||||
|
@ -135,7 +140,7 @@ RestStatus RestAqlUserFunctionsHandler::execute() {
|
|||
auto res = toArrayUserFunctions(_vocbase, functionNamespace, arrayOfFunctions);
|
||||
|
||||
// error handling
|
||||
if(res.ok()){
|
||||
if (res.ok()) {
|
||||
generateOk(rest::ResponseCode::OK, arrayOfFunctions.slice());
|
||||
} else {
|
||||
generateError(res);
|
||||
|
|
|
@ -291,7 +291,6 @@ Result arangodb::registerUserFunction(TRI_vocbase_t* vocbase,
|
|||
opOptions.isRestore = false;
|
||||
opOptions.waitForSync = true;
|
||||
opOptions.silent = false;
|
||||
opOptions.isSynchronousReplicationFrom = true;
|
||||
|
||||
// find and load collection given by name or identifier
|
||||
auto ctx = transaction::StandaloneContext::Create(vocbase);
|
||||
|
@ -324,9 +323,12 @@ Result arangodb::registerUserFunction(TRI_vocbase_t* vocbase,
|
|||
Result arangodb::toArrayUserFunctions(TRI_vocbase_t* vocbase,
|
||||
std::string const& functionFilterPrefix,
|
||||
velocypack::Builder& result) {
|
||||
std::string aql;
|
||||
auto binds = std::make_shared<VPackBuilder>();
|
||||
binds->openObject();
|
||||
if (! functionFilterPrefix.empty()) {
|
||||
if (!functionFilterPrefix.empty()) {
|
||||
aql = "FOR function IN @@col FILTER LEFT(function._key, @fnLength) == @ucName RETURN function";
|
||||
|
||||
std::string uc(functionFilterPrefix);
|
||||
basics::StringUtils::toupperInPlace(&uc);
|
||||
if ((uc.length() < 2) ||
|
||||
|
@ -336,16 +338,12 @@ Result arangodb::toArrayUserFunctions(TRI_vocbase_t* vocbase,
|
|||
}
|
||||
binds->add("fnLength", VPackValue(uc.length()));
|
||||
binds->add("ucName", VPackValue(uc));
|
||||
} else {
|
||||
aql = "FOR function IN @@col RETURN function";
|
||||
}
|
||||
binds->add("@col", VPackValue(collectionName));
|
||||
binds->close();
|
||||
|
||||
std::string const aql(
|
||||
"FOR function IN @@col "
|
||||
"FILTER LEFT(function._key, @fnLength) == @ucName "
|
||||
"RETURN function"
|
||||
);
|
||||
|
||||
arangodb::aql::Query query(false, vocbase, arangodb::aql::QueryString(aql),
|
||||
binds, nullptr, arangodb::aql::PART_MAIN);
|
||||
|
||||
|
|
|
@ -58,8 +58,9 @@ std::string const StaticStrings::WaitForSyncString("waitForSync");
|
|||
std::string const StaticStrings::IsSynchronousReplicationString(
|
||||
"isSynchronousReplication");
|
||||
std::string const StaticStrings::Group("group");
|
||||
std::string const StaticStrings::ReplaceExisting("replaceExisting");
|
||||
std::string const StaticStrings::Namespace("namespace");
|
||||
std::string const StaticStrings::Prefix("prefix");
|
||||
std::string const StaticStrings::ReplaceExisting("replaceExisting");
|
||||
|
||||
// replication headers
|
||||
std::string const StaticStrings::ReplicationHeaderCheckMore("x-arango-replication-checkmore");
|
||||
|
|
|
@ -63,6 +63,7 @@ class StaticStrings {
|
|||
static std::string const WaitForSyncString;
|
||||
static std::string const IsSynchronousReplicationString;
|
||||
static std::string const Group;
|
||||
static std::string const Namespace;
|
||||
static std::string const ReplaceExisting;
|
||||
static std::string const Prefix;;
|
||||
|
||||
|
|
Loading…
Reference in New Issue