diff options
author | feldsherov <feldsherov@yandex-team.ru> | 2022-02-10 16:49:29 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:29 +0300 |
commit | e73723ec73b27276cd45b9b46b752138a51d669c (patch) | |
tree | 055f8efa1a290665c7be6bb571131e050cd9517a /library/cpp/tvmauth | |
parent | 4d75b7f76712a8150bd526a7ef43d279d9892eb7 (diff) | |
download | ydb-e73723ec73b27276cd45b9b46b752138a51d669c.tar.gz |
Restoring authorship annotation for <feldsherov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/tvmauth')
10 files changed, 128 insertions, 128 deletions
diff --git a/library/cpp/tvmauth/client/client_status.h b/library/cpp/tvmauth/client/client_status.h index bbaf29d289..8805d471c8 100644 --- a/library/cpp/tvmauth/client/client_status.h +++ b/library/cpp/tvmauth/client/client_status.h @@ -10,7 +10,7 @@ namespace NTvmAuth { Ok, Warning, Error, - IncompleteTicketsSet, + IncompleteTicketsSet, }; TClientStatus(ECode state, TString&& lastError) @@ -35,23 +35,23 @@ namespace NTvmAuth { } TString CreateJugglerMessage() const { - return TStringBuilder() << GetJugglerCode() << ";TvmClient: " << LastError_ << "\n"; + return TStringBuilder() << GetJugglerCode() << ";TvmClient: " << LastError_ << "\n"; } private: - int32_t GetJugglerCode() const { - switch (Code_) { - case ECode::Ok: + int32_t GetJugglerCode() const { + switch (Code_) { + case ECode::Ok: return 0; // OK juggler check state - case ECode::Warning: - case ECode::IncompleteTicketsSet: + case ECode::Warning: + case ECode::IncompleteTicketsSet: return 1; // WARN juggler check state - case ECode::Error: + case ECode::Error: return 2; // CRIT juggler check state - } - return 2; // This should not happen, so set check state as CRIT. - } - + } + return 2; // This should not happen, so set check state as CRIT. + } + ECode Code_ = Ok; TString LastError_; }; diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp index 6ec15c0e88..f441cc3c35 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp @@ -53,10 +53,10 @@ namespace NTvmAuth::NDynamicClient { { } - TTvmClient::~TTvmClient() { - TBase::StopWorker(); - } - + TTvmClient::~TTvmClient() { + TBase::StopWorker(); + } + void TTvmClient::Worker() { TBase::Worker(); ProcessTasks(); diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h index 58ed953b63..ed9ba237a5 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h @@ -30,7 +30,7 @@ namespace NTvmAuth::NDynamicClient { class TTvmClient: public NTvmApi::TThreadedUpdater { public: static TAsyncUpdaterPtr Create(const NTvmApi::TClientSettings& settings, TLoggerPtr logger); - virtual ~TTvmClient(); + virtual ~TTvmClient(); NThreading::TFuture<TAddResponse> Add(TDsts&& dsts); std::optional<TString> GetOptionalServiceTicketFor(const TTvmId dst); diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp index 89403c15e4..cd20efc4d9 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp @@ -86,7 +86,7 @@ Y_UNIT_TEST_SUITE(DynamicClient) { mutable std::vector<TString> Tickets; }; - Y_UNIT_TEST(StartWithIncompleteTicketsSet) { + Y_UNIT_TEST(StartWithIncompleteTicketsSet) { TInstant now = TInstant::Now(); CleanCache(); WriteFile("./service_tickets", @@ -96,12 +96,12 @@ Y_UNIT_TEST_SUITE(DynamicClient) { NTvmApi::TClientSettings s; s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}, false); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - - { + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}, false); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + + { TOfflineUpdater client(s, l, false, @@ -109,51 +109,51 @@ Y_UNIT_TEST_SUITE(DynamicClient) { R"({"213" : { "error" : "some error"}})", R"({"123" : { "ticket" : "service_ticket_3"}})", }); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); - - NThreading::TFuture<TAddResponse> fut = client.Add({123}); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - - client.Worker(); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - + + NThreading::TFuture<TAddResponse> fut = client.Add({123}); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); + + client.Worker(); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); - - UNIT_ASSERT(fut.HasValue()); - TAddResponse resp{ - {123, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); - + + UNIT_ASSERT(fut.HasValue()); + TAddResponse resp{ + {123, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); + UNIT_ASSERT(client.Tickets.empty()); - - TDsts dsts{19, 123, 213}; - UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); - - UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(213), TMissingServiceTicket, "some error"); - } - } - - Y_UNIT_TEST(StartWithEmptyTicketsSet) { + + TDsts dsts{19, 123, 213}; + UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); + + UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(213), TMissingServiceTicket, "some error"); + } + } + + Y_UNIT_TEST(StartWithEmptyTicketsSet) { CleanCache(); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"kolmo", 213}}, false); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - - { + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"kolmo", 213}}, false); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + + { TOfflineUpdater client(s, l, false, @@ -161,46 +161,46 @@ Y_UNIT_TEST_SUITE(DynamicClient) { R"({"213" : { "error" : "some error"}})", R"({"123" : { "ticket" : "3:serv:CBAQ__________9_IgYIlJEGEHs:CcafYQH-FF5XaXMuJrgLZj98bIC54cs1ZkcFS9VV_9YM9iOM_0PXCtMkdg85rFjxE_BMpg7bE8ZuoqNfdw0FPt0BAKNeISwlydj4o0IjY82--LZBpP8CRn-EpAnkRaDShdlfrcF2pk1SSmEX8xdyZVQEnkUPY0cHGlFnu231vnE"}})", }); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(213), TMissingServiceTicket, "some error"); - - NThreading::TFuture<TAddResponse> fut = client.Add({123}); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - - client.Worker(); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - + UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(213), TMissingServiceTicket, "some error"); + + NThreading::TFuture<TAddResponse> fut = client.Add({123}); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); + + client.Worker(); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); + UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); - - UNIT_ASSERT(fut.HasValue()); - TAddResponse resp{ - {123, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); - + + UNIT_ASSERT(fut.HasValue()); + TAddResponse resp{ + {123, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); + UNIT_ASSERT(client.Tickets.empty()); - - TDsts dsts{123, 213}; - UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); - - UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(213), TMissingServiceTicket, "some error"); - } - }; - Y_UNIT_TEST(StartWithIncompleteCacheAndAdd) { - TInstant now = TInstant::Now(); + + TDsts dsts{123, 213}; + UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); + + UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(213), TMissingServiceTicket, "some error"); + } + }; + Y_UNIT_TEST(StartWithIncompleteCacheAndAdd) { + TInstant now = TInstant::Now(); CleanCache(); WriteFile("./service_tickets", - R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" - "\t100500", - now); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); + R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" + "\t100500", + now); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); s.SetDiskCacheDir(CACHE_DIR); diff --git a/library/cpp/tvmauth/client/misc/api/settings.h b/library/cpp/tvmauth/client/misc/api/settings.h index 715ab3e02c..f0050b65e7 100644 --- a/library/cpp/tvmauth/client/misc/api/settings.h +++ b/library/cpp/tvmauth/client/misc/api/settings.h @@ -163,9 +163,9 @@ namespace NTvmAuth::NTvmApi { } // Deprecated: set attributes directly - void EnableServiceTicketsFetchOptions(const TStringBuf selfSecret, - TDstMap&& dsts, - const bool considerIncompleteTicketsSetAsError = true) { + void EnableServiceTicketsFetchOptions(const TStringBuf selfSecret, + TDstMap&& dsts, + const bool considerIncompleteTicketsSetAsError = true) { IsIncompleteTicketsSetAnError = considerIncompleteTicketsSetAsError; Secret = selfSecret; @@ -179,9 +179,9 @@ namespace NTvmAuth::NTvmApi { } // Deprecated: set attributes directly - void EnableServiceTicketsFetchOptions(const TStringBuf selfSecret, - TDstVector&& dsts, - const bool considerIncompleteTicketsSetAsError = true) { + void EnableServiceTicketsFetchOptions(const TStringBuf selfSecret, + TDstVector&& dsts, + const bool considerIncompleteTicketsSetAsError = true) { IsIncompleteTicketsSetAnError = considerIncompleteTicketsSetAsError; Secret = selfSecret; FetchServiceTicketsForDsts = std::move(dsts); diff --git a/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp b/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp index a7df49c05d..3b691042cd 100644 --- a/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp +++ b/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp @@ -50,7 +50,7 @@ namespace NTvmAuth::NTvmApi { TClientStatus TThreadedUpdater::GetStatus() const { const TClientStatus::ECode state = GetState(); - return TClientStatus(state, GetLastError(state == TClientStatus::Ok || state == TClientStatus::IncompleteTicketsSet)); + return TClientStatus(state, GetLastError(state == TClientStatus::Ok || state == TClientStatus::IncompleteTicketsSet)); } NRoles::TRolesPtr TThreadedUpdater::GetRoles() const { @@ -72,10 +72,10 @@ namespace NTvmAuth::NTvmApi { } if (tickets->TicketsById.size() < Destinations_.size()) { if (Settings_.IsIncompleteTicketsSetAnError) { - return TClientStatus::Error; - } else { - return TClientStatus::IncompleteTicketsSet; - } + return TClientStatus::Error; + } else { + return TClientStatus::IncompleteTicketsSet; + } } } if ((Settings_.IsServiceTicketCheckingRequired() || Settings_.IsUserTicketCheckingRequired()) && ArePublicKeysInvalid(now)) { @@ -375,9 +375,9 @@ namespace NTvmAuth::NTvmApi { SetUpdateTimeOfServiceTickets(time); - if (count > 0) { - LogInfo(TStringBuilder() << "Cache was updated with " << count << " service ticket(s): " << time); - } + if (count > 0) { + LogInfo(TStringBuilder() << "Cache was updated with " << count << " service ticket(s): " << time); + } } void TThreadedUpdater::UpdatePublicKeysCache(const TString& publicKeys, TInstant time) { diff --git a/library/cpp/tvmauth/client/misc/async_updater.cpp b/library/cpp/tvmauth/client/misc/async_updater.cpp index 9cb0332ed4..a8adef3d1f 100644 --- a/library/cpp/tvmauth/client/misc/async_updater.cpp +++ b/library/cpp/tvmauth/client/misc/async_updater.cpp @@ -49,8 +49,8 @@ namespace NTvmAuth { } bool TAsyncUpdaterBase::AreServiceTicketsInvalid(TInstant now) const { - TServiceTicketsPtr c = GetCachedServiceTickets(); - // Empty set of tickets is allways valid. + TServiceTicketsPtr c = GetCachedServiceTickets(); + // Empty set of tickets is allways valid. return c && !c->TicketsById.empty() && IsInvalid(GetInvalidationTimeOfServiceTickets(), now); } diff --git a/library/cpp/tvmauth/client/misc/async_updater.h b/library/cpp/tvmauth/client/misc/async_updater.h index 7b556d7a38..1ff0b4f4e7 100644 --- a/library/cpp/tvmauth/client/misc/async_updater.h +++ b/library/cpp/tvmauth/client/misc/async_updater.h @@ -29,15 +29,15 @@ namespace NTvmAuth { public: using TMapAliasStr = THashMap<TClientSettings::TAlias, TString>; using TMapIdStr = THashMap<TTvmId, TString>; - using TIdSet = THashSet<TTvmId>; - using TAliasSet = THashSet<TClientSettings::TAlias>; + using TIdSet = THashSet<TTvmId>; + using TAliasSet = THashSet<TClientSettings::TAlias>; using TMapAliasId = THashMap<TClientSettings::TAlias, TTvmId>; TServiceTickets(TMapIdStr&& tickets, TMapIdStr&& errors, const TMapAliasId& dstMap) : TicketsById(std::move(tickets)) , ErrorsById(std::move(errors)) { - InitAliasesAndUnfetchedIds(dstMap); + InitAliasesAndUnfetchedIds(dstMap); InitInvalidationTime(); } @@ -66,7 +66,7 @@ namespace NTvmAuth { TAliasSet UnfetchedAliases; private: - void InitAliasesAndUnfetchedIds(const TMapAliasId& dstMap) { + void InitAliasesAndUnfetchedIds(const TMapAliasId& dstMap) { for (const auto& pair : dstMap) { auto it = TicketsById.find(pair.second); auto errIt = ErrorsById.find(pair.second); @@ -74,11 +74,11 @@ namespace NTvmAuth { if (it == TicketsById.end()) { if (errIt != ErrorsById.end()) { Y_ENSURE(ErrorsByAlias.insert({pair.first, errIt->second}).second, - "failed to add: " << pair.first); - } else { + "failed to add: " << pair.first); + } else { UnfetchedAliases.insert(pair.first); UnfetchedIds.insert(pair.second); - } + } } else { Y_ENSURE(TicketsByAlias.insert({pair.first, it->second}).second, "failed to add: " << pair.first); diff --git a/library/cpp/tvmauth/client/misc/getter.h b/library/cpp/tvmauth/client/misc/getter.h index b0327d69e9..3f627dd4d4 100644 --- a/library/cpp/tvmauth/client/misc/getter.h +++ b/library/cpp/tvmauth/client/misc/getter.h @@ -28,8 +28,8 @@ namespace NTvmAuth { } private: - template <class Key, class Cont, class UnfetchedCont> - TString GetTicketImpl(const Key& dst, const Cont& tickets, const Cont& errors, const UnfetchedCont& unfetched) const { + template <class Key, class Cont, class UnfetchedCont> + TString GetTicketImpl(const Key& dst, const Cont& tickets, const Cont& errors, const UnfetchedCont& unfetched) const { auto it = tickets.find(dst); if (it != tickets.end()) { return it->second; @@ -42,11 +42,11 @@ namespace NTvmAuth { << it->second; } - if (unfetched.contains(dst)) { - ythrow TMissingServiceTicket() - << "Failed to get ticket for '" << dst << "': this dst was not fetched yet."; - } - + if (unfetched.contains(dst)) { + ythrow TMissingServiceTicket() + << "Failed to get ticket for '" << dst << "': this dst was not fetched yet."; + } + ythrow TBrokenTvmClientSettings() << "Destination '" << dst << "' was not specified in settings. " << "Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"; diff --git a/library/cpp/tvmauth/client/ut/async_updater_ut.cpp b/library/cpp/tvmauth/client/ut/async_updater_ut.cpp index 1c1e8cbaae..0252ffcfc8 100644 --- a/library/cpp/tvmauth/client/ut/async_updater_ut.cpp +++ b/library/cpp/tvmauth/client/ut/async_updater_ut.cpp @@ -83,9 +83,9 @@ Y_UNIT_TEST_SUITE(AsyncUpdater) { Y_UNIT_TEST(ServiceTickets_Aliases) { using TId = TServiceTickets::TMapIdStr; - using TUnfetchedId = TServiceTickets::TIdSet; + using TUnfetchedId = TServiceTickets::TIdSet; using TStr = TServiceTickets::TMapAliasStr; - using TUnfetchedAlias = TServiceTickets::TAliasSet; + using TUnfetchedAlias = TServiceTickets::TAliasSet; using TAls = TServiceTickets::TMapAliasId; TServiceTickets t(TId{}, TId{}, TAls{}); @@ -106,14 +106,14 @@ Y_UNIT_TEST_SUITE(AsyncUpdater) { UNIT_ASSERT_EQUAL(TStr({{"1", "t1"}, {"2", "t2"}}), t.TicketsByAlias); UNIT_ASSERT_EQUAL(TStr({{"3", "e1"}}), t.ErrorsByAlias); UNIT_ASSERT_EQUAL(TUnfetchedAlias({}), t.UnfetchedAliases); - } - - Y_UNIT_TEST(ServiceTickets_UnfetchedIds) { - using TId = TServiceTickets::TMapIdStr; - using TUnfetchedId = TServiceTickets::TIdSet; - using TStr = TServiceTickets::TMapAliasStr; - using TUnfetchedAlias = TServiceTickets::TAliasSet; - using TAls = TServiceTickets::TMapAliasId; + } + + Y_UNIT_TEST(ServiceTickets_UnfetchedIds) { + using TId = TServiceTickets::TMapIdStr; + using TUnfetchedId = TServiceTickets::TIdSet; + using TStr = TServiceTickets::TMapAliasStr; + using TUnfetchedAlias = TServiceTickets::TAliasSet; + using TAls = TServiceTickets::TMapAliasId; TServiceTickets t(TId({{1, "t1"}, {2, "t2"}}), TId(), TAls({{"1", 1}, {"2", 2}, {"3", 3}})); |