> bzr merge lp:~sil/desktopcouch/create-oauth-tokens-startup
M data/couchdb.tmpl
M desktopcouch/start_local_couchdb.py
Text conflict in desktopcouch/start_local_couchdb.py
1 conflicts encountered.
-def write_bookmark_file():
+def write_bookmark_file(username, password):
"""Write out an HTML document that the user can bookmark to find their DB"""
bookmark_file = os.path.join(local_files.DIR_DB, "couchdb.html")
@@ -182,21 +254,24 @@
pass
else:
fp = open(bookmark_file, "w")
- fp.write(html.replace("[[COUCHDB_PORT]]", port))
+ out = html.replace("[[COUCHDB_PORT]]", port)
+ out = out.replace("[[COUCHDB_USERNAME]]", username)
+ out = out.replace("[[COUCHDB_PASSWORD]]", password)
+ fp.write(out)
fp.close()
print "Browse your desktop CouchDB at file://%s" % \ os.path.realpath(bookmark_file)
def start_couchdb():
"""Execute each step to start a desktop CouchDB"""
- create_ini_file()
+ username, password = create_ini_file()
run_couchdb()
# Note that we do not call update_design_documents here. This is because
# Couch won't actually have started yet, so when update_design_documents
# calls the Records API, that will call back into get_pid and we end up
# starting Couch again. Instead, get_pid calls update_design_documents
# *after* Couch startup has occurred.
- write_bookmark_file()
+ write_bookmark_file(username, password)
> bzr merge lp:~sil/desktopcouch/create-oauth-tokens-startup start_local_ couchdb. py start_local_ couchdb. py
M data/couchdb.tmpl
M desktopcouch/
Text conflict in desktopcouch/
1 conflicts encountered.
> bzr diff desktopcouch/ start_local_ couchdb. py start_local_ couchdb. py' start_local_ couchdb. py 2009-08-21 22:45:24 +0000 start_local_ couchdb. py 2009-08-24 11:12:48 +0000
=== modified file 'desktopcouch/
--- desktopcouch/
+++ desktopcouch/
@@ -34,14 +34,16 @@
"""
from __future__ import with_statement records. server import CouchDatabase
-import os, subprocess, sys, glob
+import os, subprocess, sys, glob, random, string
import desktopcouch
from desktopcouch import local_files
import xdg.BaseDirectory
import errno
-import time
+import time, gtk, gnomekeyring
from desktopcouch.
+ACCEPTABLE_ USERNAME_ PASSWORD_ CHARS = string.lowercase + string.uppercase
ini_path= local_files. FILE_INI, db_dir= local_files. DIR_DB,
log_path= local_files. FILE_LOG, port="0"): exists( ini_path) : exists( local_files. FILE_INI) : find_items_ sync(gnomekeyri ng.ITEM_ GENERIC_ SECRET, NoMatchError: .secret. split(" :") string( count): [random. choice( ACCEPTABLE_ USERNAME_ PASSWORD_ CHARS) USERNAME = make_random_ string( 10) BASIC_AUTH_ PASSWORD = make_random_ string( 10) string( 10) string( 10) string( 10) string( 10)
' database_ dir': db_dir,
' view_index_ dir': db_dir,
' file': log_path,
' level': 'info', USERNAME: ADMIN_ACCOUNT_ BASIC_AUTH_ PASSWORD consumer_ secrets' : { token_secrets' : { token_users' : { USERNAME valid_user' : 'true'
+
def dump_ini(data, filename):
"""Dump INI data with sorted sections and keywords"""
fd = open(filename, 'w')
@@ -60,9 +62,38 @@
"""Write CouchDB ini file if not already present"""
+<<<<<<< TREE
if os.path.
return
ini = {
+=======
+ if os.path.
+ # load the username and password from the keyring
+ try:
+ data = gnomekeyring.
+ {'desktopcouch': 'basic'})
+ except gnomekeyring.
+ data = None
+ if data:
+ username, password = data[0]
+ return username, password
+ # otherwise fall through; for some reason the access details aren't
+ # in the keyring, so re-create the ini file and do it all again
+
+ # randomly generate tokens and usernames
+ def make_random_
+ return ''.join(
+ for x in range(count)])
+
+ ADMIN_ACCOUNT_
+ ADMIN_ACCOUNT_
+ CONSUMER_KEY = make_random_
+ CONSUMER_SECRET = make_random_
+ TOKEN = make_random_
+ TOKEN_SECRET = make_random_
+
+ local = {
+>>>>>>> MERGE-SOURCE
'couchdb': {
@@ -75,10 +106,51 @@
},
+ 'admins': {
+ ADMIN_ACCOUNT_
+ },
+ 'oauth_
+ CONSUMER_KEY: CONSUMER_SECRET
+ },
+ 'oauth_
+ TOKEN: TOKEN_SECRET
+ },
+ 'oauth_
+ TOKEN: ADMIN_ACCOUNT_
+ },
+ 'couch_httpd_auth': {
+ 'require_
+ }
}
+<<<<<<< TREE
dump_ini(ini, ini_path)
def run_couchdb( exec_command= local_files. COUCH_EXEC_ COMMAND) : FILE_INI) item_create_ sync( ITEM_GENERIC_ SECRET, ACCOUNT_ USERNAME, ADMIN_ACCOUNT_ BASIC_AUTH_ PASSWORD) , item_create_ sync( ITEM_GENERIC_ SECRET, ACCOUNT_ USERNAME, ADMIN_ACCOUNT_ BASIC_AUTH_ PASSWORD)
db.add_ view(view_ name, mapjs, reducejs, dd_name)
+=======
+
+ dump_ini(local, local_files.
+ # save admin account details in keyring
+ item_id = gnomekeyring.
+ None,
+ gnomekeyring.
+ 'Desktop Couch user authentication',
+ {'desktopcouch': 'basic'},
+ "%s:%s" % (ADMIN_
+ True)
+ # and oauth tokens
+ item_id = gnomekeyring.
+ None,
+ gnomekeyring.
+ 'Desktop Couch user authentication',
+ {'desktopcouch': 'oauth'},
+ "%s:%s:%s:%s" % (CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET),
+ True)
+
+
+ return (ADMIN_
+
+def run_couchdb():
+>>>>>>> MERGE-SOURCE
"""Actually start the CouchDB process"""
local_exec = exec_command + ['-b']
try:
@@ -142,7 +214,7 @@
# than inefficiently just overwriting it regardless
-def write_bookmark_ file(): file(username, password): join(local_ files.DIR_ DB, "couchdb.html")
+def write_bookmark_
"""Write out an HTML document that the user can bookmark to find their DB"""
bookmark_file = os.path.
@@ -182,21 +254,24 @@ html.replace( "[[COUCHDB_ PORT]]" , port)) "[[COUCHDB_ PORT]]" , port) "[[COUCHDB_ USERNAME] ]", username) "[[COUCHDB_ PASSWORD] ]", password)
os. path.realpath( bookmark_ file)
pass
else:
fp = open(bookmark_file, "w")
- fp.write(
+ out = html.replace(
+ out = out.replace(
+ out = out.replace(
+ fp.write(out)
fp.close()
print "Browse your desktop CouchDB at file://%s" % \
def start_couchdb(): design_ documents here. This is because design_ documents design_ documents file() file(username, password)
"""Execute each step to start a desktop CouchDB"""
- create_ini_file()
+ username, password = create_ini_file()
run_couchdb()
# Note that we do not call update_
# Couch won't actually have started yet, so when update_
# calls the Records API, that will call back into get_pid and we end up
# starting Couch again. Instead, get_pid calls update_
# *after* Couch startup has occurred.
- write_bookmark_
+ write_bookmark_
if __name__ == "__main__":