// Author: Nikola Hardi 3/6/2019 #ifndef ROOT_TJAlienCredentials #define ROOT_TJAlienCredentials #include #include #include "TObject.h" #include "TJClientFile.h" using std::string; using std::map; enum CredentialsKind { cJBOX_TOKEN = 0, cFULL_GRID_CERT, cJOB_TOKEN, cOTHER_TOKEN, }; struct TJAlienCredentialsObject { string certpath; string keypath; string source; CredentialsKind kind; TJAlienCredentialsObject() {} TJAlienCredentialsObject(string certpath, string keypath, CredentialsKind kind = cOTHER_TOKEN, string source = "") { this->certpath = certpath; this->keypath = keypath; this->kind = kind; this->source = source; }; bool exists() { return fileExists(certpath) && fileExists(keypath); } string getKey(); string getCertificate(); private: bool fileExists(string filename) { bool fileExists = false; FILE *f = fopen(filename.c_str(), "r"); if (f != NULL ) { fclose(f); fileExists = true; } else { fileExists = false; } return fileExists; } }; class TJAlienCredentials : public TObject { public: TJAlienCredentials(); ~TJAlienCredentials(); string getTmpDir(); string getHomeDir(); void loadCredentials(); bool has(CredentialsKind kind); TJAlienCredentialsObject get(CredentialsKind kind); static const char *ENV_JOBTOKEN_KEY; static const char *ENV_JOBTOKEN_CERT; static const char *TMP_JOBTOKEN_KEY_FNAME; static const char *TMP_JOBTOKEN_CERT_FNAME; private: void loadTokenCertificate(); void loadFullGridCertificate(); void loadJobTokenCertificate(); string getUsercertPath(); string getUserkeyPath(); string getTokencertPath(); string getTokenkeyPath(); string tmpdir; string homedir; map found_credentials; TJClientFile jcf; ClassDef(TJAlienCredentials, 0) }; #endif