Skip to content

Commit 43c9302

Browse files
committed
Add support for volumes for deployments
1 parent 19e281f commit 43c9302

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

src/commands/config.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@ const pairValidation = input => {
2020
return key && val;
2121
});
2222
if (res.some(r => !r)) {
23-
return `Value should be specified in 'key=val,key2=val2' format!`;
23+
return `Values should be specified in 'key=val,key2=val2' format!`;
24+
}
25+
return true;
26+
};
27+
28+
const volumeValidation = input => {
29+
if (!input) {
30+
return true;
31+
}
32+
33+
const pairs = input.split(',');
34+
const res = pairs.map(pair => {
35+
const s = pair.split(':');
36+
const [key, val] = s;
37+
return key && val;
38+
});
39+
if (res.some(r => !r)) {
40+
return `Values should be specified in 'src:dest,src2:dest2' format!`;
2441
}
2542
return true;
2643
};
@@ -112,6 +129,14 @@ exports.handler = async () => {
112129
filter,
113130
validate: pairValidation,
114131
});
132+
prompts.push({
133+
type: 'input',
134+
name: 'volumes',
135+
message: 'Volumes [comma-separated, optional]:',
136+
default: defaultConfig.volumes ? defaultConfig.volumes.join(', ') : '',
137+
filter,
138+
validate: volumeValidation,
139+
});
115140
prompts.push({
116141
type: 'confirm',
117142
name: 'enableRatelimit',
@@ -167,6 +192,7 @@ exports.handler = async () => {
167192
type: 'confirm',
168193
name: 'basicAuth',
169194
message: 'Add a basic auth user? [optional]:',
195+
default: Boolean(defaultConfig.basicAuth),
170196
});
171197

172198
// prompts for recursive questions
@@ -209,6 +235,7 @@ exports.handler = async () => {
209235
project,
210236
env,
211237
labels,
238+
volumes,
212239
enableRatelimit,
213240
ratelimitPeriod,
214241
ratelimitAverage,
@@ -247,6 +274,9 @@ exports.handler = async () => {
247274
.map(pair => ({key: pair[0].trim(), value: pair[1].trim()}))
248275
.reduce((prev, obj) => Object.assign(prev, {[obj.key]: obj.value}), {});
249276
}
277+
if (volumes && volumes.length) {
278+
config.volumes = volumes.split(',').map(v => v.trim());
279+
}
250280
if (enableRatelimit) {
251281
config.rateLimit = {
252282
period: ratelimitPeriod,

test/config.test.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,27 @@ const configData = {
2626
ratelimitPeriod: 10,
2727
ratelimitAverage: 20,
2828
ratelimitBurst: 30,
29+
volumes: 'test:/volume',
2930
basicAuth: true,
3031
};
31-
const users = [{
32-
username: 'user1',
33-
password: 'pass',
34-
askAgain: true
35-
}, {
36-
username: 'user2',
37-
password: 'pass',
38-
askAgain: false
39-
}];
32+
const users = [
33+
{
34+
username: 'user1',
35+
password: 'pass',
36+
askAgain: true,
37+
},
38+
{
39+
username: 'user2',
40+
password: 'pass',
41+
askAgain: false,
42+
},
43+
];
4044
const configPath = path.join(process.cwd(), 'exoframe.json');
4145

4246
const verifyBasicAuth = (input, actual) => {
4347
actual.split(',').forEach((element, index) => {
44-
const hash = element.split(':')[1]
45-
expect(hash).toEqual(md5(input[index].password, hash))
48+
const hash = element.split(':')[1];
49+
expect(hash).toEqual(md5(input[index].password, hash));
4650
});
4751
};
4852

@@ -58,10 +62,14 @@ beforeAll(() => {
5862
// test config generation
5963
test('Should generate config file', done => {
6064
// stup inquirer answers
61-
sinon.stub(inquirer, 'prompt')
62-
.onFirstCall().callsFake(() => Promise.resolve(configData))
63-
.onSecondCall().callsFake(() => Promise.resolve(users[0]))
64-
.onThirdCall().callsFake(() => Promise.resolve(users[1]));
65+
sinon
66+
.stub(inquirer, 'prompt')
67+
.onFirstCall()
68+
.callsFake(() => Promise.resolve(configData))
69+
.onSecondCall()
70+
.callsFake(() => Promise.resolve(users[0]))
71+
.onThirdCall()
72+
.callsFake(() => Promise.resolve(users[1]));
6573
// spy on console
6674
const consoleSpy = sinon.spy(console, 'log');
6775
// execute login

0 commit comments

Comments
 (0)