UNPKG

@getanthill/datastore

Version:

Event-Sourced Datastore

167 lines 4.71 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.properties = void 0; const c = __importStar(require("../../../constants")); const MODEL_DATABASE = 'datastore'; const MODEL_NAME = 'policies'; const MODEL_DESCRIPTION = 'ABAC authorization policies'; const CORRELATION_FIELD = 'policy_id'; const is_enabled = c.COMPONENTS.is_enabled; const name = { ...c.COMPONENT_TAG_SNAKECASE, description: 'Name of the policy', }; const description = { ...c.COMPONENT_STRING, description: 'Description of this policy', }; const verb = { ...c.COMPONENT_STRING, description: 'Policy verb after rules validation', enum: ['allow', 'deny'], }; const schema = { type: 'object', description: 'JSON Schema', }; const rule = { type: 'object', required: ['name', 'action', 'subject', 'object', 'context'], properties: { name: { ...c.COMPONENT_TAG_SNAKECASE, description: 'Rule name', }, description: { ...c.COMPONENT_STRING, description: 'Rule description', }, subject: schema, action: schema, object: schema, context: schema, }, }; const rules = { type: 'array', description: 'List of rules', items: rule, minItems: 1, }; const obligation = { type: 'object', required: ['name', 'type', 'source'], properties: { name: { ...c.COMPONENT_TAG_SNAKECASE, description: 'Obligation name', }, description: { ...c.COMPONENT_STRING, description: 'Obligation description', }, type: { type: 'string', description: 'Type of the obligation', enum: ['patch', 'pick'], }, source: { type: 'string', description: 'Source of the request to apply the obligation on', enum: ['body', 'query', 'payload', 'headers'], }, value: { description: 'Value associated to the obligation', anyOf: [ { type: 'string' }, { type: 'number' }, { type: 'boolean' }, { type: 'object' }, { type: 'array' }, ], }, }, }; const obligations = { type: 'array', description: 'List of obligations', items: obligation, }; const scope = { ...c.COMPONENT_TAGS_SNAKECASE, description: 'Scope of the policy', minItems: 1, }; exports.properties = { is_enabled, name, description, scope, verb, rules, obligations, }; const modelConfig = { is_enabled: true, is_internal: true, db: MODEL_DATABASE, name: MODEL_NAME, description: MODEL_DESCRIPTION, correlation_field: CORRELATION_FIELD, schema: { model: { properties: exports.properties, }, events: { [c.EVENT_TYPE_CREATED]: { '0_0_0': { properties: exports.properties, }, }, [c.EVENT_TYPE_UPDATED]: { '0_0_0': { properties: exports.properties, }, }, [c.EVENT_TYPE_RESTORED]: { '0_0_0': { properties: exports.properties, }, }, }, }, indexes: [ { collection: MODEL_NAME, fields: { scope: 1, is_enabled: 1 }, opts: { name: 'scope_1_is_enabled_1', }, }, ], }; exports.default = modelConfig; //# sourceMappingURL=policies.js.map