Merge lp:~bmerry/duplicity/pydrive-regular into lp:~duplicity-team/duplicity/0.7-series

Proposed by Bruce Merry
Status: Merged
Merged at revision: 1096
Proposed branch: lp:~bmerry/duplicity/pydrive-regular
Merge into: lp:~duplicity-team/duplicity/0.7-series
Diff against target: 96 lines (+53/-15)
2 files modified
bin/duplicity.1 (+42/-7)
duplicity/backends/pydrivebackend.py (+11/-8)
To merge this branch: bzr merge lp:~bmerry/duplicity/pydrive-regular
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+260645@code.launchpad.net

Description of the change

This implements the proposal made by somebody else (http://lists.gnu.org/archive/html/duplicity-talk/2015-02/msg00037.html) to allow the pydrive backend to work with a normal drive account instead of a service account. It seems to be working for me: I was able to migrate seamlessly from the gdocs backend. It's set up so that a service account can still be used, depending on which environment variable is set. The man page is updated to describe how to use the new functionality.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/duplicity.1'
2--- bin/duplicity.1 2015-05-08 12:28:47 +0000
3+++ bin/duplicity.1 2015-05-30 12:03:43 +0000
4@@ -1755,13 +1755,17 @@
5 .B REQUIREMENTS
6 above.
7
8-You need to create a service account in "Google developers console" at https://console.developers.google.com
9-
10-Make sure Drive API is enabled.
11-
12-The email address of the account will be used as part of URL. See
13-.B URL FORMAT
14-above.
15+There are two ways to use PyDrive: with a regular account or with a
16+"service account". With a service account, a separate account is
17+created, that is only accessible with Google APIs and not a web login.
18+With a regular account, you can store backups in your normal Google
19+Drive.
20+
21+To use a service account, go to the Google developers
22+console at https://console.developers.google.com. Create a project,
23+and make sure Drive API is enabled for the project. Under "APIs and
24+auth", click Create New Client ID, then select Service Account with P12
25+key.
26
27 Download the .p12 key file of the account and convert it to the .pem format:
28 .br
29@@ -1771,6 +1775,37 @@
30 .BR GOOGLE_DRIVE_ACCOUNT_KEY
31 environment variable for authentification.
32
33+The email address of the account will be used as part of URL. See
34+.B URL FORMAT
35+above.
36+
37+The alternative is to use a regular account. To do this, start as above,
38+but when creating a new Client ID, select "Installed application" of
39+type "Other". Create a file with the following content, and pass its
40+filename in the
41+.BR GOOGLE_DRIVE_SETTINGS
42+environment variable:
43+.PP
44+.nf
45+.RS
46+client_config_backend: settings
47+client_config:
48+ client_id: <Client ID from developers' console>
49+ client_secret: <Client secret from developers' console>
50+save_credentials: True
51+save_credentials_backend: file
52+save_credentials_file: <filename to cache credentials>
53+get_refresh_token: True
54+.RE
55+.fi
56+
57+In this scenario, the username and host parts of the URL play no role;
58+only the path matters. During the first run, you will be prompted to
59+visit an URL in your browser to grant access to your drive. Once
60+granted, you will receive a verification code to paste back into
61+Duplicity. The credentials are then cached in the file references above
62+for future use.
63+
64 .SH A NOTE ON MULTI BACKEND
65
66 The multi backend allows duplicity to combine the storage available in
67
68=== modified file 'duplicity/backends/pydrivebackend.py'
69--- duplicity/backends/pydrivebackend.py 2015-01-31 23:30:49 +0000
70+++ duplicity/backends/pydrivebackend.py 2015-05-30 12:03:43 +0000
71@@ -39,14 +39,17 @@
72 raise BackendException('PyDrive backend requires PyDrive installation'
73 'Please read the manpage to fix.')
74
75- if 'GOOGLE_DRIVE_ACCOUNT_KEY' not in os.environ:
76- raise BackendException('GOOGLE_DRIVE_ACCOUNT_KEY environment variable not set. Please read the manpage to fix.')
77- account_key = os.environ['GOOGLE_DRIVE_ACCOUNT_KEY']
78-
79- credentials = SignedJwtAssertionCredentials(parsed_url.username + '@' + parsed_url.hostname, account_key, scope='https://www.googleapis.com/auth/drive')
80- credentials.authorize(httplib2.Http())
81- gauth = GoogleAuth()
82- gauth.credentials = credentials
83+ if 'GOOGLE_DRIVE_ACCOUNT_KEY' in os.environ:
84+ account_key = os.environ['GOOGLE_DRIVE_ACCOUNT_KEY']
85+ credentials = SignedJwtAssertionCredentials(parsed_url.username + '@' + parsed_url.hostname, account_key, scope='https://www.googleapis.com/auth/drive')
86+ credentials.authorize(httplib2.Http())
87+ gauth = GoogleAuth()
88+ gauth.credentials = credentials
89+ elif 'GOOGLE_DRIVE_SETTINGS' in os.environ:
90+ gauth = GoogleAuth(settings_file=os.environ['GOOGLE_DRIVE_SETTINGS'])
91+ gauth.CommandLineAuth()
92+ else:
93+ raise BackendException('GOOGLE_DRIVE_ACCOUNT_KEY or GOOGLE_DRIVE_SETTINGS environment variable not set. Please read the manpage to fix.')
94 self.drive = GoogleDrive(gauth)
95
96 # Dirty way to find root folder id

Subscribers

People subscribed via source and target branches