forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseConnectionString.cpp
28 lines (25 loc) · 1.17 KB
/
DatabaseConnectionString.cpp
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
26
27
28
// Copyright 2017 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "DatabaseConnectionString.h"
#include <regex>
namespace stellar
{
std::string
removePasswordFromConnectionString(std::string connectionString)
{
std::string escapedSingleQuotePat("\\\\'");
std::string nonSingleQuotePat("[^']");
std::string singleQuotedStringPat("'(?:" + nonSingleQuotePat + "|" +
escapedSingleQuotePat + ")*'");
std::string bareWordPat("\\w+");
std::string paramValPat("(?:" + bareWordPat + "|" + singleQuotedStringPat +
")");
std::string paramPat("(?:" + bareWordPat + " *= *" + paramValPat + " *)");
std::string passwordParamPat("password( *= *)" + paramValPat);
std::string connPat("^(" + bareWordPat + ":// *)(" + paramPat + "*)" +
passwordParamPat + "( *)(" + paramPat + "*)$");
return std::regex_replace(connectionString, std::regex(connPat),
"$1$2password$3********$4$5");
}
}