Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.13 KB

README.md

File metadata and controls

46 lines (33 loc) · 1.13 KB

main

This library implements a Casbin adapter for Cloud Spanner.

To install:

$ go get github.com/flowerinthenight/casbin-spanner-adapter

Example usage:

package main

import (
    "flag"
    "log"
    "time"

    "github.com/casbin/casbin/v2"
    spanneradapter "github.com/flowerinthenight/casbin-spanner-adapter"
)

func main() {
    a, _ := spanneradapter.NewAdapter(
        "projects/{v}/instances/{v}/databases/{v}",
        spanneradapter.WithSkipDatabaseCreation(true),
    )

    e, _ := casbin.NewEnforcer("rbac_model.conf", a)

    // Load stored policy from database.
    e.LoadPolicy()

    // Do permission checking.
    e.Enforce("alice", "data1", "write")

    // Do some mutations.
    e.AddPolicy("alice", "data2", "write")
    e.RemovePolicy("alice", "data1", "write")

    // Persist policy to database.
    e.SavePolicy()
}