Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid hard coding the postgres username #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/adm.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ function clear(opts, cb) {
*/
function rebuild(opts, cb) {
var config = opts.config;
var pgUrl = 'tcp://postgres@' + config.ip + ':' + config.postgresPort +
'/postgres';
var pgUrl = 'tcp://' + config.postgresMgrCfg.dbUser + '@' + config.ip +
':' + config.postgresPort + '/postgres';
var dataset = config.postgresMgrCfg.zfsClientCfg.dataset;
var shard = path.basename(config.shardPath);

Expand Down Expand Up @@ -651,8 +651,8 @@ function promote(opts, cb) {
var config = opts.config;
var cookie = config.postgresMgrCfg.syncStateCheckerCfg.cookieLocation;
var shard = path.basename(config.shardPath);
var pgUrl = 'tcp://postgres@' + config.ip + ':' + config.postgresPort +
'/postgres';
var pgUrl = 'tcp://' + config.postgresMgrCfg.dbUser + '@' + config.ip +
':' + config.postgresPort + '/postgres';

vasync.pipeline({funcs: [
function _getShardStatus(_, _cb) {
Expand Down Expand Up @@ -974,7 +974,9 @@ function transformBackupUrl(zkNode) {
* @return {string} The transformed pg url, e.g.
* tcp://postgres@10.0.0.0:5432/postgres
*/
function transformPgUrl(zkNode) {
function transformPgUrl(opts, zkNode) {
var config = opts.config;
var data = zkNode.split('-')[0].split(':');
return 'tcp://postgres@' + data[0] + ':' + data[1] + '/postgres';
return 'tcp://' + config.postgresMgrCfg.dbUser + '@' + data[0] + ':' +
data[1] + '/postgres';
}
9 changes: 5 additions & 4 deletions lib/shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Shard.prototype.TRANSITION_FUNCS = {
var self = ctx.self;
var log = self._log;
var myLeader = ctx.leader;
var pgUrl = self._transformPgUrl(myLeader);
var pgUrl = self._transformPgUrl(myLeader, self._postgresMgr._dbUser);
var backupUrl = self._transformBackupUrl(myLeader);
self._leader = pgUrl;
var postgresMgr = self._postgresMgr;
Expand Down Expand Up @@ -540,7 +540,8 @@ Shard.prototype.TRANSITION_FUNCS = {
var self = ctx.self;
var log = self._log;
var postgresMgr = self._postgresMgr;
var standbyUrl = self._transformPgUrl(ctx.standby);
var standbyUrl = self._transformPgUrl(ctx.standby,
self._postgresMgr._dbUser);
self._currStandby = standbyUrl;

log.info({standby: standbyUrl}, 'Shard.NEW_STANDBY: entering');
Expand Down Expand Up @@ -1744,9 +1745,9 @@ Shard.prototype._writeRegistrar = function (callback) {
* @return {string} The transformed pg url, e.g.
* tcp://postgres@10.0.0.0:5432/postgres
*/
Shard.prototype._transformPgUrl = function (zkNode) {
Shard.prototype._transformPgUrl = function (zkNode, dbUser) {
var data = zkNode.split('-')[0].split(':');
return 'tcp://postgres@' + data[0] + ':' + data[1] + '/postgres';
return 'tcp://' + dbUser + '@' + data[0] + ':' + data[1] + '/postgres';
};

/**
Expand Down