Skip to content
Snippets Groups Projects
Commit d158257f authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan :coffee:
Browse files

frontend-grpc: validate user request arguments

parent 4a941a95
Branches v4.8.2-1
No related tags found
No related merge requests found
......@@ -37,14 +37,33 @@ Status CtaRpcImpl::Archive(::grpc::ServerContext* context, const ::cta::dcache::
sp.add("request", "archive");
const std::string storageClass = request->file().storageclass();
if (storageClass.empty()) {
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Storage class is not set.");
}
lc.log(cta::log::DEBUG, "Archive request for storageClass: " + storageClass);
cta::common::dataStructures::RequesterIdentity requester;
requester.name = request->cli().user().username();
requester.group = request->cli().user().groupname();
auto instance = request->instance().name();
// check validate request args
if (request->instance().name().empty()) {
lc.log(cta::log::WARNING, "CTA instance is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA instance is not set.");
}
if (request->cli().user().username().empty()) {
lc.log(cta::log::WARNING, "CTA username is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA username is not set.");
}
if (request->cli().user().groupname().empty()) {
lc.log(cta::log::WARNING, "CTA groupname is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA groupname is not set.");
}
auto instance = request->instance().name();
sp.add("instance", instance);
sp.add("username", request->cli().user().username());
sp.add("groupname", request->cli().user().groupname());
......@@ -102,6 +121,27 @@ Status CtaRpcImpl::Delete(::grpc::ServerContext* context, const ::cta::dcache::r
lc.log(cta::log::DEBUG, "Delete request");
sp.add("request", "delete");
// check validate request args
if (request->instance().name().empty()) {
lc.log(cta::log::WARNING, "CTA instance is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA instance is not set.");
}
if (request->cli().user().username().empty()) {
lc.log(cta::log::WARNING, "CTA username is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA username is not set.");
}
if (request->cli().user().groupname().empty()) {
lc.log(cta::log::WARNING, "CTA groupname is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA groupname is not set.");
}
if (request->archiveid() == 0) {
lc.log(cta::log::WARNING, "Invalid archive file id");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Invalid archive file id.");
}
auto instance = request->instance().name();
// Unpack message
cta::common::dataStructures::DeleteArchiveRequest deleteRequest;
......@@ -148,8 +188,33 @@ Status CtaRpcImpl::Retrieve(::grpc::ServerContext* context, const ::cta::dcache:
sp.add("request", "retrieve");
const std::string storageClass = request->file().storageclass();
if (storageClass.empty()) {
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Storage class is not set.");
}
lc.log(cta::log::DEBUG, "Retrieve request for storageClass: " + storageClass);
// check validate request args
if (request->instance().name().empty()) {
lc.log(cta::log::WARNING, "CTA instance is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA instance is not set.");
}
if (request->cli().user().username().empty()) {
lc.log(cta::log::WARNING, "CTA username is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA username is not set.");
}
if (request->cli().user().groupname().empty()) {
lc.log(cta::log::WARNING, "CTA groupname is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA groupname is not set.");
}
if (request->archiveid() == 0) {
lc.log(cta::log::WARNING, "Invalid archive file id");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Invalid archive file id.");
}
auto instance = request->instance().name();
sp.add("instance", instance);
......@@ -205,6 +270,27 @@ Status CtaRpcImpl::CancelRetrieve(::grpc::ServerContext* context, const ::cta::d
lc.log(cta::log::DEBUG, "CancelRetrieve request");
sp.add("request", "cancel");
// check validate request args
if (request->instance().name().empty()) {
lc.log(cta::log::WARNING, "CTA instance is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA instance is not set.");
}
if (request->cli().user().username().empty()) {
lc.log(cta::log::WARNING, "CTA username is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA username is not set.");
}
if (request->cli().user().groupname().empty()) {
lc.log(cta::log::WARNING, "CTA groupname is not set");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "CTA groupname is not set.");
}
if (request->fid() == 0) {
lc.log(cta::log::WARNING, "Invalid archive file id");
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Invalid archive file id.");
}
auto instance = request->instance().name();
// Unpack message
cta::common::dataStructures::CancelRetrieveRequest cancelRequest;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment