userver: userver/storages/postgres/dsn.hpp Source File
Loading...
Searching...
No Matches
dsn.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/dsn.hpp
4/// @brief DSN manipulation helpers
5
6#include <string>
7#include <vector>
8
9#include <userver/clients/dns/resolver_fwd.hpp>
10#include <userver/engine/deadline.hpp>
11#include <userver/utils/strong_typedef.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace storages::postgres {
16
17using Dsn = USERVER_NAMESPACE::utils::NonLoggable<class DsnTag, std::string>;
18using DsnList = std::vector<Dsn>;
19
20DsnList SplitByHost(const Dsn& dsn);
21
22/// Create a string `<user>@<host>:<port>/<dbname>` of a single-host DSN
23/// or escape all the punctuation with _ for test
24std::string MakeDsnNick(const Dsn& dsn, bool escape);
25
26struct DsnOptions {
27 std::string host;
28 std::string port;
29 std::string dbname;
30};
31
32/// Read options from a DSN
33/// First unique option is used if found, otherwise default is taken
34DsnOptions OptionsFromDsn(const Dsn& dsn);
35
36/// Return `<host>[:<port>]` string for a single-host DSN
37std::string GetHostPort(const Dsn& dsn);
38
39/// Return DSN string without 'password' field
40std::string DsnCutPassword(const Dsn& dsn);
41/// Return DSN string with password contents masked
42std::string DsnMaskPassword(const Dsn& dsn);
43
44std::string EscapeHostName(const std::string& hostname, char escape_char = '_');
45
46/// Return DSN string with hosts resolved as hostaddr values
47/// If given DSN has no host or already contains hostaddr, does nothing
50
51} // namespace storages::postgres
52
53USERVER_NAMESPACE_END