Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move zypper plugin to core library logging
  • Loading branch information
Bernd Wachter committed Mar 11, 2013
1 parent 8b7d073 commit a392521
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
20 changes: 18 additions & 2 deletions rndssucli/rndssucli.cpp
Expand Up @@ -33,8 +33,7 @@ void RndSsuCli::run(){

QStringList arguments = QCoreApplication::arguments();


if (arguments.count() != 2){
if (arguments.count() >= 2){
usage();
return;
}
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions rpm/ssu.changes
@@ -1,3 +1,8 @@
* Mon Mar 11 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 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 <bernd.wachter@jollamobile.com> - 0.21
- Reduce time before credentials get refreshed
- Add logging for url resolver
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
33 changes: 8 additions & 25 deletions ssuurlresolver/ssuurlresolver.cpp
Expand Up @@ -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<QString, QString> 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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit a392521

Please sign in to comment.