blob: 2974f99c8058977916337e810de89f88a49fbcc7 (
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include "url_preprocessing.h"
#include <yql/essentials/providers/common/proto/gateways_config.pb.h>
#include <yql/essentials/utils/log/log.h>
#include <util/generic/yexception.h>
namespace NYql {
void TUrlPreprocessing::Configure(bool restrictedUser, const TGatewaysConfig& cfg) {
RestrictedUser_ = restrictedUser;
try {
if (cfg.HasFs()) {
const auto fsCfg = cfg.GetFs();
for (auto& s: fsCfg.GetCustomSchemes()) {
Mapper_.AddMapping(s.GetPattern(), s.GetTargetUrl());
}
if (restrictedUser) {
for (auto& a: fsCfg.GetExternalAllowedUrls()) {
AllowedUrls_.Add(a.GetPattern(), a.GetAlias());
}
} else {
for (auto& a: fsCfg.GetAllowedUrls()) {
AllowedUrls_.Add(a.GetPattern(), a.GetAlias());
}
}
}
} catch (const yexception& e) {
ythrow yexception() << "UrlPreprocessing: " << e.what();
}
}
std::pair<TString, TString> TUrlPreprocessing::Preprocess(const TString& url) {
TString convertedUrl;
if (!Mapper_.MapUrl(url, convertedUrl)) {
convertedUrl = url;
} else {
YQL_LOG(INFO) << "Remap url from " << url << " to " << convertedUrl;
}
TString alias;
if (RestrictedUser_ || !AllowedUrls_.IsEmpty()) {
if (auto a = AllowedUrls_.Match(convertedUrl)) {
alias = *a;
} else {
YQL_LOG(WARN) << "Url " << convertedUrl << " is not in allowed list, reject accessing";
ythrow yexception() << "It is not allowed to access url " << url;
}
}
YQL_LOG(INFO) << "UrlPreprocessing: " << convertedUrl << ", alias=" << alias;
return {convertedUrl, alias};
}
} // NYql
|