Skip to content

Commit a1921a4

Browse files
committed
Allow using token for deploy command, closes #33
1 parent 607b4ac commit a1921a4

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

src/commands/deploy.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ const streamToResponse = ({tarStream, remoteUrl, options}) =>
3737

3838
exports.command = ['*', 'deploy'];
3939
exports.describe = 'deploy current folder';
40-
exports.builder = {};
41-
exports.handler = async args => {
42-
if (!isLoggedIn()) {
40+
exports.builder = {
41+
token: {
42+
alias: 't',
43+
},
44+
};
45+
exports.handler = async (args = {}) => {
46+
const deployToken = args.token;
47+
48+
// exit if not logged in and no token provided
49+
if (!deployToken && !isLoggedIn()) {
4350
return;
4451
}
4552

46-
const folder = args && args._ ? args._.filter(arg => arg !== 'deploy').shift() : undefined;
53+
const folder = args._ ? args._.filter(arg => arg !== 'deploy').shift() : undefined;
4754

4855
console.log(chalk.bold(`Deploying ${folder || 'current project'} to endpoint:`), userConfig.endpoint);
4956

@@ -86,9 +93,14 @@ exports.handler = async args => {
8693
ignore: name => ig.ignores(name),
8794
});
8895

96+
let token = userConfig.token;
97+
if (deployToken) {
98+
token = deployToken;
99+
console.log('Deploying using given token..');
100+
}
89101
const options = {
90102
headers: {
91-
Authorization: `Bearer ${userConfig.token}`,
103+
Authorization: `Bearer ${token}`,
92104
},
93105
};
94106

src/commands/login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ exports.command = 'login';
1717
exports.describe = 'login into exoframe server';
1818
exports.builder = {
1919
key: {
20-
short: 'k',
20+
alias: 'k',
2121
},
2222
passphrase: {
23-
short: 'p',
23+
alias: 'p',
2424
},
2525
};
2626
exports.handler = async ({key, passphrase}) => {

test/deploy.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,47 @@ module.exports = () => {
104104
});
105105
});
106106

107+
// test
108+
tap.test('Should deploy without auth but with token', t => {
109+
// spy on console
110+
const consoleSpy = sinon.spy(console, 'log');
111+
// copy original config for restoration
112+
const originalConfig = Object.assign({}, userConfig);
113+
114+
// handle correct request
115+
const deployServer = nock('http://localhost:8080').post('/deploy').reply((uri, requestBody, cb) => {
116+
cb(null, [200, {status: 'success', deployments}]);
117+
});
118+
119+
// remove auth from config
120+
updateConfig({endpoint: 'http://localhost:8080'});
121+
122+
// execute login
123+
deploy({token: 'test-token'}).then(() => {
124+
// make sure log in was successful
125+
// check that server was called
126+
t.ok(deployServer.isDone());
127+
// first check console output
128+
t.deepEqual(
129+
consoleSpy.args,
130+
[
131+
['Deploying current project to endpoint:', 'http://localhost:8080'],
132+
['Deploying using given token..'],
133+
['Your project is now deployed as:\n'],
134+
[' ID URL Hostname \n test http://localhost test '],
135+
],
136+
'Correct log output'
137+
);
138+
// restore console
139+
console.log.restore();
140+
// tear down nock
141+
deployServer.done();
142+
// restore original config
143+
updateConfig(originalConfig);
144+
t.end();
145+
});
146+
});
147+
107148
// test
108149
tap.test('Should not deploy with broken config', t => {
109150
// spy on console

0 commit comments

Comments
 (0)