Skip to content

Commit

Permalink
created pg setting for log min error statements
Browse files Browse the repository at this point in the history
  • Loading branch information
brahyt-sf committed Sep 12, 2024
1 parent 2aa043a commit f7e5928
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/cli/src/commands/pg/settings/log-min-error-statement.ts
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)
`))
})
})

0 comments on commit f7e5928

Please sign in to comment.