Skip to content

Instantly share code, notes, and snippets.

@EdoGimo
Last active December 30, 2021 21:24
Show Gist options
  • Save EdoGimo/d9df53b07308813a6cb28511180351ed to your computer and use it in GitHub Desktop.
Save EdoGimo/d9df53b07308813a6cb28511180351ed to your computer and use it in GitHub Desktop.
AccessControl nodes interactions with MongoDB

An example of joint use of the accesscontrol and mongodb nodes.

Requirements

How to

First, change the MongoDB settings to connect with it.

The 5 flows included are:

  • Export: creates the permissions, which tests and exports to MongoDB;
  • Print: prints all the documents in MongoDB;
  • Init: removes all permissions from memory (not on MongoDB);
  • Import: retrieves the correct document from MongoDB.
  • Purge DB: deletes the whole collection on the specified MongoDB server (caution!).

Use the flows in this order to create some permissions and import them on MongoDB, print the saved documents, initialize the AccessControl memory, import from MongoDB and check the permissions are correct. Then, delete everything.

[
{
"id": "6bd95b6b501c544e",
"type": "inject",
"z": "f9dfd849f78bbbe2",
"name": "Export",
"props": [
{
"p": "payload"
},
{
"p": "role",
"v": "role1",
"vt": "str"
},
{
"p": "object",
"v": "object",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 110,
"y": 300,
"wires": [
[
"66ead65da9417dc2"
]
]
},
{
"id": "66ead65da9417dc2",
"type": "AC init",
"z": "f9dfd849f78bbbe2",
"name": "",
"force": true,
"check": true,
"outputs": 1,
"x": 150,
"y": 340,
"wires": [
[
"2fe710cb1ace6b79"
]
],
"info": "Initialize the AccessControl module."
},
{
"id": "2fe710cb1ace6b79",
"type": "AC grant",
"z": "f9dfd849f78bbbe2",
"name": "",
"who": "role",
"whoType": "msg",
"createAny": "true",
"createAnyType": "bool",
"createOwn": "false",
"createOwnType": "bool",
"create": "database",
"createType": "str",
"readAny": "false",
"readAnyType": "bool",
"readOwn": "false",
"readOwnType": "bool",
"read": "",
"readType": "str",
"updateAny": "false",
"updateAnyType": "bool",
"updateOwn": "false",
"updateOwnType": "bool",
"update": "",
"updateType": "str",
"deleteAny": "false",
"deleteAnyType": "bool",
"deleteOwn": "false",
"deleteOwnType": "bool",
"delete": "",
"deleteType": "str",
"what": "object",
"whatType": "msg",
"x": 270,
"y": 340,
"wires": [
[
"d145c0ddeaba5ed9",
"96ccd63c4c5096c2"
]
],
"info": "Grants update permissions to _role_ on _object_, with attributes _[one,two,three]_."
},
{
"id": "d145c0ddeaba5ed9",
"type": "AC permissions",
"z": "f9dfd849f78bbbe2",
"name": "",
"who": "role",
"whoType": "msg",
"createAny": "true",
"createAnyType": "bool",
"createOwn": "false",
"createOwnType": "bool",
"readAny": "false",
"readAnyType": "bool",
"readOwn": "false",
"readOwnType": "bool",
"updateAny": "false",
"updateAnyType": "bool",
"updateOwn": "false",
"updateOwnType": "bool",
"deleteAny": "false",
"deleteAnyType": "bool",
"deleteOwn": "false",
"deleteOwnType": "bool",
"what": "object",
"whatType": "msg",
"x": 430,
"y": 340,
"wires": [
[
"637559dc6bbe1da2"
]
]
},
{
"id": "637559dc6bbe1da2",
"type": "debug",
"z": "f9dfd849f78bbbe2",
"name": "Payload",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 600,
"y": 340,
"wires": []
},
{
"id": "96ccd63c4c5096c2",
"type": "AC grant",
"z": "f9dfd849f78bbbe2",
"name": "",
"who": "role2",
"whoType": "str",
"createAny": "false",
"createAnyType": "bool",
"createOwn": "false",
"createOwnType": "bool",
"create": "",
"createType": "str",
"readAny": "false",
"readAnyType": "bool",
"readOwn": "true",
"readOwnType": "bool",
"read": "",
"readType": "str",
"updateAny": "true",
"updateAnyType": "bool",
"updateOwn": "false",
"updateOwnType": "bool",
"update": "dataset, database",
"updateType": "str",
"deleteAny": "false",
"deleteAnyType": "bool",
"deleteOwn": "true",
"deleteOwnType": "bool",
"delete": "",
"deleteType": "str",
"what": "object",
"whatType": "str",
"x": 270,
"y": 400,
"wires": [
[
"216b1151ca770bcc",
"a350503a31f06fb5"
]
],
"info": "Grants update permissions to _role_ on _object_, with attributes _[one,two,three]_."
},
{
"id": "216b1151ca770bcc",
"type": "AC permissions",
"z": "f9dfd849f78bbbe2",
"name": "",
"who": "role2",
"whoType": "str",
"createAny": "false",
"createAnyType": "bool",
"createOwn": "false",
"createOwnType": "bool",
"readAny": "false",
"readAnyType": "bool",
"readOwn": "true",
"readOwnType": "bool",
"updateAny": "true",
"updateAnyType": "bool",
"updateOwn": "true",
"updateOwnType": "bool",
"deleteAny": "false",
"deleteAnyType": "bool",
"deleteOwn": "true",
"deleteOwnType": "bool",
"what": "object",
"whatType": "str",
"x": 430,
"y": 400,
"wires": [
[
"0bc53286532a2ca6"
]
]
},
{
"id": "0bc53286532a2ca6",
"type": "debug",
"z": "f9dfd849f78bbbe2",
"name": "Payload",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 600,
"y": 400,
"wires": []
},
{
"id": "a350503a31f06fb5",
"type": "AC export",
"z": "f9dfd849f78bbbe2",
"name": "",
"mongo": "accesscontrol",
"mongoType": "str",
"x": 220,
"y": 460,
"wires": [
[
"3d01d5586d644fa0"
]
]
},
{
"id": "3d01d5586d644fa0",
"type": "mongodb out",
"z": "f9dfd849f78bbbe2",
"mongodb": "9acf517e79c080cb",
"name": "",
"collection": "user",
"payonly": true,
"upsert": false,
"multi": true,
"operation": "store",
"x": 510,
"y": 460,
"wires": []
},
{
"id": "3ecb45d3b1316168",
"type": "inject",
"z": "f9dfd849f78bbbe2",
"name": "Print",
"props": [
{
"p": "payload"
},
{
"p": "role",
"v": "role",
"vt": "str"
},
{
"p": "object",
"v": "object",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 110,
"y": 540,
"wires": [
[
"2f167037eb4b9dc7"
]
]
},
{
"id": "2f167037eb4b9dc7",
"type": "mongodb in",
"z": "f9dfd849f78bbbe2",
"mongodb": "9acf517e79c080cb",
"name": "",
"collection": "user",
"operation": "find",
"x": 350,
"y": 540,
"wires": [
[
"5545f2bdcd989021"
]
]
},
{
"id": "5545f2bdcd989021",
"type": "debug",
"z": "f9dfd849f78bbbe2",
"name": "Payload",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 600,
"y": 540,
"wires": []
},
{
"id": "0190f1fec0a848e9",
"type": "inject",
"z": "f9dfd849f78bbbe2",
"name": "Purge DB",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{}",
"payloadType": "json",
"x": 120,
"y": 880,
"wires": [
[
"e88c9dfd08440746"
]
]
},
{
"id": "e88c9dfd08440746",
"type": "mongodb out",
"z": "f9dfd849f78bbbe2",
"mongodb": "9acf517e79c080cb",
"name": "",
"collection": "user",
"payonly": false,
"upsert": true,
"multi": true,
"operation": "delete",
"x": 350,
"y": 880,
"wires": []
},
{
"id": "1a5cc563186440e5",
"type": "inject",
"z": "f9dfd849f78bbbe2",
"name": "Import",
"props": [
{
"p": "payload"
},
{
"p": "role",
"v": "role",
"vt": "str"
},
{
"p": "object",
"v": "object",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 110,
"y": 700,
"wires": [
[
"0f3829d6c608d14e"
]
]
},
{
"id": "0f3829d6c608d14e",
"type": "mongodb in",
"z": "f9dfd849f78bbbe2",
"mongodb": "9acf517e79c080cb",
"name": "",
"collection": "user",
"operation": "find",
"x": 350,
"y": 700,
"wires": [
[
"383e29b18996083d"
]
]
},
{
"id": "383e29b18996083d",
"type": "AC import",
"z": "f9dfd849f78bbbe2",
"name": "",
"mongo": "accesscontrol",
"mongoType": "str",
"x": 250,
"y": 780,
"wires": [
[
"184c4fc4d5a3b163",
"e3686ae06a454bfa"
]
]
},
{
"id": "184c4fc4d5a3b163",
"type": "AC permissions",
"z": "f9dfd849f78bbbe2",
"name": "",
"who": "role2",
"whoType": "str",
"createAny": "false",
"createAnyType": "bool",
"createOwn": "false",
"createOwnType": "bool",
"readAny": "false",
"readAnyType": "bool",
"readOwn": "true",
"readOwnType": "bool",
"updateAny": "true",
"updateAnyType": "bool",
"updateOwn": "true",
"updateOwnType": "bool",
"deleteAny": "false",
"deleteAnyType": "bool",
"deleteOwn": "true",
"deleteOwnType": "bool",
"what": "object",
"whatType": "str",
"x": 430,
"y": 800,
"wires": [
[
"665d0af6e9b0168a"
]
]
},
{
"id": "eebd0a3aa3bb1b57",
"type": "inject",
"z": "f9dfd849f78bbbe2",
"name": "Init",
"props": [
{
"p": "payload"
},
{
"p": "role",
"v": "role1",
"vt": "str"
},
{
"p": "object",
"v": "object",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 110,
"y": 620,
"wires": [
[
"b31ac91491bf4efa"
]
]
},
{
"id": "b31ac91491bf4efa",
"type": "AC init",
"z": "f9dfd849f78bbbe2",
"name": "",
"force": true,
"x": 250,
"y": 620,
"wires": [],
"info": "Initialize the AccessControl module."
},
{
"id": "e3686ae06a454bfa",
"type": "AC permissions",
"z": "f9dfd849f78bbbe2",
"name": "",
"who": "role1",
"whoType": "str",
"createAny": "true",
"createAnyType": "bool",
"createOwn": "false",
"createOwnType": "bool",
"readAny": "false",
"readAnyType": "bool",
"readOwn": "false",
"readOwnType": "bool",
"updateAny": "false",
"updateAnyType": "bool",
"updateOwn": "false",
"updateOwnType": "bool",
"deleteAny": "false",
"deleteAnyType": "bool",
"deleteOwn": "false",
"deleteOwnType": "bool",
"what": "object",
"whatType": "str",
"x": 430,
"y": 760,
"wires": [
[
"665d0af6e9b0168a"
]
]
},
{
"id": "665d0af6e9b0168a",
"type": "debug",
"z": "f9dfd849f78bbbe2",
"name": "Payload",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 600,
"y": 780,
"wires": []
},
{
"id": "9acf517e79c080cb",
"type": "mongodb",
"hostname": "mongodb-server",
"topology": "direct",
"connectOptions": "",
"port": "27017",
"db": "newdb",
"name": ""
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment