oso

package module
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 14 Imported by: 10

README

Oso go library

This is the publish repository for the oso go library. It contains prebuilt oso-core libraries so that you can reference this module directly in go code.

All development happens on https://github.com/osohq/oso.

go get github.com/osohq/go-oso

    import "github.com/osohq/go-oso"
    ...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Oso

type Oso struct {
	// contains filtered or unexported fields
}

The central object to manage policy state and verify requests.

func NewOso

func NewOso() (Oso, error)

Construct a new Oso instance.

import oso "github.com/osohq/go-oso"
if o, err := oso.NewOso(); err != nil {
	t.Fatalf("Failed to set up Oso: %v", err)
}

func (Oso) ClearRules

func (o Oso) ClearRules() error

Clear all rules from the Oso knowledge base (i.e., remove all loaded policies).

func (Oso) IsAllowed

func (o Oso) IsAllowed(actor interface{}, action interface{}, resource interface{}) (bool, error)

Check if an (actor, action, resource) combination is allowed by the policy. Returns the result as a bool, or an error.

func (Oso) LoadFile

func (o Oso) LoadFile(f string) error

Load Polar policy from a ".polar" file, checking that all inline queries succeed.

func (Oso) LoadString

func (o Oso) LoadString(s string) error

Load Polar policy from a string, checking that all inline queries succeed.

func (Oso) NewQueryFromRule

func (o Oso) NewQueryFromRule(name string, args ...interface{}) (*Query, error)

Create policy query for a rule. Accepts the name of the rule to query, and a variadic list of rule arguments. Returns a new *Query, on which `Next()` can be called to get the next result, or an error.

func (Oso) NewQueryFromStr

func (o Oso) NewQueryFromStr(q string) (*Query, error)

Create policy query from a query string. Accepts the string to query for. Returns a new *Query, on which `Next()` can be called to get the next result, or an error.

func (Oso) QueryRule

func (o Oso) QueryRule(name string, args ...interface{}) (<-chan map[string]interface{}, <-chan error)

Query the policy for a rule; the query is run in a new Go routine. Accepts the name of the rule to query, and a variadic list of rule arguments. Returns a channel of resulting binding maps, and a channel for errors. As the query is evaluated, all resulting bindings will be written to the results channel, and any errors will be written to the error channel.

func (Oso) QueryStr

func (o Oso) QueryStr(q string) (<-chan map[string]interface{}, <-chan error)

Query the policy using a query string; the query is run in a new Go routine. Accepts the string to query for. Returns a channel of resulting binding maps, and a channel for errors. As the query is evaluated, all resulting bindings will be written to the results channel, and any errors will be written to the error channel.

func (Oso) RegisterClass added in v0.0.3

func (o Oso) RegisterClass(cls reflect.Type, cptr interface{}) error

Register a Go type so that it can be referenced within Polar files. Accepts a constructor function, or nil if no constructor is required.

func (Oso) RegisterClassWithName added in v0.0.3

func (o Oso) RegisterClassWithName(cls reflect.Type, cptr interface{}, name string) error

Register a Go type under a certain name/alias, so that it can be referenced within Polar files by that name. Accepts a constructor function, or nil if no constructor is required.

func (Oso) RegisterConstant added in v0.0.3

func (o Oso) RegisterConstant(value interface{}, name string) error

Register a Go value as a Polar constant variable called `name`.

func (Oso) Repl added in v0.11.0

func (o Oso) Repl() error

Start the oso repl where you can make queries and see results printed out.

type Polar

type Polar struct {
	// contains filtered or unexported fields
}

type Query

type Query struct {
	// contains filtered or unexported fields
}

Execute a Polar query through the FFI/event interface.

func (*Query) GetAllResults added in v0.0.3

func (q *Query) GetAllResults() ([]map[string]interface{}, error)

Executes the query until all results have been returned, and returns results as a list of binding maps.

func (*Query) Next

func (q *Query) Next() (*map[string]interface{}, error)

Get the next query result. Returns a pointer to a map of result bindings, or a nil pointer if there are no results.

Directories

Path Synopsis
cmd
oso
internal
ffi

Jump to

Keyboard shortcuts

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