1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | 'use strict';
|
15 |
|
16 | var path = require('path');
|
17 | var tmp = require('tmp');
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function apiDefaults() {
|
23 | return {
|
24 | parallelism: 5,
|
25 | bufferSize: 500,
|
26 | requestTimeout: 120000,
|
27 | log: tmp.fileSync().name,
|
28 | resume: false,
|
29 | mode: 'full'
|
30 | };
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function cliDefaults() {
|
37 | var defaults = apiDefaults();
|
38 |
|
39 |
|
40 | defaults.db = 'test';
|
41 | defaults.url = 'http://localhost:5984';
|
42 |
|
43 | return defaults;
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | function applyEnvironmentVariables(opts) {
|
50 |
|
51 | if (typeof process.env.COUCH_URL !== 'undefined') {
|
52 | opts.url = process.env.COUCH_URL;
|
53 | }
|
54 |
|
55 |
|
56 | if (typeof process.env.COUCH_DATABASE !== 'undefined') {
|
57 | opts.db = process.env.COUCH_DATABASE;
|
58 | }
|
59 |
|
60 |
|
61 | if (typeof process.env.COUCH_BUFFER_SIZE !== 'undefined') {
|
62 | opts.bufferSize = parseInt(process.env.COUCH_BUFFER_SIZE);
|
63 | }
|
64 |
|
65 |
|
66 | if (typeof process.env.COUCH_PARALLELISM !== 'undefined') {
|
67 | opts.parallelism = parseInt(process.env.COUCH_PARALLELISM);
|
68 | }
|
69 |
|
70 |
|
71 | if (typeof process.env.COUCH_REQUEST_TIMEOUT !== 'undefined') {
|
72 | opts.requestTimeout = parseInt(process.env.COUCH_REQUEST_TIMEOUT);
|
73 | }
|
74 |
|
75 |
|
76 | if (typeof process.env.COUCH_LOG !== 'undefined') {
|
77 | opts.log = path.normalize(process.env.COUCH_LOG);
|
78 | }
|
79 |
|
80 |
|
81 | if (typeof process.env.COUCH_RESUME !== 'undefined' && process.env.COUCH_RESUME === 'true') {
|
82 | opts.resume = true;
|
83 | }
|
84 |
|
85 |
|
86 | if (typeof process.env.COUCH_OUTPUT !== 'undefined') {
|
87 | opts.output = path.normalize(process.env.COUCH_OUTPUT);
|
88 | }
|
89 |
|
90 |
|
91 | if (typeof process.env.COUCH_MODE !== 'undefined' && process.env.COUCH_MODE === 'shallow') {
|
92 | opts.mode = 'shallow';
|
93 | }
|
94 |
|
95 |
|
96 | if (typeof process.env.CLOUDANT_IAM_API_KEY !== 'undefined') {
|
97 | opts.iamApiKey = process.env.CLOUDANT_IAM_API_KEY;
|
98 | }
|
99 |
|
100 |
|
101 | if (typeof process.env.CLOUDANT_IAM_TOKEN_URL !== 'undefined') {
|
102 | opts.iamTokenUrl = process.env.CLOUDANT_IAM_TOKEN_URL;
|
103 | }
|
104 | }
|
105 |
|
106 | module.exports = {
|
107 | apiDefaults: apiDefaults,
|
108 | cliDefaults: cliDefaults,
|
109 | applyEnvironmentVariables: applyEnvironmentVariables
|
110 | };
|