-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App Builder experience for Configurable Logging (#502)
* DEVX-1244: App Builder experience for Configurable Logging - added app:config:get:log-forwarding command - added app:config:set:log-forwarding command - update log forwarding config on server during app:deploy command - save log forwarding settings to project config - added log-forwarding lib - update log forwarding only if actions are deployed - save log forwarding settings returned by the Runtime `PUT` API to take into account any sanitization - added app:config:get:log-forwarding:errors command - `aio app logs` display info message in case custom log forwarding is configured
- Loading branch information
Showing
20 changed files
with
1,617 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright 2019 Adobe. 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 HHelp = require('@oclif/plugin-help').default | ||
const BaseCommand = require('../../../../BaseCommand') | ||
|
||
class IndexCommand extends BaseCommand { | ||
async run () { | ||
const help = new HHelp(this.config) | ||
help.showHelp(['app:config:get', '--help']) | ||
} | ||
} | ||
|
||
IndexCommand.description = 'Get app config' | ||
IndexCommand.aliases = ['app:config:get'] | ||
|
||
module.exports = IndexCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2019 Adobe. 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 BaseCommand = require('../../../../BaseCommand') | ||
const LogForwarding = require('../../../../lib/log-forwarding') | ||
|
||
class LogForwardingCommand extends BaseCommand { | ||
async run () { | ||
const lf = await LogForwarding.init(this.getFullConfig().aio) | ||
|
||
const localConfig = lf.getLocalConfig() | ||
const serverConfig = await lf.getServerConfig() | ||
|
||
if (!localConfig.isEqual(serverConfig)) { | ||
this.log('Local and server log forwarding configuration is different') | ||
this.log("Run either 'aio app:deploy' to update the server, " + | ||
"or 'aio app:config:set:log-forwarding' to set new local and server configuration") | ||
this.log('Local configuration:') | ||
this.printConfig(localConfig) | ||
this.log('\nServer configuration:') | ||
} | ||
this.printConfig(serverConfig) | ||
} | ||
|
||
printConfig (config) { | ||
if (config.isDefined()) { | ||
this.log(`destination: ${config.getDestination()}`) | ||
this.log('settings:', config.getSettings()) | ||
} else { | ||
this.log('Not defined') | ||
} | ||
} | ||
} | ||
|
||
LogForwardingCommand.description = 'Get log forwarding destination configuration' | ||
LogForwardingCommand.aliases = ['app:config:get:log-forwarding', 'app:config:get:lf'] | ||
|
||
module.exports = LogForwardingCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2019 Adobe. 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 BaseCommand = require('../../../../../BaseCommand') | ||
const rtLib = require('@adobe/aio-lib-runtime') | ||
const ora = require('ora') | ||
|
||
class ErrorsCommand extends BaseCommand { | ||
async run () { | ||
const spinner = ora() | ||
const lf = await this.getLogForwarding() | ||
spinner.start('Checking for errors...') | ||
const res = await lf.getErrors() | ||
const destinationMessage = res.configured_forwarder !== undefined | ||
? ` for the last configured destination '${res.configured_forwarder}'` | ||
: '' | ||
if (res.errors && res.errors.length > 0) { | ||
spinner.succeed(`Log forwarding errors${destinationMessage}:\n` + res.errors.join('\n')) | ||
} else { | ||
spinner.succeed(`No log forwarding errors${destinationMessage}`) | ||
} | ||
} | ||
|
||
async getLogForwarding () { | ||
const runtimeConfig = this.getFullConfig().aio.runtime | ||
rtLib.utils.checkOpenWhiskCredentials({ ow: runtimeConfig }) | ||
const rt = await rtLib.init({ | ||
...runtimeConfig, | ||
api_key: runtimeConfig.auth | ||
}) | ||
return rt.logForwarding | ||
} | ||
} | ||
|
||
ErrorsCommand.description = 'Get log forwarding errors' | ||
ErrorsCommand.aliases = ['app:config:get:log-forwarding:errors', 'app:config:get:lf:errors'] | ||
|
||
module.exports = ErrorsCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright 2019 Adobe. 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 HHelp = require('@oclif/plugin-help').default | ||
const BaseCommand = require('../../../BaseCommand') | ||
|
||
class IndexCommand extends BaseCommand { | ||
async run () { | ||
const help = new HHelp(this.config) | ||
help.showHelp(['app:config', '--help']) | ||
} | ||
} | ||
|
||
IndexCommand.description = 'Manage app config' | ||
IndexCommand.aliases = ['app:config', 'app:config'] | ||
|
||
module.exports = IndexCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright 2019 Adobe. 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 HHelp = require('@oclif/plugin-help').default | ||
const BaseCommand = require('../../../../BaseCommand') | ||
|
||
class IndexCommand extends BaseCommand { | ||
async run () { | ||
const help = new HHelp(this.config) | ||
help.showHelp(['app:config:set', '--help']) | ||
} | ||
} | ||
|
||
IndexCommand.description = 'Set app config' | ||
IndexCommand.aliases = ['app:config:set'] | ||
|
||
module.exports = IndexCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2019 Adobe. 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 BaseCommand = require('../../../../BaseCommand') | ||
const LogForwarding = require('../../../../lib/log-forwarding') | ||
|
||
class LogForwardingCommand extends BaseCommand { | ||
async run () { | ||
const lf = await LogForwarding.init(this.getFullConfig().aio) | ||
|
||
const destination = await this.promptDestination(lf.getSupportedDestinations()) | ||
const destinationSettingsConfig = lf.getSettingsConfig(destination) | ||
const settings = await this.prompt(destinationSettingsConfig) | ||
const lfConfig = new LogForwarding.LogForwardingConfig(destination, settings) | ||
|
||
const res = await lf.updateServerConfig(lfConfig) | ||
this.log(`Log forwarding is set to '${destination}'`) | ||
|
||
await lf.updateLocalConfig(lf.getConfigFromJson(res)) | ||
this.log('Log forwarding settings are saved to the local configuration') | ||
} | ||
|
||
async promptDestination (supportedDestinations) { | ||
const responses = await this.prompt([{ | ||
name: 'type', | ||
message: 'select log forwarding destination', | ||
type: 'list', | ||
choices: supportedDestinations | ||
}]) | ||
return responses.type | ||
} | ||
} | ||
|
||
LogForwardingCommand.description = 'Set log forwarding destination configuration' | ||
LogForwardingCommand.aliases = ['app:config:set:log-forwarding', 'app:config:set:lf'] | ||
|
||
module.exports = LogForwardingCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.