Skip to content

Commit 16b560a

Browse files
3128 create serverless function based on repository template (#3240)
* initial commit Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * template based serverless fuction Signed-off-by: msivasubramaniaan <msivasub@redhat.com> --------- Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent 06ea00f commit 16b560a

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src/serverlessFunction/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ export class ServerlessCommand {
110110
return commandText
111111
}
112112

113+
static getTemplates(): CommandText {
114+
const commandText = new CommandText('func', 'templates');
115+
commandText.addOption(new CommandOption('--json'))
116+
return commandText
117+
}
118+
113119
static getClusterVersion(): CommandText {
114120
return new CommandText('oc get clusterversion', undefined, [
115121
new CommandOption('-o', 'josn')

src/serverlessFunction/functions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import validator from 'validator';
88
import { commands, EventEmitter, Terminal, Uri, window } from 'vscode';
99
import { CliChannel } from '../cli';
1010
import { OdoImpl } from '../odo';
11+
import { CliExitData } from '../util/childProcessUtil';
1112
import { Platform } from '../util/platform';
1213
import { Progress } from '../util/progress';
1314
import { ServerlessCommand, Utils } from './commands';
@@ -229,6 +230,14 @@ export class Functions {
229230
});
230231
}
231232

233+
public async getTemplates(): Promise<CliExitData> {
234+
const result = await OdoImpl.Instance.execute(ServerlessCommand.getTemplates(), undefined, false);
235+
if (result.error) {
236+
void window.showErrorMessage(result.error.message);
237+
}
238+
return JSON.parse(result.stdout);
239+
}
240+
232241
public async deploy(context: FunctionObject) {
233242
const currentNamespace: string = await OdoImpl.Instance.getActiveProject();
234243
const yamlContent = await Utils.getFuncYamlContent(context.folderURI.fsPath);

src/webview/serverless-function/app/createFunction.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
3030
helpText?: string
3131
},
3232
images: string[],
33+
baseTemplates: string[],
3334
templates: string[],
3435
language: string,
3536
template: string,
@@ -52,6 +53,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
5253
helpText: `Image name should be in the form of '[registry]/[namespace]/[name]:[tag]'`
5354
},
5455
images: [],
56+
baseTemplates: [],
5557
templates: [],
5658
language: '',
5759
template: '',
@@ -60,7 +62,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
6062
showLoadScreen: false
6163
}
6264
VSCodeMessage.postMessage({
63-
action: 'selectFolder'
65+
action: 'getTemplates'
6466
});
6567
}
6668

@@ -98,6 +100,13 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
98100
wsFolderItems: message.data.wsFolderItems
99101
});
100102
}
103+
} else if (message.data.action === 'getTemplates') {
104+
this.setState({
105+
baseTemplates: message.data.basicTemplates
106+
});
107+
VSCodeMessage.postMessage({
108+
action: 'selectFolder'
109+
});
101110
}
102111
});
103112
}
@@ -129,15 +138,9 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
129138

130139
handleDropDownChange = (_event: any, value: string, isLang = false): void => {
131140
if (isLang) {
132-
if (value !== 'Python') {
133-
this.setState({
134-
templates: ['Cloud Events', 'HTTP']
135-
});
136-
} else {
137-
this.setState({
138-
templates: ['Cloud Events', 'Flask', 'HTTP', 'WSGI']
139-
})
140-
}
141+
this.setState({
142+
templates: this.state.baseTemplates[this.convert(value)]
143+
});
141144
this.setState({
142145
language: value,
143146
template: ''

src/webview/serverless-function/serverlessFunctionLoader.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise<
100100
await Functions.getInstance().invoke(functionName, invokeFunData);
101101
panel.dispose();
102102
break;
103+
case 'getTemplates':
104+
const templates = await Functions.getInstance().getTemplates();
105+
panel?.webview.postMessage({
106+
action: eventName,
107+
basicTemplates: templates
108+
})
103109
default:
104110
break;
105111
}

0 commit comments

Comments
 (0)