mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 01:42:37 +08:00
Clean up TenantInfo and related headers
This commit is contained in:
parent
ca29cd9f41
commit
d1dc82629e
@ -31,7 +31,7 @@
|
||||
#include "fdbrpc/LoadBalance.actor.h"
|
||||
#include "fdbrpc/Stats.h"
|
||||
#include "fdbrpc/TimedRequest.h"
|
||||
#include "fdbrpc/TenantAuth.h"
|
||||
#include "fdbrpc/TenantInfo.h"
|
||||
#include "fdbrpc/TSSComparison.h"
|
||||
#include "fdbclient/CommitTransaction.h"
|
||||
#include "fdbclient/TagThrottle.actor.h"
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "fdbrpc/FlowTransport.h"
|
||||
#include "fdbrpc/TokenCache.h"
|
||||
#include "fdbrpc/TokenSign.h"
|
||||
#include "fdbrpc/TenantInfo.h"
|
||||
#include "flow/MkCert.h"
|
||||
#include "flow/ScopeExit.h"
|
||||
#include "flow/UnitTest.h"
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* TenantInfo.h
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
||||
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(NO_INTELLISENSE) && !defined(FDBRPC_TENANT_AUTH_ACTOR_G_H)
|
||||
#define FDBRPC_TENANT_AUTH_ACTOR_G_H
|
||||
#include "fdbrpc/TenantAuth.actor.g.h"
|
||||
#elif !defined(FDBRPC_TENANT_AUTH_ACTOR_H)
|
||||
#define FDBRPC_TENANT_AUTH_ACTOR_H
|
||||
|
||||
#include <string_view>
|
||||
#include <queue>
|
||||
|
||||
#include "fdbrpc/TenantInfo.h"
|
||||
#include "fdbrpc/TokenSign.h"
|
||||
#include "fdbrpc/TokenCache.h"
|
||||
#include "fdbrpc/FlowTransport.h"
|
||||
#include "flow/flow.h"
|
||||
|
||||
#include "flow/actorcompiler.h" // has to be last include
|
||||
|
||||
template <>
|
||||
struct serializable_traits<TenantInfo> : std::true_type {
|
||||
template <class Archiver>
|
||||
static void serialize(Archiver& ar, TenantInfo& v) {
|
||||
using namespace std::literals;
|
||||
serializer(ar, v.name, v.tenantId, v.token, v.arena);
|
||||
if constexpr (Archiver::isDeserializing) {
|
||||
bool tenantAuthorized = false;
|
||||
if (v.name.present() && v.token.present()) {
|
||||
tenantAuthorized = TokenCache::instance().validate(v.name.get(), v.token.get());
|
||||
}
|
||||
v.trusted = FlowTransport::transport().currentDeliveryPeerIsTrusted();
|
||||
v.verified = v.trusted || !v.name.present() || tenantAuthorized;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -21,11 +21,12 @@
|
||||
#pragma once
|
||||
#ifndef FDBRPC_TENANTINFO_H_
|
||||
#define FDBRPC_TENANTINFO_H_
|
||||
#include "fdbrpc/TenantName.h"
|
||||
#include "fdbrpc/TokenSign.h"
|
||||
#include "fdbrpc/TokenCache.h"
|
||||
#include "fdbrpc/FlowTransport.h"
|
||||
#include "flow/Arena.h"
|
||||
|
||||
typedef StringRef TenantNameRef;
|
||||
typedef Standalone<TenantNameRef> TenantName;
|
||||
|
||||
struct TenantInfo {
|
||||
static const int64_t INVALID_TENANT = -1;
|
||||
|
||||
@ -61,4 +62,20 @@ struct TenantInfo {
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct serializable_traits<TenantInfo> : std::true_type {
|
||||
template <class Archiver>
|
||||
static void serialize(Archiver& ar, TenantInfo& v) {
|
||||
serializer(ar, v.name, v.tenantId, v.token, v.arena);
|
||||
if constexpr (Archiver::isDeserializing) {
|
||||
bool tenantAuthorized = false;
|
||||
if (v.name.present() && v.token.present()) {
|
||||
tenantAuthorized = TokenCache::instance().validate(v.name.get(), v.token.get());
|
||||
}
|
||||
v.trusted = FlowTransport::transport().currentDeliveryPeerIsTrusted();
|
||||
v.verified = v.trusted || !v.name.present() || tenantAuthorized;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // FDBRPC_TENANTINFO_H_
|
||||
|
27
fdbrpc/include/fdbrpc/TenantName.h
Normal file
27
fdbrpc/include/fdbrpc/TenantName.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* TenantName.h
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
||||
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef FDBRPC_TENANTNAME_H
|
||||
#define FDBRPC_TENANTNAME_H
|
||||
#include "flow/Arena.h"
|
||||
typedef StringRef TenantNameRef;
|
||||
typedef Standalone<TenantNameRef> TenantName;
|
||||
#endif // FDBRPC_TENANTNAME_H
|
@ -20,8 +20,8 @@
|
||||
|
||||
#ifndef TOKENCACHE_H_
|
||||
#define TOKENCACHE_H_
|
||||
#include "fdbrpc/TenantName.h"
|
||||
#include "flow/Arena.h"
|
||||
#include "fdbrpc/TenantInfo.h"
|
||||
|
||||
class TokenCache : NonCopyable {
|
||||
struct TokenCacheImpl* impl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user