diff options
| author | Per Larsson <[email protected]> | 2022-02-03 15:40:04 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2022-02-03 15:40:04 +0100 |
| commit | d6741139e1ea3c6bb1462da61a81c42a80ac6e59 (patch) | |
| tree | a422d3f591c954e9f5a20c6a28f60bd08923185e /zenserver/upstream | |
| parent | Merge branch 'main' into auth (diff) | |
| download | zen-d6741139e1ea3c6bb1462da61a81c42a80ac6e59.tar.xz zen-d6741139e1ea3c6bb1462da61a81c42a80ac6e59.zip | |
Minor cleanup of free functions.
Diffstat (limited to 'zenserver/upstream')
| -rw-r--r-- | zenserver/upstream/jupiter.cpp | 6 | ||||
| -rw-r--r-- | zenserver/upstream/jupiter.h | 6 | ||||
| -rw-r--r-- | zenserver/upstream/upstreamcache.cpp | 48 | ||||
| -rw-r--r-- | zenserver/upstream/upstreamcache.h | 29 |
4 files changed, 47 insertions, 42 deletions
diff --git a/zenserver/upstream/jupiter.cpp b/zenserver/upstream/jupiter.cpp index 6fc952bab..2b064a610 100644 --- a/zenserver/upstream/jupiter.cpp +++ b/zenserver/upstream/jupiter.cpp @@ -795,7 +795,7 @@ private: }; std::unique_ptr<CloudCacheTokenProvider> -CloudCacheTokenProvider::MakeFromStaticToken(CloudCacheAccessToken Token) +CloudCacheTokenProvider::CreateFromStaticToken(CloudCacheAccessToken Token) { return std::make_unique<StaticTokenProvider>(std::move(Token)); } @@ -849,7 +849,7 @@ private: }; std::unique_ptr<CloudCacheTokenProvider> -CloudCacheTokenProvider::MakeFromOAuthClientCredentials(const OAuthClientCredentialsParams& Params) +CloudCacheTokenProvider::CreateFromOAuthClientCredentials(const OAuthClientCredentialsParams& Params) { return std::make_unique<OAuthClientCredentialsTokenProvider>(Params); } @@ -868,7 +868,7 @@ private: }; std::unique_ptr<CloudCacheTokenProvider> -CloudCacheTokenProvider::MakeFromCallback(std::function<CloudCacheAccessToken()>&& Callback) +CloudCacheTokenProvider::CreateFromCallback(std::function<CloudCacheAccessToken()>&& Callback) { return std::make_unique<CallbackTokenProvider>(std::move(Callback)); } diff --git a/zenserver/upstream/jupiter.h b/zenserver/upstream/jupiter.h index f90ad26ed..ddd7ea160 100644 --- a/zenserver/upstream/jupiter.h +++ b/zenserver/upstream/jupiter.h @@ -147,7 +147,7 @@ public: virtual CloudCacheAccessToken AcquireAccessToken() = 0; - static std::unique_ptr<CloudCacheTokenProvider> MakeFromStaticToken(CloudCacheAccessToken Token); + static std::unique_ptr<CloudCacheTokenProvider> CreateFromStaticToken(CloudCacheAccessToken Token); struct OAuthClientCredentialsParams { @@ -156,9 +156,9 @@ public: std::string_view ClientSecret; }; - static std::unique_ptr<CloudCacheTokenProvider> MakeFromOAuthClientCredentials(const OAuthClientCredentialsParams& Params); + static std::unique_ptr<CloudCacheTokenProvider> CreateFromOAuthClientCredentials(const OAuthClientCredentialsParams& Params); - static std::unique_ptr<CloudCacheTokenProvider> MakeFromCallback(std::function<CloudCacheAccessToken()>&& Callback); + static std::unique_ptr<CloudCacheTokenProvider> CreateFromCallback(std::function<CloudCacheAccessToken()>&& Callback); }; struct CloudCacheClientOptions diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp index 7466af1d2..5990536a9 100644 --- a/zenserver/upstream/upstreamcache.cpp +++ b/zenserver/upstream/upstreamcache.cpp @@ -18,8 +18,8 @@ #include <zenstore/cas.h> #include <zenstore/cidstore.h> -#include "cache/structuredcache.h" #include <auth/authmgr.h> +#include "cache/structuredcache.h" #include "cache/structuredcachestore.h" #include "diag/logging.h" @@ -99,22 +99,23 @@ namespace detail { if (AuthConfig.OAuthUrl.empty() == false) { - TokenProvider = CloudCacheTokenProvider::MakeFromOAuthClientCredentials( + TokenProvider = CloudCacheTokenProvider::CreateFromOAuthClientCredentials( {.Url = AuthConfig.OAuthUrl, .ClientId = AuthConfig.OAuthClientId, .ClientSecret = AuthConfig.OAuthClientSecret}); } else if (AuthConfig.OpenIdProvider.empty() == false) { - TokenProvider = CloudCacheTokenProvider::MakeFromCallback([this, ProviderName = std::string(AuthConfig.OpenIdProvider)]() { - AuthMgr::OpenIdAccessToken Token = m_AuthMgr.GetOpenIdAccessToken(ProviderName); - return CloudCacheAccessToken{.Value = Token.AccessToken, .ExpireTime = Token.ExpireTime}; - }); + TokenProvider = + CloudCacheTokenProvider::CreateFromCallback([this, ProviderName = std::string(AuthConfig.OpenIdProvider)]() { + AuthMgr::OpenIdAccessToken Token = m_AuthMgr.GetOpenIdAccessToken(ProviderName); + return CloudCacheAccessToken{.Value = Token.AccessToken, .ExpireTime = Token.ExpireTime}; + }); } else { CloudCacheAccessToken AccessToken{.Value = std::string(AuthConfig.AccessToken), .ExpireTime = CloudCacheAccessToken::TimePoint::max()}; - TokenProvider = CloudCacheTokenProvider::MakeFromStaticToken(AccessToken); + TokenProvider = CloudCacheTokenProvider::CreateFromStaticToken(AccessToken); } m_Client = new CloudCacheClient(Options, std::move(TokenProvider)); @@ -1040,10 +1041,10 @@ namespace detail { ////////////////////////////////////////////////////////////////////////// -class DefaultUpstreamCache final : public UpstreamCache +class UpstreamCacheImpl final : public UpstreamCache { public: - DefaultUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) + UpstreamCacheImpl(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) : m_Log(logging::Get("upstream")) , m_Options(Options) , m_CacheStore(CacheStore) @@ -1051,16 +1052,16 @@ public: { } - virtual ~DefaultUpstreamCache() { Shutdown(); } + virtual ~UpstreamCacheImpl() { Shutdown(); } virtual void Initialize() override { for (uint32_t Idx = 0; Idx < m_Options.ThreadCount; Idx++) { - m_UpstreamThreads.emplace_back(&DefaultUpstreamCache::ProcessUpstreamQueue, this); + m_UpstreamThreads.emplace_back(&UpstreamCacheImpl::ProcessUpstreamQueue, this); } - m_EndpointMonitorThread = std::thread(&DefaultUpstreamCache::MonitorEndpoints, this); + m_EndpointMonitorThread = std::thread(&UpstreamCacheImpl::MonitorEndpoints, this); m_RunState.IsRunning = true; } @@ -1069,7 +1070,14 @@ public: const UpstreamEndpointStatus Status = Endpoint->Initialize(); const UpstreamEndpointInfo& Info = Endpoint->GetEndpointInfo(); - ZEN_INFO("register endpoint '{} - {}' {}", Info.Name, Info.Url, ToString(Status.State)); + if (Status.State == UpstreamEndpointState::kOk) + { + ZEN_INFO("register endpoint '{} - {}' {}", Info.Name, Info.Url, ToString(Status.State)); + } + else + { + ZEN_WARN("register endpoint '{} - {}' {}", Info.Name, Info.Url, ToString(Status.State)); + } // Register endpoint even if it fails, the health monitor thread will probe failing endpoint(s) std::unique_lock<std::shared_mutex> _(m_EndpointsMutex); @@ -1562,22 +1570,22 @@ private: ////////////////////////////////////////////////////////////////////////// -std::unique_ptr<UpstreamCache> -MakeUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) +std::unique_ptr<UpstreamEndpoint> +UpstreamEndpoint::CreateZenEndpoint(const ZenStructuredCacheClientOptions& Options) { - return std::make_unique<DefaultUpstreamCache>(Options, CacheStore, CidStore); + return std::make_unique<detail::ZenUpstreamEndpoint>(Options); } std::unique_ptr<UpstreamEndpoint> -MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options, const UpstreamAuthConfig& AuthConfig, AuthMgr& Mgr) +UpstreamEndpoint::CreateJupiterEndpoint(const CloudCacheClientOptions& Options, const UpstreamAuthConfig& AuthConfig, AuthMgr& Mgr) { return std::make_unique<detail::JupiterUpstreamEndpoint>(Options, AuthConfig, Mgr); } -std::unique_ptr<UpstreamEndpoint> -MakeZenUpstreamEndpoint(const ZenStructuredCacheClientOptions& Options) +std::unique_ptr<UpstreamCache> +UpstreamCache::Create(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) { - return std::make_unique<detail::ZenUpstreamEndpoint>(Options); + return std::make_unique<UpstreamCacheImpl>(Options, CacheStore, CidStore); } } // namespace zen diff --git a/zenserver/upstream/upstreamcache.h b/zenserver/upstream/upstreamcache.h index 4ccc56f79..6f18b3119 100644 --- a/zenserver/upstream/upstreamcache.h +++ b/zenserver/upstream/upstreamcache.h @@ -129,11 +129,11 @@ ToString(UpstreamEndpointState State) struct UpstreamAuthConfig { - std::string_view OAuthUrl; - std::string_view OAuthClientId; - std::string_view OAuthClientSecret; - std::string_view OpenIdProvider; - std::string_view AccessToken; + std::string_view OAuthUrl; + std::string_view OAuthClientId; + std::string_view OAuthClientSecret; + std::string_view OpenIdProvider; + std::string_view AccessToken; }; struct UpstreamEndpointStatus @@ -175,6 +175,12 @@ public: std::span<IoBuffer const> Payloads) = 0; virtual UpstreamEndpointStats& Stats() = 0; + + static std::unique_ptr<UpstreamEndpoint> CreateZenEndpoint(const ZenStructuredCacheClientOptions& Options); + + static std::unique_ptr<UpstreamEndpoint> CreateJupiterEndpoint(const CloudCacheClientOptions& Options, + const UpstreamAuthConfig& AuthConfig, + AuthMgr& Mgr); }; /** @@ -199,17 +205,8 @@ public: virtual void EnqueueUpstream(UpstreamCacheRecord CacheRecord) = 0; virtual void GetStatus(CbObjectWriter& CbO) = 0; -}; - -std::unique_ptr<UpstreamCache> MakeUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore); -std::unique_ptr<UpstreamEndpoint> MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options); - -std::unique_ptr<UpstreamEndpoint> MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options); -std::unique_ptr<UpstreamEndpoint> MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options, - const UpstreamAuthConfig& AuthConfig, - AuthMgr& Mgr); - -std::unique_ptr<UpstreamEndpoint> MakeZenUpstreamEndpoint(const ZenStructuredCacheClientOptions& Options); + static std::unique_ptr<UpstreamCache> Create(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore); +}; } // namespace zen |