-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now checking the status of /_config instead of relying on the vendor …
…details
- Loading branch information
1 parent
b62499a
commit 35510ba
Showing
11 changed files
with
136 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = checkVendor | ||
|
||
var findKey = require('lodash').findKey | ||
|
||
var toCouchDbUrl = require('../../utils/pouchdb-options-to-couchdb-url') | ||
var removeAuth = require('../../utils/remove-auth-from-url') | ||
|
||
function checkVendor (state, couch, callback) { | ||
couch({url: '/'}, function (error, response, data) { | ||
if (error || (response && response.statusCode !== 200)) { | ||
var url = toCouchDbUrl(state.db.options) | ||
return callback(new Error('Could not find CouchDB at ' + removeAuth(url))) | ||
} | ||
|
||
var vendor = findKey(data, function (property) { | ||
return /^welcome/i.test(property) | ||
}) | ||
|
||
if (vendor !== 'couchdb') { | ||
state.server.log( | ||
['database', 'warn'], | ||
'You are not running an official CouchDB distribution, ' + | ||
'but "' + vendor + '". ' + | ||
'This might not be fully supported. Proceed at your own risk.' | ||
) | ||
} | ||
|
||
callback(null) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,50 @@ | ||
module.exports = getConfig | ||
|
||
var pick = require('lodash').pick | ||
var defaults = require('lodash').defaults | ||
|
||
function getConfig (couch, callback) { | ||
function getConfig (state, couch, callback) { | ||
getCurrentConfig(couch, function (error, config) { | ||
if (error) state.server.log(['database', 'warn'], 'Could not get CouchDB values from `/_config`. Using defaults.') | ||
|
||
config = defaults(config, { | ||
admins: undefined, | ||
couch_httpd_auth: { | ||
secret: null, | ||
authentication_db: '_users' | ||
} | ||
}) | ||
|
||
// attempt to setAuthHandlers | ||
setAuthHandlers(couch, function (error) { | ||
if (error) state.server.log(['database', 'warn'], 'Could not set CouchDB values to `/_config`, hoodie may not run correctly.') | ||
|
||
callback(null, config) | ||
}) | ||
}) | ||
} | ||
|
||
function getCurrentConfig (couch, callback) { | ||
couch({ | ||
url: '/_config/couch_httpd_auth' | ||
url: '/_config' | ||
}, function (error, response, data) { | ||
if (error || (response && response.statusCode !== 200)) { | ||
return callback(new Error('Could not retrieve necessary CouchDB config values')) | ||
return callback(new Error('There was an error loading CouchDB values from `/_config`')) | ||
} | ||
|
||
if (!data.secret) { | ||
return callback(new Error('Could not retrieve CouchDB secret')) | ||
} | ||
callback(null, data) | ||
}) | ||
} | ||
|
||
if (!data.authentication_db) { | ||
return callback(new Error('Could not retrieve CouchDB authentication database')) | ||
function setAuthHandlers (couch, callback) { | ||
couch({ | ||
url: '/_config/httpd/authentication_handlers', | ||
method: 'PUT', | ||
body: '{couch_httpd_oauth, oauth_authentication_handler},{couch_httpd_auth, default_authentication_handler},{couch_httpd_auth, cookie_authentication_handler}' | ||
}, function (error, response, data) { | ||
if (error || (response && response.statusCode !== 200)) { | ||
return callback(new Error('Could not set necessary CouchDB config')) | ||
} | ||
|
||
callback(null, pick(data, ['secret', 'authentication_db'])) | ||
callback(null) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.