grest

package module
v0.0.0-...-163263d Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2020 License: MIT Imports: 16 Imported by: 0

README

Godoc Build Status Coverage Report

How-to

package main

import (
	"log"
	"net/http"

	"github.com/xdbsoft/grest"
	"github.com/xdbsoft/grest/rules"
)

func main() {

	cfg := grest.Config{
		OpenIDConnectIssuer: "https://login.okiapps.com/",                                // You may use any OIDC provider (Google, Github, or self hosted)
		DBConnStr:           "user=nestor password=nestor dbname=nestor sslmode=disable", //Connection string to the PostgreSQL database
		Rules: []rules.Rule{
			{
				Path: "test/{userId}/sub/{doc}",
				Read: rules.Allow{
					With: []rules.With{
						{
							Name: "user",
							Path: "test/{userId}",
						},
					},
					IfPath: `path.doc != "private" || path.userId == user.id || with.user.role == "admin"`,
				},
				Write: rules.Allow{
					IfPath:    `path.userId == user.id`,
					IfContent: `content.properties.policy == 'EDITABLE' || with.user.role == "admin"`,
				},
			},
		},
	}

	s, _ := grest.Server(cfg)

	http.Handle("/", s)

	log.Fatal(http.ListenAndServe(":8080", nil))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest returns whether the error cause is that the provided inputs are incorrect

func IsNotAuthorized

func IsNotAuthorized(err error) bool

IsNotAuthorized returns whether the error cause is that there was an attempt to perform a not authorized action

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns whether the error cause is that something was not found

func Server

func Server(cfg Config) (http.Handler, error)

Server instantiate a new grest server

Types

type BadRequest

type BadRequest interface {
	IsBadRequest() bool
}

BadRequest is the interface that wraps the IsBadRequest method

type Config

type Config struct {
	OpenIDConnectIssuer string
	DBConnStr           string
	Rules               []rules.Rule
}

Config contains all required information for the intialisation of a grest server

type NotAuthorized

type NotAuthorized interface {
	IsNotAuthorized() bool
}

NotAuthorized is the interface that wraps the IsNotAuthorized nethod

type NotFound

type NotFound interface {
	IsNotFound() bool
}

NotFound is the interface that wraps the IsNotFound nethod

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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