Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli) created pg setting for log min error statements #2992

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Args} from '@oclif/core'
import heredoc from 'tsheredoc'
import {PGSettingsCommand} from '../../../lib/pg/setter'
import type {Setting, SettingKey} from '../../../lib/pg/types'

export default class LogMinErrorStatement extends PGSettingsCommand {
static description = heredoc(`
log-min-error-statement controls the logging of SQL statements that cause an error at a specified severity level.
This setting is useful to prevent logging SQL queries that might contain sensitive information.
Use this setting to prevent logging SQL queries that contain sensitive information. Default is "error".
`)

static args = {
database: Args.string(),
value: Args.string({options: ['error', 'log', 'fatal', 'panic']}),
}

protected settingKey: SettingKey = 'log_min_error_statement'

protected convertValue(val: string): string {
return val
}

protected explain(setting: Setting<string>) {
return setting.values[setting.value]
}
}
1 change: 1 addition & 0 deletions packages/cli/src/lib/pg/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export type SettingKey =
'log_lock_waits'
| 'log_connections'
| 'log_min_duration_statement'
| 'log_min_error_statement'
| 'log_statement'
| 'track_functions'
| 'pgbouncer_max_client_conn'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {expect} from '@oclif/test'
import * as nock from 'nock'
import {stdout} from 'stdout-stderr'
import heredoc from 'tsheredoc'
import runCommand from '../../../../helpers/runCommand'
import Cmd from '../../../../../src/commands/pg/settings/log-min-error-statement'
import * as fixtures from '../../../../fixtures/addons/fixtures'

describe('pg:settings:log-min-error-statement', function () {
const addon = fixtures.addons['dwh-db']

beforeEach(function () {
nock('https://api.heroku.com')
.post('/actions/addons/resolve', {
app: 'myapp',
addon: 'test-database',
}).reply(200, [addon])
})

afterEach(function () {
nock.cleanAll()
})

it('shows settings for log_min_error_statement', async function () {
nock('https://api.data.heroku.com')
.get(`/postgres/v0/databases/${addon.id}/config`)
.reply(200, {
log_min_error_statement: {
value: 'error',
desc: 'Specify the minimum severity level of SQL errors to be logged.',
default: 'error',
values: {
error: 'Logs all ERROR, LOG, FATAL, and PANIC level messages. (Default)',
log: 'Logs all LOG, FATAL, and PANIC level messages.',
fatal: 'Logs all FATAL and PANIC level messages.',
panic: 'Logs only PANIC level messages.',
},
},
})

await runCommand(Cmd, ['--app', 'myapp', 'test-database'])
expect(stdout.output).to.equal(heredoc(`
log-min-error-statement is set to error for ${addon.name}.
Logs all ERROR, LOG, FATAL, and PANIC level messages. (Default)
`))
})
})
Loading