Skip to content

Commit bf562dc

Browse files
committed
CCDB: Add alien token check as proposed by Sandro
1 parent 51a9611 commit bf562dc

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

CCDB/include/CCDB/CcdbApi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class CcdbApi //: public DatabaseInterface
6363

6464
const std::string getUniqueAgentID() const { return mUniqueAgentID; }
6565

66+
static bool checkAlienToken();
67+
6668
/**
6769
* Initialize connection to CCDB
6870
*

CCDB/src/CcdbApi.cxx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ CcdbApi::~CcdbApi()
6363
curl_global_cleanup();
6464
}
6565

66+
bool CcdbApi::checkAlienToken()
67+
{
68+
#ifdef __APPLE__
69+
LOG(debug) << "On macOS we simply rely on TGrid::Connect(\"alien\").";
70+
return true;
71+
#endif
72+
if (getenv("ALICEO2_CCDB_NOTOKENCHECK") && atoi(getenv("ALICEO2_CCDB_NOTOKENCHECK"))) {
73+
return true;
74+
}
75+
if (getenv("JALIEN_TOKEN_CERT")) {
76+
return true;
77+
}
78+
auto returncode = system("alien-token-info &> /dev/nulll");
79+
if (returncode == -1) {
80+
LOG(error) << "...";
81+
}
82+
return returncode == 0;
83+
}
84+
6685
void CcdbApi::curlInit()
6786
{
6887
// todo : are there other things to initialize globally for curl ?
@@ -120,7 +139,7 @@ void CcdbApi::init(std::string const& host)
120139
}
121140

122141
const std::string httpsprefix = "https://";
123-
mNeedAlienToken = host.substr(0, httpsprefix.size()) == httpsprefix) || host == "http://alice-ccdb.cern.ch";
142+
mNeedAlienToken = host.substr(0, httpsprefix.size()) == httpsprefix || host == "http://alice-ccdb.cern.ch";
124143

125144
LOGP(info, "Init CcdApi with UserAgentID: {}, Host: {}{}", mUniqueAgentID, host,
126145
mInSnapshotMode ? "(snapshot readonly mode)" : snapshotReport.c_str());
@@ -754,10 +773,13 @@ void* CcdbApi::extractFromLocalFile(std::string const& filename, std::type_info
754773
bool CcdbApi::initTGrid() const
755774
{
756775
if (mNeedAlienToken && !mAlienInstance) {
776+
static bool allowNoToken = getenv("ALICEO2_CCDB_NOTOKENCHECK") && atoi(getenv("ALICEO2_CCDB_NOTOKENCHECK"));
777+
if (!allowNoToken && !checkAlienToken()) {
778+
LOG(fatal) << "Alien Token Check failed - Please get an alien token before running with https CCDB endpoint, or alice-ccdb.cern.ch!";
779+
}
757780
mAlienInstance = TGrid::Connect("alien");
758781
static bool errorShown = false;
759782
if (!mAlienInstance && errorShown == false) {
760-
bool allowNoToken = getenv("O2_CCDB_ALLOW_NO_TOKEN") && atoi(getenv("O2_CCDB_ALLOW_NO_TOKEN"));
761783
if (allowNoToken) {
762784
LOG(error) << "TGrid::Connect returned nullptr. May be due to missing alien token";
763785
} else {

0 commit comments

Comments
 (0)