Skip to content

Commit

Permalink
Fixed: log-forwarding secret settings are not saved (#508)
Browse files Browse the repository at this point in the history
* Fixed: log-forwarding secret settings are not saved

* Improved log forwarding message in case local config is absent
  • Loading branch information
buskamuza authored Jan 26, 2022
1 parent 0d8d4ab commit 311844c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/commands/app/config/get/log-forwarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class LogForwardingCommand extends BaseCommand {

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")
let message = 'Run'
if (localConfig.isDefined()) {
message += " either 'aio app:deploy' to update the server, or"
}
message += " 'aio app:config:set:log-forwarding' to set new local and server configuration"
this.log(message)
this.log('Local configuration:')
this.printConfig(localConfig)
this.log('\nServer configuration:')
Expand Down
3 changes: 2 additions & 1 deletion src/commands/app/config/set/log-forwarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class LogForwardingCommand extends BaseCommand {
const res = await lf.updateServerConfig(lfConfig)
this.log(`Log forwarding is set to '${destination}'`)

await lf.updateLocalConfig(lf.getConfigFromJson(res))
const fullSanitizedConfig = lfConfig.getMergedConfig(lf.getConfigFromJson(res))
await lf.updateLocalConfig(fullSanitizedConfig)
this.log('Log forwarding settings are saved to the local configuration')
}

Expand Down
8 changes: 8 additions & 0 deletions src/lib/log-forwarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ class LogForwardingConfig {
return this.settings
}

getMergedConfig (config) {
const newSettings = {}
Object.keys(this.settings).forEach(k => {
newSettings[k] = config.settings[k] !== undefined ? config.settings[k] : this.settings[k]
})
return new LogForwardingConfig(this.destination, newSettings)
}

isDefined () {
return this.destination !== undefined
}
Expand Down
2 changes: 1 addition & 1 deletion test/commands/app/config/get/log-forwarding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ test('get log forwarding settings (no local config)', async () => {
return command.run()
.then(() => {
expect(stdout.output).toEqual('Local and server log forwarding configuration is different\n' +
"Run either 'aio app:deploy' to update the server, or 'aio app:config:set:log-forwarding' to set new local and server configuration\n" +
"Run 'aio app:config:set:log-forwarding' to set new local and server configuration\n" +
'Local configuration:\n' +
'Not defined\n\n' +
'Server configuration:\n' +
Expand Down
10 changes: 8 additions & 2 deletions test/commands/app/config/set/log-forwarding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ test('set log forwarding destination', async () => {
const destination = 'destination'
const input = {
field_one: 'val_one',
field_two: 'val_two'
field_two: 'val_two',
secret: 'val_secret'
}
command.prompt.mockResolvedValueOnce({ type: destination })
command.prompt.mockResolvedValueOnce(input)
const serverSanitizedSettings = {
field_one: 'val_one',
field_two: 'val_two sanitized'
}
const fullSanitizedSettings = {
field_one: 'val_one',
field_two: 'val_two sanitized',
secret: 'val_secret'
}
const setCall = jest.fn().mockResolvedValue({
destination: serverSanitizedSettings
})
Expand All @@ -80,7 +86,7 @@ test('set log forwarding destination', async () => {
expect(setCall).toBeCalledTimes(1)
expect(setCall).toHaveBeenCalledWith(new LogForwarding.LogForwardingConfig(destination, input))
expect(localSetCall).toBeCalledTimes(1)
expect(localSetCall).toHaveBeenCalledWith(new LogForwarding.LogForwardingConfig(destination, serverSanitizedSettings))
expect(localSetCall).toHaveBeenCalledWith(new LogForwarding.LogForwardingConfig(destination, fullSanitizedSettings))
resolve()
})
})
Expand Down

0 comments on commit 311844c

Please sign in to comment.