aboutsummaryrefslogtreecommitdiff
path: root/zenserver/upstream/upstreamcache.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-02-02 16:56:38 +0100
committerPer Larsson <[email protected]>2022-02-02 16:56:38 +0100
commit5b7c068b482b563443320453064fe5fa5601d446 (patch)
tree3309bc01ef5ab2f4d08580b5e6c1098c6b45570b /zenserver/upstream/upstreamcache.cpp
parentParse expire time from OpenID refresh token and added OpenId token provider. (diff)
downloadzen-5b7c068b482b563443320453064fe5fa5601d446.tar.xz
zen-5b7c068b482b563443320453064fe5fa5601d446.zip
Added upstream auth config and removed the possibility to add endpoints via REST.
Diffstat (limited to 'zenserver/upstream/upstreamcache.cpp')
-rw-r--r--zenserver/upstream/upstreamcache.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp
index 58c025b4f..d83542701 100644
--- a/zenserver/upstream/upstreamcache.cpp
+++ b/zenserver/upstream/upstreamcache.cpp
@@ -85,9 +85,7 @@ namespace detail {
class JupiterUpstreamEndpoint final : public UpstreamEndpoint
{
public:
- JupiterUpstreamEndpoint(const CloudCacheClientOptions& Options,
- std::unique_ptr<CloudCacheTokenProvider> TokenProvider,
- AuthMgr& Mgr)
+ JupiterUpstreamEndpoint(const CloudCacheClientOptions& Options, const UpstreamAuthConfig& AuthConfig, AuthMgr& Mgr)
: m_AuthMgr(Mgr)
, m_Log(zen::logging::Get("upstream"))
, m_UseLegacyDdc(Options.UseLegacyDdc)
@@ -95,7 +93,30 @@ namespace detail {
ZEN_ASSERT(!Options.Name.empty());
m_Info.Name = Options.Name;
m_Info.Url = Options.ServiceUrl;
- m_Client = new CloudCacheClient(Options, std::move(TokenProvider));
+
+ std::unique_ptr<CloudCacheTokenProvider> TokenProvider;
+
+ if (AuthConfig.OAuthUrl.empty() == false)
+ {
+ TokenProvider = CloudCacheTokenProvider::MakeFromOAuthClientCredentials(
+ {.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};
+ });
+ }
+ else
+ {
+ CloudCacheAccessToken AccessToken{.Value = std::string(AuthConfig.AccessToken),
+ .ExpireTime = CloudCacheAccessToken::TimePoint::max()};
+
+ TokenProvider = CloudCacheTokenProvider::MakeFromStaticToken(AccessToken);
+ }
+
+ m_Client = new CloudCacheClient(Options, std::move(TokenProvider));
}
virtual ~JupiterUpstreamEndpoint() = default;
@@ -1491,9 +1512,9 @@ MakeUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore
}
std::unique_ptr<UpstreamEndpoint>
-MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options, std::unique_ptr<CloudCacheTokenProvider> TokenProvider, AuthMgr& Mgr)
+MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options, const UpstreamAuthConfig& AuthConfig, AuthMgr& Mgr)
{
- return std::make_unique<detail::JupiterUpstreamEndpoint>(Options, std::move(TokenProvider), Mgr);
+ return std::make_unique<detail::JupiterUpstreamEndpoint>(Options, AuthConfig, Mgr);
}
std::unique_ptr<UpstreamEndpoint>