diff options
author | PV99 <pridhvi.vegesna@mongodb.com> | 2020-07-14 22:34:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-17 00:43:31 +0000 |
commit | cfd99814027a4972be64742b3dd3de2695c88b84 (patch) | |
tree | 8f5ad9ad0a3a08d8053a2bfb0f0d947dcac8dccb /src/mongo/db/initialize_api_parameters.cpp | |
parent | 8b9af875a947b862c6bf82754ae7eaf582a9ab3f (diff) | |
download | mongo-cfd99814027a4972be64742b3dd3de2695c88b84.tar.gz |
SERVER-48877 Create an APIParameters class
Diffstat (limited to 'src/mongo/db/initialize_api_parameters.cpp')
-rw-r--r-- | src/mongo/db/initialize_api_parameters.cpp | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/src/mongo/db/initialize_api_parameters.cpp b/src/mongo/db/initialize_api_parameters.cpp index e6f31cbb8c5..c78f1d130f4 100644 --- a/src/mongo/db/initialize_api_parameters.cpp +++ b/src/mongo/db/initialize_api_parameters.cpp @@ -31,22 +31,55 @@ namespace mongo { -APIParametersFromClient initializeAPIParameters(const BSONObj& requestBody) { +const APIParametersFromClient initializeAPIParameters(const BSONObj& requestBody) { - auto vAPI = APIParametersFromClient::parse("APIParametersFromClient"_sd, requestBody); + auto apiParamsFromClient = + APIParametersFromClient::parse("APIParametersFromClient"_sd, requestBody); - if (vAPI.getApiDeprecationErrors() || vAPI.getApiStrict()) { + if (apiParamsFromClient.getApiDeprecationErrors() || apiParamsFromClient.getApiStrict()) { uassert(4886600, "Provided apiStrict and/or apiDeprecationErrors without passing apiVersion", - vAPI.getApiVersion()); + apiParamsFromClient.getApiVersion()); } - if (vAPI.getApiVersion()) { + if (apiParamsFromClient.getApiVersion()) { uassert(ErrorCodes::APIVersionError, "API version must be \"1\"", - "1" == vAPI.getApiVersion().value()); + "1" == apiParamsFromClient.getApiVersion().value()); } - return vAPI; + + return apiParamsFromClient; +} + +const OperationContext::Decoration<APIParameters> handle = + OperationContext::declareDecoration<APIParameters>(); + +APIParameters& APIParameters::get(OperationContext* opCtx) { + return handle(opCtx); +} + +APIParameters::APIParameters() + : _apiVersion("1"), _apiStrict(false), _apiDeprecationErrors(false) {} + +APIParameters APIParameters::fromClient(const APIParametersFromClient& apiParamsFromClient) { + APIParameters apiParameters = APIParameters(); + auto apiVersion = apiParamsFromClient.getApiVersion(); + auto apiStrict = apiParamsFromClient.getApiStrict(); + auto apiDeprecationErrors = apiParamsFromClient.getApiDeprecationErrors(); + + if (apiVersion) { + apiParameters.setAPIVersion(apiVersion.value()); + } + + if (apiStrict) { + apiParameters.setAPIStrict(apiStrict.value()); + } + + if (apiDeprecationErrors) { + apiParameters.setAPIDeprecationErrors(apiDeprecationErrors.value()); + } + + return apiParameters; } } // namespace mongo |