From a39252110bc9b6c9783acc4c66395da076af493d Mon Sep 17 00:00:00 2001 From: Bernd Wachter Date: Mon, 11 Mar 2013 16:48:44 +0200 Subject: [PATCH] Move zypper plugin to core library logging --- rndssucli/rndssucli.cpp | 20 +++++++++++++++++-- rpm/ssu.changes | 5 +++++ rpm/ssu.spec | 2 +- ssuurlresolver/ssuurlresolver.cpp | 33 ++++++++----------------------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/rndssucli/rndssucli.cpp b/rndssucli/rndssucli.cpp index 4848743..dfc5ee0 100644 --- a/rndssucli/rndssucli.cpp +++ b/rndssucli/rndssucli.cpp @@ -33,8 +33,7 @@ void RndSsuCli::run(){ QStringList arguments = QCoreApplication::arguments(); - - if (arguments.count() != 2){ + if (arguments.count() >= 2){ usage(); return; } @@ -56,6 +55,23 @@ void RndSsuCli::run(){ } else { ssu.updateCredentials(); } + } else if (arguments.at(1) == "resolve"){ + QString repo; + bool rndRepo=false; + if (arguments.count() <= 2){ + usage(); + return; + } + repo = arguments.at(2); + + if (arguments.count() >= 3){ + //qout << (arguments.at(3).compare("false")||arguments.at(3).compare("0")); + qout << (arguments.at(3).compare("false")); + + } + + qout << ssu.repoUrl(arguments.at(2)); + QCoreApplication::exit(1); } else if (arguments.at(1) == "status"){ qout << "Device registration status: " << (ssu.isRegistered() ? "registered" : "not registered") << endl; diff --git a/rpm/ssu.changes b/rpm/ssu.changes index 10956a5..a97e1b0 100644 --- a/rpm/ssu.changes +++ b/rpm/ssu.changes @@ -1,3 +1,8 @@ +* Mon Mar 11 2013 Bernd Wachter - 0.22 +- Add systemd logging to core library +- Move zypper plugin logging to core library +- Fix bug where resolverplugin does not return on credentials update + * Mon Mar 11 2013 Bernd Wachter - 0.21 - Reduce time before credentials get refreshed - Add logging for url resolver diff --git a/rpm/ssu.spec b/rpm/ssu.spec index 77963fb..d31a777 100644 --- a/rpm/ssu.spec +++ b/rpm/ssu.spec @@ -1,5 +1,5 @@ Name: ssu -Version: 0.21 +Version: 0.22 Release: 1 Summary: SSU enabler for RND Group: System/Base diff --git a/ssuurlresolver/ssuurlresolver.cpp b/ssuurlresolver/ssuurlresolver.cpp index fe821a8..b1751cf 100644 --- a/ssuurlresolver/ssuurlresolver.cpp +++ b/ssuurlresolver/ssuurlresolver.cpp @@ -16,32 +16,17 @@ SsuUrlResolver::SsuUrlResolver(): QObject(){ Qt::QueuedConnection); } -void SsuUrlResolver::printJournal(int priority, QString message){ - QByteArray ba = message.toUtf8(); - const char *ca = ba.constData(); - - if (sd_journal_print(LOG_INFO, "ssu: %s", ca) < 0){ - QFile logfile; - QTextStream logstream; - logfile.setFileName("/tmp/ssu.log"); - logfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); - logstream.setDevice(&logfile); - logstream << message << "\n"; - logstream.flush(); - } -} - bool SsuUrlResolver::writeCredentials(QString filePath, QString credentialsScope){ QFile credentialsFile(filePath); QPair credentials = ssu.credentials(credentialsScope); if (credentials.first == "" || credentials.second == ""){ - printJournal(LOG_WARNING, "Returned credentials are empty, skip writing"); + ssu.printJournal(LOG_WARNING, "Returned credentials are empty, skip writing"); return false; } if (!credentialsFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)){ - printJournal(LOG_WARNING, "Unable to open credentials file for writing"); + ssu.printJournal(LOG_WARNING, "Unable to open credentials file for writing"); return false; } @@ -63,7 +48,7 @@ void SsuUrlResolver::run(){ if (in.headerEmpty()){ // FIXME, do something; we need at least repo header - printJournal(LOG_WARNING, "Received empty header list. Most likely your ssu setup is broken"); + ssu.printJournal(LOG_WARNING, "Received empty header list. Most likely your ssu setup is broken"); } PluginFrame::HeaderListIterator it; @@ -101,17 +86,16 @@ void SsuUrlResolver::run(){ headerList.append("ssl_verify=no"); if (isRnd || ssu.isRegistered()){ - printJournal(LOG_DEBUG, "Attempting credential update"); SignalWait w; connect(&ssu, SIGNAL(done()), &w, SLOT(finished())); ssu.updateCredentials(); w.sleep(); } else - printJournal(LOG_DEBUG, "No RnD repository, and device not registered -- skipping credential update"); + ssu.printJournal(LOG_DEBUG, "No RnD repository, and device not registered -- skipping credential update"); // TODO: check for credentials scope required for repository; check if the file exists; // compare with configuration, and dump credentials to file if necessary - printJournal(LOG_DEBUG, QString("Requesting credentials for '%1' with RND status %2...").arg(repo).arg(isRnd)); + ssu.printJournal(LOG_DEBUG, QString("Requesting credentials for '%1' with RND status %2...").arg(repo).arg(isRnd)); QString credentialsScope = ssu.credentialsScope(repo, isRnd); if (!credentialsScope.isEmpty()){ headerList.append(QString("credentials=%1").arg(credentialsScope)); @@ -120,10 +104,9 @@ void SsuUrlResolver::run(){ if (!credentialsFileInfo.exists() || credentialsFileInfo.lastModified() <= ssu.lastCredentialsUpdate()){ writeCredentials(credentialsFileInfo.filePath(), credentialsScope); - } else - printJournal(LOG_DEBUG, "Skipping credential update -- file exists and was modified after last update"); + } } else - printJournal(LOG_DEBUG, "Skipping credential update due to missing credentials scope"); + ssu.printJournal(LOG_DEBUG, "Skipping credential update due to missing credentials scope"); if (headerList.isEmpty()){ resolvedUrl = ssu.repoUrl(repo, isRnd, repoParameters); @@ -133,7 +116,7 @@ void SsuUrlResolver::run(){ .arg(headerList.join("&")); } - printJournal(LOG_INFO, QString("%1 resolved to %2").arg(repo).arg(resolvedUrl)); + ssu.printJournal(LOG_INFO, QString("%1 resolved to %2").arg(repo).arg(resolvedUrl)); PluginFrame out("RESOLVEDURL"); out.setBody(resolvedUrl.toStdString());