Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-06 09:39:49

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