Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-16 05:03:40

0001 #include "CondCore/CondDB/interface/CredentialStore.h"
0002 #include "CondCore/CondDB/interface/Auth.h"
0003 //
0004 #include <cstdlib>
0005 #include <cassert>
0006 
0007 namespace cond {
0008 
0009   std::tuple<std::string, std::string, std::string> getDbCredentials(const std::string& connectionString,
0010                                                                      int accessType,
0011                                                                      const std::string& authPath) {
0012     std::string ap = authPath;
0013     if (ap.empty()) {
0014       char* auth_path_env = std::getenv(cond::auth::COND_AUTH_PATH);
0015       assert(auth_path_env);
0016       ap = std::string(auth_path_env);
0017     }
0018     auto ret = std::make_tuple(std::string(""), std::string(""), std::string(""));
0019     if (!ap.empty()) {
0020       CredentialStore credDb;
0021       credDb.setUpForConnectionString(connectionString, ap);
0022       std::string role(cond::auth::s_roleCodeArray[accessType].first);
0023       auto creds = credDb.getUserCredentials(connectionString, role);
0024       ret = std::tie(credDb.keyPrincipalName(), creds.first, creds.second);
0025     }
0026     return ret;
0027   }
0028 
0029 }  // namespace cond
0030 
0031 #include <pybind11/pybind11.h>
0032 
0033 namespace py = pybind11;
0034 
0035 PYBIND11_MODULE(libCondDBPyBind11Interface, m) {
0036   m.def("get_credentials_from_db", &cond::getDbCredentials, "Get db credentials for a connection string");
0037   m.attr("default_role") = pybind11::int_(int(cond::auth::DEFAULT_ROLE));
0038   m.attr("reader_role") = pybind11::int_(int(cond::auth::READER_ROLE));
0039   m.attr("writer_role") = pybind11::int_(int(cond::auth::WRITER_ROLE));
0040   m.attr("admin_role") = pybind11::int_(int(cond::auth::ADMIN_ROLE));
0041 }