aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-02-03 15:40:04 +0100
committerPer Larsson <[email protected]>2022-02-03 15:40:04 +0100
commitd6741139e1ea3c6bb1462da61a81c42a80ac6e59 (patch)
treea422d3f591c954e9f5a20c6a28f60bd08923185e /zenserver
parentMerge branch 'main' into auth (diff)
downloadzen-d6741139e1ea3c6bb1462da61a81c42a80ac6e59.tar.xz
zen-d6741139e1ea3c6bb1462da61a81c42a80ac6e59.zip
Minor cleanup of free functions.
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/auth/authmgr.cpp2
-rw-r--r--zenserver/auth/authmgr.h32
-rw-r--r--zenserver/compute/apply.cpp2
-rw-r--r--zenserver/upstream/jupiter.cpp6
-rw-r--r--zenserver/upstream/jupiter.h6
-rw-r--r--zenserver/upstream/upstreamcache.cpp48
-rw-r--r--zenserver/upstream/upstreamcache.h29
-rw-r--r--zenserver/zenserver.cpp18
8 files changed, 75 insertions, 68 deletions
diff --git a/zenserver/auth/authmgr.cpp b/zenserver/auth/authmgr.cpp
index fa5e0d753..0b7d7b492 100644
--- a/zenserver/auth/authmgr.cpp
+++ b/zenserver/auth/authmgr.cpp
@@ -493,7 +493,7 @@ private:
};
std::unique_ptr<AuthMgr>
-MakeAuthMgr(const AuthConfig& Config)
+AuthMgr::Create(const AuthConfig& Config)
{
return std::make_unique<AuthMgrImpl>(Config);
}
diff --git a/zenserver/auth/authmgr.h b/zenserver/auth/authmgr.h
index 9695b4366..a641b9c8f 100644
--- a/zenserver/auth/authmgr.h
+++ b/zenserver/auth/authmgr.h
@@ -9,6 +9,21 @@
namespace zen {
+struct AuthEncryptionKey
+{
+ IoBuffer Key;
+ IoBuffer IV;
+
+ static AuthEncryptionKey Default();
+};
+
+struct AuthConfig
+{
+ std::filesystem::path RootDirectory;
+ std::chrono::seconds UpdateInterval{30};
+ AuthEncryptionKey EncryptionKey;
+};
+
class AuthMgr
{
public:
@@ -38,23 +53,8 @@ public:
};
virtual OpenIdAccessToken GetOpenIdAccessToken(std::string_view ProviderName) = 0;
-};
-
-struct AuthEncryptionKey
-{
- IoBuffer Key;
- IoBuffer IV;
- static AuthEncryptionKey Default();
+ static std::unique_ptr<AuthMgr> Create(const AuthConfig& Config);
};
-struct AuthConfig
-{
- std::filesystem::path RootDirectory;
- std::chrono::seconds UpdateInterval{30};
- AuthEncryptionKey EncryptionKey;
-};
-
-std::unique_ptr<AuthMgr> MakeAuthMgr(const AuthConfig& Config);
-
} // namespace zen
diff --git a/zenserver/compute/apply.cpp b/zenserver/compute/apply.cpp
index 83fef9058..e4d5697fa 100644
--- a/zenserver/compute/apply.cpp
+++ b/zenserver/compute/apply.cpp
@@ -345,7 +345,7 @@ HttpFunctionService::HttpFunctionService(CasStore& Store, CidStore& InCidStore,
.BlobStoreNamespace = "default"sv};
auto HordeUpstreamEndpoint =
- MakeHordeUpstreamEndpoint(Options, CloudCacheTokenProvider::MakeFromStaticToken(AccessToken), m_CasStore, m_CidStore);
+ MakeHordeUpstreamEndpoint(Options, CloudCacheTokenProvider::CreateFromStaticToken(AccessToken), m_CasStore, m_CidStore);
m_UpstreamApply->RegisterEndpoint(std::move(HordeUpstreamEndpoint));
m_UpstreamApply->Initialize();
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
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index 03d59ba7c..56713e0ac 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -212,7 +212,7 @@ public:
.IV = IoBufferBuilder::MakeCloneFromMemory(MakeMemoryView(ServerOptions.EncryptionIV))};
};
- m_AuthMgr = MakeAuthMgr({.RootDirectory = m_DataRoot / "auth", .EncryptionKey = EncryptionKey});
+ m_AuthMgr = AuthMgr::Create({.RootDirectory = m_DataRoot / "auth", .EncryptionKey = EncryptionKey});
m_AuthService = std::make_unique<zen::HttpAuthService>(*m_AuthMgr);
m_Http->RegisterService(*m_AuthService);
@@ -709,7 +709,7 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
UpstreamOptions.ThreadCount = static_cast<uint32_t>(UpstreamConfig.UpstreamThreadCount);
}
- m_UpstreamCache = zen::MakeUpstreamCache(UpstreamOptions, *m_CacheStore, *m_CidStore);
+ m_UpstreamCache = zen::UpstreamCache::Create(UpstreamOptions, *m_CacheStore, *m_CidStore);
m_UpstreamService = std::make_unique<HttpUpstreamService>(*m_UpstreamCache, *m_AuthMgr);
m_UpstreamCache->Initialize();
@@ -739,11 +739,12 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
{
const auto ZenEndpointName = UpstreamConfig.ZenConfig.Name.empty() ? "Zen"sv : UpstreamConfig.ZenConfig.Name;
- std::unique_ptr<zen::UpstreamEndpoint> ZenEndpoint =
- zen::MakeZenUpstreamEndpoint({.Name = ZenEndpointName,
- .Urls = ZenUrls,
- .ConnectTimeout = std::chrono::milliseconds(UpstreamConfig.ConnectTimeoutMilliseconds),
- .Timeout = std::chrono::milliseconds(UpstreamConfig.TimeoutMilliseconds)});
+ std::unique_ptr<zen::UpstreamEndpoint> ZenEndpoint = zen::UpstreamEndpoint::CreateZenEndpoint(
+ {.Name = ZenEndpointName,
+ .Urls = ZenUrls,
+ .ConnectTimeout = std::chrono::milliseconds(UpstreamConfig.ConnectTimeoutMilliseconds),
+ .Timeout = std::chrono::milliseconds(UpstreamConfig.TimeoutMilliseconds)});
+
m_UpstreamCache->RegisterEndpoint(std::move(ZenEndpoint));
}
}
@@ -767,7 +768,8 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
.OpenIdProvider = UpstreamConfig.JupiterConfig.OpenIdProvider,
.AccessToken = UpstreamConfig.JupiterConfig.AccessToken};
- std::unique_ptr<zen::UpstreamEndpoint> JupiterEndpoint = zen::MakeJupiterUpstreamEndpoint(Options, AuthConfig, *m_AuthMgr);
+ std::unique_ptr<zen::UpstreamEndpoint> JupiterEndpoint =
+ zen::UpstreamEndpoint::CreateJupiterEndpoint(Options, AuthConfig, *m_AuthMgr);
m_UpstreamCache->RegisterEndpoint(std::move(JupiterEndpoint));
}