diff options
author | vvvv <vvvv@yandex-team.com> | 2024-11-07 12:29:36 +0300 |
---|---|---|
committer | vvvv <vvvv@yandex-team.com> | 2024-11-07 13:49:47 +0300 |
commit | d4c258e9431675bab6745c8638df6e3dfd4dca6b (patch) | |
tree | b5efcfa11351152a4c872fccaea35749141c0b11 /yql/essentials/core/url_preprocessing/url_preprocessing.cpp | |
parent | 13a4f274caef5cfdaf0263b24e4d6bdd5521472b (diff) | |
download | ydb-d4c258e9431675bab6745c8638df6e3dfd4dca6b.tar.gz |
Moved other yql/essentials libs YQL-19206
init
commit_hash:7d4c435602078407bbf20dd3c32f9c90d2bbcbc0
Diffstat (limited to 'yql/essentials/core/url_preprocessing/url_preprocessing.cpp')
-rw-r--r-- | yql/essentials/core/url_preprocessing/url_preprocessing.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/yql/essentials/core/url_preprocessing/url_preprocessing.cpp b/yql/essentials/core/url_preprocessing/url_preprocessing.cpp new file mode 100644 index 0000000000..2974f99c80 --- /dev/null +++ b/yql/essentials/core/url_preprocessing/url_preprocessing.cpp @@ -0,0 +1,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 |