CMS 3D CMS Logo

CondDBPyBind11Wrappers.cc
Go to the documentation of this file.
3 //
4 #include <cstdlib>
5 #include <cassert>
6 
7 namespace cond {
8 
9  std::tuple<std::string, std::string, std::string> getDbCredentials(const std::string& connectionString,
10  int accessType,
11  const std::string& authPath) {
12  std::string ap = authPath;
13  if (ap.empty()) {
14  char* auth_path_env = std::getenv(cond::auth::COND_AUTH_PATH);
15  assert(auth_path_env);
16  ap = std::string(auth_path_env);
17  }
18  auto ret = std::make_tuple(std::string(""), std::string(""), std::string(""));
19  if (!ap.empty()) {
20  CredentialStore credDb;
23  auto creds = credDb.getUserCredentials(connectionString, role);
24  ret = std::tie(credDb.keyPrincipalName(), creds.first, creds.second);
25  }
26  return ret;
27  }
28 
29 } // namespace cond
30 
31 #include <pybind11/pybind11.h>
32 
33 namespace py = pybind11;
34 
35 PYBIND11_MODULE(libCondDBPyBind11Interface, m) {
36  m.def("get_credentials_from_db", &cond::getDbCredentials, "Get db credentials for a connection string");
37  m.attr("default_role") = pybind11::int_(int(cond::auth::DEFAULT_ROLE));
38  m.attr("reader_role") = pybind11::int_(int(cond::auth::READER_ROLE));
39  m.attr("writer_role") = pybind11::int_(int(cond::auth::WRITER_ROLE));
40  m.attr("admin_role") = pybind11::int_(int(cond::auth::ADMIN_ROLE));
41 }
std::pair< std::string, std::string > getUserCredentials(const std::string &connectionString, const std::string &role)
PYBIND11_MODULE(libCondDBPyBind11Interface, m)
const std::string & keyPrincipalName()
std::tuple< std::string, std::string, std::string > getDbCredentials(const std::string &connectionString, int accessType, const std::string &authPath)
ret
prodAgent to be discontinued
static constexpr const char *const COND_AUTH_PATH
Definition: Auth.h:11
assert(be >=bs)
std::string setUpForConnectionString(const std::string &connectionString, const std::string &authPath)
static const std::pair< const char *, RoleCode > s_roleCodeArray[]
Definition: Auth.h:28