Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
90 additions
and
166 deletions.
There are no files selected for viewing
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,48 @@ | ||
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, { | ||
couch_httpd_auth: { | ||
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 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.
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.
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