All Projects → ehmicky → Unix Permissions

ehmicky / Unix Permissions

Licence: apache-2.0
Swiss Army knife for Unix permissions

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects
es6
455 projects

Projects that are alternatives of or similar to Unix Permissions

Ngx Permissions
Permission and roles based access control for your angular(angular 2,4,5,6,7,9+) applications(AOT, lazy modules compatible
Stars: ✭ 749 (+606.6%)
Mutual labels:  permissions, acl, access-control, access
Libterm
iOS sandboxed terminal with Python, Lua and Clang
Stars: ✭ 348 (+228.3%)
Mutual labels:  cli, terminal, unix
Casbin4D
An authorization library that supports access control models like ACL, RBAC, ABAC in Delphi
Stars: ✭ 25 (-76.42%)
Mutual labels:  permissions, acl, access-control
Nve
Run any command on specific Node.js versions
Stars: ✭ 531 (+400.94%)
Mutual labels:  cli, terminal, library
ngx-access
Add access control to your components using hierarchical configuration with logical expressions.
Stars: ✭ 21 (-80.19%)
Mutual labels:  permissions, access, access-control
nova-permissions
Add Permissions based authorization for your Nova installation via User-based Roles and Permissions. Roles are defined in the database whereas Permissions are defined in the code base.
Stars: ✭ 115 (+8.49%)
Mutual labels:  permissions, acl, access-control
Whipper
Python CD-DA ripper preferring accuracy over speed
Stars: ✭ 517 (+387.74%)
Mutual labels:  cli, terminal, unix
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (+18.87%)
Mutual labels:  cli, terminal, library
Tabulate
Table Maker for Modern C++
Stars: ✭ 862 (+713.21%)
Mutual labels:  cli, terminal, library
Python Progressbar
Progressbar 2 - A progress bar for Python 2 and Python 3 - "pip install progressbar2"
Stars: ✭ 682 (+543.4%)
Mutual labels:  cli, terminal, library
Vakt
Attribute-based access control (ABAC) SDK for Python
Stars: ✭ 92 (-13.21%)
Mutual labels:  permissions, acl, access-control
Cross Platform Node Guide
📗 How to write cross-platform Node.js code
Stars: ✭ 1,161 (+995.28%)
Mutual labels:  cli, terminal, unix
Geo
🌎 A Bash utility for easy wan, lan, router, dns, mac address, and geolocation output, with clean stdout for piping
Stars: ✭ 225 (+112.26%)
Mutual labels:  cli, terminal, unix
rbac-tool
Rapid7 | insightCloudSec | Kubernetes RBAC Power Toys - Visualize, Analyze, Generate & Query
Stars: ✭ 546 (+415.09%)
Mutual labels:  permissions, acl, access-control
Saldl
A lightweight well-featured CLI downloader optimized for speed and early preview.
Stars: ✭ 203 (+91.51%)
Mutual labels:  cli, terminal, posix
Yaspin
A lightweight terminal spinner for Python with safe pipes and redirects 🎁
Stars: ✭ 413 (+289.62%)
Mutual labels:  cli, terminal, unix
Think Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in ThinkPHP 6.0 .
Stars: ✭ 155 (+46.23%)
Mutual labels:  permissions, acl, access-control
Ytfzf
A posix script to find and watch youtube videos from the terminal. (Without API)
Stars: ✭ 2,212 (+1986.79%)
Mutual labels:  cli, terminal, posix
Wunderbar
Simple horizontal bar chart printer for your terminal
Stars: ✭ 572 (+439.62%)
Mutual labels:  cli, terminal, library
Ed
A modern UNIX ed (line editor) clone written in Go
Stars: ✭ 44 (-58.49%)
Mutual labels:  cli, terminal, unix

Codecov Build Node Twitter Medium

Swiss Army knife for Unix permissions.

Unix file permissions can take many shapes: symbolic (ug+rw), octal (660) or a list of characters (drw-rw----). This library enables using any of these (instead of being limited to a single one) with any Node.js or CLI command.

This library can also perform operations on Unix permissions such as:

  • testing, setting and unsetting. Using bitwise operations (|, &, ^, ~) can be tedious and error-prone otherwise.
  • validating syntax.
  • normalizing. For example u+r,u+w can be shortened to u+rw.
  • inverting. For example a umask of 117 means new files will be created with 661 permissions.
  • checking the minimal or maximal permissions among a list of them. This can be useful to aggregate all the permissions of several files, e.g. during a directory recursion.

Permissions are manipulated as strings, not as file paths. This means you must use other utilities (such as chmod or stat) to get and set file permissions using those strings.

Examples

In JavaScript:

// Retrieve a file's permission as an object like
// `{ user: { write: false, read: true, ... }, ... }` instead of a number
convert.object(fs.statSync('/etc/passwd').mode)

// Set a file's permission using `symbolic` notation instead of a number
fs.chmod('/etc/passwd', convert.number('a=r'))

// Set a file's permission using `symbolic` notation instead of a number
fs.writeFile('/my/file', content, { mode: convert.number('a=r') })

// Disallow executing new files using `umask`
process.umask(convert.number(invert('a-x')))

// If your library takes Unix permissions as input, using
// `unix-permissions` under the hood lets your users choose their
// favorite Unix permissions type.
myLibrary.method({ mode: 'a-wx' })
myLibrary.method({ mode: '444' })

On the command line:

$ stat -c "%a" /etc/passwd
644

$ unix-permissions convert.symbolic "$(stat -c "%a" /etc/passwd)"
u=rw,go=r

Demo

You can try this library:

Install

npm install unix-permissions

Usage (JavaScript)

const { convert } = require('unix-permissions')

// `permission` will be set to `rw-rw----`
const permission = convert.stat('660')

Several methods other than convert are available but they mostly follow the same pattern. Permission strings are passed as input and returned as output.

Usage (CLI)

$ unix-permissions convert.stat 660
rw-rw----

The same methods as in JavaScript are available. Exit code will be 1 if an error occurred, e.g. if the permission syntax is invalid.

Permission types

You can use any of the following permission types as input. You can also convert() between them:

  • octal strings like "422"
  • decimal number like 274
  • stat like rw-rw-r--
  • symbolic like a+rw
  • object like { user: { read: true, write: false, execute: false }, group: { write: false }, others: { write: false } }

Special permissions (setuid, setgid, sticky) can be used.

Please see the types full documentation.

Methods

convert.octal|number|stat|symbolic|object(permission)

Converts permission to another type.
Full documentation.

type(permission)

Returns the permission's type or invalid.
Full documentation.

normalize(permission)

Normalizes a permission to its canonical shape. Throw if permission is invalid.
Full documentation.

positive(permission)

Removes all negative permissions.
Full documentation.

contain(permission, permissions...)

Tests whether permission includes permissions.
Full documentation.

equal(permission, permissions...)

Tests whether permission equals exactly permissions.
Full documentation.

set(permission, permissions...)

Sets permissions on permission. This is useful to avoid error-prone bitwise operations (|, &, ^, ~).
Full documentation.

not(permission)

Inverts permission including special permissions. This can be used in combination with set() to unset permissions instead of setting them.
Full documentation.

invert(permission)

Inverts permission and removes special permissions.
Full documentation.

min(permissions...)

Retrieves the lowest permissions among all arguments.
Full documentation.

max(permissions...)

Retrieves the highest permissions among all arguments.
Full documentation.

Support

For any question, don't hesitate to submit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with ❤️. The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!

ehmicky
ehmicky

💻 🎨 🤔 📖
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].