aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Interpreters/formatWithPossiblyHidingSecrets.h
blob: 25e1e7a561676538aeebab7276639294ad0b5282 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once
#include "Access/ContextAccess.h"
#include "Interpreters/Context.h"

namespace DB
{
struct SecretHidingFormatSettings
{
    // We can't store const Context& as there's a dangerous usage {.ctx = *getContext()}
    // which is UB in case getContext()'s return ptr is the only one holding the object
    const ContextPtr & ctx;
    const IAST & query;
    size_t max_length = 0;
    bool one_line = true;
};

inline String format(const SecretHidingFormatSettings & settings)
{
    const bool show_secrets = settings.ctx->displaySecretsInShowAndSelect()
        && settings.ctx->getSettingsRef().format_display_secrets_in_show_and_select
        && settings.ctx->getAccess()->isGranted(AccessType::displaySecretsInShowAndSelect);

    return settings.query.formatWithPossiblyHidingSensitiveData(settings.max_length, settings.one_line, show_secrets);
}
}