0.17.1 • Published 4 years ago

@rule.js/access-mate-elasticsearch v0.17.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Access Mate: Elasticsearch Converter

Convert Access-Mate access control lists to Elasticsearch filters.

Usage:

const AccessMate = require('@rule.js/access-mate')
const toElasticsearch = require('@rule.js/access-mate-elasticsearch')

const policies = AccessMate.policySet()
	.allow()
	.name('view any todo')
	.target('todo')
	.action('read')
	.condition()
	.true('subject.admin')
	.end()

	.allow()
	.name('read own todos')
	.target('todo')
	.action('read')
	.condition()
	.propsEqual('resource.owner', 'subject.id')
	.end()

	.deny()
	.name('read private todos')
	.target('todo')
	.action('read')
	.condition()
	.true('resource.private')
	.end()

	.end()

const filter = toElasticsearch(policies, {
	target: 'todo',
	action: 'read',
	subject: {
		id: 1,
		admin: false
	},
	environment: {}
})

console.log(JSON.stringify(filter, null, 2))

Would print the following:

{
  "bool": {
    "should": [
      {
        "bool": {
          "must": [
            {
              "match_none": {}
            }
          ]
        }
      },
      {
        "bool": {
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "term": {
                      "owner": 1
                    }
                  }
                ]
              }
            },
            {
              "bool": {
                "must_not": {
                  "bool": {
                    "must": [
                      {
                        "term": {
                          "private": true
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    ]
  }
}
0.17.1

4 years ago

0.17.0

5 years ago

0.16.1

5 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago