summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/address_restriction.cpp
diff options
context:
space:
mode:
authorSara Golemon <sara.golemon@mongodb.com>2017-07-12 09:43:25 -0400
committerSpencer Jackson <spencer.jackson@mongodb.com>2017-07-13 17:44:29 -0400
commitacf804c56e1043a5c3e0c8953c78d35b9775f96b (patch)
tree8d4c399e5cfb3d43ac4632ae426182d51c6ba14d /src/mongo/db/auth/address_restriction.cpp
parente1cae24805e3e7282958ee67a01555dd6ce40039 (diff)
downloadmongo-acf804c56e1043a5c3e0c8953c78d35b9775f96b.tar.gz
SERVER-29171: Implement Restriction BSON IDL serializer/deserializer
Diffstat (limited to 'src/mongo/db/auth/address_restriction.cpp')
-rw-r--r--src/mongo/db/auth/address_restriction.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/mongo/db/auth/address_restriction.cpp b/src/mongo/db/auth/address_restriction.cpp
index e876d34b127..8b2de7770bd 100644
--- a/src/mongo/db/auth/address_restriction.cpp
+++ b/src/mongo/db/auth/address_restriction.cpp
@@ -29,15 +29,36 @@
#include "mongo/platform/basic.h"
#include "mongo/db/auth/address_restriction.h"
+#include "mongo/db/auth/address_restriction_gen.h"
+#include "mongo/stdx/memory.h"
-namespace mongo {
-namespace address_restriction_detail {
+constexpr mongo::StringData mongo::address_restriction_detail::ClientSource::label;
+constexpr mongo::StringData mongo::address_restriction_detail::ClientSource::field;
-constexpr StringData ClientSource::label;
-constexpr StringData ClientSource::field;
+constexpr mongo::StringData mongo::address_restriction_detail::ServerAddress::label;
+constexpr mongo::StringData mongo::address_restriction_detail::ServerAddress::field;
-constexpr StringData ServerAddress::label;
-constexpr StringData ServerAddress::field;
+mongo::StatusWith<mongo::RestrictionSet<>> mongo::parseAddressRestrictionSet(
+ const BSONObj& obj) try {
+ IDLParserErrorContext ctx("address restriction");
+ const auto ar = Address_restriction::parse(ctx, obj);
+ std::vector<std::unique_ptr<Restriction>> vec;
-} // address_restriction_detail
-} // mongo
+ const boost::optional<std::vector<StringData>>& client = ar.getClientSource();
+ if (client) {
+ vec.push_back(stdx::make_unique<ClientSourceRestriction>(client.get()));
+ }
+
+ const boost::optional<std::vector<StringData>>& server = ar.getServerAddress();
+ if (server) {
+ vec.push_back(stdx::make_unique<ServerAddressRestriction>(server.get()));
+ }
+
+ if (vec.empty()) {
+ return Status(ErrorCodes::CollectionIsEmpty,
+ "At least one of 'clientSource' or 'serverAddress' must be set");
+ }
+ return RestrictionSet<>(std::move(vec));
+} catch (const DBException& e) {
+ return Status(ErrorCodes::BadValue, e.what());
+}