obsidian

package
v0.0.0-...-89602ce Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: BSD-3-Clause Imports: 9 Imported by: 10

Documentation

Overview

Package obsidian provides common types and constants for implementors of REST API handlers.

Index

Constants

View Source
const (
	Product              = "Obsidian Server"
	Version              = "0.1"
	DefaultPort          = 9081
	DefaultHttpsPort     = 9443
	DefaultServerCert    = "server_cert.pem"
	DefaultServerCertKey = "server_cert.key.pem"
	DefaultClientCAs     = "ca_cert.pem"
	DefaultStaticFolder  = "/var/opt/magma/static"
	StaticURLPrefix      = "/apidocs"
	ServiceName          = "OBSIDIAN"
)
View Source
const (
	UrlSep = "/"

	MagmaNetworksUrlPart  = "networks"
	MagmaOperatorsUrlPart = "operators"

	// "/magma"
	RestRoot = UrlSep + "magma"
	// "/magma/networks"
	NetworksRoot = RestRoot + UrlSep + MagmaNetworksUrlPart
	// "/magma/operators"
	OperatorsRoot = RestRoot + UrlSep + MagmaOperatorsUrlPart

	// Supported API versions
	V0 = ""
	V1 = "v1"
	// Note the trailing slash (this is actually important for apidocs to render properly)
	V1Root = RestRoot + UrlSep + V1 + UrlSep
)

Variables

View Source
var (
	TLS                bool
	Port               int
	ServerCertPemPath  string
	ServerKeyPemPath   string
	ClientCAPoolPath   string
	AllowAnyClientCert bool
	StaticFolder       string
)

configs

Functions

func AttachAll

func AttachAll(e *echo.Echo, m ...echo.MiddlewareFunc)

AttachAll activates all registered (see: Register above) handlers Main package should call AttachAll after all handlers were registered

func AttachHandlers

func AttachHandlers(e *echo.Echo, handlers []Handler, m ...echo.MiddlewareFunc)

AttachHandlers attaches the provided obsidian handlers to the echo server

func CheckNetworkAccess

func CheckNetworkAccess(c echo.Context, networkId string) *echo.HTTPError

func CheckTenantAccess

func CheckTenantAccess(c echo.Context) *echo.HTTPError

CheckTenantAccess checks that the context has network wildcard access i.e. is admin

func CheckWildcardNetworkAccess

func CheckWildcardNetworkAccess(c echo.Context) *echo.HTTPError

func GetNetworkAndGatewayIDs

func GetNetworkAndGatewayIDs(c echo.Context) (string, string, *echo.HTTPError)

func GetNetworkId

func GetNetworkId(c echo.Context) (string, *echo.HTTPError)

func GetOperatorId

func GetOperatorId(c echo.Context) (string, *echo.HTTPError)

func GetParamValues

func GetParamValues(c echo.Context, paramNames ...string) ([]string, *echo.HTTPError)

GetParamValues returns a list of the value for each param provided in `paramNames`. Returns a status bad request HTTP error if any param value is blank.

func GetTenantID

func GetTenantID(c echo.Context) (int64, *echo.HTTPError)

func HttpError

func HttpError(err error, code ...int) *echo.HTTPError

func NetworkIdHttpErr

func NetworkIdHttpErr() *echo.HTTPError

func Register

func Register(handler Handler) error

Register registers a given handler for given path and HTTP methods Note: the handlers won't become active until they are 'attached' to the echo server, see AttachAll below

func RegisterAll

func RegisterAll(handlers []Handler) error

RegisterAll registers an array of Handlers. If an error is encountered while registering any handler, RegisterAll will exit early with that error and rollback any handlers which were already registered.

func TenantIdHttpErr

func TenantIdHttpErr() *echo.HTTPError

func Unregister

func Unregister(path string, methods HttpMethod)

Unregister unregisters the handler for the specified path and HttpMethod if it is registered. No action will be taken if no such handler is registered.

Types

type Handler

type Handler struct {
	Path string

	// Methods is a bitmask so one Handler can support multiple http methods.
	// See consts defined below.
	Methods HttpMethod

	HandlerFunc echo.HandlerFunc
}

Handler wraps a function which serves a specified path and http method.

type HttpMethod

type HttpMethod byte
const (
	GET HttpMethod = 1 << iota
	POST
	PUT
	DELETE
	ALL = GET | POST | PUT | DELETE
)

Directories

Path Synopsis
Server's main package, run with obsidian -h to see all available options
Server's main package, run with obsidian -h to see all available options

Jump to

Keyboard shortcuts

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