oparbac

package module
v0.0.0-...-714b395 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

opa-rbac

Role-based access control (RBAC) with the Open Policy Agent.

Test golangci-lint

Usage

package main

import (
	"context"
	"fmt"
	"github.com/linzhengen/opa-rbac"
)

func main() {
	var data = oparbac.Data{
		UserRoles: map[string][]string{
			"alice": {
				"admin",
			},
			"bob": {
				"employee",
			},
			"eve": {
				"customer",
			},
		},
		RoleGrants: map[string][]map[string]string{
			"customer": {
				{
					"resource": "user.get",
				},
			},
			"employee": {
				{
					"resource": "user.list",
				},
			},
		},
	}
	input := oparbac.Input{User: "alice", Resource: "employee.get"}
	fmt.Println(oparbac.Allowed(context.TODO(), data, input))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Allowed

func Allowed(ctx context.Context, data Data, input Input) (bool, error)

Types

type Data

type Data struct {
	UserRoles  map[string][]string            `json:"user_roles"`
	RoleGrants map[string][]map[string]string `json:"role_grants"`
}

type Input

type Input struct {
	User     string `json:"user"`
	Resource string `json:"resource"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL