-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 5446e00
Showing
13 changed files
with
304 additions
and
0 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,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,2 @@ | ||
coverage | ||
example.js |
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,27 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules |
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,5 @@ | ||
node_modules | ||
test | ||
coverage | ||
LICENSE | ||
.* |
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 @@ | ||
v6 |
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,10 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "5" | ||
- "6" | ||
notifications: | ||
email: false | ||
after_success: | ||
- npm run coveralls | ||
- npm run codeclimate |
Empty file.
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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Leonardo Gatica | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
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,29 @@ | ||
# config-dburi | ||
|
||
[![npm version](https://img.shields.io/npm/v/config-dburi.svg?style=flat-square)](https://www.npmjs.com/package/config-dburi) | ||
[![npm downloads](https://img.shields.io/npm/dm/config-dburi.svg?style=flat-square)](https://www.npmjs.com/package/config-dburi) | ||
[![Build Status](https://img.shields.io/travis/lgaticaq/config-dburi.svg?style=flat-square)](https://travis-ci.org/lgaticaq/config-dburi) | ||
[![Coverage Status](https://img.shields.io/coveralls/lgaticaq/config-dburi/master.svg?style=flat-square)](https://coveralls.io/github/lgaticaq/config-dburi?branch=master) | ||
[![Code Climate](https://img.shields.io/codeclimate/github/lgaticaq/config-dburi.svg?style=flat-square)](https://codeclimate.com/github/lgaticaq/config-dburi) | ||
[![dependency Status](https://img.shields.io/david/lgaticaq/config-dburi.svg?style=flat-square)](https://david-dm.org/lgaticaq/config-dburi#info=dependencies) | ||
[![devDependency Status](https://img.shields.io/david/dev/lgaticaq/config-dburi.svg?style=flat-square)](https://david-dm.org/lgaticaq/config-dburi#info=devDependencies) | ||
|
||
> Get database uris for your config settings | ||
## Installation | ||
```bash | ||
npm i -S config-dburi | ||
``` | ||
|
||
## Use | ||
|
||
[Try on Tonic](https://tonicdev.com/npm/config-dburi) | ||
```js | ||
const dburi = require('config-dburi'); | ||
|
||
console.log(dburi.mongo()); // mongodb://localhost/test | ||
``` | ||
|
||
## License | ||
|
||
[MIT](https://tldrlegal.com/license/mit-license) |
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,3 @@ | ||
const dburi = require('config-dburi'); | ||
|
||
console.log(dburi.mongo()); |
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,67 @@ | ||
{ | ||
"name": "config-dburi", | ||
"version": "0.0.0", | ||
"description": "Get database uris for your config settings", | ||
"main": "src", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"pretest": "npm run lint -s", | ||
"test": "istanbul cover _mocha", | ||
"coveralls": "coveralls < coverage/lcov.info", | ||
"codeclimate": "codeclimate-test-reporter < coverage/lcov.info", | ||
"release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags && npm publish", | ||
"release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags && npm publish", | ||
"release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags && npm publish" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/lgaticaq/config-dburi.git" | ||
}, | ||
"keywords": [], | ||
"author": "Leonardo Gatica", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lgaticaq/config-dburi/issues" | ||
}, | ||
"homepage": "https://github.com/lgaticaq/config-dburi#readme", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"codeclimate-test-reporter": "^0.3.3", | ||
"coveralls": "^2.11.14", | ||
"eslint": "3.6.0", | ||
"generate-changelog": "^1.0.2", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.0.2" | ||
}, | ||
"eslintConfig": { | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"rules": { | ||
"indent": [ | ||
2, | ||
2 | ||
], | ||
"linebreak-style": [ | ||
2, | ||
"unix" | ||
], | ||
"quotes": [ | ||
2, | ||
"single" | ||
], | ||
"semi": [ | ||
2, | ||
"always" | ||
] | ||
} | ||
}, | ||
"tonicExampleFilename": "example.js" | ||
} |
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,41 @@ | ||
'use strict'; | ||
|
||
const getMongodbUri = dbname => { | ||
dbname = dbname || 'test'; | ||
let uri = `mongodb://localhost/${dbname}`; | ||
if (process.env.MONGO_PORT_27017_TCP_ADDR && process.env.MONGO_PORT_27017_TCP_PORT) { | ||
uri = `mongodb://${process.env.MONGO_PORT_27017_TCP_ADDR}:${process.env.MONGO_PORT_27017_TCP_PORT}/${dbname}`; | ||
} else if (process.env.MONGODB_URI) { | ||
uri = process.env.MONGODB_URI; | ||
} | ||
return uri; | ||
}; | ||
|
||
const getRedisUri = () => { | ||
let uri = 'redis://localhost'; | ||
if (process.env.REDIS_PORT_6379_TCP_ADDR && process.env.REDIS_PORT_6379_TCP_PORT) { | ||
uri = `redis://${process.env.REDIS_PORT_6379_TCP_ADDR}:${process.env.REDIS_PORT_6379_TCP_PORT}`; | ||
} else if (process.env.REDIS_URI) { | ||
uri = process.env.REDIS_URI; | ||
} | ||
return uri; | ||
}; | ||
|
||
const getPostgresqlUri = password => { | ||
const username = process.env.POSTGRES_USER || 'postgres'; | ||
const dbname = process.env.POSTGRES_USER || 'postgres'; | ||
password = password || process.env.POSTGRES_PASSWORD || 'mysecretpassword'; | ||
let uri = `postgres://${username}:${password}@localhost/${dbname}`; | ||
if (process.env.POSTGRES_PORT_5432_TCP_ADDR && process.env.POSTGRES_PORT_5432_TCP_PORT && process.env.POSTGRES_PASSWORD) { | ||
uri = `postgres://${username}:${password}@${process.env.POSTGRES_PORT_5432_TCP_ADDR}:${process.env.POSTGRES_PORT_5432_TCP_PORT}/${dbname}`; | ||
} else if (process.env.POSTGRESQL_URI) { | ||
uri = process.env.POSTGRESQL_URI; | ||
} | ||
return uri; | ||
}; | ||
|
||
module.exports = { | ||
mongo: getMongodbUri, | ||
redis: getRedisUri, | ||
postgres: getPostgresqlUri | ||
}; |
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,85 @@ | ||
'use strict'; | ||
|
||
const config = require('../src'); | ||
const expect = require('chai').expect; | ||
|
||
describe('config-dburi', () => { | ||
describe('mongo', () => { | ||
it('should return mongo uri default', () => { | ||
delete process.env.MONGO_PORT_27017_TCP_ADDR; | ||
delete process.env.MONGO_PORT_27017_TCP_PORT; | ||
delete process.env.MONGODB_URI; | ||
expect(config.mongo()).to.eql('mongodb://localhost/test'); | ||
}); | ||
it('should return mongo uri docker default', () => { | ||
process.env.MONGO_PORT_27017_TCP_ADDR = '172.168.1.2'; | ||
process.env.MONGO_PORT_27017_TCP_PORT = 27017; | ||
delete process.env.MONGODB_URI; | ||
expect(config.mongo()).to.eql('mongodb://172.168.1.2:27017/test'); | ||
}); | ||
it('should return mongo uri docker with dbname', () => { | ||
process.env.MONGO_PORT_27017_TCP_ADDR = '172.168.1.2'; | ||
process.env.MONGO_PORT_27017_TCP_PORT = 27017; | ||
delete process.env.MONGODB_URI; | ||
expect(config.mongo('example')).to.eql('mongodb://172.168.1.2:27017/example'); | ||
}); | ||
it('should return mongo uri from env default', () => { | ||
delete process.env.MONGO_PORT_27017_TCP_ADDR; | ||
delete process.env.MONGO_PORT_27017_TCP_PORT; | ||
process.env.MONGODB_URI = 'mongodb://user:[email protected]:1234'; | ||
expect(config.mongo()).to.eql('mongodb://user:[email protected]:1234'); | ||
}); | ||
}); | ||
|
||
describe('redis', () => { | ||
it('should return redis uri default', () => { | ||
delete process.env.REDIS_PORT_6379_TCP_ADDR; | ||
delete process.env.REDIS_PORT_6379_TCP_PORT; | ||
delete process.env.REDIS_URI; | ||
expect(config.redis()).to.eql('redis://localhost'); | ||
}); | ||
it('should return redis uri docker default', () => { | ||
process.env.REDIS_PORT_6379_TCP_ADDR = '172.168.1.2'; | ||
process.env.REDIS_PORT_6379_TCP_PORT = 6379; | ||
delete process.env.REDIS_URI; | ||
expect(config.redis()).to.eql('redis://172.168.1.2:6379'); | ||
}); | ||
it('should return redis uri from env default', () => { | ||
delete process.env.REDIS_PORT_6379_TCP_ADDR; | ||
delete process.env.REDIS_PORT_6379_TCP_PORT; | ||
process.env.REDIS_URI = 'redis://redis:[email protected]:1234'; | ||
expect(config.redis()).to.eql('redis://redis:[email protected]:1234'); | ||
}); | ||
}); | ||
|
||
describe('postgres', () => { | ||
it('should return postgres uri default', () => { | ||
delete process.env.POSTGRES_PORT_5432_TCP_ADDR; | ||
delete process.env.POSTGRES_PORT_5432_TCP_PORT; | ||
delete process.env.POSTGRES_PASSWORD; | ||
delete process.env.POSTGRESQL_URI; | ||
expect(config.postgres()).to.eql('postgres://postgres:mysecretpassword@localhost/postgres'); | ||
}); | ||
it('should return postgres uri default with password', () => { | ||
delete process.env.POSTGRES_PORT_5432_TCP_ADDR; | ||
delete process.env.POSTGRES_PORT_5432_TCP_PORT; | ||
delete process.env.POSTGRES_PASSWORD; | ||
delete process.env.POSTGRESQL_URI; | ||
expect(config.postgres('mypass')).to.eql('postgres://postgres:mypass@localhost/postgres'); | ||
}); | ||
it('should return postgres uri docker default', () => { | ||
process.env.POSTGRES_PORT_5432_TCP_ADDR = '172.168.1.2'; | ||
process.env.POSTGRES_PORT_5432_TCP_PORT = 5432; | ||
process.env.POSTGRES_PASSWORD = 'mypass'; | ||
delete process.env.POSTGRESQL_URI; | ||
expect(config.postgres()).to.eql('postgres://postgres:[email protected]:5432/postgres'); | ||
}); | ||
it('should return postgres uri from env default', () => { | ||
delete process.env.POSTGRES_PORT_5432_TCP_ADDR; | ||
delete process.env.POSTGRES_PORT_5432_TCP_PORT; | ||
delete process.env.POSTGRES_PASSWORD; | ||
process.env.POSTGRESQL_URI = 'postgres://user:[email protected]:1234'; | ||
expect(config.postgres()).to.eql('postgres://user:[email protected]:1234'); | ||
}); | ||
}); | ||
}); |