// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ #include <optional> #include <string> #include <vector> #include "absl/types/variant.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/types/expected.h" #include "base/values.h" #include "components/policy/policy_export.h" namespace policy { namespace internal { struct POLICY_EXPORT SchemaData; struct POLICY_EXPORT SchemaNode; struct POLICY_EXPORT PropertyNode; struct POLICY_EXPORT PropertiesNode; } // namespace internal // The error path, which leads to an error occurred. Members of the // error path can either be ints in case of list items or strings in case of // dictionary keys. PolicyErrorPath; // Returns a formatted string for a given error path |error_path|, consisting // of list indices and dict keys. // For example, ErrorPathToString("TestPolicy", {4, "testField"}) will be // encoded as "TestPolicy[4].testField" POLICY_EXPORT std::string ErrorPathToString(const std::string& policy_name, PolicyErrorPath error_path); // Option flags passed to Schema::Validate() and Schema::Normalize(), describing // the strategy to handle unknown properties or invalid values for dict type. // Note that in Schema::Normalize() allowed errors will be dropped and thus // ignored. // Unknown error indicates that some value in a dictionary (may or may not be // the one in root) have unknown property name according to schema. // Invalid error indicates a validation failure against the schema. As // validation is done recursively, a validation failure of dict properties or // list items might be ignored (or dropped in Normalize()) or trigger whole // dictionary/list validation failure. enum SchemaOnErrorStrategy { … }; // Schema validation options for Schema::ParseToDictAndValidate(). constexpr int kSchemaOptionsNone = …; constexpr int kSchemaOptionsIgnoreUnknownAttributes = …; // String used to hide sensitive policy values. // It should be consistent with the mask |NetworkConfigurationPolicyHandler| // uses for network credential fields. extern const char kSensitiveValueMask[]; class Schema; SchemaList; // Describes the expected type of one policy. Also recursively describes the // types of inner elements, for structured types. // Objects of this class refer to external, immutable data and are cheap to // copy. // // See components/policy/core/common/json_schema_constants.h for a list of // supported features and data types. Only these features and data-types are // supported and enforced. For the full schema proposal see // https://json-schema.org/understanding-json-schema/index.html. // // There are also these departures from the proposal: // - "additionalProperties": false is not supported. The value of // "additionalProperties" has to be a schema if present. Otherwise, the // behavior for unknown attributes is controlled by |SchemaOnErrorStrategy|. // - "sensitiveValue" (bool) marks a value to be sensitive. This is used to // mask those values in the UI by calling |MaskSensitiveValues()|. class POLICY_EXPORT Schema { … }; } // namespace policy #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_