diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2021-04-28 15:15:11 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-29 21:00:06 +0000 |
commit | d9fbb80aa08741261580ebf3473e1b31ed795b7c (patch) | |
tree | ae945dc1480bed8a26e3594ac7f4e9ee81876617 /src/mongo/db/commands/user_management_commands.cpp | |
parent | ea6fb92054f2fc1153f4c39bc4634d34bb3f9997 (diff) | |
download | mongo-d9fbb80aa08741261580ebf3473e1b31ed795b7c.tar.gz |
SERVER-56456 Add reply types to UMC commands and simplify templates
Diffstat (limited to 'src/mongo/db/commands/user_management_commands.cpp')
-rw-r--r-- | src/mongo/db/commands/user_management_commands.cpp | 89 |
1 files changed, 41 insertions, 48 deletions
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 855c63acb60..d8c7582ad16 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -937,12 +937,12 @@ struct UMCCacheParams { static constexpr auto allowedOnSecondary = BasicCommand::AllowedOnSecondary::kAlways; }; -template <typename RequestT, typename ReplyT, typename Params = UMCStdParams> -class CmdUMCTyped : public TypedCommand<CmdUMCTyped<RequestT, ReplyT, Params>> { +template <typename RequestT, typename Params = UMCStdParams> +class CmdUMCTyped : public TypedCommand<CmdUMCTyped<RequestT, Params>> { public: using Request = RequestT; - using Reply = ReplyT; - using TC = TypedCommand<CmdUMCTyped<RequestT, ReplyT, Params>>; + using Reply = typename RequestT::Reply; + using TC = TypedCommand<CmdUMCTyped<RequestT, Params>>; class Invocation final : public TC::InvocationBase { public: @@ -974,7 +974,7 @@ public: } }; -class CmdCreateUser : public CmdUMCTyped<CreateUserCommand, void> { +class CmdCreateUser : public CmdUMCTyped<CreateUserCommand> { public: static constexpr StringData kPwdField = "pwd"_sd; @@ -984,7 +984,7 @@ public: } cmdCreateUser; template <> -void CmdUMCTyped<CreateUserCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<CreateUserCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); @@ -1083,7 +1083,7 @@ void CmdUMCTyped<CreateUserCommand, void>::Invocation::typedRun(OperationContext uassertStatusOK(status); } -class CmdUpdateUser : public CmdUMCTyped<UpdateUserCommand, void> { +class CmdUpdateUser : public CmdUMCTyped<UpdateUserCommand> { public: static constexpr StringData kPwdField = "pwd"_sd; @@ -1093,7 +1093,7 @@ public: } cmdUpdateUser; template <> -void CmdUMCTyped<UpdateUserCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<UpdateUserCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); UserName userName(cmd.getCommandParameter(), dbname); @@ -1189,9 +1189,9 @@ void CmdUMCTyped<UpdateUserCommand, void>::Invocation::typedRun(OperationContext uassertStatusOK(status); } -CmdUMCTyped<DropUserCommand, void> cmdDropUser; +CmdUMCTyped<DropUserCommand> cmdDropUser; template <> -void CmdUMCTyped<DropUserCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<DropUserCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); UserName userName(cmd.getCommandParameter(), dbname); @@ -1218,11 +1218,9 @@ void CmdUMCTyped<DropUserCommand, void>::Invocation::typedRun(OperationContext* numMatched > 0); } -CmdUMCTyped<DropAllUsersFromDatabaseCommand, DropAllUsersFromDatabaseReply> - cmdDropAllUsersFromDatabase; +CmdUMCTyped<DropAllUsersFromDatabaseCommand> cmdDropAllUsersFromDatabase; template <> -DropAllUsersFromDatabaseReply -CmdUMCTyped<DropAllUsersFromDatabaseCommand, DropAllUsersFromDatabaseReply>::Invocation::typedRun( +DropAllUsersFromDatabaseReply CmdUMCTyped<DropAllUsersFromDatabaseCommand>::Invocation::typedRun( OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); @@ -1247,9 +1245,9 @@ CmdUMCTyped<DropAllUsersFromDatabaseCommand, DropAllUsersFromDatabaseReply>::Inv return reply; } -CmdUMCTyped<GrantRolesToUserCommand, void> cmdGrantRolesToUser; +CmdUMCTyped<GrantRolesToUserCommand> cmdGrantRolesToUser; template <> -void CmdUMCTyped<GrantRolesToUserCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<GrantRolesToUserCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); UserName userName(cmd.getCommandParameter(), dbname); @@ -1282,9 +1280,9 @@ void CmdUMCTyped<GrantRolesToUserCommand, void>::Invocation::typedRun(OperationC uassertStatusOK(status); } -CmdUMCTyped<RevokeRolesFromUserCommand, void> cmdRevokeRolesFromUser; +CmdUMCTyped<RevokeRolesFromUserCommand> cmdRevokeRolesFromUser; template <> -void CmdUMCTyped<RevokeRolesFromUserCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<RevokeRolesFromUserCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); UserName userName(cmd.getCommandParameter(), dbname); @@ -1317,9 +1315,9 @@ void CmdUMCTyped<RevokeRolesFromUserCommand, void>::Invocation::typedRun(Operati uassertStatusOK(status); } -CmdUMCTyped<UsersInfoCommand, UsersInfoReply, UMCInfoParams> cmdUsersInfo; +CmdUMCTyped<UsersInfoCommand, UMCInfoParams> cmdUsersInfo; template <> -UsersInfoReply CmdUMCTyped<UsersInfoCommand, UsersInfoReply, UMCInfoParams>::Invocation::typedRun( +UsersInfoReply CmdUMCTyped<UsersInfoCommand, UMCInfoParams>::Invocation::typedRun( OperationContext* opCtx) { const auto& cmd = request(); const auto& arg = cmd.getCommandParameter(); @@ -1446,9 +1444,9 @@ UsersInfoReply CmdUMCTyped<UsersInfoCommand, UsersInfoReply, UMCInfoParams>::Inv return reply; } -CmdUMCTyped<CreateRoleCommand, void> cmdCreateRole; +CmdUMCTyped<CreateRoleCommand> cmdCreateRole; template <> -void CmdUMCTyped<CreateRoleCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<CreateRoleCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); @@ -1499,9 +1497,9 @@ void CmdUMCTyped<CreateRoleCommand, void>::Invocation::typedRun(OperationContext uassertStatusOK(insertRoleDocument(opCtx, roleObjBuilder.done())); } -CmdUMCTyped<UpdateRoleCommand, void> cmdUpdateRole; +CmdUMCTyped<UpdateRoleCommand> cmdUpdateRole; template <> -void CmdUMCTyped<UpdateRoleCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<UpdateRoleCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); RoleName roleName(cmd.getCommandParameter(), dbname); @@ -1574,10 +1572,9 @@ void CmdUMCTyped<UpdateRoleCommand, void>::Invocation::typedRun(OperationContext uassertStatusOK(status); } -CmdUMCTyped<GrantPrivilegesToRoleCommand, void> cmdGrantPrivilegesToRole; +CmdUMCTyped<GrantPrivilegesToRoleCommand> cmdGrantPrivilegesToRole; template <> -void CmdUMCTyped<GrantPrivilegesToRoleCommand, void>::Invocation::typedRun( - OperationContext* opCtx) { +void CmdUMCTyped<GrantPrivilegesToRoleCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); RoleName roleName(cmd.getCommandParameter(), dbname); @@ -1624,10 +1621,9 @@ void CmdUMCTyped<GrantPrivilegesToRoleCommand, void>::Invocation::typedRun( uassertStatusOK(status); } -CmdUMCTyped<RevokePrivilegesFromRoleCommand, void> cmdRevokePrivilegesFromRole; +CmdUMCTyped<RevokePrivilegesFromRoleCommand> cmdRevokePrivilegesFromRole; template <> -void CmdUMCTyped<RevokePrivilegesFromRoleCommand, void>::Invocation::typedRun( - OperationContext* opCtx) { +void CmdUMCTyped<RevokePrivilegesFromRoleCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); RoleName roleName(cmd.getCommandParameter(), dbname); @@ -1679,9 +1675,9 @@ void CmdUMCTyped<RevokePrivilegesFromRoleCommand, void>::Invocation::typedRun( uassertStatusOK(status); } -CmdUMCTyped<GrantRolesToRoleCommand, void> cmdGrantRolesToRole; +CmdUMCTyped<GrantRolesToRoleCommand> cmdGrantRolesToRole; template <> -void CmdUMCTyped<GrantRolesToRoleCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<GrantRolesToRoleCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); RoleName roleName(cmd.getCommandParameter(), dbname); @@ -1719,9 +1715,9 @@ void CmdUMCTyped<GrantRolesToRoleCommand, void>::Invocation::typedRun(OperationC uassertStatusOK(status); } -CmdUMCTyped<RevokeRolesFromRoleCommand, void> cmdRevokeRolesFromRole; +CmdUMCTyped<RevokeRolesFromRoleCommand> cmdRevokeRolesFromRole; template <> -void CmdUMCTyped<RevokeRolesFromRoleCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<RevokeRolesFromRoleCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); RoleName roleName(cmd.getCommandParameter(), dbname); @@ -1824,9 +1820,9 @@ Status retryTransactionOps(OperationContext* opCtx, return status; } -CmdUMCTyped<DropRoleCommand, void> cmdDropRole; +CmdUMCTyped<DropRoleCommand> cmdDropRole; template <> -void CmdUMCTyped<DropRoleCommand, void>::Invocation::typedRun(OperationContext* opCtx) { +void CmdUMCTyped<DropRoleCommand>::Invocation::typedRun(OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); RoleName roleName(cmd.getCommandParameter(), dbname); @@ -1890,11 +1886,9 @@ void CmdUMCTyped<DropRoleCommand, void>::Invocation::typedRun(OperationContext* } } -CmdUMCTyped<DropAllRolesFromDatabaseCommand, DropAllRolesFromDatabaseReply> - cmdDropAllRolesFromDatabase; +CmdUMCTyped<DropAllRolesFromDatabaseCommand> cmdDropAllRolesFromDatabase; template <> -DropAllRolesFromDatabaseReply -CmdUMCTyped<DropAllRolesFromDatabaseCommand, DropAllRolesFromDatabaseReply>::Invocation::typedRun( +DropAllRolesFromDatabaseReply CmdUMCTyped<DropAllRolesFromDatabaseCommand>::Invocation::typedRun( OperationContext* opCtx) { const auto& cmd = request(); const auto& dbname = cmd.getDbName(); @@ -1986,9 +1980,9 @@ CmdUMCTyped<DropAllRolesFromDatabaseCommand, DropAllRolesFromDatabaseReply>::Inv * these roles. This format may change over time with changes to the auth * schema. */ -CmdUMCTyped<RolesInfoCommand, RolesInfoReply, UMCInfoParams> cmdRolesInfo; +CmdUMCTyped<RolesInfoCommand, UMCInfoParams> cmdRolesInfo; template <> -RolesInfoReply CmdUMCTyped<RolesInfoCommand, RolesInfoReply, UMCInfoParams>::Invocation::typedRun( +RolesInfoReply CmdUMCTyped<RolesInfoCommand, UMCInfoParams>::Invocation::typedRun( OperationContext* opCtx) { const auto& cmd = request(); const auto& arg = cmd.getCommandParameter(); @@ -2036,21 +2030,20 @@ RolesInfoReply CmdUMCTyped<RolesInfoCommand, RolesInfoReply, UMCInfoParams>::Inv return reply; } -CmdUMCTyped<InvalidateUserCacheCommand, void, UMCCacheParams> cmdInvalidateUserCache; +CmdUMCTyped<InvalidateUserCacheCommand, UMCCacheParams> cmdInvalidateUserCache; template <> -void CmdUMCTyped<InvalidateUserCacheCommand, void, UMCCacheParams>::Invocation::typedRun( +void CmdUMCTyped<InvalidateUserCacheCommand, UMCCacheParams>::Invocation::typedRun( OperationContext* opCtx) { auto* authzManager = AuthorizationManager::get(opCtx->getServiceContext()); auto lk = requireReadableAuthSchema26Upgrade(opCtx, authzManager); authzManager->invalidateUserCache(opCtx); } -CmdUMCTyped<GetUserCacheGenerationCommand, GetUserCacheGenerationReply, UMCCacheParams> - cmdGetUserCacheGeneration; +CmdUMCTyped<GetUserCacheGenerationCommand, UMCCacheParams> cmdGetUserCacheGeneration; template <> GetUserCacheGenerationReply -CmdUMCTyped<GetUserCacheGenerationCommand, GetUserCacheGenerationReply, UMCCacheParams>:: - Invocation::typedRun(OperationContext* opCtx) { +CmdUMCTyped<GetUserCacheGenerationCommand, UMCCacheParams>::Invocation::typedRun( + OperationContext* opCtx) { uassert(ErrorCodes::IllegalOperation, "_getUserCacheGeneration can only be run on config servers", serverGlobalParams.clusterRole == ClusterRole::ConfigServer); |