This is an automated email from the ASF dual-hosted git repository. japetrsn pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openwhisk-package-kafka.git
View the commit online: https://github.com/apache/openwhisk-package-kafka/commit/b6e1d0d736cb074f5c33d4f154565e9088bb8e37 The following commit(s) were added to refs/heads/master by this push: new b6e1d0d Allow feed to be deleted if trigger does not exist (#359) b6e1d0d is described below commit b6e1d0d736cb074f5c33d4f154565e9088bb8e37 Author: James Dubee <jwdu...@us.ibm.com> AuthorDate: Wed Nov 20 12:10:20 2019 -0500 Allow feed to be deleted if trigger does not exist (#359) --- action/kafkaFeedWeb.js | 12 ++++++------ action/lib/common.js | 10 +++++++--- action/messageHubFeedWeb.js | 12 ++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/action/kafkaFeedWeb.js b/action/kafkaFeedWeb.js index fb46096..1886107 100644 --- a/action/kafkaFeedWeb.js +++ b/action/kafkaFeedWeb.js @@ -47,7 +47,7 @@ function main(params) { // do these in parallel! return Promise.all([ db.ensureTriggerIsUnique(validatedParams.triggerName), - verifyTriggerAuth(validatedParams.triggerURL, params.authKey) + verifyTriggerAuth(validatedParams.triggerURL, params.authKey, true) ]); }) .then(() => { @@ -82,7 +82,7 @@ function main(params) { } else if (params.__ow_method === "get") { const triggerURL = common.getTriggerURL(params.endpoint, params.triggerName); - return verifyTriggerAuth(triggerURL, params.authKey) + return verifyTriggerAuth(triggerURL, params.authKey, true) .then(() => { db = new Database(params.DB_URL, params.DB_NAME); return db.getTrigger(params.triggerName); @@ -112,7 +112,7 @@ function main(params) { } else if (params.__ow_method === "put") { const triggerURL = common.getTriggerURL(params.endpoint, params.triggerName); - return verifyTriggerAuth(triggerURL, params.authKey) + return verifyTriggerAuth(triggerURL, params.authKey, true) .then(() => { db = new Database(params.DB_URL, params.DB_NAME); return db.getTrigger(params.triggerName); @@ -142,7 +142,7 @@ function main(params) { } else if (params.__ow_method === "delete") { const triggerURL = common.getTriggerURL(params.endpoint, params.triggerName); - return verifyTriggerAuth(triggerURL, params.authKey) + return verifyTriggerAuth(triggerURL, params.authKey, false) .then(() => { db = new Database(params.DB_URL, params.DB_NAME); return db.deleteTrigger(params.triggerName); @@ -195,9 +195,9 @@ function validateParameters(rawParams) { return promise; } -function verifyTriggerAuth(triggerURL, apiKey) { +function verifyTriggerAuth(triggerURL, apiKey, rejectNotFound) { var auth = apiKey.split(':'); - return common.verifyTriggerAuth(triggerURL, { user: auth[0], pass: auth[1] }); + return common.verifyTriggerAuth(triggerURL, { user: auth[0], pass: auth[1] }, rejectNotFound); } exports.main = main; diff --git a/action/lib/common.js b/action/lib/common.js index e55d22b..e154d13 100644 --- a/action/lib/common.js +++ b/action/lib/common.js @@ -38,7 +38,7 @@ function getTriggerURL(endpoint, triggerName) { return url; } -function verifyTriggerAuth(triggerURL, auth) { +function verifyTriggerAuth(triggerURL, auth, rejectNotFound) { var options = { method: 'GET', url: triggerURL, @@ -52,8 +52,12 @@ function verifyTriggerAuth(triggerURL, auth) { return request(options) .catch(err => { - console.log(`Trigger auth error: ${JSON.stringify(err)}`); - return Promise.reject({ authError: 'You are not authorized for this trigger.'}); + if (err.statusCode && err.statusCode === 404 && !rejectNotFound) { + return Promise.resolve() + } else { + console.log(`Trigger auth error: ${JSON.stringify(err)}`); + return Promise.reject({ authError: 'You are not authorized for this trigger.'}); + } }); } diff --git a/action/messageHubFeedWeb.js b/action/messageHubFeedWeb.js index 779e700..e1fb9d8 100644 --- a/action/messageHubFeedWeb.js +++ b/action/messageHubFeedWeb.js @@ -50,7 +50,7 @@ function main(params) { // do these in parallel! return Promise.all([ db.ensureTriggerIsUnique(validatedParams.triggerName), - verifyTriggerAuth(validatedParams.triggerURL, params.authKey, params.isIamKey, params.iamUrl), + verifyTriggerAuth(validatedParams.triggerURL, params.authKey, params.isIamKey, params.iamUrl, true), checkMessageHubCredentials(validatedParams) ]); }) @@ -86,7 +86,7 @@ function main(params) { } else if (params.__ow_method === "get") { const triggerURL = common.getTriggerURL(params.endpoint, params.triggerName); - return verifyTriggerAuth(triggerURL, params.authKey, params.isIamKey, params.iamUrl) + return verifyTriggerAuth(triggerURL, params.authKey, params.isIamKey, params.iamUrl, true) .then(() => { db = new Database(params.DB_URL, params.DB_NAME); return db.getTrigger(params.triggerName); @@ -119,7 +119,7 @@ function main(params) { } else if (params.__ow_method === "put") { const triggerURL = common.getTriggerURL(params.endpoint, params.triggerName); - return verifyTriggerAuth(triggerURL, params.authKey, params.isIamKey, params.iamUrl) + return verifyTriggerAuth(triggerURL, params.authKey, params.isIamKey, params.iamUrl, true) .then(() => { db = new Database(params.DB_URL, params.DB_NAME); return db.getTrigger(params.triggerName); @@ -149,7 +149,7 @@ function main(params) { } else if (params.__ow_method === "delete") { const triggerURL = common.getTriggerURL(params.endpoint, params.triggerName); - return verifyTriggerAuth(triggerURL, params.authKey, params.isIamKey, params.iamUrl) + return verifyTriggerAuth(triggerURL, params.authKey, params.isIamKey, params.iamUrl, false) .then(() => { db = new Database(params.DB_URL, params.DB_NAME); return db.deleteTrigger(params.triggerName); @@ -293,12 +293,12 @@ function checkMessageHubCredentials(params) { }); } -function verifyTriggerAuth(triggerURL, apiKey, isIamKey, iamUrl) { +function verifyTriggerAuth(triggerURL, apiKey, isIamKey, iamUrl, rejectNotFound) { if (isIamKey === true) { return new itm({ 'iamApikey': apiKey, 'iamUrl': iamUrl }).getToken().then( token => common.verifyTriggerAuth(triggerURL, { bearer: token })); } else { var auth = apiKey.split(':'); - return common.verifyTriggerAuth(triggerURL, { user: auth[0], pass: auth[1] }); + return common.verifyTriggerAuth(triggerURL, { user: auth[0], pass: auth[1] }, rejectNotFound); } }