Commit 76c70f3d authored by Aard's avatar Aard

[ssud] Implement all methods requiring uid0 in ssu cli

parent 6ed15989
......@@ -25,6 +25,7 @@
<node name="/org/nemo/ssu">
<interface name="org.nemo.ssu">
<!-- credential management -->
<method name="registerDevice">
<arg direction="in" type="s" name="username"/>
<arg direction="in" type="s" name="password"/>
......@@ -34,12 +35,54 @@
<method name="isRegistered">
<arg direction="out" type="b" name="status"/>
</method>
<!-- deviceInfo related methods -->
<method name="deviceModel">
<arg direction="out" type="s" name="model"/>
</method>
<method name="deviceFamily">
<arg direction="out" type="s" name="model"/>
</method>
<method name="deviceUid">
<arg direction="out" type="s" name="model"/>
</method>
<method name="deviceVariant">
<arg direction="out" type="s" name="model"/>
</method>
<!-- repository management -->
<method name="deviceMode">
<arg direction="out" type="i" name="mode"/>
</method>
<method name="setDeviceMode">
<arg direction="in" type="i" name="mode"/>
</method>
<method name="flavour">
<arg direction="out" type="s" name="flavour"/>
</method>
<method name="setFlavour">
<arg direction="in" type="s" name="flavour"/>
</method>
<method name="release">
<arg direction="out" type="s" name="release"/>
<arg direction="in" type="b" name="rnd" />
</method>
<method name="setRelease">
<arg direction="in" type="s" name="release"/>
<arg direction="in" type="b" name="rnd" />
</method>
<!-- actions are remove(0), add(1), disable(2) and enable(3) -->
<method name="modifyRepo">
<arg direction="in" type="i" name="action"/>
<arg direction="in" type="s" name="repo" />
</method>
<method name="addRepo">
<arg direction="in" type="s" name="repo" />
<arg direction="in" type="s" name="url" />
</method>
<method name="updateRepos">
</method>
<method name="error">
<arg direction="out" type="b" name="status"/>
</method>
......
......@@ -32,6 +32,10 @@ RndSsuCli::RndSsuCli(): QObject(){
state = Idle;
}
RndSsuCli::~RndSsuCli(){
ssuProxy->quit();
}
void RndSsuCli::handleResponse(){
QTextStream qout(stdout);
......@@ -76,6 +80,7 @@ void RndSsuCli::optDomain(QStringList opt){
void RndSsuCli::optFlavour(QStringList opt){
QTextStream qout(stdout);
QTextStream qerr(stderr);
if (opt.count() == 3 && opt.at(2) == "-s"){
qout << ssu.flavour();
......@@ -83,11 +88,17 @@ void RndSsuCli::optFlavour(QStringList opt){
} else if (opt.count() == 3){
qout << "Changing flavour from " << ssu.flavour()
<< " to " << opt.at(2) << endl;
ssu.setFlavour(opt.at(2));
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
QDBusPendingReply<> reply = ssuProxy->setFlavour(opt.at(2));
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
ssu.setFlavour(opt.at(2));
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
}
state = Idle;
} else if (opt.count() == 2) {
......@@ -98,6 +109,7 @@ void RndSsuCli::optFlavour(QStringList opt){
void RndSsuCli::optMode(QStringList opt){
QTextStream qout(stdout);
QTextStream qerr(stderr);
// TODO: allow setting meaningful names instead of numbers
......@@ -128,11 +140,17 @@ void RndSsuCli::optMode(QStringList opt){
} else if (opt.count() == 3){
qout << "Setting device mode from " << ssu.deviceMode()
<< " to " << opt.at(2) << endl;
ssu.setDeviceMode(opt.at(2).toInt());
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
QDBusPendingReply<> reply = ssuProxy->setDeviceMode(opt.at(2).toInt());
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
ssu.setDeviceMode(opt.at(2).toInt());
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
}
state = Idle;
}
......@@ -158,27 +176,33 @@ void RndSsuCli::optModifyRepo(int action, QStringList opt){
QTextStream qerr(stderr);
if (opt.count() == 3){
switch(action){
case Add:
repoManager.add(opt.at(2));
repoManager.update();
uidWarning();
break;
case Remove:
repoManager.remove(opt.at(2));
repoManager.update();
uidWarning();
break;
case Disable:
repoManager.disable(opt.at(2));
repoManager.update();
uidWarning();
break;
case Enable:
repoManager.enable(opt.at(2));
repoManager.update();
uidWarning();
break;
QDBusPendingReply<> reply = ssuProxy->modifyRepo(action, opt.at(2));
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
switch(action){
case Add:
repoManager.add(opt.at(2));
repoManager.update();
uidWarning();
break;
case Remove:
repoManager.remove(opt.at(2));
repoManager.update();
uidWarning();
break;
case Disable:
repoManager.disable(opt.at(2));
repoManager.update();
uidWarning();
break;
case Enable:
repoManager.enable(opt.at(2));
repoManager.update();
uidWarning();
break;
}
}
} else if (opt.count() == 4 && action == Add){
QString url, repo;
......@@ -194,9 +218,14 @@ void RndSsuCli::optModifyRepo(int action, QStringList opt){
return;
}
repoManager.add(repo, url);
repoManager.update();
uidWarning();
QDBusPendingReply<> reply = ssuProxy->addRepo(repo, url);
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
repoManager.add(repo, url);
repoManager.update();
uidWarning();
}
}
}
......@@ -244,6 +273,7 @@ void RndSsuCli::optRegister(QStringList opt){
void RndSsuCli::optRelease(QStringList opt){
QTextStream qout(stdout);
QTextStream qerr(stderr);
if (opt.count() == 3){
if (opt.at(2) == "-r"){
......@@ -253,11 +283,17 @@ void RndSsuCli::optRelease(QStringList opt){
qout << "Changing release from " << ssu.release()
<< " to " << opt.at(2) << endl;
qout << "Your device is now in release mode!" << endl;
ssu.setRelease(opt.at(2));
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
QDBusPendingReply<> reply = ssuProxy->setRelease(opt.at(2), false);
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
ssu.setRelease(opt.at(2));
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
}
state = Idle;
}
......@@ -268,11 +304,17 @@ void RndSsuCli::optRelease(QStringList opt){
qout << "Changing release (RnD) from " << ssu.release(true)
<< " to " << opt.at(3) << endl;
qout << "Your device is now in RnD mode!" << endl;
ssu.setRelease(opt.at(3), true);
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
QDBusPendingReply<> reply = ssuProxy->setRelease(opt.at(3), true);
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
ssu.setRelease(opt.at(3), true);
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
}
state = Idle;
}
......@@ -478,16 +520,28 @@ void RndSsuCli::optUpdateCredentials(QStringList opt){
}
void RndSsuCli::optUpdateRepos(){
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
QTextStream qerr(stdout);
QDBusPendingReply<> reply = ssuProxy->updateRepos();
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
}
}
void RndSsuCli::run(){
QTextStream qout(stdout);
QTextStream qerr(stderr);
QStringList arguments = QCoreApplication::arguments();
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();
if (!ssuSettings->isWritable())
qerr << "WARNING: ssu.ini does not seem to be writable. Setting values might not work." << endl;
if (arguments.at(0).endsWith("rndssu"))
qout << "NOTE: this binary is now called ssu. The rndssu symlink will go away after some time" << endl;
......
......@@ -21,6 +21,7 @@ class RndSsuCli: public QObject {
public:
RndSsuCli();
~RndSsuCli();
public slots:
void run();
......@@ -45,10 +46,10 @@ class RndSsuCli: public QObject {
void optUpdateRepos();
enum Actions {
Remove,
Add,
Disable,
Enable
Remove = 0,
Add = 1,
Disable = 2,
Enable = 3,
};
enum State {
......
......@@ -126,7 +126,7 @@ Group: Documentation
%build
mkdir -p build && cd build
qmake -qt=5 DEFINES+='TARGET_ARCH=\\\"\"%{_target_cpu}\"\\\"' -recursive ..
%qmake5 DEFINES+='TARGET_ARCH=\\\"\"%{_target_cpu}\"\\\"' -recursive ..
make %{?_smp_mflags}
cd .. && doxygen doc/Doxyfile
......
......@@ -9,6 +9,7 @@
#include "ssuadaptor.h"
#include "libssu/ssudeviceinfo.h"
#include "libssu/ssurepomanager.h"
#include <QDBusConnection>
......@@ -42,13 +43,25 @@ QString Ssud::deviceModel(){
SsuDeviceInfo deviceInfo;
return deviceInfo.deviceModel();
};
}
QString Ssud::deviceFamily(){
SsuDeviceInfo deviceInfo;
return deviceInfo.deviceFamily();
}
QString Ssud::deviceUid(){
SsuDeviceInfo deviceInfo;
return deviceInfo.deviceUid();
};
}
QString Ssud::deviceVariant(){
SsuDeviceInfo deviceInfo;
return deviceInfo.deviceVariant();
}
bool Ssud::error(){
return ssu.error();
......@@ -58,14 +71,14 @@ QString Ssud::lastError(){
return ssu.lastError();
}
bool Ssud::isRegistered(){
return ssu.isRegistered();
}
void Ssud::quit(){
QCoreApplication::quit();
}
bool Ssud::isRegistered(){
return ssu.isRegistered();
}
void Ssud::registerDevice(const QString &username, const QString &password){
ssu.sendRegistration(username, password);
}
......@@ -73,3 +86,70 @@ void Ssud::registerDevice(const QString &username, const QString &password){
void Ssud::unregisterDevice(){
ssu.unregister();
};
int Ssud::deviceMode(){
return ssu.deviceMode();
}
void Ssud::setDeviceMode(int mode){
ssu.setDeviceMode(mode);
SsuRepoManager repoManager;
repoManager.update();
}
QString Ssud::flavour(){
return ssu.flavour();
}
void Ssud::setFlavour(const QString &flavour){
ssu.setFlavour(flavour);
SsuRepoManager repoManager;
repoManager.update();
}
QString Ssud::release(bool rnd){
return ssu.release(rnd);
}
void Ssud::setRelease(const QString &release, bool rnd){
ssu.setRelease(release, rnd);
SsuRepoManager repoManager;
repoManager.update();
}
void Ssud::modifyRepo(int action, const QString &repo){
SsuRepoManager repoManager;
switch(action){
case Add:
repoManager.add(repo);
break;
case Remove:
repoManager.remove(repo);
break;
case Disable:
repoManager.disable(repo);
break;
case Enable:
repoManager.enable(repo);
break;
}
repoManager.update();
}
void Ssud::addRepo(const QString &repo, const QString &url){
SsuRepoManager repoManager;
repoManager.add(repo, url);
repoManager.update();
}
void Ssud::updateRepos(){
SsuRepoManager repoManager;
repoManager.update();
}
......@@ -21,14 +21,31 @@ class Ssud: public QObject {
virtual ~Ssud();
public slots:
/* device info */
QString deviceModel();
QString deviceFamily();
QString deviceUid();
bool error();
QString lastError();
QString deviceVariant();
/* credential management */
bool isRegistered();
void quit();
void registerDevice(const QString &username, const QString &password);
void unregisterDevice();
/* repository management */
int deviceMode();
void setDeviceMode(int mode);
QString flavour();
void setFlavour(const QString &release);
QString release(bool rnd);
void setRelease(const QString &release, bool rnd);
void modifyRepo(int action, const QString &repo);
void addRepo(const QString &repo, const QString &url);
void updateRepos();
bool error();
QString lastError();
void quit();
signals:
void done();
......@@ -39,6 +56,13 @@ class Ssud: public QObject {
Ssu ssu;
static const char *SERVICE_NAME;
static const char *OBJECT_PATH;
enum Actions {
Remove = 0,
Add = 1,
Disable = 2,
Enable = 3,
};
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment