Merge lp:~dbarth/ubuntuone-credentials/acl-updater-script into lp:~mardy/ubuntuone-credentials/lp1376445-migration

Proposed by David Barth
Status: Merged
Merged at revision: 164
Proposed branch: lp:~dbarth/ubuntuone-credentials/acl-updater-script
Merge into: lp:~mardy/ubuntuone-credentials/lp1376445-migration
Diff against target: 206 lines (+26/-161)
4 files modified
acl-updater/CMakeLists.txt (+0/-19)
acl-updater/acl-updater (+26/-0)
acl-updater/acl-updater.cpp (+0/-94)
acl-updater/acl-updater.h (+0/-48)
To merge this branch: bzr merge lp:~dbarth/ubuntuone-credentials/acl-updater-script
Reviewer Review Type Date Requested Status
Alberto Mardegan Needs Fixing
Review via email: mp+252098@code.launchpad.net

Description of the change

Turn the acl-updater program into a shell script, to work in multi-arch contexts.

To post a comment you must log in.
164. By David Barth

turn the acl-updater program into a script

Revision history for this message
Alberto Mardegan (mardy) wrote :

Some suggestions.

review: Needs Fixing
165. By David Barth

better, safer

Revision history for this message
David Barth (dbarth) wrote :
Download full text (7.6 KiB)

Updated; thanks for the review

On Fri, Mar 6, 2015 at 1:35 PM, Alberto Mardegan <
<email address hidden>> wrote:

> Review: Needs Fixing
>
> Some suggestions.
>
> Diff comments:
>
> > === removed file 'acl-updater/CMakeLists.txt'
> > --- acl-updater/CMakeLists.txt 2015-01-15 11:29:50 +0000
> > +++ acl-updater/CMakeLists.txt 1970-01-01 00:00:00 +0000
> > @@ -1,19 +0,0 @@
> > -# Qt5 bits
> > -SET (CMAKE_INCLUDE_CURRENT_DIR ON)
> > -SET (CMAKE_AUTOMOC ON)
> > -find_package(Qt5Core REQUIRED)
> > -
> > -# The sources for building the library
> > -FILE (GLOB SOURCES *.cpp)
> > -# HEADERS only includes the public headers for installation.
> > -FILE (GLOB HEADERS *.h)
> > -
> > -SET (ACL_UPDATER acl-updater)
> > -
> > -add_executable (${ACL_UPDATER} ${SOURCES})
> > -qt5_use_modules (${ACL_UPDATER} Core)
> > -target_link_libraries (${ACL_UPDATER}
> > - ${LIBSIGNON_LDFLAGS}
> > -)
> > -
> > -# We don't install this; dh-migrations will pick it up from the build
> dir.
> >
> > === added file 'acl-updater/acl-updater'
> > --- acl-updater/acl-updater 1970-01-01 00:00:00 +0000
> > +++ acl-updater/acl-updater 2015-03-06 12:20:19 +0000
> > @@ -0,0 +1,19 @@
> > +#!/bin/bash
>
> AFAIK, if bash is not needed it's better to use /bin/sh, which is more
> lightweight. The current script should work, you'll only have to replace
> `command` with $(command).
>
> > +#
> > +
> > +export LC_ALL=C
> > +SIGNON_DB=".config/signond/signon.db"
>
> Better prefix $HOME/ here, just in case the script gets executed from some
> other directory.
>
> > +
> > +ACCOUNT_ID=`account-console list | grep -i ubuntuone | grep -o
> '[0-9]\+'`
>
> Exit if this is empty
>
> > +CREDS_ID=`account-console show $ACCOUNT_ID | grep CredentialsId | grep
> -o '[0-9]\+'`
> > +
> > +echo "Upgrading ACL for U1 account (id:$CREDS_ID)"
> > +sqlite3 $SIGNON_DB "select * from ACL where identity_id=$CREDS_ID"
>
> This is not needed, is it?
>
> > +
> > +# ensure the 'unconfined' element exists in the table
> > +sqlite3 $SIGNON_DB 'insert or ignore into TOKENS(token) values
> ("unconfined")'
> > +
> > +# add the ACL to protect the U1 account
> > +sqlite3 $SIGNON_DB "insert or ignore into ACL (identity_id, token_id)
> values ($CREDS_ID, (select id from TOKENS where token='unconfined'))"
> > +
> > +echo "done"
> >
> > === removed file 'acl-updater/acl-updater.cpp'
> > --- acl-updater/acl-updater.cpp 2015-01-15 11:29:50 +0000
> > +++ acl-updater/acl-updater.cpp 1970-01-01 00:00:00 +0000
> > @@ -1,94 +0,0 @@
> > -/*
> > - * Copyright 2015 Canonical Ltd.
> > - *
> > - * This program is free software; you can redistribute it and/or
> > - * modify it under the terms of version 3 of the GNU Lesser General
> Public
> > - * License as published by the Free Software Foundation.
> > - *
> > - * This program is distributed in the hope that it will be useful,
> > - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > - * General Public License for more details.
> > - *
> > - * You should have received a copy of the GNU Lesser General Public
> > - * License along with this library; if not, write t...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'acl-updater/CMakeLists.txt'
2--- acl-updater/CMakeLists.txt 2015-01-15 11:29:50 +0000
3+++ acl-updater/CMakeLists.txt 1970-01-01 00:00:00 +0000
4@@ -1,19 +0,0 @@
5-# Qt5 bits
6-SET (CMAKE_INCLUDE_CURRENT_DIR ON)
7-SET (CMAKE_AUTOMOC ON)
8-find_package(Qt5Core REQUIRED)
9-
10-# The sources for building the library
11-FILE (GLOB SOURCES *.cpp)
12-# HEADERS only includes the public headers for installation.
13-FILE (GLOB HEADERS *.h)
14-
15-SET (ACL_UPDATER acl-updater)
16-
17-add_executable (${ACL_UPDATER} ${SOURCES})
18-qt5_use_modules (${ACL_UPDATER} Core)
19-target_link_libraries (${ACL_UPDATER}
20- ${LIBSIGNON_LDFLAGS}
21-)
22-
23-# We don't install this; dh-migrations will pick it up from the build dir.
24
25=== added file 'acl-updater/acl-updater'
26--- acl-updater/acl-updater 1970-01-01 00:00:00 +0000
27+++ acl-updater/acl-updater 2015-03-06 12:45:26 +0000
28@@ -0,0 +1,26 @@
29+#!/bin/sh
30+#
31+
32+export LC_ALL=C
33+SIGNON_DB="$HOME/.config/signond/signon.db"
34+
35+ACCOUNT_ID=`account-console list | grep -i ubuntuone | grep -o '[0-9]\+'`
36+if [ -z $ACCOUNT_ID ]; then
37+ echo "no U1 account found; exiting"
38+ exit 1
39+fi
40+CREDS_ID=`account-console show $ACCOUNT_ID | grep CredentialsId | grep -o '[0-9]\+'`
41+if [ -z $CREDS_ID ]; then
42+ echo "no U1 account found; exiting"
43+ exit 1
44+fi
45+
46+echo "Upgrading ACL for U1 account (id:$CREDS_ID)"
47+
48+# ensure the 'unconfined' element exists in the table
49+sqlite3 $SIGNON_DB 'insert or ignore into TOKENS(token) values ("unconfined")'
50+
51+# add the ACL to protect the U1 account
52+sqlite3 $SIGNON_DB "insert or ignore into ACL (identity_id, token_id) values ($CREDS_ID, (select id from TOKENS where token='unconfined'))"
53+
54+echo "done"
55
56=== removed file 'acl-updater/acl-updater.cpp'
57--- acl-updater/acl-updater.cpp 2015-01-15 11:29:50 +0000
58+++ acl-updater/acl-updater.cpp 1970-01-01 00:00:00 +0000
59@@ -1,94 +0,0 @@
60-/*
61- * Copyright 2015 Canonical Ltd.
62- *
63- * This program is free software; you can redistribute it and/or
64- * modify it under the terms of version 3 of the GNU Lesser General Public
65- * License as published by the Free Software Foundation.
66- *
67- * This program is distributed in the hope that it will be useful,
68- * but WITHOUT ANY WARRANTY; without even the implied warranty of
69- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
70- * General Public License for more details.
71- *
72- * You should have received a copy of the GNU Lesser General Public
73- * License along with this library; if not, write to the
74- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
75- * Boston, MA 02110-1301, USA.
76- */
77-
78-#include <Accounts/Account>
79-#include <Accounts/Manager>
80-
81-#include <QCoreApplication>
82-#include <QDebug>
83-
84-#include <SignOn/Identity>
85-#include <SignOn/IdentityInfo>
86-
87-#include "acl-updater.h"
88-
89-AclUpdater::AclUpdater(quint32 credentialsId, QObject *parent):
90- QObject(parent),
91- identity(0)
92-{
93- qDebug() << "Loading identity" << credentialsId;
94-
95- identity = SignOn::Identity::existingIdentity(credentialsId, this);
96- QObject::connect(identity, SIGNAL(info(const SignOn::IdentityInfo&)),
97- this, SLOT(onInfoReady(const SignOn::IdentityInfo&)));
98- QObject::connect(identity, SIGNAL(error(const SignOn::Error&)),
99- this, SLOT(onError(const SignOn::Error&)));
100- identity->queryInfo();
101-}
102-
103-void AclUpdater::onInfoReady(const SignOn::IdentityInfo &info)
104-{
105- QStringList currentAcl = info.accessControlList();
106- QString unconfined = QStringLiteral("unconfined");
107-
108- if (currentAcl.contains(unconfined)) {
109- // nothing to do
110- qDebug() << "ACL already contains 'unconfined'";
111- Q_EMIT finished();
112- return;
113- }
114-
115- qDebug() << "Updating identity";
116- SignOn::IdentityInfo updatedInfo(info);
117- updatedInfo.setAccessControlList(currentAcl << unconfined);
118-
119- QObject::connect(identity, SIGNAL(credentialsStored(const quint32)),
120- this, SIGNAL(finished()));
121- identity->storeCredentials(updatedInfo);
122-}
123-
124-void AclUpdater::onError(const SignOn::Error &error)
125-{
126- qWarning() << "Error updating identity" << identity->id() <<
127- ":" << error.message();
128- Q_EMIT finished();
129-}
130-
131-int main(int argc, char **argv)
132-{
133- QCoreApplication app(argc, argv);
134-
135- Accounts::Manager manager;
136- AclUpdater *updater = 0;
137-
138- Q_FOREACH(Accounts::AccountId accountId, manager.accountList()) {
139- Accounts::Account *account = manager.account(accountId);
140- if (account->providerName() == QStringLiteral("ubuntuone")) {
141- updater = new AclUpdater(account->credentialsId());
142- break;
143- }
144- }
145-
146- if (updater) {
147- QObject::connect(updater, SIGNAL(finished()),
148- &app, SLOT(quit()));
149- return app.exec();
150- } else {
151- return EXIT_SUCCESS;
152- }
153-}
154
155=== removed file 'acl-updater/acl-updater.h'
156--- acl-updater/acl-updater.h 2015-01-15 11:29:50 +0000
157+++ acl-updater/acl-updater.h 1970-01-01 00:00:00 +0000
158@@ -1,48 +0,0 @@
159-/*
160- * Copyright 2015 Canonical Ltd.
161- *
162- * This program is free software; you can redistribute it and/or
163- * modify it under the terms of version 3 of the GNU Lesser General Public
164- * License as published by the Free Software Foundation.
165- *
166- * This program is distributed in the hope that it will be useful,
167- * but WITHOUT ANY WARRANTY; without even the implied warranty of
168- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
169- * General Public License for more details.
170- *
171- * You should have received a copy of the GNU Lesser General Public
172- * License along with this library; if not, write to the
173- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
174- * Boston, MA 02110-1301, USA.
175- */
176-
177-#ifndef _ACL_UPDATER_H_
178-#define _ACL_UPDATER_H_
179-
180-#include <QObject>
181-
182-namespace SignOn {
183- class Error;
184- class Identity;
185- class IdentityInfo;
186-};
187-
188-class AclUpdater : public QObject
189-{
190- Q_OBJECT
191-
192-public:
193- AclUpdater(quint32 credentialsId, QObject *parent = 0);
194-
195-Q_SIGNALS:
196- void finished();
197-
198-private Q_SLOTS:
199- void onInfoReady(const SignOn::IdentityInfo &info);
200- void onError(const SignOn::Error &error);
201-
202-private:
203- SignOn::Identity *identity;
204-};
205-
206-#endif // _ACL_UPDATER_H_

Subscribers

People subscribed via source and target branches

to all changes: