Skip to content

Latest commit

 

History

History
145 lines (98 loc) · 4.65 KB

rest.md

File metadata and controls

145 lines (98 loc) · 4.65 KB

rest

import "github.com/image357/password/rest"

Index

func DebugAccessCallback(token string, ip string, resource string, id string) bool

DebugAccessCallback returns the global variable debugAccessSuccess. It will log the arguments to the package logger in debug level.

Example

err := StartSimpleService(":8080", "/", "123", DebugAccessCallback)
if err != nil {
	// handle error
}

func EnableTLS(certFile string, keyFile string)

EnableTLS will set the REST backend to https mode. Must be used before starting a REST sever with accessible paths to a public certificate file and private key file.

func FullAccessCallback(_ string, _ string, _ string, _ string) bool

FullAccessCallback will grant access to every REST request.

Example

err := StartSimpleService(":8080", "/", "123", FullAccessCallback)
if err != nil {
	// handle error
}

func StartMultiService(bindAddress string, prefix string, key string, callback TestAccessFunc) error

StartMultiService creates a multi password REST service. The service binds to "/prefix/overwrite" (PUT), "/prefix/get" (GET), "/prefix/check" (GET), "/prefix/set" (PUT), "/prefix/unset" (DELETE), "/prefix/exists" (GET), "/prefix/list" (GET), "/prefix/delete" (DELETE), "/prefix/clean" (DELETE). The callback of type TestAccessFunc will be called for every request to determine access.

Example

// Start rest service on localhost:8080 without any access control.
err := StartMultiService(":8080", "/prefix", "123", func(string, string, string, string) bool { return true })
if err != nil {
	// handle error
}

func StartSimpleService(bindAddress string, prefix string, key string, callback TestAccessFunc) error

StartSimpleService creates a single password REST service. The service binds to "/prefix/overwrite" (PUT), "/prefix/get" (GET), "/prefix/check" (GET), "/prefix/set" (PUT), "/prefix/unset" (DELETE), "/prefix/exists" (GET), "/prefix/delete" (DELETE). The callback of type TestAccessFunc will be called for every request to determine access.

Example

// Start rest service on localhost:8080 without any access control.
err := StartSimpleService(":8080", "/prefix", "123", func(string, string, string, string) bool { return true })
if err != nil {
	// handle error
}

func StopService(timeout int, bindAddress string, prefix string) error

StopService will block execution and try to gracefully shut down any REST service during the timeout period. The service is guaranteed to be closed at the end of the timeout.

TestAccessFunc is a callback signature. The callback will be called by the REST service for every request to determine access based on the accessToken.

type TestAccessFunc func(token string, ip string, resource string, id string) bool

Generated by gomarkdoc