Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 120b49c

Browse files
committed
Format API host correctly when protocol is already present.
1 parent a6a6b90 commit 120b49c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

info/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class OpenWhiskInfo {
3434

3535
return this.provider.props().then(props => {
3636
this.props = props;
37+
this.props.apihost = formatApiHost(props.apihost);
3738
return this.provider.client();
3839
}).then(client => {
3940
this.client = client;
@@ -93,7 +94,7 @@ class OpenWhiskInfo {
9394
return this.provider.props().then(props => {
9495
web_actions.forEach(action => {
9596
const nsPkge = extractNsAndPkge(action.namespace)
96-
this.consoleLog(`https://${props.apihost}/api/v1/web/${nsPkge.ns}/${nsPkge.pkge}/${action.name}`)
97+
this.consoleLog(`${formatApiHost(props.apihost)}/api/v1/web/${nsPkge.ns}/${nsPkge.pkge}/${action.name}`)
9798
})
9899
})
99100
}
@@ -173,4 +174,13 @@ class OpenWhiskInfo {
173174
}
174175
}
175176

177+
function formatApiHost(apihost) {
178+
if (apihost && !(apihost.startsWith('http://') || apihost.startsWith('https://'))) {
179+
// assume https unless explicitly declared
180+
return `https://${apihost}`;
181+
} else {
182+
return apihost;
183+
}
184+
}
185+
176186
module.exports = OpenWhiskInfo;

info/tests/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,27 @@ describe('OpenWhiskInfo', () => {
307307
expect(log.args[3][0].match(/https:\/\/openwhisk.ng.bluemix.net\/api\/v1\/web\/user_name\/custom_package\/sixth/)).to.be.ok;
308308
}));
309309
})
310+
311+
it('should show web action routes returned with apihost that include a protocol', () => {
312+
const apihost = 'http://localhost'
313+
openwhiskInfo.provider = { props: () => Promise.resolve({ apihost }) }
314+
const log = sandbox.stub(openwhiskInfo, 'consoleLog')
315+
openwhiskInfo._actions = [
316+
{name: 'first', namespace: 'user_name', annotations: [{key: 'web-export', value: true}, {key: 'a', value: 'b'}]},
317+
{name: 'second', namespace: 'user_name', annotations: [{key: 'web-export', value: false}]},
318+
{name: 'third'},
319+
{name: 'fourth', namespace: 'user_name', annotations: [{key: 'web-export', value: true}]},
320+
{name: 'fifth', annotations: []},
321+
{name: 'sixth', namespace: 'user_name/custom_package', annotations: [{key: 'web-export', value: true}]},
322+
];
323+
324+
return expect(openwhiskInfo.showWebActionsInfo().then(() => {
325+
expect(log.callCount).to.be.equal(4);
326+
expect(log.args[0][0].match(/endpoints \(web actions\):/)).to.be.ok;
327+
expect(log.args[1][0].match(/http:\/\/localhost\/api\/v1\/web\/user_name\/default\/first/)).to.be.ok;
328+
expect(log.args[2][0].match(/http:\/\/localhost\/api\/v1\/web\/user_name\/default\/fourth/)).to.be.ok;
329+
expect(log.args[3][0].match(/http:\/\/localhost\/api\/v1\/web\/user_name\/custom_package\/sixth/)).to.be.ok;
330+
}));
331+
})
310332
})
311333
});

0 commit comments

Comments
 (0)