diff --git a/README.md b/README.md index d966c572..2575d952 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ $ aio runtime --help * [`aio runtime namespace log-forwarding set adobe-io-runtime`](#aio-runtime-namespace-log-forwarding-set-adobe-io-runtime) * [`aio runtime namespace log-forwarding set azure-log-analytics`](#aio-runtime-namespace-log-forwarding-set-azure-log-analytics) * [`aio runtime namespace log-forwarding set splunk-hec`](#aio-runtime-namespace-log-forwarding-set-splunk-hec) +* [`aio runtime namespace log-forwarding set new-relic`](#aio-runtime-namespace-log-forwarding-set-new-relic) * [`aio runtime package`](#aio-runtime-package) * [`aio runtime package bind PACKAGENAME BINDPACKAGENAME`](#aio-runtime-package-bind-packagename-bindpackagename) * [`aio runtime package create PACKAGENAME`](#aio-runtime-package-create-packagename) @@ -1282,6 +1283,42 @@ ALIASES $ aio rt ns lf set splunk-hec ``` +## `aio runtime namespace log-forwarding set new-relic` + +Set log forwarding destination to New Relic + +``` +USAGE + $ aio runtime namespace log-forwarding set new-relic --base-uri --license-key [--cert] [--key] + [--apiversion] [--apihost] [-u] [-i] [--debug ] [-v] [--version] [--help] + +FLAGS + -i, --insecure bypass certificate check + -u, --auth whisk auth + -v, --verbose Verbose output + --apihost whisk API host + --apiversion whisk API version + --base-uri= (optional) Base URI + --cert client cert + --debug= Debug level output + --help Show help + --key client key + --license-key= (required) License key + --version Show version + +DESCRIPTION + Set log forwarding destination to New Relic + +ALIASES + $ aio runtime ns log-forwarding set new-relic + $ aio runtime ns lf set new-relic + $ aio runtime namespace lf set new-relic + $ aio rt namespace log-forwarding set new-relic + $ aio rt namespace lf set new-relic + $ aio rt ns log-forwarding set new-relic + $ aio rt ns lf set new-relic +``` + ## `aio runtime package` Manage your packages diff --git a/src/commands/runtime/namespace/log-forwarding/set/new-relic.js b/src/commands/runtime/namespace/log-forwarding/set/new-relic.js new file mode 100644 index 00000000..13f22c5a --- /dev/null +++ b/src/commands/runtime/namespace/log-forwarding/set/new-relic.js @@ -0,0 +1,56 @@ +/* +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 { Flags } = require('@oclif/core') +const RuntimeBaseCommand = require('../../../../../RuntimeBaseCommand') + +class NewRelicCommand extends RuntimeBaseCommand { + async run () { + const { flags } = await this.parse(NewRelicCommand) + const ow = await this.wsk() + try { + await ow.logForwarding.setDestination('new_relic', { + base_uri: flags['base-uri'], + license_key: flags['license-key'] + }) + this.log('Log forwarding was set to new_relic for this namespace') + } catch (e) { + await this.handleError('failed to update log forwarding configuration', e) + } + } +} + +NewRelicCommand.description = 'Set log forwarding destination to New Relic' + +NewRelicCommand.flags = { + ...RuntimeBaseCommand.flags, + 'base-uri': Flags.string({ + description: 'Base URI', + required: true + }), + 'license-key': Flags.string({ + description: 'License Key', + required: true + }) +} + +NewRelicCommand.aliases = [ + 'runtime:ns:log-forwarding:set:new-relic', + 'runtime:ns:lf:set:new-relic', + 'runtime:namespace:lf:set:new-relic', + 'rt:namespace:log-forwarding:set:new-relic', + 'rt:namespace:lf:set:new-relic', + 'rt:ns:log-forwarding:set:new-relic', + 'rt:ns:lf:set:new-relic' +] + +module.exports = NewRelicCommand diff --git a/test/commands/runtime/namespace/log-forwarding/set.test.js b/test/commands/runtime/namespace/log-forwarding/set.test.js index 89033271..878ae109 100644 --- a/test/commands/runtime/namespace/log-forwarding/set.test.js +++ b/test/commands/runtime/namespace/log-forwarding/set.test.js @@ -29,6 +29,10 @@ const dataFixtures = [ port: 'port1', index: 'index1', hec_token: 'token1' + }], + ['new_relic', { + base_uri: 'uri1', + license_key: 'key1' }] ] diff --git a/test/commands/runtime/namespace/log-forwarding/set/new-relic-runtime.test.js b/test/commands/runtime/namespace/log-forwarding/set/new-relic-runtime.test.js new file mode 100644 index 00000000..0b3b4119 --- /dev/null +++ b/test/commands/runtime/namespace/log-forwarding/set/new-relic-runtime.test.js @@ -0,0 +1,42 @@ +/* +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/set/new-relic') +const { stdout } = require('stdout-stderr') + +let command, rtLib +beforeEach(async () => { + command = new TheCommand([]) + rtLib = await RuntimeLib.init({ apihost: 'fakehost', api_key: 'fakekey' }) +}) + +test('set log forwarding settings to new_relic', () => { + return new Promise(resolve => { + const setCall = jest.fn() + rtLib.logForwarding.setDestination = setCall + command.argv = ['--base-uri', 'uri1', '--license-key', 'key1'] + return command.run() + .then(() => { + expect(stdout.output).toMatch(/Log forwarding was set to new_relic for this namespace/) + expect(setCall).toBeCalledTimes(1) + expect(setCall).toHaveBeenCalledWith('new_relic', { base_uri: 'uri1', license_key: 'key1' }) + resolve() + }) + }) +}) + +test('failed to set log forwarding settings to new_relic', async () => { + rtLib.logForwarding.setDestination = jest.fn().mockRejectedValue(new Error('mocked error')) + command.argv = ['--base-uri', 'uri1', '--license-key', 'key1'] + await expect(command.run()).rejects.toThrow('failed to update log forwarding configuration: mocked error') +})