expenses

package
v0.0.0-...-1643d90 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2020 License: UPL-1.0 Imports: 4 Imported by: 0

README

Speedle Embedeed Sample

Build

Please make sure envionment variables GOROOT and GOPATH have been properly set. And you are currently under this folder.

$ go build -o expenses_sample cmd/expenses_sample

After building, a executable file expenses_sample can be found under this folder.

Policies for this sample

The policy definitations for this sample can be found in file expenses.spdl

[service.expenses]
[policy]
GRANT ROLE employee get, post, delete /reports
GRANT ROLE auditor get, modify /reports
[rolepolicy]
GRANT USER alice employee

In this file, there is a service named expenses, and under this service, there are two policies defined, role employee can get, post and delete resource /reports; and role auditor can get and modify resource /reports.

And user alice is an employee.

Run and test the sample

# Run the sample, the sample will listen on localhost:8080
$ ./expenses_sample expenses.spdl
# Test if user alice has permission to delete /reports
$ curl -X DELETE -u alice:afdsa http://localhost:8080/reports
deleteing an expense report is done

# Test if user bob has permission to delete /reports
$ curl -X DELETE -u bob:afdsa http://localhost:8080/reports
forbidden.

Add bob as an employee, and test

# Add user bob as an employee
$ echo "GRANT USER bob employee" >> expenses.spdl
# Test if bob has permission to delete /reports
$ curl -X DELETE -u bob:afdsa http://localhost:8080/reports
deleteing an expense report is done

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExpenseHTTPHandler http.Handler

ExpenseHTTPHandler is the handler for all handler functions

Functions

func Wrap

func Wrap(handler http.Handler, service, spdlLoc string) (http.HandlerFunc, error)

Wrap wraps an HTTP handler with a new HTTP handler for authorization

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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