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

Commit bba1548

Browse files
committed
Add final param for web actions.
Fixes #132
1 parent 016e9ea commit bba1548

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

compile/functions/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,29 @@ class OpenWhiskCompileFunctions {
105105
.map(key => ({ key, value: functionObject.parameters[key] }));
106106

107107
// optional action annotations
108-
const Annotations = Object.keys(functionObject.annotations || {})
109-
.map(key => ({ key, value: functionObject.annotations[key] }));
108+
const Annotations = this.constructAnnotations(functionObject.annotations);
110109

111110
return this.compileFunctionAction(
112111
{ FunctionName, NameSpace, Overwrite, Exec, Timeout, MemorySize, Parameters, Annotations }
113112
);
114113
});
115114
}
116115

116+
constructAnnotations (annotations) {
117+
if (!annotations) return []
118+
119+
// finalise action parameters when exposing as external HTTP endpoint.
120+
// mirrors behaviour from OpenWhisk CLI.
121+
if (annotations['web-export']) {
122+
annotations['final'] = true
123+
}
124+
125+
const converted = Object.keys(annotations)
126+
.map(key => ({ key, value: annotations[key] }));
127+
128+
return converted
129+
}
130+
117131
logCompiledFunction (name, fn) {
118132
const clone = JSON.parse(JSON.stringify(fn))
119133
if (clone.action.exec.code) {

compile/functions/tests/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ describe('OpenWhiskCompileFunctions', () => {
7171
});
7272
});
7373

74+
describe('#constructAnnotations()', () => {
75+
it('should handle missing annotations', () => {
76+
expect(openwhiskCompileFunctions.constructAnnotations())
77+
.to.deep.equal([]);
78+
})
79+
it('should handle empty annotations', () => {
80+
expect(openwhiskCompileFunctions.constructAnnotations({}))
81+
.to.deep.equal([]);
82+
})
83+
it('should handle annotations present', () => {
84+
expect(openwhiskCompileFunctions.constructAnnotations({
85+
hello: 'world', foo: 'bar'
86+
})).to.deep.equal([
87+
{ key: 'hello', value: 'world' },
88+
{ key: 'foo', value: 'bar' }
89+
]);
90+
})
91+
it('should add final annotations if web-export is present', () => {
92+
expect(openwhiskCompileFunctions.constructAnnotations({
93+
hello: 'world', foo: 'bar', "web-export": true
94+
})).to.deep.equal([
95+
{ key: 'hello', value: 'world' },
96+
{ key: 'foo', value: 'bar' },
97+
{ key: 'web-export', value: true },
98+
{ key: 'final', value: true }
99+
]);
100+
})
101+
})
102+
74103
describe('#calculateFunctionNameSpace()', () => {
75104
it('should return namespace from function object', () => {
76105
expect(openwhiskCompileFunctions

0 commit comments

Comments
 (0)