Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:24

0001 #ifndef CondCore_CondDB_DecodingKey_h
0002 #define CondCore_CondDB_DecodingKey_h
0003 
0004 #include <iostream>
0005 #include <string>
0006 #include <set>
0007 #include <map>
0008 
0009 namespace cond {
0010 
0011   namespace auth {
0012 
0013     struct ServiceCredentials {
0014       ServiceCredentials();
0015       std::string connectionString;
0016       std::string userName;
0017       std::string password;
0018     };
0019 
0020     class KeyGenerator {
0021     public:
0022       KeyGenerator();
0023 
0024       std::string make(size_t keySize);
0025       std::string makeWithRandomSize(size_t maxSize);
0026 
0027     private:
0028       int m_iteration;
0029     };
0030 
0031     class DecodingKey {
0032     public:
0033       static constexpr const char* const KEY_FMT_VERSION = "2.0";
0034       static constexpr const char* const FILE_NAME = "db.key";
0035       static constexpr const char* const FILE_PATH = ".cms_cond/db.key";
0036       static constexpr size_t DEFAULT_KEY_SIZE = 100;
0037 
0038       static std::string templateFile();
0039 
0040     public:
0041       DecodingKey();
0042 
0043       virtual ~DecodingKey() {}
0044 
0045       size_t init(const std::string& keyFileName, const std::string& password, bool readMode = true);
0046 
0047       size_t createFromInputFile(const std::string& inputFileName, size_t generatedKeySize = 0);
0048 
0049       void list(std::ostream& out);
0050 
0051       void flush();
0052 
0053       const std::string& version() const;
0054 
0055       const std::string& principalName() const;
0056 
0057       const std::string& principalKey() const;
0058 
0059       bool isNominal() const;
0060 
0061       const std::string& ownerName() const;
0062 
0063       const std::map<std::string, ServiceCredentials>& services() const;
0064 
0065       void addDefaultService(const std::string& connectionString);
0066 
0067       void addService(const std::string& serviceName,
0068                       const std::string& connectionString,
0069                       const std::string& userName,
0070                       const std::string& password);
0071 
0072     private:
0073       std::string m_fileName;
0074 
0075       std::string m_version;
0076 
0077       bool m_mode;
0078 
0079       std::string m_pwd;
0080 
0081       std::string m_principalName;
0082 
0083       std::string m_principalKey;
0084 
0085       std::string m_owner;
0086 
0087       std::map<std::string, ServiceCredentials> m_services;
0088     };
0089   }  // namespace auth
0090 }  // namespace cond
0091 
0092 inline cond::auth::KeyGenerator::KeyGenerator() : m_iteration(0) {}
0093 
0094 inline cond::auth::ServiceCredentials::ServiceCredentials() : connectionString(""), userName(""), password("") {}
0095 
0096 inline cond::auth::DecodingKey::DecodingKey()
0097     : m_fileName(""),
0098       m_version(""),
0099       m_mode(true),
0100       m_pwd(""),
0101       m_principalName(""),
0102       m_principalKey(""),
0103       m_owner(""),
0104       m_services() {}
0105 
0106 inline const std::string& cond::auth::DecodingKey::version() const { return m_version; }
0107 
0108 inline const std::string& cond::auth::DecodingKey::principalName() const { return m_principalName; }
0109 
0110 inline const std::string& cond::auth::DecodingKey::principalKey() const { return m_principalKey; }
0111 
0112 inline bool cond::auth::DecodingKey::isNominal() const { return !m_owner.empty(); }
0113 
0114 inline const std::string& cond::auth::DecodingKey::ownerName() const { return m_owner; }
0115 
0116 inline const std::map<std::string, cond::auth::ServiceCredentials>& cond::auth::DecodingKey::services() const {
0117   return m_services;
0118 }
0119 
0120 #endif  //  CondCore_CondDB_DecodingKey_h