Skip to content

A simple but powerful Access Control List manager

License

Notifications You must be signed in to change notification settings

txgruppi/acl-go

Repository files navigation

GoDoc Codeship Codecov Go Report Card

ACL - Access Control List

ACL is a simple but powerful Access Control List manager

Installation

go get -u github.com/txgruppi/acl-go

Example

You should not ignore the errors returned by the methods

package main

import (
  "fmt"

  "github.com/txgruppi/acl-go"
  "github.com/txgruppi/acl-go/driver/memory"
)

func main() {
  driver := memory.NewDriver()

  // Driver can be directly used as ACL managers
  var manager acl.ACL = driver

  // Set the default policy as Deny
  acl.SetDefaultPolicy(acl.Deny)

  // Get some users
  userCEO, _ := acl.GetActor("userCEO_UUID")
  userDeveloper, _ := acl.GetActor("userDeveloper_UUID")

  // Get some actions
  accessBackAccount, _ := acl.GetAction("accessBackAccount")
  accessProductionServer, _ := acl.GetAction("accessProductionServer")

  // Set rules
  acl.Set(userCEO, accessBackAccount, acl.Allow)
  acl.Set(userDeveloper, accessProductionServer, acl.Allow)

  // Check using the ACL manager
  allowed, _ := acl.IsAllowed(userCEO, accessBackAccount)
  fmt.Println(allowed) // true
  allowed, _ = acl.IsAllowed(userDeveloper, accessBackAccount)
  fmt.Println(allowed) // false

  // Check using the Actor or Action struct
  allowed, _ := userCEO.IsAllowed(accessProductionServer)
  fmt.Println(allowed) // false
  allowed, _ = accessProductionServer.Allows(userDeveloper)
  fmt.Println(allowed) // true
}

Tests

go get -u -t github.com/txgruppi/acl-go
cd $GOPATH/src/github.com/txgruppi/acl-go
go test ./...

License

MIT

About

A simple but powerful Access Control List manager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published