//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2018 ArangoDB GmbH, Cologne, Germany /// /// 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. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Frank Celler //////////////////////////////////////////////////////////////////////////////// #include "Collection.h" #include "Logger/Logger.h" using namespace arangodb; using namespace arangodb::maskings; ParseResult Collection::parse(Maskings* maskings, VPackSlice const& def) { if (!def.isObject()) { return ParseResult( ParseResult::PARSE_FAILED, "expecting an object for collection definition"); } std::string type = ""; std::vector attributes; for (auto const& entry : VPackObjectIterator(def, false)) { std::string key = entry.key.copyString(); if (key == "type") { if (!entry.value.isString()) { return ParseResult( ParseResult::ILLEGAL_PARAMETER, "expecting a string for collection type"); } type = entry.value.copyString(); } else if (key == "maskings") { if (!entry.value.isArray()) { return ParseResult( ParseResult::ILLEGAL_PARAMETER, "expecting an array for collection maskings"); } for (auto const& mask : VPackArrayIterator(entry.value)) { ParseResult am = AttributeMasking::parse(maskings, mask); if (am.status != ParseResult::VALID) { return ParseResult((ParseResult::StatusCode)( int)am.status, am.message); } attributes.push_back(am.result); } } } CollectionSelection selection = CollectionSelection::FULL; if (type == "full") { selection = CollectionSelection::FULL; } else if (type == "exclude") { selection = CollectionSelection::EXCLUDE; } else if (type == "masked") { selection = CollectionSelection::MASKED; } else if (type == "structure") { selection = CollectionSelection::STRUCTURE; } else { return ParseResult(ParseResult::UNKNOWN_TYPE, "found unknown collection type '" + type + "'"); } return ParseResult(Collection(selection, attributes)); } MaskingFunction* Collection::masking(std::vector const& path) { for (auto const& m : _maskings) { if (m.match(path)) { return m.func(); } } return nullptr; }