Giter Club home page Giter Club logo

mosquitto-acl-parser's Introduction

mosquitto-acl-parser

NPM version Dependency Status Build Status Coverage Status XO code style License

Parse and Stringify Mosquitto ACLs

This tiny module parses Mosquitto ACLs into a Javascript object and stringifies objects back into a ACL string.

Usage

npm install mosquitto-acl-parser

.parse(string)

const macl = require('mosquitto-acl-parser');

const acl = macl.parse(`# This affects access control for clients with no username.
topic read $SYS/#

# This only affects clients with username "roger".
user roger
topic foo/bar

# This affects all clients.
pattern write $SYS/broker/connection/%c/state`);

acl contains then...

{
  "topics": [
    {
      "perm": "read",
      "topic": "$SYS/#"
    }
  ],
  "users": {
    "roger": [
      {
        "perm": "readwrite",
        "topic": "foo/bar"
      }
    ]
  },
  "patterns": [
    {
      "perm": "write",
      "topic": "$SYS/broker/connection/%c/state"
    }
  ]
}

.stringify(acl)

const macl = require('mosquitto-acl-parser');

console.log(macl.stringify({
    topics: [
        {
            perm: 'read',
            topic: 'everyone/can/read  '
        },
        {
            perm: 'readwrite',
            topic: 'everyone/can/readwrite'
        }
    ],
    users: {
        user1: [
            {
                perm: 'read',
                topic: 'user1/can/read'
            },
            {
                perm: 'readwrite',
                topic: 'user1/can/readwrite'
            }
        ],
        user2: [
            {
                perm: 'read',
                topic: 'user2/can/read'
            },
            {
                perm: 'readwrite',
                topic: 'user2/can/readwrite'
            }
        ]
    },
    patterns: [
        {
            perm: 'read',
            topic: 'pattern/%u/can/read'
        },
        {
            perm: 'readwrite',
            topic: 'pattern/%u/can/readwrite'
        }
    ]
}));

Outputs...

# created by mosquitto-acl-parser

topic read everyone/can/read  
topic readwrite everyone/can/readwrite

user user1
topic read user1/can/read
topic readwrite user1/can/readwrite

user user2
topic read user2/can/read
topic readwrite user2/can/readwrite

pattern read pattern/%u/can/read
pattern readwrite pattern/%u/can/readwrite

License

MIT (c) 2017 Sebastian Raff

mosquitto-acl-parser's People

Contributors

hobbyquaker avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.