blob: 8c60b59610db92754fe73a5bc61e055d1540f9bb (
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
|
#pragma once
#include <library/cpp/tvmauth/client/misc/fetch_result.h>
#include <library/cpp/tvmauth/client/misc/utils.h>
#include <library/cpp/tvmauth/client/misc/roles/roles.h>
#include <library/cpp/tvmauth/client/logger.h>
#include <util/datetime/base.h>
#include <util/generic/string.h>
namespace NTvmAuth::NTvmTool {
struct TRolesFetcherSettings {
TString SelfAlias;
TDuration UpdatePeriod = TDuration::Minutes(1);
TDuration WarnPeriod = TDuration::Minutes(20);
};
class TRolesFetcher {
public:
TRolesFetcher(const TRolesFetcherSettings& settings, TLoggerPtr logger);
bool IsTimeToUpdate(TDuration sinceUpdate) const;
bool ShouldWarn(TDuration sinceUpdate) const;
bool AreRolesOk() const;
NUtils::TFetchResult FetchActualRoles(const TKeepAliveHttpClient::THeaders& authHeader,
TKeepAliveHttpClient& client) const;
void Update(NUtils::TFetchResult&& fetchResult);
NTvmAuth::NRoles::TRolesPtr GetCurrentRoles() const;
protected:
struct TRequest {
TString Url;
TKeepAliveHttpClient::THeaders Headers;
};
protected:
TRequest CreateRequest(const TKeepAliveHttpClient::THeaders& authHeader) const;
private:
const TRolesFetcherSettings Settings_;
const TLoggerPtr Logger_;
const TString IfNoneMatch_ = "If-None-Match";
NUtils::TProtectedValue<NTvmAuth::NRoles::TRolesPtr> CurrentRoles_;
};
}
|