diff options
author | Rishab Joshi <rishab.joshi@mongodb.com> | 2021-02-19 06:20:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-19 09:32:47 +0000 |
commit | b785ca3a3d785814ac7201d5a7d52e718df7e689 (patch) | |
tree | ca0f6c2aa5a3ccd142ca8894fda6939f240c398d /src/mongo/s/query/cluster_aggregate.cpp | |
parent | a40e23d8613ad123e26112a61e26963909f1fa07 (diff) | |
download | mongo-b785ca3a3d785814ac7201d5a7d52e718df7e689.tar.gz |
SERVER-54072 Added internal-client checks for aggregation command.
Diffstat (limited to 'src/mongo/s/query/cluster_aggregate.cpp')
-rw-r--r-- | src/mongo/s/query/cluster_aggregate.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/mongo/s/query/cluster_aggregate.cpp b/src/mongo/s/query/cluster_aggregate.cpp index fa0d714d31c..1a2cdb8467f 100644 --- a/src/mongo/s/query/cluster_aggregate.cpp +++ b/src/mongo/s/query/cluster_aggregate.cpp @@ -188,6 +188,21 @@ void updateHostsTargetedMetrics(OperationContext* opCtx, } } +/** + * Performs validations related to API versioning before running the aggregation command. + * Throws uassert if any of the validations fails + * - validation on each stage on the pipeline + * - validation on 'AggregateCommand' request + */ +void performAPIVersionChecks(const OperationContext* opCtx, + const AggregateCommand& request, + const LiteParsedPipeline& liteParsedPipeline) { + invariant(opCtx); + + liteParsedPipeline.validatePipelineStagesforAPIVersion(opCtx); + aggregation_request_helper::validateRequestForAPIVersion(opCtx, request); +} + } // namespace Status ClusterAggregate::runAggregate(OperationContext* opCtx, @@ -204,14 +219,8 @@ Status ClusterAggregate::runAggregate(OperationContext* opCtx, const LiteParsedPipeline& liteParsedPipeline, const PrivilegeVector& privileges, BSONObjBuilder* result) { - // If 'apiStrict: true', validates that the pipeline does not contain stages which are not in - // this API version. - auto apiParameters = APIParameters::get(opCtx); - if (apiParameters.getAPIStrict().value_or(false)) { - auto apiVersion = apiParameters.getAPIVersion().value_or(""); - if (!apiVersion.empty()) - liteParsedPipeline.validatePipelineStagesIfAPIStrict(apiVersion); - } + // Perform API versioning validation checks. + performAPIVersionChecks(opCtx, request, liteParsedPipeline); uassert(51028, "Cannot specify exchange option to a mongos", !request.getExchange()); uassert(51143, |