-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created pg setting for log min error statements
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/cli/src/commands/pg/settings/log-min-error-statement.ts
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,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] | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
packages/cli/test/unit/commands/pg/settings/log-min-error-statement.test.ts
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,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) | ||
`)) | ||
}) | ||
}) |