Giter Site home page Giter Site logo

chakra's Introduction

chakra

GoDoc Widget

chakra allows you to easily add resource/operation based access control to https://github.com/pressly/chi

You can define any access control rules you want as a middleware - chakra will make sure they are checked.

Forcing security as you code with minimum overhead

chakra will:

  • build resource routes (identifiers) for your access checks
  • inject access control right before the last handlers in chain - not optional
  • not let you run your code without providing access control function - it will panic
  • not let you create new router without providing the next part of resource route or explicitly telling it to use parent one - it will panic

It's not airtight - you can still escape the added security, but it requires more effort than being secure. You can write a buggy access control function too - it can't help with that - but at least you won't forget to use it.

How to use it?

Almost exactly the same way you'd use chi

chi without access control

r := chi.NewRouter()
r.Mount("/api", func(r chi.Router){
    r = chi.NewRouter()
    r.Post("/endpoint1", handler1)
    ...
})

chakra - chi with access control

chakra.SetAC(myAccessControlRules) // you only do this once

r := chakra.NewRouter(chakra.UseParentRoute)
r.Mount("/api", func(r chi.Router){
    r = chakra.NewRouter("secure_api")
    r.Post("/endpoint1", handler1)
    ...
})

And you are DONE! - myAccessControlRules will be called right before handler1 to check permissions to POST to {"secure_api", "endpoint1"} resource

Examples

Example access control function

Credits

TODO

  • More examples
  • A lot of unit tests (and then some!)

Contributions are always welcome - fork it, do your thing, open a pull request!

License

Copyright (c) 2015 Maciej Lisiewski

Licensed under MIT License

chakra's People

Contributors

c2h5oh avatar

Watchers

 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.