Added safeguard against unknown operations

This commit is contained in:
Uwe Seimet 2021-12-18 13:35:40 +01:00
parent 6b14ba6511
commit b8599ba088
3 changed files with 33 additions and 25 deletions

View File

@ -173,10 +173,12 @@ message PbOperationParameter {
// The list of parameters supported by an operation
message PbOperationMetaData {
// The operation name at the time the server-side protobuf code was generated.
string name = 1;
// Optional short localized description, key is the lower case locale (e.g. en, de).
// Falling back to "en" is recommended if a description for a particular language is missing.
map<string, string> description = 1;
repeated PbOperationParameter parameters = 2;
map<string, string> description = 2;
repeated PbOperationParameter parameters = 3;
}
// Mapping of operations to their ordinals

View File

@ -467,6 +467,7 @@ PbOperationInfo *RascsiResponse::GetOperationInfo(PbResult& result)
void RascsiResponse::CreateOperation(PbOperationInfo *operation_info, PbOperationMetaData *meta_data,
const PbOperation& operation, const string& description)
{
meta_data->set_name(PbOperation_Name(operation));
(*meta_data->mutable_description())["en"] = description;
int ordinal = PbOperation_descriptor()->FindValueByName(PbOperation_Name(operation))->index();
(*operation_info->mutable_operations())[ordinal] = *meta_data;

View File

@ -281,7 +281,8 @@ void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info)
cout << "Remote operations supported by rascsi and their parameters:" << endl;
for (const auto& operation : operations) {
cout << " " << PbOperation_Name(operation.first);
if (PbOperation_IsValid(operation.first)) {
cout << " " << PbOperation_Name(static_cast<PbOperation>(operation.first));
if (!operation.second.description().empty()) {
cout << " (" << operation.second.description().at("en") << ")";
}
@ -313,4 +314,8 @@ void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info)
}
}
}
else {
cout << " " << operation.second.name() << " (Unknown server-side operation)" << endl;
}
}
}