Add ASF License headers to all source files. Fix other scan errors. (#23)
diff --git a/gulpfile.js b/gulpfile.js
index 08a9938..f1bd5ff 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,21 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
var gulp = require('gulp');
var zip = require('gulp-vinyl-zip').zip;
gulp.task('build-zip', () => {
- const platform = process.platform;
+ const platform = process.platform;
- return gulp.src([
- 'static-src/commands/**',
- 'static-src/templates/**',
- 'static-src/extension.js',
- 'node_modules/**',
- 'LICENSE',
- 'package.json',
- 'github-assets/**',
- 'README.md',
- '!node_modules/.bin/**',
- '!node_modules/**/.bin'
- ], { base: '.' })
- .pipe(zip(`openwhisk-vscode-${platform}.zip`))
- .pipe(gulp.dest('./out'));
-});
\ No newline at end of file
+ return gulp.src([
+ 'static-src/commands/**',
+ 'static-src/templates/**',
+ 'static-src/extension.js',
+ 'node_modules/**',
+ 'LICENSE',
+ 'package.json',
+ 'github-assets/**',
+ 'README.md',
+ '!node_modules/.bin/**',
+ '!node_modules/**/.bin'
+ ], { base: '.' })
+ .pipe(zip(`openwhisk-vscode-${platform}.zip`))
+ .pipe(gulp.dest('./out'));
+});
diff --git a/static-src/commands/controller.js b/static-src/commands/controller.js
index 046eca5..597e735 100644
--- a/static-src/commands/controller.js
+++ b/static-src/commands/controller.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
"use strict";
var vscode = require('vscode');
@@ -20,23 +37,23 @@
function init(context) {
- //api key and namespace will be set when config values are loaded
- ow = openwhisk({api: 'https://openwhisk.ng.bluemix.net/api/v1/', api_key: 'invalid', namespace: ''});
+ //api key and namespace will be set when config values are loaded
+ ow = openwhisk({api: 'https://openwhisk.ng.bluemix.net/api/v1/', api_key: 'invalid', namespace: ''});
- util.setLog(log);
+ util.setLog(log);
- wskProperty.register(ow, context, log);
- wskLst.register(ow, context, log, wskProperty);
- wskHelp.register(ow, context, log, wskProperty);
- wskAction.register(ow, context, log, wskProperty);
- wskPackage.register(ow, context, log, wskProperty);
- wskTrigger.register(ow, context, log, wskProperty);
- wskRule.register(ow, context, log, wskProperty);
- wskUtil.register(ow, context, log, wskProperty);
- wskActivation.register(ow, context, log, wskProperty);
+ wskProperty.register(ow, context, log);
+ wskLst.register(ow, context, log, wskProperty);
+ wskHelp.register(ow, context, log, wskProperty);
+ wskAction.register(ow, context, log, wskProperty);
+ wskPackage.register(ow, context, log, wskProperty);
+ wskTrigger.register(ow, context, log, wskProperty);
+ wskRule.register(ow, context, log, wskProperty);
+ wskUtil.register(ow, context, log, wskProperty);
+ wskActivation.register(ow, context, log, wskProperty);
}
module.exports = {
- init: init,
- ow: ow
-};
\ No newline at end of file
+ init: init,
+ ow: ow
+};
diff --git a/static-src/commands/util.js b/static-src/commands/util.js
index 4ee21d2..8dd0480 100644
--- a/static-src/commands/util.js
+++ b/static-src/commands/util.js
@@ -1,110 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
let log;
function pad(input, length) {
- if (input == undefined) {
- input = '';
- }
- while (input.length < length) {
- input += ' ';
- }
- return input;
+ if (input == undefined) {
+ input = '';
+ }
+ while (input.length < length) {
+ input += ' ';
+ }
+ return input;
}
function appendHeading(name) {
- log.appendLine('\n'+name+'\n---------------------------------------------------------------------------------');
+ log.appendLine('\n'+name+'\n---------------------------------------------------------------------------------');
}
function appendEntry(entry, qualified) {
- var qualifiedName = formatQualifiedName(entry, qualified);
- var suffix = ''
+ var qualifiedName = formatQualifiedName(entry, qualified);
+ var suffix = ''
- if ( entry.hasOwnProperty('binding') && entry.binding ) {
- suffix = ' binding';
- }
+ if ( entry.hasOwnProperty('binding') && entry.binding ) {
+ suffix = ' binding';
+ }
- log.appendLine( pad(qualifiedName, 66) + (entry.publish ? 'public':'private') + suffix);
+ log.appendLine( pad(qualifiedName, 66) + (entry.publish ? 'public':'private') + suffix);
}
function appendActivation(entry, qualified) {
- var qualifiedName = formatQualifiedName(entry, qualified);
- var suffix = ''
+ var qualifiedName = formatQualifiedName(entry, qualified);
+ var suffix = ''
- if ( entry.hasOwnProperty('binding') && entry.binding ) {
- suffix = ' binding';
- }
+ if ( entry.hasOwnProperty('binding') && entry.binding ) {
+ suffix = ' binding';
+ }
- log.appendLine( pad(entry.activationId, 45) + entry.name);
+ log.appendLine( pad(entry.activationId, 45) + entry.name);
}
function formatQualifiedName(entry, qualified) {
- if (qualified == undefined) {
- qualified = true;
- }
+ if (qualified == undefined) {
+ qualified = true;
+ }
- var qualifiedName = (qualified ? (entry.namespace + '/'):'') + entry.name;
- return qualifiedName;
+ var qualifiedName = (qualified ? (entry.namespace + '/'):'') + entry.name;
+ return qualifiedName;
}
function parseQualifiedName(name) {
- var nameString = name.toString();
- var startIndex = nameString.indexOf('/');
- var namespace = nameString.substring(0, startIndex);
- var parsedName = nameString.substring(startIndex+1);
- return {
- "name":parsedName,
- "namespace":namespace
- };
+ var nameString = name.toString();
+ var startIndex = nameString.indexOf('/');
+ var namespace = nameString.substring(0, startIndex);
+ var parsedName = nameString.substring(startIndex+1);
+ return {
+ "name":parsedName,
+ "namespace":namespace
+ };
}
function setLog(_log) {
- log = _log;
+ log = _log;
}
function printOpenWhiskError(error) {
- log.appendLine('\nERROR: '+error.toString());
- if (error.error.activationId) {
- log.appendLine('activationId: '+error.error.activationId);
- }
- if (error.error.logs && (error.error.logs.length > 0)) {
- for (var x=0; x<error.error.logs.length; x++) {
- log.appendLine(error.error.logs[x]);
- }
- }
+ log.appendLine('\nERROR: '+error.toString());
+ if (error.error.activationId) {
+ log.appendLine('activationId: '+error.error.activationId);
+ }
+ if (error.error.logs && (error.error.logs.length > 0)) {
+ for (var x=0; x<error.error.logs.length; x++) {
+ log.appendLine(error.error.logs[x]);
+ }
+ }
}
function parseParametersString(parameterString) {
- var params = {};
+ var params = {};
- var tokens = parameterString.split('-p ');
+ var tokens = parameterString.split('-p ');
- for (var x=0; x<tokens.length; x++) {
- var token = tokens[x]
- var firstSpace = token.indexOf(' ');
- if (token.length >0 && firstSpace >= 0) {
- var key = token.substring(0, firstSpace).trim();
- var value = token.substring(firstSpace+1).trim();
- params[key] = value;
- }
- }
+ for (var x=0; x<tokens.length; x++) {
+ var token = tokens[x]
+ var firstSpace = token.indexOf(' ');
+ if (token.length >0 && firstSpace >= 0) {
+ var key = token.substring(0, firstSpace).trim();
+ var value = token.substring(firstSpace+1).trim();
+ params[key] = value;
+ }
+ }
- console.log(params)
+ console.log(params)
- return params;
+ return params;
}
module.exports = {
- pad:pad,
- appendHeading:appendHeading,
- appendEntry:appendEntry,
- formatQualifiedName:formatQualifiedName,
- setLog:setLog,
- printOpenWhiskError: printOpenWhiskError,
- parseParametersString: parseParametersString,
- parseQualifiedName:parseQualifiedName,
- appendActivation:appendActivation
-}
\ No newline at end of file
+ pad:pad,
+ appendHeading:appendHeading,
+ appendEntry:appendEntry,
+ formatQualifiedName:formatQualifiedName,
+ setLog:setLog,
+ printOpenWhiskError: printOpenWhiskError,
+ parseParametersString: parseParametersString,
+ parseQualifiedName:parseQualifiedName,
+ appendActivation:appendActivation
+}
diff --git a/static-src/commands/wsk.action.js b/static-src/commands/wsk.action.js
index 0500e56..f680046 100644
--- a/static-src/commands/wsk.action.js
+++ b/static-src/commands/wsk.action.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -17,175 +34,175 @@
//supported OpenWhisk file formats
var NODE = 'JavaScript',
- NODE6 = 'JavaScript 6',
- PYTHON = 'Python',
- SWIFT = 'Swift';
+ NODE6 = 'JavaScript 6',
+ PYTHON = 'Python',
+ SWIFT = 'Swift';
var sequenceComplete = {
- description:'',
- detail:'Sequence Complete - select this option to complete the sequence. No additional action will be added to the sequence.',
- label:'-- No Action --',
- }//'--- - Sequence Complete ---';
+ description:'',
+ detail:'Sequence Complete - select this option to complete the sequence. No additional action will be added to the sequence.',
+ label:'-- No Action --',
+ }//'--- - Sequence Complete ---';
function register(_ow, _context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
- context = _context
+ ow = _ow;
+ log = _log;
+ props = _props;
+ context = _context
- var defaultDisposable = vscode.commands.registerCommand('extension.wsk.action', defaultAction);
- var listDisposable = vscode.commands.registerCommand('extension.wsk.action.list', listAction);
- var invokeDisposable = vscode.commands.registerCommand('extension.wsk.action.invoke', invokeAction);
- var debugDisposable = vscode.commands.registerCommand('extension.wsk.action.debug', debugAction);
- var createDisposable = vscode.commands.registerCommand('extension.wsk.action.create', createAction);
- var updateDisposable = vscode.commands.registerCommand('extension.wsk.action.update', updateAction);
- var deleteDisposable = vscode.commands.registerCommand('extension.wsk.action.delete', deleteAction);
- var getDisposable = vscode.commands.registerCommand('extension.wsk.action.get', getAction);
- var initDisposable = vscode.commands.registerCommand('extension.wsk.action.init', initAction);
- var restDisposable = vscode.commands.registerCommand('extension.wsk.action.rest', restAction);
- var createSequenceDisposable = vscode.commands.registerCommand('extension.wsk.action.sequence.create', createSequenceAction);
+ var defaultDisposable = vscode.commands.registerCommand('extension.wsk.action', defaultAction);
+ var listDisposable = vscode.commands.registerCommand('extension.wsk.action.list', listAction);
+ var invokeDisposable = vscode.commands.registerCommand('extension.wsk.action.invoke', invokeAction);
+ var debugDisposable = vscode.commands.registerCommand('extension.wsk.action.debug', debugAction);
+ var createDisposable = vscode.commands.registerCommand('extension.wsk.action.create', createAction);
+ var updateDisposable = vscode.commands.registerCommand('extension.wsk.action.update', updateAction);
+ var deleteDisposable = vscode.commands.registerCommand('extension.wsk.action.delete', deleteAction);
+ var getDisposable = vscode.commands.registerCommand('extension.wsk.action.get', getAction);
+ var initDisposable = vscode.commands.registerCommand('extension.wsk.action.init', initAction);
+ var restDisposable = vscode.commands.registerCommand('extension.wsk.action.rest', restAction);
+ var createSequenceDisposable = vscode.commands.registerCommand('extension.wsk.action.sequence.create', createSequenceAction);
- context.subscriptions.push(defaultDisposable, listDisposable, invokeDisposable, debugDisposable, createDisposable, updateDisposable, deleteDisposable, getDisposable, initDisposable, createSequenceDisposable, restDisposable);
+ context.subscriptions.push(defaultDisposable, listDisposable, invokeDisposable, debugDisposable, createDisposable, updateDisposable, deleteDisposable, getDisposable, initDisposable, createSequenceDisposable, restDisposable);
}
function defaultAction(params) {
- log.show(true);
- log.appendLine('\n$ wsk action');
- log.appendLine('available commands:');
- log.appendLine(' init create new action boilerplate file');
- log.appendLine(' create create new action');
- log.appendLine(' sequence create a new sequence of actions');
- log.appendLine(' update update an existing action');
- log.appendLine(' invoke invoke action');
- log.appendLine(' get get action');
- log.appendLine(' delete delete action');
- log.appendLine(' list list all actions');
- log.appendLine(' rest display CURL rest invocation parameters');
+ log.show(true);
+ log.appendLine('\n$ wsk action');
+ log.appendLine('available commands:');
+ log.appendLine(' init create new action boilerplate file');
+ log.appendLine(' create create new action');
+ log.appendLine(' sequence create a new sequence of actions');
+ log.appendLine(' update update an existing action');
+ log.appendLine(' invoke invoke action');
+ log.appendLine(' get get action');
+ log.appendLine(' delete delete action');
+ log.appendLine(' list list all actions');
+ log.appendLine(' rest display CURL rest invocation parameters');
}
function listAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- log.show(true);
- log.appendLine('\n$ wsk action list');
- list();
+ log.show(true);
+ log.appendLine('\n$ wsk action list');
+ list();
}
function list() {
- return getList().then(function (actions) {
- util.appendHeading('actions');
- for (var x=0; x<actions.length; x ++){
- util.appendEntry(actions[x]);
- }
- }).catch(function(error) {
- util.printOpenWhiskError(error);
- });
+ return getList().then(function (actions) {
+ util.appendHeading('actions');
+ for (var x=0; x<actions.length; x ++){
+ util.appendEntry(actions[x]);
+ }
+ }).catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
}
function getList() {
- return new Promise(function (fulfill, reject){
- return ow.actions.list().then(function (_actions) {
- actions = _actions;
- fulfill(actions);
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
- });
+ return new Promise(function (fulfill, reject){
+ return ow.actions.list().then(function (_actions) {
+ actions = _actions;
+ fulfill(actions);
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
+ });
}
function getListAsStringArray() {
- return getList().then(function (actions) {
- var result = [];
- for (var x=0; x<actions.length; x ++){
- var actionName = util.formatQualifiedName(actions[x]);
- result.push(actionName)
- }
- return result;
- })
+ return getList().then(function (actions) {
+ var result = [];
+ for (var x=0; x<actions.length; x ++){
+ var actionName = util.formatQualifiedName(actions[x]);
+ result.push(actionName)
+ }
+ return result;
+ })
}
function getListAsStringArrayForSequenceDialog(firstCall) {
- return getListAsStringArray().then(function (actions) {
- if (firstCall !== true ) {
- actions.unshift(sequenceComplete)
- }
- return actions;
- })
+ return getListAsStringArray().then(function (actions) {
+ if (firstCall !== true ) {
+ actions.unshift(sequenceComplete)
+ }
+ return actions;
+ })
}
function invokeAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- selectActionAndRequestParameters( function(namespace, actionToInvoke, parametersString) {
-
- log.show(true);
- log.appendLine('\n$ wsk action invoke ' + actionToInvoke + ' ' + parametersString);
+ selectActionAndRequestParameters( function(namespace, actionToInvoke, parametersString) {
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
+ log.show(true);
+ log.appendLine('\n$ wsk action invoke ' + actionToInvoke + ' ' + parametersString);
- var startTime = new Date().getTime();
- var invocationParams = {
- actionName: actionToInvoke,
- blocking:true,
- namespace: namespace
- }
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
- if (parametersString.length>0) {
- invocationParams.params = util.parseParametersString(parametersString);
- }
- ow.actions.invoke(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine('\n'+JSON.stringify(result.response, null, 4));
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
-
- })
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ actionName: actionToInvoke,
+ blocking:true,
+ namespace: namespace
+ }
+
+ if (parametersString.length>0) {
+ invocationParams.params = util.parseParametersString(parametersString);
+ }
+ ow.actions.invoke(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine('\n'+JSON.stringify(result.response, null, 4));
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+
+ })
}
function selectActionAndRequestParameters(callback) {
- vscode.window.showQuickPick( getListAsStringArray(), {placeHolder:'Select an action.'}).then( function (action) {
+ vscode.window.showQuickPick( getListAsStringArray(), {placeHolder:'Select an action.'}).then( function (action) {
- if (action == undefined) {
- return;
- }
+ if (action == undefined) {
+ return;
+ }
- var actionString = action.toString();
- var startIndex = actionString.indexOf('/');
- var namespace = actionString.substring(0, startIndex);
- var actionToInvoke = actionString.substring(startIndex+1);
+ var actionString = action.toString();
+ var startIndex = actionString.indexOf('/');
+ var namespace = actionString.substring(0, startIndex);
+ var actionToInvoke = actionString.substring(startIndex+1);
- vscode.window.showInputBox({
- placeHolder:'Enter parameters list (-p key value) or leave blank for no parameters:',
- value:props.get(actionToInvoke)
- }).then(function (parametersString) {
+ vscode.window.showInputBox({
+ placeHolder:'Enter parameters list (-p key value) or leave blank for no parameters:',
+ value:props.get(actionToInvoke)
+ }).then(function (parametersString) {
- var pString = ''
- if (parametersString != undefined) {
- pString = parametersString
- }
+ var pString = ''
+ if (parametersString != undefined) {
+ pString = parametersString
+ }
- props.set(actionToInvoke, pString, true);
+ props.set(actionToInvoke, pString, true);
- callback( namespace, actionToInvoke, parametersString )
- });
- });
+ callback( namespace, actionToInvoke, parametersString )
+ });
+ });
}
@@ -193,627 +210,627 @@
var wskdb = undefined;
function debugAction(params) {
- if (!props.validate()){
- return;
- }
- selectActionAndRequestParameters( function(namespace, actionToInvoke, parametersString) {
+ if (!props.validate()){
+ return;
+ }
+ selectActionAndRequestParameters( function(namespace, actionToInvoke, parametersString) {
- wskdb = spawn('wskdb', []);
- wskdb.stdout.setEncoding('utf-8');
- wskdb.stdin.setEncoding('utf-8');
+ wskdb = spawn('wskdb', []);
+ wskdb.stdout.setEncoding('utf-8');
+ wskdb.stdin.setEncoding('utf-8');
- wskdb.on('error', (error) => {
- console.error(error);
- log.appendLine("Unable to invoke the wskdb debugger. Please make sure that you have it installed.");
- })
-
- wskdb.stderr.on('data', (data) => {
- console.log(`stderr: ${data}`);
- log.appendLine("ERROR:" + data.toString())
- wskdb.kill();
- });
+ wskdb.on('error', (error) => {
+ console.error(error);
+ log.appendLine("Unable to invoke the wskdb debugger. Please make sure that you have it installed.");
+ })
- wskdb.on('close', (code) => {
- console.log(`child process exited with code ${code}`);
- wskdb = undefined;
- });
+ wskdb.stderr.on('data', (data) => {
+ console.log(`stderr: ${data}`);
+ log.appendLine("ERROR:" + data.toString())
+ wskdb.kill();
+ });
- var OK = /ok[\n|.*]*?\(wskdb\)/;
- var ERROR = /^Error\:/;
+ wskdb.on('close', (code) => {
+ console.log(`child process exited with code ${code}`);
+ wskdb = undefined;
+ });
- var exit = function() {
- wskdb.stdout.removeAllListeners("data")
- wskdb.stdin.write("exit\n");
- }
+ var OK = /ok[\n|.*]*?\(wskdb\)/;
+ var ERROR = /^Error\:/;
- var attachDebugger = function() {
- log.appendLine('\n$ attaching wskdb to ' + actionToInvoke);
+ var exit = function() {
+ wskdb.stdout.removeAllListeners("data")
+ wskdb.stdin.write("exit\n");
+ }
- wskdb.stdout.removeAllListeners("data")
- wskdb.stdin.write("attach " + actionToInvoke + "\n");
-
- var stdoutData;
- wskdb.stdout.on('data', (data) => {
- //console.log(`stdout: ${data}`);
+ var attachDebugger = function() {
+ log.appendLine('\n$ attaching wskdb to ' + actionToInvoke);
- if (stdoutData == undefined) {
- stdoutData = data;
- } else {
- stdoutData += data;
- }
+ wskdb.stdout.removeAllListeners("data")
+ wskdb.stdin.write("attach " + actionToInvoke + "\n");
- var str = data.toString();
- if (stdoutData.match(OK)) {
- invokeAction();
- } else if (stdoutData.match(ERROR)) {
- log.appendLine(str);
- exit();
- }
- });
- }
+ var stdoutData;
+ wskdb.stdout.on('data', (data) => {
+ //console.log(`stdout: ${data}`);
- var invokeAction = function() {
+ if (stdoutData == undefined) {
+ stdoutData = data;
+ } else {
+ stdoutData += data;
+ }
- log.appendLine('$ invoking wskdb with ' + actionToInvoke + ' ' + parametersString);
- wskdb.stdout.removeAllListeners("data")
- var stdinData = "invoke " + actionToInvoke + ' ' + parametersString;
- wskdb.stdin.write(stdinData + "\n");
-
- var stdoutData;
- var wroteOutput = false;
-
- wskdb.stdout.on('data', (data) => {
- //console.log(`stdout: ${data}`);
+ var str = data.toString();
+ if (stdoutData.match(OK)) {
+ invokeAction();
+ } else if (stdoutData.match(ERROR)) {
+ log.appendLine(str);
+ exit();
+ }
+ });
+ }
- var str = data.toString();
+ var invokeAction = function() {
- if (stdoutData == undefined) {
- stdoutData = data;
- } else {
- stdoutData += data;
- }
+ log.appendLine('$ invoking wskdb with ' + actionToInvoke + ' ' + parametersString);
+ wskdb.stdout.removeAllListeners("data")
+ var stdinData = "invoke " + actionToInvoke + ' ' + parametersString;
+ wskdb.stdin.write(stdinData + "\n");
- //clean garbage that sometimes gets shoved into stdout when writing to stdin
- if (stdoutData.indexOf(stdinData) >= 0) {
- stdoutData = stdoutData.substring( stdoutData.indexOf(stdinData)+stdinData.length+1 )
- }
+ var stdoutData;
+ var wroteOutput = false;
- //if contains a complete json doc, print it
- if (stdoutData.match(/{([^}]*)}/) && !wroteOutput) {
- var outString = stdoutData.substring(stdoutData.indexOf("{"))
- outString = outString.substring(0, outString.lastIndexOf("}")+1);
- log.appendLine(outString);
- wroteOutput = true
- }
-
- if (stdoutData.match(OK)) {
- exit();
- } else if (stdoutData.match(ERROR)) {
- log.appendLine(str);
- exit();
- }
- });
- }
+ wskdb.stdout.on('data', (data) => {
+ //console.log(`stdout: ${data}`);
- log.show(true);
- attachDebugger();
-
- });
+ var str = data.toString();
+
+ if (stdoutData == undefined) {
+ stdoutData = data;
+ } else {
+ stdoutData += data;
+ }
+
+ //clean garbage that sometimes gets shoved into stdout when writing to stdin
+ if (stdoutData.indexOf(stdinData) >= 0) {
+ stdoutData = stdoutData.substring( stdoutData.indexOf(stdinData)+stdinData.length+1 )
+ }
+
+ //if contains a complete json doc, print it
+ if (stdoutData.match(/{([^}]*)}/) && !wroteOutput) {
+ var outString = stdoutData.substring(stdoutData.indexOf("{"))
+ outString = outString.substring(0, outString.lastIndexOf("}")+1);
+ log.appendLine(outString);
+ wroteOutput = true
+ }
+
+ if (stdoutData.match(OK)) {
+ exit();
+ } else if (stdoutData.match(ERROR)) {
+ log.appendLine(str);
+ exit();
+ }
+ });
+ }
+
+ log.show(true);
+ attachDebugger();
+
+ });
}
function createAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- if (vscode.window.activeTextEditor == undefined || vscode.window.activeTextEditor.document == undefined) {
- vscode.window.showWarningMessage('Must have a document open for editing. The currently focused document will be used to create the OpenWhisk action.');
- return;
- }
+ if (vscode.window.activeTextEditor == undefined || vscode.window.activeTextEditor.document == undefined) {
+ vscode.window.showWarningMessage('Must have a document open for editing. The currently focused document will be used to create the OpenWhisk action.');
+ return;
+ }
- vscode.window.showInputBox({placeHolder:'Enter a name for your action:'})
- .then(function(action){
+ vscode.window.showInputBox({placeHolder:'Enter a name for your action:'})
+ .then(function(action){
- if (action == undefined) {
- return;
- }
+ if (action == undefined) {
+ return;
+ }
- log.show(true);
- log.appendLine('\n$ wsk action create ' + action);
+ log.show(true);
+ log.appendLine('\n$ wsk action create ' + action);
- log.appendLine('Creating a new action using the currently open document: ' + vscode.window.activeTextEditor.document.uri);
+ log.appendLine('Creating a new action using the currently open document: ' + vscode.window.activeTextEditor.document.uri);
- var options = {
- actionName: action,
- action: vscode.window.activeTextEditor.document.getText()
- };
+ var options = {
+ actionName: action,
+ action: vscode.window.activeTextEditor.document.getText()
+ };
- var swiftExt = '.swift';
- var lastIndex = vscode.window.activeTextEditor.document.uri.fsPath.lastIndexOf(swiftExt);
- if (lastIndex == vscode.window.activeTextEditor.document.uri.fsPath.length - swiftExt.length) {
- //it's a swift file, handle it differently
- options.action = { exec: { kind: 'swift:3', code: options.action }}
- }
+ var swiftExt = '.swift';
+ var lastIndex = vscode.window.activeTextEditor.document.uri.fsPath.lastIndexOf(swiftExt);
+ if (lastIndex == vscode.window.activeTextEditor.document.uri.fsPath.length - swiftExt.length) {
+ //it's a swift file, handle it differently
+ options.action = { exec: { kind: 'swift:3', code: options.action }}
+ }
- ow.actions.create(options)
- .then(function(result) {
- log.appendLine('OpenWhisk action created: ' + util.formatQualifiedName(result));
- vscode.window.showInformationMessage('OpenWhisk action created: ' + util.formatQualifiedName(result));
- })
- .catch(function(error) {
- util.printOpenWhiskError(error);
- });
- });
+ ow.actions.create(options)
+ .then(function(result) {
+ log.appendLine('OpenWhisk action created: ' + util.formatQualifiedName(result));
+ vscode.window.showInformationMessage('OpenWhisk action created: ' + util.formatQualifiedName(result));
+ })
+ .catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
+ });
}
function updateAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- if (vscode.window.activeTextEditor == undefined || vscode.window.activeTextEditor.document == undefined) {
- vscode.window.showWarningMessage('Must have a document open for editing. The currently focused document will be used to create the OpenWhisk action.');
- return;
- }
+ if (vscode.window.activeTextEditor == undefined || vscode.window.activeTextEditor.document == undefined) {
+ vscode.window.showWarningMessage('Must have a document open for editing. The currently focused document will be used to create the OpenWhisk action.');
+ return;
+ }
- var YES = 'Yes';
- var NO = 'No';
+ var YES = 'Yes';
+ var NO = 'No';
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select an action to update:'})
- .then(function(action){
-
- if (action == undefined) {
- return;
- }
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select an action to update:'})
+ .then(function(action){
- vscode.window.showWarningMessage('Are you sure you want to overwrite ' + action, YES, NO)
- .then( function(selection) {
- if (selection === YES) {
+ if (action == undefined) {
+ return;
+ }
- var actionString = action.toString();
- var startIndex = actionString.indexOf('/');
- var namespace = actionString.substring(0, startIndex);
- var actionToUpdate = actionString.substring(startIndex+1);
+ vscode.window.showWarningMessage('Are you sure you want to overwrite ' + action, YES, NO)
+ .then( function(selection) {
+ if (selection === YES) {
- log.show(true);
- log.appendLine('\n$ wsk action update ' + actionToUpdate);
+ var actionString = action.toString();
+ var startIndex = actionString.indexOf('/');
+ var namespace = actionString.substring(0, startIndex);
+ var actionToUpdate = actionString.substring(startIndex+1);
- log.appendLine('Updating action ' + actionToUpdate + ' using the currently open document: ' + vscode.window.activeTextEditor.document.uri);
+ log.show(true);
+ log.appendLine('\n$ wsk action update ' + actionToUpdate);
- var options = {
- actionName: actionToUpdate,
- action: vscode.window.activeTextEditor.document.getText()
- };
+ log.appendLine('Updating action ' + actionToUpdate + ' using the currently open document: ' + vscode.window.activeTextEditor.document.uri);
- var swiftExt = '.swift';
- var lastIndex = vscode.window.activeTextEditor.document.uri.fsPath.lastIndexOf(swiftExt);
- if (lastIndex == vscode.window.activeTextEditor.document.uri.fsPath.length - swiftExt.length) {
- //it's a swift file, handle it differently
- options.action = { exec: { kind: 'swift:3', code: options.action }}
- }
+ var options = {
+ actionName: actionToUpdate,
+ action: vscode.window.activeTextEditor.document.getText()
+ };
- ow.actions.update(options)
- .then(function(result) {
- var message = 'OpenWhisk action updated: ' + util.formatQualifiedName(result)
- log.appendLine(message);
- vscode.window.showInformationMessage(message);
- })
- .catch(function(error) {
- util.printOpenWhiskError(error);
- });
- }
- });
- });
+ var swiftExt = '.swift';
+ var lastIndex = vscode.window.activeTextEditor.document.uri.fsPath.lastIndexOf(swiftExt);
+ if (lastIndex == vscode.window.activeTextEditor.document.uri.fsPath.length - swiftExt.length) {
+ //it's a swift file, handle it differently
+ options.action = { exec: { kind: 'swift:3', code: options.action }}
+ }
+
+ ow.actions.update(options)
+ .then(function(result) {
+ var message = 'OpenWhisk action updated: ' + util.formatQualifiedName(result)
+ log.appendLine(message);
+ vscode.window.showInformationMessage(message);
+ })
+ .catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
+ }
+ });
+ });
}
function createSequenceAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showInputBox({placeHolder:'Enter a name for your action:'})
- .then(function(action){
+ vscode.window.showInputBox({placeHolder:'Enter a name for your action:'})
+ .then(function(action){
- if (action == undefined) {
- return;
- }
+ if (action == undefined) {
+ return;
+ }
- //first get the pipe action, so we can create the sequence action
- ow.actions.get({
- actionName: 'system/pipe',
- blocking:true,
- namespace: 'whisk.system'
- }).then(function(result) {
+ //first get the pipe action, so we can create the sequence action
+ ow.actions.get({
+ actionName: 'system/pipe',
+ blocking:true,
+ namespace: 'whisk.system'
+ }).then(function(result) {
- console.log(result);
- var pipeCode = result.exec.code;
+ console.log(result);
+ var pipeCode = result.exec.code;
- log.show(true);
- log.appendLine('\n$ wsk action create ' + action + ' --sequence');
+ log.show(true);
+ log.appendLine('\n$ wsk action create ' + action + ' --sequence');
- var sequenceActions = [];
+ var sequenceActions = [];
- var selectSequenceActions = function(firstCall) {
+ var selectSequenceActions = function(firstCall) {
- vscode.window.showQuickPick(getListAsStringArrayForSequenceDialog(firstCall), {placeHolder:`Select action #${(sequenceActions.length+1)} for the sequence.`})
- .then(function(selectedActionStep){
+ vscode.window.showQuickPick(getListAsStringArrayForSequenceDialog(firstCall), {placeHolder:`Select action #${(sequenceActions.length+1)} for the sequence.`})
+ .then(function(selectedActionStep){
- if (selectedActionStep == undefined) {
- log.appendLine('cancelled by user ESC');
- return;
- }
- else if (selectedActionStep != sequenceComplete) {
+ if (selectedActionStep == undefined) {
+ log.appendLine('cancelled by user ESC');
+ return;
+ }
+ else if (selectedActionStep != sequenceComplete) {
- sequenceActions.push('/'+selectedActionStep);
- selectSequenceActions(false);
- }
- else {
- //sequence complete
- if (sequenceActions.length > 0) {
+ sequenceActions.push('/'+selectedActionStep);
+ selectSequenceActions(false);
+ }
+ else {
+ //sequence complete
+ if (sequenceActions.length > 0) {
- var options = {
- actionName: action,
- action: { exec: { kind: 'nodejs', code: pipeCode },
- parameters:[{
- 'key': '_actions',
- 'value': sequenceActions
- }]
- }
- };
+ var options = {
+ actionName: action,
+ action: { exec: { kind: 'nodejs', code: pipeCode },
+ parameters:[{
+ 'key': '_actions',
+ 'value': sequenceActions
+ }]
+ }
+ };
- ow.actions.create(options)
- .then(function(result) {
- var message = 'OpenWhisk sequence created: ' + util.formatQualifiedName(result);
- log.appendLine(message);
- vscode.window.showInformationMessage(message);
- })
- .catch(function(error) {
- util.printOpenWhiskError(error);
- });
- }
- }
- });
- }
+ ow.actions.create(options)
+ .then(function(result) {
+ var message = 'OpenWhisk sequence created: ' + util.formatQualifiedName(result);
+ log.appendLine(message);
+ vscode.window.showInformationMessage(message);
+ })
+ .catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
+ }
+ }
+ });
+ }
- selectSequenceActions(true);
+ selectSequenceActions(true);
- });
- });
+ });
+ });
}
function deleteAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select an action to delete:'})
- .then(function(action){
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select an action to delete:'})
+ .then(function(action){
- if (action == undefined) {
- return;
- }
+ if (action == undefined) {
+ return;
+ }
- var actionString = action.toString();
- var startIndex = actionString.indexOf('/');
- var namespace = actionString.substring(0, startIndex);
- var actionToDelete = actionString.substring(startIndex+1);
+ var actionString = action.toString();
+ var startIndex = actionString.indexOf('/');
+ var namespace = actionString.substring(0, startIndex);
+ var actionToDelete = actionString.substring(startIndex+1);
- log.show(true);
- log.appendLine('\n$ wsk action delete ' + actionToDelete);
+ log.show(true);
+ log.appendLine('\n$ wsk action delete ' + actionToDelete);
- var options = {
- actionName: actionToDelete
- };
+ var options = {
+ actionName: actionToDelete
+ };
- var YES = 'Yes';
- var NO = 'No';
+ var YES = 'Yes';
+ var NO = 'No';
- vscode.window.showWarningMessage('Are you sure you want to delete ' + actionToDelete, YES, NO)
- .then( function(selection) {
- if (selection === YES) {
- ow.actions.delete(options)
- .then(function(result) {
- console.log(result);
- log.appendLine('OpenWhisk action deleted: ' + util.formatQualifiedName(result));
- vscode.window.showInformationMessage('OpenWhisk action deleted: ' + util.formatQualifiedName(result));
- })
- .catch(function(error) {
- util.printOpenWhiskError(error);
- });
- }
- });
- });
+ vscode.window.showWarningMessage('Are you sure you want to delete ' + actionToDelete, YES, NO)
+ .then( function(selection) {
+ if (selection === YES) {
+ ow.actions.delete(options)
+ .then(function(result) {
+ console.log(result);
+ log.appendLine('OpenWhisk action deleted: ' + util.formatQualifiedName(result));
+ vscode.window.showInformationMessage('OpenWhisk action deleted: ' + util.formatQualifiedName(result));
+ })
+ .catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
+ }
+ });
+ });
}
function getAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- if (!hasValidProjectRoot()) {
- return;
- }
+ if (!hasValidProjectRoot()) {
+ return;
+ }
- vscode.window.showQuickPick( getListAsStringArray(), {placeHolder:'Select an action to retrieve:'}).then( function (action) {
+ vscode.window.showQuickPick( getListAsStringArray(), {placeHolder:'Select an action to retrieve:'}).then( function (action) {
- if (action == undefined) {
- return;
- }
+ if (action == undefined) {
+ return;
+ }
- var actionString = action.toString();
- var startIndex = actionString.indexOf('/');
- var namespace = actionString.substring(0, startIndex);
- var actionToGet = actionString.substring(startIndex+1);
+ var actionString = action.toString();
+ var startIndex = actionString.indexOf('/');
+ var namespace = actionString.substring(0, startIndex);
+ var actionToGet = actionString.substring(startIndex+1);
- log.show(true);
- log.appendLine('\n$ wsk action get ' + actionToGet);
+ log.show(true);
+ log.appendLine('\n$ wsk action get ' + actionToGet);
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
- var startTime = new Date().getTime();
- ow.actions.get({
- actionName: actionToGet,
- blocking:true,
- namespace: namespace
- }).then(function(result) {
- var totalTime = startTime - (new Date().getTime());;
- clearInterval(activityInterval);
- log.appendLine('>> completed in ' + (-totalTime) + 'ms')
+ var startTime = new Date().getTime();
+ ow.actions.get({
+ actionName: actionToGet,
+ blocking:true,
+ namespace: namespace
+ }).then(function(result) {
+ var totalTime = startTime - (new Date().getTime());;
+ clearInterval(activityInterval);
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms')
- if (isSequence(result)) {
- var message = actionToGet + ' is a sequence. It cannot be edited directly, and has not be written to a file.';
- log.appendLine(message)
- vscode.window.showWarningMessage(message);
- log.appendLine('You can edit these individual sequence actions: ');
- for (var x=0; x < result.parameters.length; x ++){
- var param = result.parameters[x];
- if (param.key == '_actions') {
- for (var y=0; y < param.value.length; y ++){
- log.appendLine(' > ' + param.value[y])
- }
- }
- }
- }
- else {
- log.appendLine(JSON.stringify(result, null, 4))
- //todo: check if file exists before writing
- //todo: make sure user has selected a directory to import into
+ if (isSequence(result)) {
+ var message = actionToGet + ' is a sequence. It cannot be edited directly, and has not be written to a file.';
+ log.appendLine(message)
+ vscode.window.showWarningMessage(message);
+ log.appendLine('You can edit these individual sequence actions: ');
+ for (var x=0; x < result.parameters.length; x ++){
+ var param = result.parameters[x];
+ if (param.key == '_actions') {
+ for (var y=0; y < param.value.length; y ++){
+ log.appendLine(' > ' + param.value[y])
+ }
+ }
+ }
+ }
+ else {
+ log.appendLine(JSON.stringify(result, null, 4))
+ //todo: check if file exists before writing
+ //todo: make sure user has selected a directory to import into
- var buffer = new Buffer(result.exec.code);
- var fileName = result.name;
-
- var fileExt = '';
- if (result.exec.kind.toString().search('swift') >= 0) {
- fileName += '.swift'
- } else if (result.exec.kind.toString().search('python') >= 0) {
- fileName += '.py'
- } else {
- fileName += '.js'
- }
+ var buffer = new Buffer(result.exec.code);
+ var fileName = result.name;
- var path = vscode.workspace.rootPath + importDirectory
+ var fileExt = '';
+ if (result.exec.kind.toString().search('swift') >= 0) {
+ fileName += '.swift'
+ } else if (result.exec.kind.toString().search('python') >= 0) {
+ fileName += '.py'
+ } else {
+ fileName += '.js'
+ }
- if (!fs.existsSync(path)){
- fs.mkdirSync(path);
- }
+ var path = vscode.workspace.rootPath + importDirectory
- var filePath = getUniqueFilename(path, fileName, fileExt);
+ if (!fs.existsSync(path)){
+ fs.mkdirSync(path);
+ }
- fs.open(filePath, 'w', function(err, fd) {
- if (err) {
- throw 'error opening file: ' + err;
- }
+ var filePath = getUniqueFilename(path, fileName, fileExt);
- fs.write(fd, buffer, 0, buffer.length, null, function(err) {
- if (err) throw 'error writing file: ' + err;
- fs.close(fd, function() {
- //console.log('file written');
+ fs.open(filePath, 'w', function(err, fd) {
+ if (err) {
+ throw 'error opening file: ' + err;
+ }
- vscode.workspace.openTextDocument(filePath)
- .then(function(document) {
- vscode.window.showTextDocument(document);
- vscode.window.showInformationMessage('Successfully imported ' + importDirectory + fileName);
- log.appendLine('Successfully imported file to ' + filePath);
- });
+ fs.write(fd, buffer, 0, buffer.length, null, function(err) {
+ if (err) throw 'error writing file: ' + err;
+ fs.close(fd, function() {
+ //console.log('file written');
- })
- });
- });
- }
- })
- .catch(function(error) {
- util.printOpenWhiskError(error);
- });
- });
+ vscode.workspace.openTextDocument(filePath)
+ .then(function(document) {
+ vscode.window.showTextDocument(document);
+ vscode.window.showInformationMessage('Successfully imported ' + importDirectory + fileName);
+ log.appendLine('Successfully imported file to ' + filePath);
+ });
+
+ })
+ });
+ });
+ }
+ })
+ .catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
+ });
}
function isSequence(result) {
- if (result.parameters) {
- for (var x=0; x < result.parameters.length; x ++){
- var param = result.parameters[x];
- if (param.key == '_actions') {
- return true;
- }
- }
- }
- return false;
+ if (result.parameters) {
+ for (var x=0; x < result.parameters.length; x ++){
+ var param = result.parameters[x];
+ if (param.key == '_actions') {
+ return true;
+ }
+ }
+ }
+ return false;
}
function initAction(params) {
- if (!hasValidProjectRoot()) {
- return;
- }
+ if (!hasValidProjectRoot()) {
+ return;
+ }
- vscode.window.showQuickPick( [NODE, PYTHON, SWIFT], {placeHolder:'Select the type of action:'}).then( function (action) {
+ vscode.window.showQuickPick( [NODE, PYTHON, SWIFT], {placeHolder:'Select the type of action:'}).then( function (action) {
- if (action == undefined) {
- return;
- }
+ if (action == undefined) {
+ return;
+ }
- log.show(true);
- log.appendLine('\n$ wsk action init:' + action);
+ log.show(true);
+ log.appendLine('\n$ wsk action init:' + action);
- var templateName = action.toLowerCase()
- templateName = templateName.replace(/\s/g, '');
- templateName = context.extensionPath + "/static-src/templates/" + templateName + ".template"
- var template = '';
+ var templateName = action.toLowerCase()
+ templateName = templateName.replace(/\s/g, '');
+ templateName = context.extensionPath + "/static-src/templates/" + templateName + ".template"
+ var template = '';
- var path = vscode.workspace.rootPath + importDirectory
+ var path = vscode.workspace.rootPath + importDirectory
- fs.readFile( templateName, 'utf8', function (err,data) {
- if (err) {
- log.appendLine(err);
- console.log(err)
- return false;
- }
-
- template = data.toString()
+ fs.readFile( templateName, 'utf8', function (err,data) {
+ if (err) {
+ log.appendLine(err);
+ console.log(err)
+ return false;
+ }
- //todo: make it look for unique names or prompt for name
+ template = data.toString()
- var buffer = new Buffer(template);
- var fileName = 'newAction';
- var fileExt = '';
- if (action == NODE || action == NODE6) {
- fileExt += '.js'
- } else if (action == PYTHON) {
- fileExt += '.py'
- } else {
- fileExt += '.swift'
- }
+ //todo: make it look for unique names or prompt for name
- var path = vscode.workspace.rootPath + importDirectory
+ var buffer = new Buffer(template);
+ var fileName = 'newAction';
+ var fileExt = '';
+ if (action == NODE || action == NODE6) {
+ fileExt += '.js'
+ } else if (action == PYTHON) {
+ fileExt += '.py'
+ } else {
+ fileExt += '.swift'
+ }
- if (!fs.existsSync(path)){
- fs.mkdirSync(path);
- }
-
- var filePath = getUniqueFilename(path, fileName, fileExt);
+ var path = vscode.workspace.rootPath + importDirectory
- fs.open(filePath, 'w', function(err, fd) {
- if (err) {
- throw 'error opening file: ' + err;
- }
+ if (!fs.existsSync(path)){
+ fs.mkdirSync(path);
+ }
- fs.write(fd, buffer, 0, buffer.length, null, function(err) {
- if (err) throw 'error writing file: ' + err;
- fs.close(fd, function() {
- //console.log('file written');
+ var filePath = getUniqueFilename(path, fileName, fileExt);
- vscode.workspace.openTextDocument(filePath)
- .then(function(document) {
- //console.log(document)
- vscode.window.showTextDocument(document);
- log.appendLine('Created new action using ' + action + ' template as ' + filePath);
- });
+ fs.open(filePath, 'w', function(err, fd) {
+ if (err) {
+ throw 'error opening file: ' + err;
+ }
- })
- });
- });
+ fs.write(fd, buffer, 0, buffer.length, null, function(err) {
+ if (err) throw 'error writing file: ' + err;
+ fs.close(fd, function() {
+ //console.log('file written');
- });
- });
+ vscode.workspace.openTextDocument(filePath)
+ .then(function(document) {
+ //console.log(document)
+ vscode.window.showTextDocument(document);
+ log.appendLine('Created new action using ' + action + ' template as ' + filePath);
+ });
+
+ })
+ });
+ });
+
+ });
+ });
}
function restAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick( getListAsStringArray(), {placeHolder:'Select an action to retrieve:'}).then( function (action) {
+ vscode.window.showQuickPick( getListAsStringArray(), {placeHolder:'Select an action to retrieve:'}).then( function (action) {
- if (action == undefined) {
- return;
- }
+ if (action == undefined) {
+ return;
+ }
- var actionString = action.toString();
- var startIndex = actionString.indexOf('/');
- var namespace = actionString.substring(0, startIndex);
- var actionToGet = actionString.substring(startIndex+1);
+ var actionString = action.toString();
+ var startIndex = actionString.indexOf('/');
+ var namespace = actionString.substring(0, startIndex);
+ var actionToGet = actionString.substring(startIndex+1);
- log.show(true);
- log.appendLine('\n$ wsk action get ' + actionToGet);
+ log.show(true);
+ log.appendLine('\n$ wsk action get ' + actionToGet);
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
- var apiRoot = ow.actions.options.api
- var startTime = new Date().getTime();
- ow.actions.get({
- actionName: actionToGet,
- blocking:true,
- namespace: namespace
- }).then(function(result) {
- var totalTime = startTime - (new Date().getTime());;
- clearInterval(activityInterval);
+ var apiRoot = ow.actions.options.api
+ var startTime = new Date().getTime();
+ ow.actions.get({
+ actionName: actionToGet,
+ blocking:true,
+ namespace: namespace
+ }).then(function(result) {
+ var totalTime = startTime - (new Date().getTime());;
+ clearInterval(activityInterval);
- var hash = new Buffer(props.get('auth')).toString('base64')
- var parsedNamespace = util.parseQualifiedName(result.namespace)
+ var hash = new Buffer(props.get('auth')).toString('base64')
+ var parsedNamespace = util.parseQualifiedName(result.namespace)
- var restEndpoint =`curl -d '{ "arg": "value" }' '${props.host()}namespaces/${parsedNamespace.namespace}/actions/${parsedNamespace.name}/${result.name}?blocking=true' -X POST -H 'Authorization: Basic ${hash}' -H 'Content-Type: application/json'`;
+ var restEndpoint =`curl -d '{ "arg": "value" }' '${props.host()}namespaces/${parsedNamespace.namespace}/actions/${parsedNamespace.name}/${result.name}?blocking=true' -X POST -H 'Authorization: Basic ${hash}' -H 'Content-Type: application/json'`;
- log.appendLine(`\nCURL REST invocation (You still need to set parameter key/value pairs):`);
- log.appendLine(`-------------------------------------------------------------------------`);
- log.appendLine(`\n${restEndpoint}`);
- })
- .catch(function(error) {
- util.printOpenWhiskError(error);
- });
- });
+ log.appendLine(`\nCURL REST invocation (You still need to set parameter key/value pairs):`);
+ log.appendLine(`-------------------------------------------------------------------------`);
+ log.appendLine(`\n${restEndpoint}`);
+ })
+ .catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
+ });
}
function hasValidProjectRoot() {
- if (vscode.workspace.rootPath == undefined) {
- var message = 'You must specify a project folder before you can import actions from OpenWhisk. Please use the \'File\' menu, select \'Open\', then select a folder for your project.';
-
- log.show();
- log.appendLine(message);
+ if (vscode.workspace.rootPath == undefined) {
+ var message = 'You must specify a project folder before you can import actions from OpenWhisk. Please use the \'File\' menu, select \'Open\', then select a folder for your project.';
- vscode.window.showWarningMessage(message)
- return false;
- }
- return true;
+ log.show();
+ log.appendLine(message);
+
+ vscode.window.showWarningMessage(message)
+ return false;
+ }
+ return true;
}
function getUniqueFilename(path, fileName, fileExt) {
- var unique = false;
- var attempt = 0;
- while (!unique) {
- var suffix = (attempt > 0) ? (attempt+1):"";
- var uniquePath = path + fileName + suffix + fileExt;
+ var unique = false;
+ var attempt = 0;
+ while (!unique) {
+ var suffix = (attempt > 0) ? (attempt+1):"";
+ var uniquePath = path + fileName + suffix + fileExt;
- //if file exists, updated attempt count and try again in the loop
- if (fs.existsSync(uniquePath)) {
- attempt++;
- }
- else {
- var unique = true;
- return uniquePath;
- }
- }
- return undefined;
+ //if file exists, updated attempt count and try again in the loop
+ if (fs.existsSync(uniquePath)) {
+ attempt++;
+ }
+ else {
+ var unique = true;
+ return uniquePath;
+ }
+ }
+ return undefined;
}
module.exports = {
- register: register,
- list:list,
- getListAsStringArray:getListAsStringArray
-};
\ No newline at end of file
+ register: register,
+ list:list,
+ getListAsStringArray:getListAsStringArray
+};
diff --git a/static-src/commands/wsk.activation.js b/static-src/commands/wsk.activation.js
index 4d61d91..538e594 100644
--- a/static-src/commands/wsk.activation.js
+++ b/static-src/commands/wsk.activation.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -8,30 +25,30 @@
var props;
function register(_ow, context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
+ ow = _ow;
+ log = _log;
+ props = _props;
- var defaultDisposable = vscode.commands.registerCommand('extension.wsk.activation', defaultAction);
- var listDisposable = vscode.commands.registerCommand('extension.wsk.activation.list', listAction);
- var getDisposable = vscode.commands.registerCommand('extension.wsk.activation.get', getAction);
- var logsDisposable = vscode.commands.registerCommand('extension.wsk.activation.logs', logsAction);
- var resultDisposable = vscode.commands.registerCommand('extension.wsk.activation.result', resultAction);
+ var defaultDisposable = vscode.commands.registerCommand('extension.wsk.activation', defaultAction);
+ var listDisposable = vscode.commands.registerCommand('extension.wsk.activation.list', listAction);
+ var getDisposable = vscode.commands.registerCommand('extension.wsk.activation.get', getAction);
+ var logsDisposable = vscode.commands.registerCommand('extension.wsk.activation.logs', logsAction);
+ var resultDisposable = vscode.commands.registerCommand('extension.wsk.activation.result', resultAction);
- context.subscriptions.push(defaultDisposable, listDisposable, getDisposable, logsDisposable,resultDisposable );
+ context.subscriptions.push(defaultDisposable, listDisposable, getDisposable, logsDisposable,resultDisposable );
}
function defaultAction(params) {
- log.show(true);
- log.appendLine('\n$ wsk activation');
- log.appendLine('available commands:');
- log.appendLine(' list retrieve activations');
- log.appendLine(' get get activation');
- log.appendLine(' logs get the logs of an activation');
- log.appendLine(' result get resul tof an activation');
+ log.show(true);
+ log.appendLine('\n$ wsk activation');
+ log.appendLine('available commands:');
+ log.appendLine(' list retrieve activations');
+ log.appendLine(' get get activation');
+ log.appendLine(' logs get the logs of an activation');
+ log.appendLine(' result get resul tof an activation');
}
@@ -40,154 +57,154 @@
function listAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- log.show(true);
- log.appendLine('\n$ wsk activation list');
- list();
+ log.show(true);
+ log.appendLine('\n$ wsk activation list');
+ list();
}
function list() {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- return getList().then(function (activations) {
- util.appendHeading('activations');
- for (var x=0; x<activations.length; x ++){
- util.appendActivation(activations[x]);
- }
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
+ return getList().then(function (activations) {
+ util.appendHeading('activations');
+ for (var x=0; x<activations.length; x ++){
+ util.appendActivation(activations[x]);
+ }
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
}
function getList() {
- return new Promise(function (fulfill, reject){
- return ow.activations.list({
- "docs":false,
- "skip":0,
- "limit":30,
- "namespace":"_"
- }).then(function (activations) {
- fulfill(activations);
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
- });
+ return new Promise(function (fulfill, reject){
+ return ow.activations.list({
+ "docs":false,
+ "skip":0,
+ "limit":30,
+ "namespace":"_"
+ }).then(function (activations) {
+ fulfill(activations);
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
+ });
}
function getListAsStringArray() {
- return getList().then(function (rules) {
- var result = [];
- for (var x=0; x<rules.length; x ++){
- var name = util.formatQualifiedName(rules[x]);
- result.push(name)
- }
- return result;
- })
+ return getList().then(function (rules) {
+ var result = [];
+ for (var x=0; x<rules.length; x ++){
+ var name = util.formatQualifiedName(rules[x]);
+ result.push(name)
+ }
+ return result;
+ })
}
function getAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- var startTime = new Date().getTime();
- var callback = function(result) {
- var totalTime = startTime - (new Date().getTime());
- log.appendLine("\n"+JSON.stringify(result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- };
+ var startTime = new Date().getTime();
+ var callback = function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ log.appendLine("\n"+JSON.stringify(result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ };
- getActionImpl(params, "get", callback);
+ getActionImpl(params, "get", callback);
}
function logsAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- var startTime = new Date().getTime();
- var callback = function(result) {
- var totalTime = startTime - (new Date().getTime());
- var logs = result.logs;
- log.appendLine("");
- if (result.logs) {
- for (var x =0; x <logs.length; x++) {
- log.appendLine(logs[x]);
- }
- }
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- };
+ var startTime = new Date().getTime();
+ var callback = function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ var logs = result.logs;
+ log.appendLine("");
+ if (result.logs) {
+ for (var x =0; x <logs.length; x++) {
+ log.appendLine(logs[x]);
+ }
+ }
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ };
- getActionImpl(params, "logs", callback);
+ getActionImpl(params, "logs", callback);
}
function resultAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- var startTime = new Date().getTime();
- var callback = function(result) {
- var totalTime = startTime - (new Date().getTime());
- log.appendLine("\n"+JSON.stringify(result.response.result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- };
+ var startTime = new Date().getTime();
+ var callback = function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ log.appendLine("\n"+JSON.stringify(result.response.result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ };
- getActionImpl(params, "result", callback);
+ getActionImpl(params, "result", callback);
}
function getActionImpl(params, command, callback) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showInputBox({placeHolder:'Enter an activation id:'})
- .then(function(activationId){
+ vscode.window.showInputBox({placeHolder:'Enter an activation id:'})
+ .then(function(activationId){
- if (activationId == undefined) {
- return;
- }
+ if (activationId == undefined) {
+ return;
+ }
- log.appendLine('\n$ wsk activation ' + command + ' ' + activationId);
+ log.appendLine('\n$ wsk activation ' + command + ' ' + activationId);
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
- var invocationParams = {
- "activation": activationId,
- "namespace": "_"
- }
- ow.activations.get(invocationParams)
- .then(function(result) {
- clearInterval(activityInterval);
- callback(result)
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
- });
+ var invocationParams = {
+ "activation": activationId,
+ "namespace": "_"
+ }
+ ow.activations.get(invocationParams)
+ .then(function(result) {
+ clearInterval(activityInterval);
+ callback(result)
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+ });
}
module.exports = {
- register: register,
- list:list
-};
\ No newline at end of file
+ register: register,
+ list:list
+};
diff --git a/static-src/commands/wsk.help.js b/static-src/commands/wsk.help.js
index 056e492..e1bed27 100644
--- a/static-src/commands/wsk.help.js
+++ b/static-src/commands/wsk.help.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -7,27 +24,27 @@
var props;
function register(_ow, context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
+ ow = _ow;
+ log = _log;
+ props = _props;
- var disposable = vscode.commands.registerCommand('extension.wsk.help', defaultAction);
- context.subscriptions.push(disposable);
+ var disposable = vscode.commands.registerCommand('extension.wsk.help', defaultAction);
+ context.subscriptions.push(disposable);
}
function defaultAction(params) {
- log.show(true);
- log.appendLine('\n$ wsk help');
- log.appendLine('available commands:');
- log.appendLine(' bluemix launch OpenWhisk console on Bluemix');
- log.appendLine(' docs open OpenWhisk docs');
- log.appendLine(' property set set property');
- log.appendLine(' property unset unset property');
- log.appendLine(' property get get property');
- log.appendLine(' action see available commands for OpenWhisk actions');
+ log.show(true);
+ log.appendLine('\n$ wsk help');
+ log.appendLine('available commands:');
+ log.appendLine(' bluemix launch OpenWhisk console on Bluemix');
+ log.appendLine(' docs open OpenWhisk docs');
+ log.appendLine(' property set set property');
+ log.appendLine(' property unset unset property');
+ log.appendLine(' property get get property');
+ log.appendLine(' action see available commands for OpenWhisk actions');
}
module.exports = {
- register: register
-};
\ No newline at end of file
+ register: register
+};
diff --git a/static-src/commands/wsk.list.js b/static-src/commands/wsk.list.js
index e822490..18a8a13 100644
--- a/static-src/commands/wsk.list.js
+++ b/static-src/commands/wsk.list.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -13,36 +30,36 @@
var props;
function register(_ow, context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
+ ow = _ow;
+ log = _log;
+ props = _props;
- var disposable = vscode.commands.registerCommand('extension.wsk.list', list);
- context.subscriptions.push(disposable);
+ var disposable = vscode.commands.registerCommand('extension.wsk.list', list);
+ context.subscriptions.push(disposable);
}
function list() {
- log.appendLine('\n$ wsk list');
+ log.appendLine('\n$ wsk list');
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- wskPackage.list()
- .then(function(){
- return wskAction.list()
- })
- .then(function(){
- return wskTrigger.list()
- })
- .then(function(){
- return wskRule.list()
- })
+ wskPackage.list()
+ .then(function(){
+ return wskAction.list()
+ })
+ .then(function(){
+ return wskTrigger.list()
+ })
+ .then(function(){
+ return wskRule.list()
+ })
}
module.exports = {
- register: register
-};
\ No newline at end of file
+ register: register
+};
diff --git a/static-src/commands/wsk.package.js b/static-src/commands/wsk.package.js
index 97ee601..aa60e6b 100644
--- a/static-src/commands/wsk.package.js
+++ b/static-src/commands/wsk.package.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -8,45 +25,45 @@
var props;
function register(_ow, context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
+ ow = _ow;
+ log = _log;
+ props = _props;
- var defaultDisposable = vscode.commands.registerCommand('extension.wsk.package', defaultAction);
- context.subscriptions.push(defaultDisposable);
+ var defaultDisposable = vscode.commands.registerCommand('extension.wsk.package', defaultAction);
+ context.subscriptions.push(defaultDisposable);
}
function defaultAction(params) {
- log.show(true);
- log.appendLine('\n$ wsk package');
- log.appendLine('available commands:');
- log.appendLine(' create create a new package');
- log.appendLine(' update create a new package');
- log.appendLine(' bind bind parameters to the package');
- log.appendLine(' refresh refresh package bindings');
- log.appendLine(' get get package');
- log.appendLine(' delete delete package');
- log.appendLine(' list list all packages');
+ log.show(true);
+ log.appendLine('\n$ wsk package');
+ log.appendLine('available commands:');
+ log.appendLine(' create create a new package');
+ log.appendLine(' update create a new package');
+ log.appendLine(' bind bind parameters to the package');
+ log.appendLine(' refresh refresh package bindings');
+ log.appendLine(' get get package');
+ log.appendLine(' delete delete package');
+ log.appendLine(' list list all packages');
}
function list() {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- return ow.packages.list().then(function (packages) {
- util.appendHeading('packages');
- for (var x=0; x<packages.length; x ++){
- util.appendEntry(packages[x]);
- }
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
+ return ow.packages.list().then(function (packages) {
+ util.appendHeading('packages');
+ for (var x=0; x<packages.length; x ++){
+ util.appendEntry(packages[x]);
+ }
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
}
module.exports = {
- register: register,
- list:list
-};
\ No newline at end of file
+ register: register,
+ list:list
+};
diff --git a/static-src/commands/wsk.property.js b/static-src/commands/wsk.property.js
index 9679727..416f237 100644
--- a/static-src/commands/wsk.property.js
+++ b/static-src/commands/wsk.property.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -17,203 +34,203 @@
let AUTH = 'auth';
var config = {
- auth: '',
- namespace:'',
- apiHost:'openwhisk.ng.bluemix.net',
- apiVersion:'v1'
+ auth: '',
+ namespace:'',
+ apiHost:'openwhisk.ng.bluemix.net',
+ apiVersion:'v1'
}
function userHome() {
- if (/^win/.test(process.platform)) {
- var homeDrive = process.env['HOMEDRIVE'];
- var homePath = process.env['HOMEPATH'];
- var home = path.join(homeDrive, homePath);
- if (homeDrive === undefined || homePath === undefined) {
- return process.env['USERPROFILE'];
- }
- else {
- return home;
- }
- }
- else {
- return process.env['HOME'];
- }
+ if (/^win/.test(process.platform)) {
+ var homeDrive = process.env['HOMEDRIVE'];
+ var homePath = process.env['HOMEPATH'];
+ var home = path.join(homeDrive, homePath);
+ if (homeDrive === undefined || homePath === undefined) {
+ return process.env['USERPROFILE'];
+ }
+ else {
+ return home;
+ }
+ }
+ else {
+ return process.env['HOME'];
+ }
}
function configFile() {
- return path.join(userHome(), '.openwhisk/vscode-config.json');
+ return path.join(userHome(), '.openwhisk/vscode-config.json');
}
function configDir() {
- return path.join(userHome(), '.openwhisk/');
+ return path.join(userHome(), '.openwhisk/');
}
function register(_ow, context, _log) {
- ow = _ow;
- log = _log;
+ ow = _ow;
+ log = _log;
- readConfigurationFile();
- updateOW();
+ readConfigurationFile();
+ updateOW();
- var setDisposable = vscode.commands.registerCommand('extension.wsk.property.set', setAction);
- var getDisposable = vscode.commands.registerCommand('extension.wsk.property.get', getAction);
- var unsetDisposable = vscode.commands.registerCommand('extension.wsk.property.unset', unsetAction);
- context.subscriptions.push(setAction, getAction, unsetAction);
+ var setDisposable = vscode.commands.registerCommand('extension.wsk.property.set', setAction);
+ var getDisposable = vscode.commands.registerCommand('extension.wsk.property.get', getAction);
+ var unsetDisposable = vscode.commands.registerCommand('extension.wsk.property.unset', unsetAction);
+ context.subscriptions.push(setAction, getAction, unsetAction);
}
function validate() {
- log.show(true);
- if (config.auth =='') {
- log.show(true);
- log.appendLine('Please check OpenWhisk config. Use \'wsk property set\' to specify missing values. ')
- getAction();
- return false;
- }
- return true;
+ log.show(true);
+ if (config.auth =='') {
+ log.show(true);
+ log.appendLine('Please check OpenWhisk config. Use \'wsk property set\' to specify missing values. ')
+ getAction();
+ return false;
+ }
+ return true;
}
function get(key) {
- if (config.hasOwnProperty(key)) {
- return config[key];
- }
- else return '';
+ if (config.hasOwnProperty(key)) {
+ return config[key];
+ }
+ else return '';
}
function set(key, value, silent) {
- config[key] = value;
+ config[key] = value;
- switch(key) {
- case HOST:
- ow.apiHost
- }
- updateOW();
- setNeedsWrite(silent);
- if (silent != true) {
- log.appendLine(`set config: ${key}=${value}`);
- }
+ switch(key) {
+ case HOST:
+ ow.apiHost
+ }
+ updateOW();
+ setNeedsWrite(silent);
+ if (silent != true) {
+ log.appendLine(`set config: ${key}=${value}`);
+ }
}
function host() {
- return `https://${config.apiHost}/api/${config.apiVersion}/`;
+ return `https://${config.apiHost}/api/${config.apiVersion}/`;
}
function setNeedsWrite(silent) {
- clearTimeout(writeDelayTimeout);
- setTimeout(function() {
- clearTimeout(writeDelayTimeout);
- writeConfigurationFile(silent);
- }, WRITE_DELAY_MS)
+ clearTimeout(writeDelayTimeout);
+ setTimeout(function() {
+ clearTimeout(writeDelayTimeout);
+ writeConfigurationFile(silent);
+ }, WRITE_DELAY_MS)
}
function readConfigurationFile() {
- if (fs.existsSync(configFile())) {
- try {
- var obj = JSON.parse(fs.readFileSync(configFile(), 'utf8'));
- for (var key in obj) {
- config[key] = obj[key];
- }
- }
- catch( error ) {
- log.appendLine('Error reading configuration file: ' + error.toString());
- }
- }
+ if (fs.existsSync(configFile())) {
+ try {
+ var obj = JSON.parse(fs.readFileSync(configFile(), 'utf8'));
+ for (var key in obj) {
+ config[key] = obj[key];
+ }
+ }
+ catch( error ) {
+ log.appendLine('Error reading configuration file: ' + error.toString());
+ }
+ }
}
function writeConfigurationFile(silent) {
- var str = JSON.stringify(config);
- var buffer = new Buffer(str);
+ var str = JSON.stringify(config);
+ var buffer = new Buffer(str);
- if (!fs.existsSync(configDir())){
- fs.mkdirSync(configDir());
- }
+ if (!fs.existsSync(configDir())){
+ fs.mkdirSync(configDir());
+ }
- fs.open(configFile(), 'w', function(err, fd) {
- if (err) {
- throw 'error opening file: ' + err;
- }
+ fs.open(configFile(), 'w', function(err, fd) {
+ if (err) {
+ throw 'error opening file: ' + err;
+ }
- fs.write(fd, buffer, 0, buffer.length, null, function(err) {
- if (err) throw 'error writing file: ' + err;
- fs.close(fd, function() {
- if (silent != true) {
- log.appendLine('Configuration saved in ' + configFile());
- }
- })
- });
+ fs.write(fd, buffer, 0, buffer.length, null, function(err) {
+ if (err) throw 'error writing file: ' + err;
+ fs.close(fd, function() {
+ if (silent != true) {
+ log.appendLine('Configuration saved in ' + configFile());
+ }
+ })
+ });
- });
+ });
}
function getAvailableProperties() {
- return [HOST, NAMESPACE, AUTH]
+ return [HOST, NAMESPACE, AUTH]
}
function setAction(params) {
- vscode.window.showQuickPick(getAvailableProperties(), {prompt:'Select a property to update:'})
- .then(function(property){
+ vscode.window.showQuickPick(getAvailableProperties(), {prompt:'Select a property to update:'})
+ .then(function(property){
- if (!property) {
- return;
- }
+ if (!property) {
+ return;
+ }
- vscode.window.showInputBox({prompt:`Enter value for ${property}:`})
- .then(function(value){
+ vscode.window.showInputBox({prompt:`Enter value for ${property}:`})
+ .then(function(value){
- if (!value) {
- return;
- }
- log.show(true);
- log.appendLine(`$ wsk property set ${property} ${value}`);
- set(property, value);
- });
+ if (!value) {
+ return;
+ }
+ log.show(true);
+ log.appendLine(`$ wsk property set ${property} ${value}`);
+ set(property, value);
+ });
- });
+ });
}
function getAction(params) {
- log.show(true);
- log.appendLine('$ wsk property get');
- var props = getAvailableProperties()
- for (var x=0; x<props.length; x++) {
- var key = props[x];
- var output = util.pad(key, 20) + get(key);
- log.appendLine(output);
- }
+ log.show(true);
+ log.appendLine('$ wsk property get');
+ var props = getAvailableProperties()
+ for (var x=0; x<props.length; x++) {
+ var key = props[x];
+ var output = util.pad(key, 20) + get(key);
+ log.appendLine(output);
+ }
}
function unsetAction(params) {
- vscode.window.showQuickPick(getAvailableProperties(), {prompt:'Select a property to update:'})
- .then(function(property){
+ vscode.window.showQuickPick(getAvailableProperties(), {prompt:'Select a property to update:'})
+ .then(function(property){
- if (!property) {
- return;
- }
- log.show(true);
- log.appendLine(`$ wsk property unset ${property}`);
- set(property, undefined);
- });
+ if (!property) {
+ return;
+ }
+ log.show(true);
+ log.appendLine(`$ wsk property unset ${property}`);
+ set(property, undefined);
+ });
}
function updateOW() {
- var options = {api: host(), api_key: get(AUTH), namespace: get(NAMESPACE)};
- ow.actions.options = options;
- ow.packages.options = options;
- ow.rules.options = options;
- ow.triggers.options = options;
- ow.namespaces.options = options;
- ow.activations.options = options;
+ var options = {api: host(), api_key: get(AUTH), namespace: get(NAMESPACE)};
+ ow.actions.options = options;
+ ow.packages.options = options;
+ ow.rules.options = options;
+ ow.triggers.options = options;
+ ow.namespaces.options = options;
+ ow.activations.options = options;
}
module.exports = {
- register:register,
- get: get,
- set: set,
- host: host,
- validate:validate
+ register:register,
+ get: get,
+ set: set,
+ host: host,
+ validate:validate
}
diff --git a/static-src/commands/wsk.rule.js b/static-src/commands/wsk.rule.js
index 560e903..324e0d3 100644
--- a/static-src/commands/wsk.rule.js
+++ b/static-src/commands/wsk.rule.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -12,37 +29,37 @@
var props;
function register(_ow, context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
+ ow = _ow;
+ log = _log;
+ props = _props;
- var defaultDisposable = vscode.commands.registerCommand('extension.wsk.rule', defaultAction);
- var listDisposable = vscode.commands.registerCommand('extension.wsk.rule.list', listAction);
- var createDisposable = vscode.commands.registerCommand('extension.wsk.rule.create', createAction);
- var updateDisposable = vscode.commands.registerCommand('extension.wsk.rule.update', updateAction);
- var deleteDisposable = vscode.commands.registerCommand('extension.wsk.rule.delete', deleteAction);
- var getDisposable = vscode.commands.registerCommand('extension.wsk.rule.get', getAction);
- var statusDisposable = vscode.commands.registerCommand('extension.wsk.rule.status', statusAction);
- var enableDisposable = vscode.commands.registerCommand('extension.wsk.rule.enable', enableAction);
- var disableDisposable = vscode.commands.registerCommand('extension.wsk.rule.disable', disableAction);
-
- context.subscriptions.push(defaultDisposable, listDisposable, createDisposable, updateDisposable, deleteDisposable, getDisposable, statusDisposable, enableDisposable, disableDisposable, enableAction, disableAction);
+ var defaultDisposable = vscode.commands.registerCommand('extension.wsk.rule', defaultAction);
+ var listDisposable = vscode.commands.registerCommand('extension.wsk.rule.list', listAction);
+ var createDisposable = vscode.commands.registerCommand('extension.wsk.rule.create', createAction);
+ var updateDisposable = vscode.commands.registerCommand('extension.wsk.rule.update', updateAction);
+ var deleteDisposable = vscode.commands.registerCommand('extension.wsk.rule.delete', deleteAction);
+ var getDisposable = vscode.commands.registerCommand('extension.wsk.rule.get', getAction);
+ var statusDisposable = vscode.commands.registerCommand('extension.wsk.rule.status', statusAction);
+ var enableDisposable = vscode.commands.registerCommand('extension.wsk.rule.enable', enableAction);
+ var disableDisposable = vscode.commands.registerCommand('extension.wsk.rule.disable', disableAction);
+
+ context.subscriptions.push(defaultDisposable, listDisposable, createDisposable, updateDisposable, deleteDisposable, getDisposable, statusDisposable, enableDisposable, disableDisposable, enableAction, disableAction);
}
function defaultAction(params) {
- log.show(true);
- log.appendLine('\n$ wsk rule');
- log.appendLine('available commands:');
- log.appendLine(' create create new rule');
- log.appendLine(' delete delete rule');
- log.appendLine(' update update an existing rule');
- log.appendLine(' enable enable rule');
- log.appendLine(' disable disable rule');
- log.appendLine(' status get rule status');
- log.appendLine(' get get rule');
- log.appendLine(' list list all rules');
+ log.show(true);
+ log.appendLine('\n$ wsk rule');
+ log.appendLine('available commands:');
+ log.appendLine(' create create new rule');
+ log.appendLine(' delete delete rule');
+ log.appendLine(' update update an existing rule');
+ log.appendLine(' enable enable rule');
+ log.appendLine(' disable disable rule');
+ log.appendLine(' status get rule status');
+ log.appendLine(' get get rule');
+ log.appendLine(' list list all rules');
}
@@ -51,214 +68,214 @@
function listAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- log.show(true);
- log.appendLine('\n$ wsk rule list');
- list();
+ log.show(true);
+ log.appendLine('\n$ wsk rule list');
+ list();
}
function list() {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- return getList().then(function (rules) {
- util.appendHeading('rules');
- for (var x=0; x<rules.length; x ++){
- util.appendEntry(rules[x]);
- }
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
+ return getList().then(function (rules) {
+ util.appendHeading('rules');
+ for (var x=0; x<rules.length; x ++){
+ util.appendEntry(rules[x]);
+ }
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
}
function getList() {
- return new Promise(function (fulfill, reject){
- return ow.rules.list().then(function (rules) {
- fulfill(rules);
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
- });
+ return new Promise(function (fulfill, reject){
+ return ow.rules.list().then(function (rules) {
+ fulfill(rules);
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
+ });
}
function getListAsStringArray() {
- return getList().then(function (rules) {
- var result = [];
- for (var x=0; x<rules.length; x ++){
- var name = util.formatQualifiedName(rules[x]);
- result.push(name)
- }
- return result;
- })
+ return getList().then(function (rules) {
+ var result = [];
+ for (var x=0; x<rules.length; x ++){
+ var name = util.formatQualifiedName(rules[x]);
+ result.push(name)
+ }
+ return result;
+ })
}
function getActionListAsStringArray() {
- return wskAction.getListAsStringArray()
+ return wskAction.getListAsStringArray()
}
function getTriggerListAsStringArray() {
- return wskTrigger.getListAsStringArray()
+ return wskTrigger.getListAsStringArray()
}
function createAction(params) {
- if (!props.validate()){
- return;
- }
-
- var YES = 'Yes';
- var NO = 'No';
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showInputBox({placeHolder:'Enter a name for your rule:'})
- .then(function(rule){
+ var YES = 'Yes';
+ var NO = 'No';
- if (rule == undefined) {
- return;
- }
-
- vscode.window.showQuickPick(getTriggerListAsStringArray(), {placeHolder:'Select a trigger to bind:'})
- .then(function(trigger){
-
- if (trigger == undefined) {
- return;
- }
-
-
- vscode.window.showQuickPick(getActionListAsStringArray(), {placeHolder:'Select a action to bind:'})
- .then(function(action){
-
- if (action == undefined) {
- return;
- }
-
- var parsedTrigger = util.parseQualifiedName(trigger);
- var parsedAction = util.parseQualifiedName(action);
-
- log.show(true);
- log.appendLine(`\n$ wsk rule create ${rule} ${parsedTrigger.name} ${parsedAction.name}`);
-
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- ruleName: rule,
- trigger:parsedTrigger.name,
- action:parsedAction.name
- }
-
- ow.rules.create(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(JSON.stringify(result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
-
-
- vscode.window.showWarningMessage('Would you like to activate ' + rule + '?', YES, NO)
- .then( function(selection) {
- if (selection === YES) {
-
- var qualifiedRule = props.get("namespace") + "/" + rule;
-
- doStatusChange(qualifiedRule, true);
- }
- });
-
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
-
- })
- })
- });
+ vscode.window.showInputBox({placeHolder:'Enter a name for your rule:'})
+ .then(function(rule){
+
+ if (rule == undefined) {
+ return;
+ }
+
+ vscode.window.showQuickPick(getTriggerListAsStringArray(), {placeHolder:'Select a trigger to bind:'})
+ .then(function(trigger){
+
+ if (trigger == undefined) {
+ return;
+ }
+
+
+ vscode.window.showQuickPick(getActionListAsStringArray(), {placeHolder:'Select a action to bind:'})
+ .then(function(action){
+
+ if (action == undefined) {
+ return;
+ }
+
+ var parsedTrigger = util.parseQualifiedName(trigger);
+ var parsedAction = util.parseQualifiedName(action);
+
+ log.show(true);
+ log.appendLine(`\n$ wsk rule create ${rule} ${parsedTrigger.name} ${parsedAction.name}`);
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ ruleName: rule,
+ trigger:parsedTrigger.name,
+ action:parsedAction.name
+ }
+
+ ow.rules.create(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(JSON.stringify(result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+
+
+ vscode.window.showWarningMessage('Would you like to activate ' + rule + '?', YES, NO)
+ .then( function(selection) {
+ if (selection === YES) {
+
+ var qualifiedRule = props.get("namespace") + "/" + rule;
+
+ doStatusChange(qualifiedRule, true);
+ }
+ });
+
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+
+ })
+ })
+ });
}
function updateAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- var YES = 'Yes';
- var NO = 'No';
+ var YES = 'Yes';
+ var NO = 'No';
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to update:'})
- .then(function(rule){
-
- if (rule == undefined) {
- return;
- }
-
- var parsedRule = util.parseQualifiedName(rule);
- rule = parsedRule.name;
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to update:'})
+ .then(function(rule){
-
- vscode.window.showQuickPick(getTriggerListAsStringArray(), {placeHolder:'Select a trigger to bind:'})
- .then(function(trigger){
-
- if (trigger == undefined) {
- return;
- }
-
- vscode.window.showQuickPick(getActionListAsStringArray(), {placeHolder:'Select a action to bind:'})
- .then(function(action){
-
- if (action == undefined) {
- return;
- }
-
- var parsedTrigger = util.parseQualifiedName(trigger);
- var parsedAction = util.parseQualifiedName(action);
-
- log.show(true);
- log.appendLine(`\n$ wsk rule update ${rule} ${parsedTrigger.name} ${parsedAction.name}`);
-
- vscode.window.showWarningMessage('Are you sure you want to overwrite ' + rule, YES, NO)
- .then( function(selection) {
- if (selection === YES) {
-
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- ruleName: rule,
- trigger:parsedTrigger.name,
- action:parsedAction.name
- }
-
- ow.rules.update(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(JSON.stringify(result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
- } else {
- log.appendLine('cancelled by user')
- }
- })
- })
- })
- });
+ if (rule == undefined) {
+ return;
+ }
+
+ var parsedRule = util.parseQualifiedName(rule);
+ rule = parsedRule.name;
+
+
+ vscode.window.showQuickPick(getTriggerListAsStringArray(), {placeHolder:'Select a trigger to bind:'})
+ .then(function(trigger){
+
+ if (trigger == undefined) {
+ return;
+ }
+
+ vscode.window.showQuickPick(getActionListAsStringArray(), {placeHolder:'Select a action to bind:'})
+ .then(function(action){
+
+ if (action == undefined) {
+ return;
+ }
+
+ var parsedTrigger = util.parseQualifiedName(trigger);
+ var parsedAction = util.parseQualifiedName(action);
+
+ log.show(true);
+ log.appendLine(`\n$ wsk rule update ${rule} ${parsedTrigger.name} ${parsedAction.name}`);
+
+ vscode.window.showWarningMessage('Are you sure you want to overwrite ' + rule, YES, NO)
+ .then( function(selection) {
+ if (selection === YES) {
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ ruleName: rule,
+ trigger:parsedTrigger.name,
+ action:parsedAction.name
+ }
+
+ ow.rules.update(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(JSON.stringify(result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+ } else {
+ log.appendLine('cancelled by user')
+ }
+ })
+ })
+ })
+ });
}
@@ -267,129 +284,129 @@
function deleteAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to delete:'})
- .then(function(rule){
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to delete:'})
+ .then(function(rule){
- if (rule == undefined) {
- return;
- }
+ if (rule == undefined) {
+ return;
+ }
- var parsedRule = util.parseQualifiedName(rule)
+ var parsedRule = util.parseQualifiedName(rule)
- log.show(true);
- log.appendLine('\n$ wsk trigger delete ' + parsedRule.name);
+ log.show(true);
+ log.appendLine('\n$ wsk trigger delete ' + parsedRule.name);
- var options = {
- ruleName: parsedRule.name,
- namespace: parsedRule.namespace
- };
+ var options = {
+ ruleName: parsedRule.name,
+ namespace: parsedRule.namespace
+ };
- var YES = 'Yes';
- var NO = 'No';
+ var YES = 'Yes';
+ var NO = 'No';
- vscode.window.showWarningMessage('Are you sure you want to delete ' + parsedRule.name, YES, NO)
- .then( function(selection) {
- if (selection === YES) {
- ow.rules.delete(options)
- .then(function(result) {
- var message = 'OpenWhisk rule deleted: ' + util.formatQualifiedName(result);
- log.appendLine(message);
- vscode.window.showInformationMessage(message);
- })
- .catch(function(error) {
- log.appendLine('rule status must be \'inactive\' to delete');
- });
- }
- });
- });
+ vscode.window.showWarningMessage('Are you sure you want to delete ' + parsedRule.name, YES, NO)
+ .then( function(selection) {
+ if (selection === YES) {
+ ow.rules.delete(options)
+ .then(function(result) {
+ var message = 'OpenWhisk rule deleted: ' + util.formatQualifiedName(result);
+ log.appendLine(message);
+ vscode.window.showInformationMessage(message);
+ })
+ .catch(function(error) {
+ log.appendLine('rule status must be \'inactive\' to delete');
+ });
+ }
+ });
+ });
}
function getAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to fetch:'})
- .then(function(rule){
-
- if (rule == undefined) {
- return;
- }
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to fetch:'})
+ .then(function(rule){
- var parsedRule = util.parseQualifiedName(rule)
-
- log.appendLine('\n$ wsk rule get ' + parsedRule.name);
+ if (rule == undefined) {
+ return;
+ }
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- ruleName: parsedRule.name,
- blocking:true,
- namespace: parsedRule.namespace
- }
- ow.rules.get(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(JSON.stringify(result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
- });
+ var parsedRule = util.parseQualifiedName(rule)
+
+ log.appendLine('\n$ wsk rule get ' + parsedRule.name);
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ ruleName: parsedRule.name,
+ blocking:true,
+ namespace: parsedRule.namespace
+ }
+ ow.rules.get(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(JSON.stringify(result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+ });
}
function statusAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to fetch:'})
- .then(function(rule){
-
- if (rule == undefined) {
- return;
- }
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a rule to fetch:'})
+ .then(function(rule){
- var parsedRule = util.parseQualifiedName(rule)
-
- log.appendLine('\n$ wsk rule status ' + parsedRule.name);
+ if (rule == undefined) {
+ return;
+ }
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- ruleName: parsedRule.name,
- blocking:true,
- namespace: parsedRule.namespace
- }
- ow.rules.get(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(`\nok: rule ${parsedRule.name} is ${result.status}`)
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
- });
+ var parsedRule = util.parseQualifiedName(rule)
+
+ log.appendLine('\n$ wsk rule status ' + parsedRule.name);
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ ruleName: parsedRule.name,
+ blocking:true,
+ namespace: parsedRule.namespace
+ }
+ ow.rules.get(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(`\nok: rule ${parsedRule.name} is ${result.status}`)
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+ });
}
@@ -397,74 +414,74 @@
function enableAction(params) {
- doStatusChange(undefined, true);
+ doStatusChange(undefined, true);
}
function disableAction(params) {
- doStatusChange(undefined, false);
+ doStatusChange(undefined, false);
}
function doStatusChange(rule, enable) {
- if (!props.validate()){
- return;
- }
-
- var statusChangeImpl = function(rule){
-
- if (rule == undefined) {
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- var parsedRule = util.parseQualifiedName(rule)
- log.appendLine(`\n$ wsk rule ${enable?'enable':'disable'} ${parsedRule.name}`);
+ var statusChangeImpl = function(rule){
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- ruleName: parsedRule.name,
- blocking:true,
- namespace: parsedRule.namespace
- }
-
- var callback = function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(`ok: rule ${parsedRule.name} ${enable?'enabled':'disabled'}`)
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- }
- var error = function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- }
-
- if (enable) {
- ow.rules.enable(invocationParams)
- .then(callback)
- .catch(error);
- } else {
- ow.rules.disable(invocationParams)
- .then(callback)
- .catch(error);
- }
- }
-
- if (rule == undefined) {
- //${enable?'enable'?'disable'}
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:`Select a rule to :`})
- .then(statusChangeImpl);
- } else {
- statusChangeImpl(rule)
- }
+ if (rule == undefined) {
+ return;
+ }
+
+ var parsedRule = util.parseQualifiedName(rule)
+ log.appendLine(`\n$ wsk rule ${enable?'enable':'disable'} ${parsedRule.name}`);
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ ruleName: parsedRule.name,
+ blocking:true,
+ namespace: parsedRule.namespace
+ }
+
+ var callback = function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(`ok: rule ${parsedRule.name} ${enable?'enabled':'disabled'}`)
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ }
+ var error = function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ }
+
+ if (enable) {
+ ow.rules.enable(invocationParams)
+ .then(callback)
+ .catch(error);
+ } else {
+ ow.rules.disable(invocationParams)
+ .then(callback)
+ .catch(error);
+ }
+ }
+
+ if (rule == undefined) {
+ //${enable?'enable'?'disable'}
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:`Select a rule to :`})
+ .then(statusChangeImpl);
+ } else {
+ statusChangeImpl(rule)
+ }
}
module.exports = {
- register: register,
- list:list
-};
\ No newline at end of file
+ register: register,
+ list:list
+};
diff --git a/static-src/commands/wsk.trigger.js b/static-src/commands/wsk.trigger.js
index a434c3f..d6668b2 100644
--- a/static-src/commands/wsk.trigger.js
+++ b/static-src/commands/wsk.trigger.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -8,401 +25,401 @@
var props;
function register(_ow, context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
+ ow = _ow;
+ log = _log;
+ props = _props;
- var defaultDisposable = vscode.commands.registerCommand('extension.wsk.trigger', defaultAction);
- var listDisposable = vscode.commands.registerCommand('extension.wsk.trigger.list', listAction);
- var createDisposable = vscode.commands.registerCommand('extension.wsk.trigger.create', createAction);
- var updateDisposable = vscode.commands.registerCommand('extension.wsk.trigger.update', updateAction);
- var deleteDisposable = vscode.commands.registerCommand('extension.wsk.trigger.delete', deleteAction);
- var getDisposable = vscode.commands.registerCommand('extension.wsk.trigger.get', getAction);
- var fireDisposable = vscode.commands.registerCommand('extension.wsk.trigger.fire', fireAction);
+ var defaultDisposable = vscode.commands.registerCommand('extension.wsk.trigger', defaultAction);
+ var listDisposable = vscode.commands.registerCommand('extension.wsk.trigger.list', listAction);
+ var createDisposable = vscode.commands.registerCommand('extension.wsk.trigger.create', createAction);
+ var updateDisposable = vscode.commands.registerCommand('extension.wsk.trigger.update', updateAction);
+ var deleteDisposable = vscode.commands.registerCommand('extension.wsk.trigger.delete', deleteAction);
+ var getDisposable = vscode.commands.registerCommand('extension.wsk.trigger.get', getAction);
+ var fireDisposable = vscode.commands.registerCommand('extension.wsk.trigger.fire', fireAction);
- context.subscriptions.push(defaultDisposable, listDisposable, createDisposable, updateDisposable, deleteDisposable, getDisposable, fireDisposable);
+ context.subscriptions.push(defaultDisposable, listDisposable, createDisposable, updateDisposable, deleteDisposable, getDisposable, fireDisposable);
}
function defaultAction(params) {
- log.show(true);
- log.appendLine('\n$ wsk trigger');
- log.appendLine('available commands:');
- log.appendLine(' create create new trigger');
- log.appendLine(' update update an existing trigger');
- log.appendLine(' fire fire trigger event');
- log.appendLine(' get get trigger');
- log.appendLine(' delete delete trigger');
- log.appendLine(' list list all triggers');
+ log.show(true);
+ log.appendLine('\n$ wsk trigger');
+ log.appendLine('available commands:');
+ log.appendLine(' create create new trigger');
+ log.appendLine(' update update an existing trigger');
+ log.appendLine(' fire fire trigger event');
+ log.appendLine(' get get trigger');
+ log.appendLine(' delete delete trigger');
+ log.appendLine(' list list all triggers');
}
function listAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- log.show(true);
- log.appendLine('\n$ wsk trigger list');
- list();
+ log.show(true);
+ log.appendLine('\n$ wsk trigger list');
+ list();
}
function list() {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- return getList().then(function (triggers) {
- util.appendHeading('triggers');
- for (var x=0; x<triggers.length; x ++){
- util.appendEntry(triggers[x]);
- }
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
+ return getList().then(function (triggers) {
+ util.appendHeading('triggers');
+ for (var x=0; x<triggers.length; x ++){
+ util.appendEntry(triggers[x]);
+ }
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
}
function getList() {
- return new Promise(function (fulfill, reject){
- return ow.triggers.list().then(function (triggers) {
- fulfill(triggers);
- }).catch(function(error) {
- log.appendLine(error.toString())
- });
- });
+ return new Promise(function (fulfill, reject){
+ return ow.triggers.list().then(function (triggers) {
+ fulfill(triggers);
+ }).catch(function(error) {
+ log.appendLine(error.toString())
+ });
+ });
}
function getListAsStringArray() {
- return getList().then(function (triggers) {
- var result = [];
- for (var x=0; x<triggers.length; x ++){
- var name = util.formatQualifiedName(triggers[x]);
- result.push(name)
- }
- return result;
- })
+ return getList().then(function (triggers) {
+ var result = [];
+ for (var x=0; x<triggers.length; x ++){
+ var name = util.formatQualifiedName(triggers[x]);
+ result.push(name)
+ }
+ return result;
+ })
}
function createAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showInputBox({placeHolder:'Enter a name for your trigger:'})
- .then(function(trigger){
+ vscode.window.showInputBox({placeHolder:'Enter a name for your trigger:'})
+ .then(function(trigger){
- if (trigger == undefined) {
- return;
- }
-
- vscode.window.showInputBox({
- placeHolder:'Enter parameters to bind (-p key value) or leave blank for no parameters:',
- value:''
- }).then(function (parametersString) {
+ if (trigger == undefined) {
+ return;
+ }
- var pString = ''
- if (parametersString != undefined) {
- pString = parametersString
- }
-
- log.show(true);
- log.appendLine('\n$ wsk trigger create ' + trigger + ' ' + pString);
+ vscode.window.showInputBox({
+ placeHolder:'Enter parameters to bind (-p key value) or leave blank for no parameters:',
+ value:''
+ }).then(function (parametersString) {
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
+ var pString = ''
+ if (parametersString != undefined) {
+ pString = parametersString
+ }
- var startTime = new Date().getTime();
- var invocationParams = {
- triggerName: trigger,
- blocking:true
- }
+ log.show(true);
+ log.appendLine('\n$ wsk trigger create ' + trigger + ' ' + pString);
- if (pString.length>0) {
- var params = util.parseParametersString(pString);
- var paramsArray = [];
-
- for (var key in params) {
- var object = {};
- object.key = key;
- object.value = params[key];
- paramsArray.push(object)
- }
-
- invocationParams.trigger = {
- "parameters":paramsArray
- };
- }
- ow.triggers.create(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(JSON.stringify(result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
- });
- });
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ triggerName: trigger,
+ blocking:true
+ }
+
+ if (pString.length>0) {
+ var params = util.parseParametersString(pString);
+ var paramsArray = [];
+
+ for (var key in params) {
+ var object = {};
+ object.key = key;
+ object.value = params[key];
+ paramsArray.push(object)
+ }
+
+ invocationParams.trigger = {
+ "parameters":paramsArray
+ };
+ }
+ ow.triggers.create(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(JSON.stringify(result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+ });
+ });
}
function updateAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- var YES = 'Yes';
- var NO = 'No';
+ var YES = 'Yes';
+ var NO = 'No';
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to update:'})
- .then(function(trigger){
-
- if (trigger == undefined) {
- return;
- }
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to update:'})
+ .then(function(trigger){
-
+ if (trigger == undefined) {
+ return;
+ }
- var triggerString = trigger.toString();
- var startIndex = triggerString.indexOf('/');
- var namespace = triggerString.substring(0, startIndex);
- var triggerToUpdate = triggerString.substring(startIndex+1);
-
- vscode.window.showInputBox({
- placeHolder:'Enter parameters to bind (-p key value) or leave blank for no parameters:',
- value:''
- }).then(function (parametersString) {
- var pString = ''
- if (parametersString != undefined) {
- pString = parametersString
- }
-
- log.show(true);
- log.appendLine('\n$ wsk trigger update ' + trigger + ' ' + pString);
-
- vscode.window.showWarningMessage('Are you sure you want to overwrite ' + trigger, YES, NO)
- .then( function(selection) {
- if (selection === YES) {
+ var triggerString = trigger.toString();
+ var startIndex = triggerString.indexOf('/');
+ var namespace = triggerString.substring(0, startIndex);
+ var triggerToUpdate = triggerString.substring(startIndex+1);
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- triggerName: triggerToUpdate,
- blocking:true,
- namespace: namespace
- }
- if (pString.length>0) {
- var params = util.parseParametersString(pString);
- var paramsArray = [];
-
- for (var key in params) {
- var object = {};
- object.key = key;
- object.value = params[key];
- paramsArray.push(object)
- }
-
- invocationParams.trigger = {
- "parameters":paramsArray
- };
- }
- ow.triggers.update(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(JSON.stringify(result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
-
- } else {
- log.appendLine('cancelled by user')
- }
- });
+ vscode.window.showInputBox({
+ placeHolder:'Enter parameters to bind (-p key value) or leave blank for no parameters:',
+ value:''
+ }).then(function (parametersString) {
- });
- });
+ var pString = ''
+ if (parametersString != undefined) {
+ pString = parametersString
+ }
+
+ log.show(true);
+ log.appendLine('\n$ wsk trigger update ' + trigger + ' ' + pString);
+
+ vscode.window.showWarningMessage('Are you sure you want to overwrite ' + trigger, YES, NO)
+ .then( function(selection) {
+ if (selection === YES) {
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ triggerName: triggerToUpdate,
+ blocking:true,
+ namespace: namespace
+ }
+
+ if (pString.length>0) {
+ var params = util.parseParametersString(pString);
+ var paramsArray = [];
+
+ for (var key in params) {
+ var object = {};
+ object.key = key;
+ object.value = params[key];
+ paramsArray.push(object)
+ }
+
+ invocationParams.trigger = {
+ "parameters":paramsArray
+ };
+ }
+ ow.triggers.update(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(JSON.stringify(result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+
+ } else {
+ log.appendLine('cancelled by user')
+ }
+ });
+
+ });
+ });
}
function deleteAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to delete:'})
- .then(function(trigger){
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to delete:'})
+ .then(function(trigger){
- if (trigger == undefined) {
- return;
- }
+ if (trigger == undefined) {
+ return;
+ }
- var triggerString = trigger.toString();
- var startIndex = triggerString.indexOf('/');
- var namespace = triggerString.substring(0, startIndex);
- var triggerToDelete = triggerString.substring(startIndex+1);
+ var triggerString = trigger.toString();
+ var startIndex = triggerString.indexOf('/');
+ var namespace = triggerString.substring(0, startIndex);
+ var triggerToDelete = triggerString.substring(startIndex+1);
- log.show(true);
- log.appendLine('\n$ wsk trigger delete ' + triggerToDelete);
+ log.show(true);
+ log.appendLine('\n$ wsk trigger delete ' + triggerToDelete);
- var options = {
- triggerName: triggerToDelete
- };
+ var options = {
+ triggerName: triggerToDelete
+ };
- var YES = 'Yes';
- var NO = 'No';
+ var YES = 'Yes';
+ var NO = 'No';
- vscode.window.showWarningMessage('Are you sure you want to delete ' + triggerToDelete, YES, NO)
- .then( function(selection) {
- if (selection === YES) {
- ow.triggers.delete(options)
- .then(function(result) {
- var message = 'OpenWhisk trigger deleted: ' + util.formatQualifiedName(result);
- log.appendLine(message);
- vscode.window.showInformationMessage(message);
- })
- .catch(function(error) {
- util.printOpenWhiskError(error);
- });
- }
- });
- });
+ vscode.window.showWarningMessage('Are you sure you want to delete ' + triggerToDelete, YES, NO)
+ .then( function(selection) {
+ if (selection === YES) {
+ ow.triggers.delete(options)
+ .then(function(result) {
+ var message = 'OpenWhisk trigger deleted: ' + util.formatQualifiedName(result);
+ log.appendLine(message);
+ vscode.window.showInformationMessage(message);
+ })
+ .catch(function(error) {
+ util.printOpenWhiskError(error);
+ });
+ }
+ });
+ });
}
function getAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to fetch:'})
- .then(function(trigger){
-
- if (trigger == undefined) {
- return;
- }
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to fetch:'})
+ .then(function(trigger){
- var triggerString = trigger.toString();
- var startIndex = triggerString.indexOf('/');
- var namespace = triggerString.substring(0, startIndex);
- var triggerToGet = triggerString.substring(startIndex+1);
-
- log.appendLine('\n$ wsk trigger get ' + triggerToGet);
+ if (trigger == undefined) {
+ return;
+ }
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- triggerName: triggerToGet,
- blocking:true,
- namespace: namespace
- }
- ow.triggers.get(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(JSON.stringify(result, null, 4))
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
- });
+ var triggerString = trigger.toString();
+ var startIndex = triggerString.indexOf('/');
+ var namespace = triggerString.substring(0, startIndex);
+ var triggerToGet = triggerString.substring(startIndex+1);
+
+ log.appendLine('\n$ wsk trigger get ' + triggerToGet);
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ triggerName: triggerToGet,
+ blocking:true,
+ namespace: namespace
+ }
+ ow.triggers.get(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(JSON.stringify(result, null, 4))
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+ });
}
function fireAction(params) {
- if (!props.validate()){
- return;
- }
+ if (!props.validate()){
+ return;
+ }
- vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to fire:'})
- .then(function(trigger){
-
- if (trigger == undefined) {
- return;
- }
+ vscode.window.showQuickPick(getListAsStringArray(), {placeHolder:'Select a trigger to fire:'})
+ .then(function(trigger){
- var triggerString = trigger.toString();
- var startIndex = triggerString.indexOf('/');
- var namespace = triggerString.substring(0, startIndex);
- var triggerToFire = triggerString.substring(startIndex+1);
+ if (trigger == undefined) {
+ return;
+ }
- vscode.window.showInputBox({
- placeHolder:'Enter parameters (-p key value) or leave blank for no parameters:',
- value:''
- }).then(function (parametersString) {
+ var triggerString = trigger.toString();
+ var startIndex = triggerString.indexOf('/');
+ var namespace = triggerString.substring(0, startIndex);
+ var triggerToFire = triggerString.substring(startIndex+1);
- var pString = ''
- if (parametersString != undefined) {
- pString = parametersString
- }
-
- log.show(true);
- log.appendLine('\n$ wsk trigger fire ' + trigger + ' ' + pString);
-
- var activityInterval = setInterval(function() {
- log.append('.');
- },300);
-
- var startTime = new Date().getTime();
- var invocationParams = {
- triggerName: triggerToFire,
- blocking:true,
- namespace: namespace
- }
+ vscode.window.showInputBox({
+ placeHolder:'Enter parameters (-p key value) or leave blank for no parameters:',
+ value:''
+ }).then(function (parametersString) {
- if (pString.length>0) {
- invocationParams.params = util.parseParametersString(pString);
- }
- ow.triggers.invoke(invocationParams)
- .then(function(result) {
- var totalTime = startTime - (new Date().getTime());
- clearInterval(activityInterval);
- log.appendLine(`\nok: triggered ${trigger}`);
- log.appendLine(JSON.stringify(result, null, 4));
- log.appendLine('>> completed in ' + (-totalTime) + 'ms');
- })
- .catch(function(error) {
- clearInterval(activityInterval);
- util.printOpenWhiskError(error);
- });
-
- });
- });
+ var pString = ''
+ if (parametersString != undefined) {
+ pString = parametersString
+ }
+
+ log.show(true);
+ log.appendLine('\n$ wsk trigger fire ' + trigger + ' ' + pString);
+
+ var activityInterval = setInterval(function() {
+ log.append('.');
+ },300);
+
+ var startTime = new Date().getTime();
+ var invocationParams = {
+ triggerName: triggerToFire,
+ blocking:true,
+ namespace: namespace
+ }
+
+ if (pString.length>0) {
+ invocationParams.params = util.parseParametersString(pString);
+ }
+ ow.triggers.invoke(invocationParams)
+ .then(function(result) {
+ var totalTime = startTime - (new Date().getTime());
+ clearInterval(activityInterval);
+ log.appendLine(`\nok: triggered ${trigger}`);
+ log.appendLine(JSON.stringify(result, null, 4));
+ log.appendLine('>> completed in ' + (-totalTime) + 'ms');
+ })
+ .catch(function(error) {
+ clearInterval(activityInterval);
+ util.printOpenWhiskError(error);
+ });
+
+ });
+ });
}
module.exports = {
- register: register,
- list:list,
- getListAsStringArray:getListAsStringArray
-};
\ No newline at end of file
+ register: register,
+ list:list,
+ getListAsStringArray:getListAsStringArray
+};
diff --git a/static-src/commands/wsk.util.js b/static-src/commands/wsk.util.js
index ecf8da5..4f2f8c9 100644
--- a/static-src/commands/wsk.util.js
+++ b/static-src/commands/wsk.util.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
'use strict';
var vscode = require('vscode');
@@ -9,29 +26,29 @@
var props;
function register(_ow, context, _log, _props) {
- ow = _ow;
- log = _log;
- props = _props;
+ ow = _ow;
+ log = _log;
+ props = _props;
- var bluemixDisposable = vscode.commands.registerCommand('extension.wsk.util.bluemix', bluemixAction);
- var docsDisposable = vscode.commands.registerCommand('extension.wsk.util.docs', docsAction);
- context.subscriptions.push(bluemixDisposable, docsDisposable);
+ var bluemixDisposable = vscode.commands.registerCommand('extension.wsk.util.bluemix', bluemixAction);
+ var docsDisposable = vscode.commands.registerCommand('extension.wsk.util.docs', docsAction);
+ context.subscriptions.push(bluemixDisposable, docsDisposable);
}
function bluemixAction(params) {
- log.show(true);
- log.appendLine('\n$ opening OpenWhisk console on Bluemix');
- open('https://new-console.ng.bluemix.net/openwhisk');
+ log.show(true);
+ log.appendLine('\n$ opening OpenWhisk console on Bluemix');
+ open('https://new-console.ng.bluemix.net/openwhisk');
}
function docsAction(params) {
- log.show(true);
- log.appendLine('\n$ opening OpenWhisk console on Bluemix');
- open('https://new-console.ng.bluemix.net/docs/openwhisk/index.html');
+ log.show(true);
+ log.appendLine('\n$ opening OpenWhisk console on Bluemix');
+ open('https://new-console.ng.bluemix.net/docs/openwhisk/index.html');
}
module.exports = {
- register: register
-};
\ No newline at end of file
+ register: register
+};
diff --git a/static-src/extension.js b/static-src/extension.js
index 032cadb..c77a594 100644
--- a/static-src/extension.js
+++ b/static-src/extension.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
"use strict";
// The module 'vscode' contains the VS Code extensibility API
@@ -10,15 +27,15 @@
// your extension is activated the very first time the command is executed
function activate(context) {
- // Use the console to output diagnostic information (console.log) and errors (console.error)
- // This line of code will only be executed once when your extension is activated
- console.log('Congratulations, your extension "vscode-openwhisk" is now active!');
+ // Use the console to output diagnostic information (console.log) and errors (console.error)
+ // This line of code will only be executed once when your extension is activated
+ console.log('Congratulations, your extension "vscode-openwhisk" is now active!');
- // The command has been defined in the package.json file
- // Now provide the implementation of the command with registerCommand
- // The commandId parameter must match the command field in package.json
+ // The command has been defined in the package.json file
+ // Now provide the implementation of the command with registerCommand
+ // The commandId parameter must match the command field in package.json
- controller.init(context);
+ controller.init(context);
}
exports.activate = activate;
diff --git a/static-src/vsc-extension-quickstart.md b/static-src/vsc-extension-quickstart.md
index 40679aa..80ce82a 100644
--- a/static-src/vsc-extension-quickstart.md
+++ b/static-src/vsc-extension-quickstart.md
@@ -2,16 +2,16 @@
## What's in the folder
* This folder contains all of the files necessary for your extension
-* `package.json` - this is the manifest file in which you declare your extension and command.
-The sample plugin registers a command and defines its title and command name. With this information
-VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
-* `extension.js` - this is the main file where you will provide the implementation of your command.
-The file exports one function, `activate`, which is called the very first time your extension is
-activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
-We pass the function containing the implementation of the command as the second parameter to
+* `package.json` - this is the manifest file in which you declare your extension and command.
+The sample plugin registers a command and defines its title and command name. With this information
+VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
+* `extension.js` - this is the main file where you will provide the implementation of your command.
+The file exports one function, `activate`, which is called the very first time your extension is
+activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
+We pass the function containing the implementation of the command as the second parameter to
`registerCommand`.
-## Get up and running straight away
+## Get up and running straight away
* press `F5` to open a new window with your extension loaded
* run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`
* set breakpoints in your code inside extension.ts to debug your extension
@@ -29,5 +29,5 @@
* press `F5` to run the tests in a new window with your extension loaded
* see the output of the test result in the debug console
* make changes to `test/extension.test.js` or create new test files inside the `test` folder
- * by convention, the test runner will only consider files matching the name pattern `**.test.js`
- * you can create folders inside the `test` folder to structure your tests any way you want
\ No newline at end of file
+ * by convention, the test runner will only consider files matching the name pattern `**.test.js`
+ * you can create folders inside the `test` folder to structure your tests any way you want