Skip to content

Commit

Permalink
Review the management of errors from the REST API
Browse files Browse the repository at this point in the history
* Always process the errors, not only in case an AC has been returned
* For certain errors (user doesn't exist, is suspended, is inactive) do
  not try the legacy endpoint, which doesn't even exist for VOMS AA
* Leave some commented-out debug messages, to be possibly included in
  the output in debug mode (requires some work to propagate the debug
  flag)
  • Loading branch information
giacomini committed Apr 2, 2024
1 parent 2d20ec4 commit 4c487ab
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/api/ccapi/voms_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,18 @@ bool vomsdata::InterpretOutput(const std::string &message, std::string& output)

if (!a.ac.empty()) {
output = a.ac;
if (a.errs.size() != 0) {
std::vector<errorp>::const_iterator end = a.errs.end();
for (std::vector<errorp>::const_iterator i = a.errs.begin();
i != end; ++i) {
serverrors += i->message;
if (i->num > ERROR_OFFSET)
result = false;
if (i->num == WARN_NO_FIRST_SELECT)
seterror(VERR_ORDER, "Cannot put requested attributes in the specified order.");
}
}
}
else if (!a.data.empty()) {
output = a.data;
}
for (std::vector<errorp>::const_iterator i = a.errs.begin(), end = a.errs.end();
i != end; ++i) {
serverrors += i->message;
if (i->num > ERROR_OFFSET)
result = false;
if (i->num == WARN_NO_FIRST_SELECT)
seterror(VERR_ORDER, "Cannot put requested attributes in the specified order.");
}
if (!result && ver_type) {
seterror(VERR_SERVERCODE, "The server returned an error.");
return false;
Expand Down Expand Up @@ -289,9 +286,15 @@ bool vomsdata::ContactRaw(std::string hostname, int port, std::string servsubjec
/* Try REST connection first */
bool ret = ContactRESTRaw(hostname, port, command, raw, version, timeout);

if (ret)
if (ret
|| serverrors.find("User unknown to this VO") != std::string::npos
|| serverrors.find("suspended") != std::string::npos
|| serverrors.find("not active") != std::string::npos)
return ret;

// reset the errors
serverrors.clear();

std::vector<std::string>::const_iterator end = targets.end();
std::vector<std::string>::const_iterator begin = targets.begin();
for (std::vector<std::string>::const_iterator i = begin; i != end; ++i) {
Expand All @@ -303,8 +306,12 @@ bool vomsdata::ContactRaw(std::string hostname, int port, std::string servsubjec

comm = XML_Req_Encode(command, ordering, targs, duration);

if (!contact(hostname, port, servsubject, comm, buffer, subject, ca, timeout))
ret = contact(hostname, port, servsubject, comm, buffer, subject, ca, timeout);
// std::cerr << '\n' << comm << '\n' << buffer << '\n';

if (!ret) {
return false;
}

version = 1;
return InterpretOutput(buffer, raw);
Expand Down Expand Up @@ -359,6 +366,8 @@ bool vomsdata::ContactRESTRaw(const std::string& hostname, int port, const std::
std::string user, userca, output;
bool res = contact(hostname, port, "", realCommand, output, user, userca, timeout);

// std::cerr << '\n' << realCommand << '\n' << output << '\n';

bool ret = false;

if (res) {
Expand Down

0 comments on commit 4c487ab

Please sign in to comment.