[ra_tls] improve error handle

This commit is contained in:
Zheng, Qi 2023-02-28 11:57:13 +08:00 committed by volcano
parent c72a46bd41
commit bfa204c295

@ -54,7 +54,7 @@ class GrSecretClient {
return reply.secret(); return reply.secret();
} else { } else {
std::cout << status.error_code() << ": " << status.error_message() << std::endl; std::cout << status.error_code() << ": " << status.error_message() << std::endl;
return "RPC failed"; return "";
} }
} }
@ -128,21 +128,27 @@ int grpc_ratls_get_secret(
GrSecretClient gr_secret(channel); GrSecretClient gr_secret(channel);
std::string secret = gr_secret.GetSecret(name); std::string secret = gr_secret.GetSecret(name);
//std::cout << "secret received: " << secret << std::endl; // std::cout << "secret received: " << secret << "len: " << secret.length() << std::endl;
//Decode From Base64 if (secret.empty()) {
size_t len = base64_decode_len(secret.c_str()); return -1;
if (len) { } else {
char *secret_orig = (char *)malloc(len); //Decode From Base64
base64_decode(secret.c_str(), (unsigned char *)secret_orig, len); size_t len = base64_decode_len(secret.c_str());
std::string secret_string(secret_orig, secret_orig + len - 1); if (len) {
char *secret_orig = (char *)malloc(len);
base64_decode(secret.c_str(), (unsigned char *)secret_orig, len);
std::string secret_string(secret_orig, secret_orig + len - 1);
//write to file //write to file
std::ofstream myfile; std::ofstream myfile;
myfile.open(secret_file); myfile.open(secret_file);
myfile << secret_string; myfile << secret_string;
myfile.close(); myfile.close();
return 0;
}
return -2;
} }
return 0;
} }