in metadata/src/metadata.cpp [150:202]
int write_meta_data_json( std::list<krb_ticket_info_t*> krb_ticket_info_list,
std::string lease_id, std::string krb_files_dir )
{
try
{
std::string meta_file_name = lease_id + "_metadata.json";
std::string file_path = krb_files_dir + "/" + lease_id + "/" + meta_file_name;
// create the meta file in the lease directory
std::filesystem::path dirPath( file_path );
std::filesystem::create_directories( dirPath.parent_path() );
// parse the kerberos info and serialize to json
Json::Value root;
Json::Value krb_ticket_info_parent;
for ( auto krb_ticket_info : krb_ticket_info_list )
{
Json::Value ticket_info;
ticket_info["krb_file_path"] = krb_ticket_info->krb_file_path;
ticket_info["service_account_name"] = krb_ticket_info->service_account_name;
ticket_info["domain_name"] = krb_ticket_info->domain_name;
ticket_info["domainless_user"] = krb_ticket_info->domainless_user;
ticket_info["credspec_info"] = krb_ticket_info->credspec_info;
ticket_info["distinguished_name"] = krb_ticket_info->distinguished_name;
krb_ticket_info_parent.append( ticket_info );
}
root["krb_ticket_info"] = krb_ticket_info_parent;
Json::StreamWriterBuilder writer;
std::string jsonString = Json::writeString( writer, root );
std::ofstream json_file( file_path );
if ( json_file.is_open() )
{
json_file << jsonString;
json_file.close();
}
else
{
std::cout << Util::getCurrentTime() << '\t' << "ERROR: Failed to write JSON file: " << file_path << std::endl;
}
}
catch ( const std::exception& ex )
{
std::cout << Util::getCurrentTime() << '\t' << "ERROR: '" << ex.what() << "'!" << std::endl;
std::cout << Util::getCurrentTime() << '\t' << "ERROR: failed to write meta data file" <<
std::endl;
return -1;
}
return 0;
}