diff --git a/README.md b/README.md index f07ee9b8..c626e02e 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ $ aio runtime --help * [`aio runtime:namespace:get`](#aio-runtimenamespaceget) * [`aio runtime:namespace:list`](#aio-runtimenamespacelist) * [`aio runtime:namespace:log-forwarding`](#aio-runtimenamespacelog-forwarding) +* [`aio runtime:namespace:log-forwarding:errors`](#aio-runtimenamespacelog-forwardingerrors) * [`aio runtime:namespace:log-forwarding:get`](#aio-runtimenamespacelog-forwardingget) * [`aio runtime:namespace:log-forwarding:set`](#aio-runtimenamespacelog-forwardingset) * [`aio runtime:namespace:log-forwarding:set:adobe-io-runtime`](#aio-runtimenamespacelog-forwardingsetadobe-io-runtime) @@ -103,8 +104,6 @@ $ aio runtime --help ## `aio runtime` -Execute runtime commands - ``` USAGE $ aio runtime @@ -129,8 +128,6 @@ _See code: [src/commands/runtime/index.js](https://github.com/adobe/aio-cli-plug ## `aio runtime:action` -Manage your actions - ``` USAGE $ aio runtime:action @@ -155,8 +152,6 @@ _See code: [src/commands/runtime/action/index.js](https://github.com/adobe/aio-c ## `aio runtime:action:create ACTIONNAME [ACTIONPATH]` -Creates an Action - ``` USAGE $ aio runtime:action:create ACTIONNAME [ACTIONPATH] @@ -219,8 +214,6 @@ _See code: [src/commands/runtime/action/create.js](https://github.com/adobe/aio- ## `aio runtime:action:delete ACTIONNAME` -Deletes an Action - ``` USAGE $ aio runtime:action:delete ACTIONNAME @@ -248,8 +241,6 @@ _See code: [src/commands/runtime/action/delete.js](https://github.com/adobe/aio- ## `aio runtime:action:get ACTIONNAME` -Retrieves an Action - ``` USAGE $ aio runtime:action:get ACTIONNAME @@ -278,8 +269,6 @@ _See code: [src/commands/runtime/action/get.js](https://github.com/adobe/aio-cli ## `aio runtime:action:invoke ACTIONNAME` -Invokes an Action - ``` USAGE $ aio runtime:action:invoke ACTIONNAME @@ -308,8 +297,6 @@ _See code: [src/commands/runtime/action/invoke.js](https://github.com/adobe/aio- ## `aio runtime:action:list [PACKAGENAME]` -Lists all the Actions - ``` USAGE $ aio runtime:action:list [PACKAGENAME] @@ -346,8 +333,6 @@ _See code: [src/commands/runtime/action/list.js](https://github.com/adobe/aio-cl ## `aio runtime:action:update ACTIONNAME [ACTIONPATH]` -Updates an Action - ``` USAGE $ aio runtime:action:update ACTIONNAME [ACTIONPATH] @@ -410,8 +395,6 @@ _See code: [src/commands/runtime/action/update.js](https://github.com/adobe/aio- ## `aio runtime:activation` -Manage your activations - ``` USAGE $ aio runtime:activation @@ -436,8 +419,6 @@ _See code: [src/commands/runtime/activation/index.js](https://github.com/adobe/a ## `aio runtime:activation:get [ACTIVATIONID]` -Retrieves an Activation - ``` USAGE $ aio runtime:activation:get [ACTIVATIONID] @@ -464,8 +445,6 @@ _See code: [src/commands/runtime/activation/get.js](https://github.com/adobe/aio ## `aio runtime:activation:list [ACTIVATION_NAME]` -Lists all the Activations - ``` USAGE $ aio runtime:activation:list [ACTIVATION_NAME] @@ -508,8 +487,6 @@ _See code: [src/commands/runtime/activation/list.js](https://github.com/adobe/ai ## `aio runtime:activation:logs [ACTIVATIONID]` -Retrieves the Logs for an Activation - ``` USAGE $ aio runtime:activation:logs [ACTIVATIONID] @@ -550,8 +527,6 @@ _See code: [src/commands/runtime/activation/logs.js](https://github.com/adobe/ai ## `aio runtime:activation:result [ACTIVATIONID]` -Retrieves the Results for an Activation - ``` USAGE $ aio runtime:activation:result [ACTIVATIONID] @@ -577,8 +552,6 @@ _See code: [src/commands/runtime/activation/result.js](https://github.com/adobe/ ## `aio runtime:deploy` -The Runtime Deployment Tool - ``` USAGE $ aio runtime:deploy @@ -607,8 +580,6 @@ _See code: [src/commands/runtime/deploy/index.js](https://github.com/adobe/aio-c ## `aio runtime:deploy:export` -Exports managed project assets from Runtime to manifest and function files - ``` USAGE $ aio runtime:deploy:export @@ -635,8 +606,6 @@ _See code: [src/commands/runtime/deploy/export.js](https://github.com/adobe/aio- ## `aio runtime:deploy:report` -Provides a summary report of Runtime assets being deployed/undeployed based on manifest/deployment YAML - ``` USAGE $ aio runtime:deploy:report @@ -663,8 +632,6 @@ _See code: [src/commands/runtime/deploy/report.js](https://github.com/adobe/aio- ## `aio runtime:deploy:sync` -A tool to sync deployment and undeployment of Runtime packages using a manifest and optional deployment files using YAML - ``` USAGE $ aio runtime:deploy:sync @@ -691,8 +658,6 @@ _See code: [src/commands/runtime/deploy/sync.js](https://github.com/adobe/aio-cl ## `aio runtime:deploy:undeploy` -Undeploy removes Runtime assets which were deployed from the manifest and deployment YAML - ``` USAGE $ aio runtime:deploy:undeploy @@ -719,8 +684,6 @@ _See code: [src/commands/runtime/deploy/undeploy.js](https://github.com/adobe/ai ## `aio runtime:deploy:version` -Prints the version number of aio runtime deploy - ``` USAGE $ aio runtime:deploy:version @@ -745,8 +708,6 @@ _See code: [src/commands/runtime/deploy/version.js](https://github.com/adobe/aio ## `aio runtime:namespace` -Manage your namespaces - ``` USAGE $ aio runtime:namespace @@ -773,8 +734,6 @@ _See code: [src/commands/runtime/namespace/index.js](https://github.com/adobe/ai ## `aio runtime:namespace:get` -Get triggers, actions, and rules in the registry for namespace - ``` USAGE $ aio runtime:namespace:get @@ -806,8 +765,6 @@ _See code: [src/commands/runtime/namespace/get.js](https://github.com/adobe/aio- ## `aio runtime:namespace:list` -Lists all of your namespaces for Adobe I/O Runtime - ``` USAGE $ aio runtime:namespace:list @@ -839,8 +796,6 @@ _See code: [src/commands/runtime/namespace/list.js](https://github.com/adobe/aio ## `aio runtime:namespace:log-forwarding` -Manage log forwarding settings - ``` USAGE $ aio runtime:namespace:log-forwarding @@ -869,9 +824,39 @@ ALIASES _See code: [src/commands/runtime/namespace/log-forwarding/index.js](https://github.com/adobe/aio-cli-plugin-runtime/blob/5.2.0/src/commands/runtime/namespace/log-forwarding/index.js)_ -## `aio runtime:namespace:log-forwarding:get` +## `aio runtime:namespace:log-forwarding:errors` + +``` +Get log forwarding errors -Get log forwarding destination configuration +USAGE + $ aio runtime:namespace:log-forwarding:errors + +OPTIONS + -i, --insecure bypass certificate check + -u, --auth whisk auth + -v, --verbose Verbose output + --apihost whisk API host + --apiversion whisk API version + --cert client cert + --debug=debug Debug level output + --help Show help + --key client key + --version Show version + +ALIASES + $ aio runtime:ns:log-forwarding:errors + $ aio runtime:ns:lf:errors + $ aio runtime:namespace:lf:errors + $ aio rt:namespace:log-forwarding:errors + $ aio rt:namespace:lf:errors + $ aio rt:ns:log-forwarding:errors + $ aio rt:ns:lf:errors +``` + +_See code: [src/commands/runtime/namespace/log-forwarding/errors.js](https://github.com/adobe/aio-cli-plugin-runtime/blob/5.1.0/src/commands/runtime/namespace/log-forwarding/errors.js)_ + +## `aio runtime:namespace:log-forwarding:get` ``` USAGE @@ -903,8 +888,6 @@ _See code: [src/commands/runtime/namespace/log-forwarding/get.js](https://github ## `aio runtime:namespace:log-forwarding:set` -Configure log forwarding destination (interactive) - ``` USAGE $ aio runtime:namespace:log-forwarding:set @@ -935,8 +918,6 @@ _See code: [src/commands/runtime/namespace/log-forwarding/set.js](https://github ## `aio runtime:namespace:log-forwarding:set:adobe-io-runtime` -Set log forwarding destination to Adobe I/O Runtime (Logs will be accessible via aio CLI) - ``` USAGE $ aio runtime:namespace:log-forwarding:set:adobe-io-runtime @@ -967,8 +948,6 @@ _See code: [src/commands/runtime/namespace/log-forwarding/set/adobe-io-runtime.j ## `aio runtime:namespace:log-forwarding:set:azure-log-analytics` -Set log forwarding destination to Azure Log Analytics - ``` USAGE $ aio runtime:namespace:log-forwarding:set:azure-log-analytics @@ -1002,8 +981,6 @@ _See code: [src/commands/runtime/namespace/log-forwarding/set/azure-log-analytic ## `aio runtime:namespace:log-forwarding:set:splunk-hec` -Set log forwarding destination to Splunk HEC - ``` USAGE $ aio runtime:namespace:log-forwarding:set:splunk-hec @@ -1038,8 +1015,6 @@ _See code: [src/commands/runtime/namespace/log-forwarding/set/splunk-hec.js](htt ## `aio runtime:package` -Manage your packages - ``` USAGE $ aio runtime:package @@ -1066,8 +1041,6 @@ _See code: [src/commands/runtime/package/index.js](https://github.com/adobe/aio- ## `aio runtime:package:bind PACKAGENAME BINDPACKAGENAME` -Bind parameters to a package - ``` USAGE $ aio runtime:package:bind PACKAGENAME BINDPACKAGENAME @@ -1099,8 +1072,6 @@ _See code: [src/commands/runtime/package/bind.js](https://github.com/adobe/aio-c ## `aio runtime:package:create PACKAGENAME` -Creates a Package - ``` USAGE $ aio runtime:package:create PACKAGENAME @@ -1133,8 +1104,6 @@ _See code: [src/commands/runtime/package/create.js](https://github.com/adobe/aio ## `aio runtime:package:delete PACKAGENAME` -Deletes a Package - ``` USAGE $ aio runtime:package:delete PACKAGENAME @@ -1152,8 +1121,6 @@ _See code: [src/commands/runtime/package/delete.js](https://github.com/adobe/aio ## `aio runtime:package:get PACKAGENAME` -Retrieves a Package - ``` USAGE $ aio runtime:package:get PACKAGENAME @@ -1180,8 +1147,6 @@ _See code: [src/commands/runtime/package/get.js](https://github.com/adobe/aio-cl ## `aio runtime:package:list [NAMESPACE]` -Lists all the Packages - ``` USAGE $ aio runtime:package:list [NAMESPACE] @@ -1218,8 +1183,6 @@ _See code: [src/commands/runtime/package/list.js](https://github.com/adobe/aio-c ## `aio runtime:package:update PACKAGENAME` -Updates a Package - ``` USAGE $ aio runtime:package:update PACKAGENAME @@ -1252,8 +1215,6 @@ _See code: [src/commands/runtime/package/update.js](https://github.com/adobe/aio ## `aio runtime:property` -Execute property commands - ``` USAGE $ aio runtime:property @@ -1280,8 +1241,6 @@ _See code: [src/commands/runtime/property/index.js](https://github.com/adobe/aio ## `aio runtime:property:get` -get property - ``` USAGE $ aio runtime:property:get @@ -1313,8 +1272,6 @@ _See code: [src/commands/runtime/property/get.js](https://github.com/adobe/aio-c ## `aio runtime:property:set` -set property - ``` USAGE $ aio runtime:property:set @@ -1342,8 +1299,6 @@ _See code: [src/commands/runtime/property/set.js](https://github.com/adobe/aio-c ## `aio runtime:property:unset` -unset property - ``` USAGE $ aio runtime:property:unset @@ -1371,8 +1326,6 @@ _See code: [src/commands/runtime/property/unset.js](https://github.com/adobe/aio ## `aio runtime:route` -Manage your routes - ``` USAGE $ aio runtime:route @@ -1398,8 +1351,6 @@ _See code: [src/commands/runtime/route/index.js](https://github.com/adobe/aio-cl ## `aio runtime:route:create [BASEPATH] [RELPATH] [APIVERB] [ACTION]` -create a new api route - ``` USAGE $ aio runtime:route:create [BASEPATH] [RELPATH] [APIVERB] [ACTION] @@ -1447,8 +1398,6 @@ _See code: [src/commands/runtime/route/create.js](https://github.com/adobe/aio-c ## `aio runtime:route:delete BASEPATHORAPINAME [RELPATH] [APIVERB]` -delete an API - ``` USAGE $ aio runtime:route:delete BASEPATHORAPINAME [RELPATH] [APIVERB] @@ -1480,8 +1429,6 @@ _See code: [src/commands/runtime/route/delete.js](https://github.com/adobe/aio-c ## `aio runtime:route:get BASEPATHORAPINAME` -get API details - ``` USAGE $ aio runtime:route:get BASEPATHORAPINAME @@ -1511,8 +1458,6 @@ _See code: [src/commands/runtime/route/get.js](https://github.com/adobe/aio-cli- ## `aio runtime:route:list [BASEPATH] [RELPATH] [APIVERB]` -list route/apis for Adobe I/O Runtime - ``` USAGE $ aio runtime:route:list [BASEPATH] [RELPATH] [APIVERB] @@ -1551,8 +1496,6 @@ _See code: [src/commands/runtime/route/list.js](https://github.com/adobe/aio-cli ## `aio runtime:rule` -Manage your rules - ``` USAGE $ aio runtime:rule @@ -1577,8 +1520,6 @@ _See code: [src/commands/runtime/rule/index.js](https://github.com/adobe/aio-cli ## `aio runtime:rule:create NAME TRIGGER ACTION` -Create a Rule - ``` USAGE $ aio runtime:rule:create NAME TRIGGER ACTION @@ -1609,8 +1550,6 @@ _See code: [src/commands/runtime/rule/create.js](https://github.com/adobe/aio-cl ## `aio runtime:rule:delete NAME` -Delete a Rule - ``` USAGE $ aio runtime:rule:delete NAME @@ -1639,8 +1578,6 @@ _See code: [src/commands/runtime/rule/delete.js](https://github.com/adobe/aio-cl ## `aio runtime:rule:disable NAME` -Disable a Rule - ``` USAGE $ aio runtime:rule:disable NAME @@ -1668,8 +1605,6 @@ _See code: [src/commands/runtime/rule/disable.js](https://github.com/adobe/aio-c ## `aio runtime:rule:enable NAME` -Enable a Rule - ``` USAGE $ aio runtime:rule:enable NAME @@ -1697,8 +1632,6 @@ _See code: [src/commands/runtime/rule/enable.js](https://github.com/adobe/aio-cl ## `aio runtime:rule:get NAME` -Retrieves a Rule - ``` USAGE $ aio runtime:rule:get NAME @@ -1726,8 +1659,6 @@ _See code: [src/commands/runtime/rule/get.js](https://github.com/adobe/aio-cli-p ## `aio runtime:rule:list` -Retrieves a list of Rules - ``` USAGE $ aio runtime:rule:list @@ -1760,8 +1691,6 @@ _See code: [src/commands/runtime/rule/list.js](https://github.com/adobe/aio-cli- ## `aio runtime:rule:status NAME` -Gets the status of a rule - ``` USAGE $ aio runtime:rule:status NAME @@ -1789,8 +1718,6 @@ _See code: [src/commands/runtime/rule/status.js](https://github.com/adobe/aio-cl ## `aio runtime:rule:update NAME TRIGGER ACTION` -Update a Rule - ``` USAGE $ aio runtime:rule:update NAME TRIGGER ACTION @@ -1821,8 +1748,6 @@ _See code: [src/commands/runtime/rule/update.js](https://github.com/adobe/aio-cl ## `aio runtime:trigger` -Manage your triggers - ``` USAGE $ aio runtime:trigger @@ -1847,8 +1772,6 @@ _See code: [src/commands/runtime/trigger/index.js](https://github.com/adobe/aio- ## `aio runtime:trigger:create TRIGGERNAME` -Create a trigger for Adobe I/O Runtime - ``` USAGE $ aio runtime:trigger:create TRIGGERNAME @@ -1881,8 +1804,6 @@ _See code: [src/commands/runtime/trigger/create.js](https://github.com/adobe/aio ## `aio runtime:trigger:delete TRIGGERPATH` -Delete a trigger for Adobe I/O Runtime - ``` USAGE $ aio runtime:trigger:delete TRIGGERPATH @@ -1910,8 +1831,6 @@ _See code: [src/commands/runtime/trigger/delete.js](https://github.com/adobe/aio ## `aio runtime:trigger:fire TRIGGERNAME` -Fire a trigger for Adobe I/O Runtime - ``` USAGE $ aio runtime:trigger:fire TRIGGERNAME @@ -1941,8 +1860,6 @@ _See code: [src/commands/runtime/trigger/fire.js](https://github.com/adobe/aio-c ## `aio runtime:trigger:get TRIGGERPATH` -Get a trigger for Adobe I/O Runtime - ``` USAGE $ aio runtime:trigger:get TRIGGERPATH @@ -1970,8 +1887,6 @@ _See code: [src/commands/runtime/trigger/get.js](https://github.com/adobe/aio-cl ## `aio runtime:trigger:list` -Lists all of your triggers for Adobe I/O Runtime - ``` USAGE $ aio runtime:trigger:list @@ -2004,8 +1919,6 @@ _See code: [src/commands/runtime/trigger/list.js](https://github.com/adobe/aio-c ## `aio runtime:trigger:update TRIGGERNAME` -Update or create a trigger for Adobe I/O Runtime - ``` USAGE $ aio runtime:trigger:update TRIGGERNAME diff --git a/src/commands/runtime/namespace/log-forwarding/errors.js b/src/commands/runtime/namespace/log-forwarding/errors.js new file mode 100644 index 00000000..5ae68075 --- /dev/null +++ b/src/commands/runtime/namespace/log-forwarding/errors.js @@ -0,0 +1,48 @@ +/* +Copyright 2019 Adobe Inc. All rights reserved. +This file is licensed 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +const RuntimeBaseCommand = require('../../../../RuntimeBaseCommand') + +class ErrorsCommand extends RuntimeBaseCommand { + async run () { + const ow = await this.wsk() + try { + const res = await ow.logForwarding.getErrors() + const destinationMessage = res.configured_forwarder !== undefined ? ` for the last configured destination '${res.configured_forwarder}'` : '' + if (res.errors && res.errors.length > 0) { + this.logJSON(`Log forwarding errors${destinationMessage}:\n`, res.errors) + } else { + this.log(`No log forwarding errors${destinationMessage}`) + } + } catch (e) { + this.handleError('Failed to get log forwarding errors', e) + } + } +} + +ErrorsCommand.description = `Get log forwarding errors` + +ErrorsCommand.flags = { + ...RuntimeBaseCommand.flags +} + +ErrorsCommand.aliases = [ + 'runtime:ns:log-forwarding:errors', + 'runtime:ns:lf:errors', + 'runtime:namespace:lf:errors', + 'rt:namespace:log-forwarding:errors', + 'rt:namespace:lf:errors', + 'rt:ns:log-forwarding:errors', + 'rt:ns:lf:errors' +] + +module.exports = ErrorsCommand diff --git a/test/__fixtures__/namespace/log-forwarding/errors-remote.json b/test/__fixtures__/namespace/log-forwarding/errors-remote.json new file mode 100644 index 00000000..d553223a --- /dev/null +++ b/test/__fixtures__/namespace/log-forwarding/errors-remote.json @@ -0,0 +1,7 @@ +{ + "configured_forwarder": "destination", + "errors": [ + "error1", + "error2" + ] +} diff --git a/test/__fixtures__/namespace/log-forwarding/errors-result.txt b/test/__fixtures__/namespace/log-forwarding/errors-result.txt new file mode 100644 index 00000000..572815d6 --- /dev/null +++ b/test/__fixtures__/namespace/log-forwarding/errors-result.txt @@ -0,0 +1,5 @@ +Log forwarding errors for the last configured destination 'destination': +[ +"error1", +"error2" +] diff --git a/test/commands/runtime/namespace/log-forwarding/errors.test.js b/test/commands/runtime/namespace/log-forwarding/errors.test.js new file mode 100644 index 00000000..50a524c5 --- /dev/null +++ b/test/commands/runtime/namespace/log-forwarding/errors.test.js @@ -0,0 +1,59 @@ +/* +Copyright 2019 Adobe Inc. All rights reserved. +This file is licensed 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +const RuntimeLib = require('@adobe/aio-lib-runtime') +const TheCommand = require('../../../../../src/commands/runtime/namespace/log-forwarding/errors') +const { stdout } = require('stdout-stderr') + +let command, rtLib +beforeEach(async () => { + command = new TheCommand([]) + rtLib = await RuntimeLib.init({ apihost: 'fakehost', api_key: 'fakekey' }) +}) + +test('get log forwarding errors', () => { + return new Promise(resolve => { + rtLib.logForwarding.getErrors = jest.fn().mockReturnValue(fixtureJson('namespace/log-forwarding/errors-remote.json')) + return command.run() + .then(() => { + expect(stdout.output).toMatchFixtureIgnoreWhite('namespace/log-forwarding/errors-result.txt') + resolve() + }) + }) +}) + +test.each([ + [ + 'no errors', + { configured_forwarder: 'destination', errors: [] }, + "No log forwarding errors for the last configured destination 'destination'\n" + ], + [ + 'empty response', + { }, + 'No log forwarding errors\n' + ] +])('get log forwarding errors (%s)', (test, libResponse, expected) => { + return new Promise(resolve => { + rtLib.logForwarding.getErrors = jest.fn().mockResolvedValue(libResponse) + return command.run() + .then(() => { + expect(stdout.output).toBe(expected) + resolve() + }) + }) +}) + +test('failed to get log forwarding errors', async () => { + rtLib.logForwarding.getErrors = jest.fn().mockRejectedValue(new Error('mocked error')) + await expect(command.run()).rejects.toThrow('Failed to get log forwarding errors: mocked error') +}) diff --git a/test/commands/runtime/namespace/log-forwarding/set.test.js b/test/commands/runtime/namespace/log-forwarding/set.test.js index 62dbca38..da12a0ee 100644 --- a/test/commands/runtime/namespace/log-forwarding/set.test.js +++ b/test/commands/runtime/namespace/log-forwarding/set.test.js @@ -32,11 +32,10 @@ const dataFixtures = [ }] ] -let command, setCall, prompt, rtLib +let command, prompt, rtLib beforeEach(async () => { command = new TheCommand([]) - setCall = jest.fn() prompt = jest.fn() inquirer.prompt = prompt rtLib = await RuntimeLib.init({ apihost: 'fakehost', api_key: 'fakekey' }) @@ -62,6 +61,7 @@ test('choices contain all supported log destinations', () => { test.each(dataFixtures)('set log forwarding settings to %s (interactive)', async (destination, input) => { return new Promise(resolve => { + const setCall = jest.fn() mockSelectedDestination(destination, setCall) if (input !== undefined) { mockDestinationConfig(input)