handlers

package
v0.0.0-...-5107381 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package handlers defines handlers for all of the endpoints accessible from the core server.

Index

Constants

This section is empty.

Variables

View Source
var AuthError = errors.New(
	"Unauthorized: The request lacks valid authentication credentials for the target resource.",
)

Functions

func Playground

func Playground(title string, endpoint string) http.HandlerFunc

Types

type Auth

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

Auth provides a middleware handler that handles cross-origin requests and pulling of authentication from incoming requests. It also handles the registration and deregistration of plugins and updates its authorizer methods accordingly.

func NewAuth

func NewAuth(c config.Config, initPayloadGetter InitPayloadGetter, l *zap.Logger) (*Auth, error)

NewAuth creates a new instance of Auth. InitPayloadGetter provides a way to grab credentials from the context when the connection is made via Websockets.

func (*Auth) AddPlugin

func (a *Auth) AddPlugin(ctx context.Context, pluginURL string) (string, error)

AddPlugin registers the provided plugin URL in the system and returns the token that the plugin can use to make requests. If the plugin URL cannot be parsed, it fails to create a token and returns an error.

func (*Auth) AllowOriginFunc

func (a *Auth) AllowOriginFunc(origin string) bool

AllowOriginFunc returns true only if the origin is referenced by any URL of the registered plugins.

func (*Auth) AuthorizeAdminToken

func (a *Auth) AuthorizeAdminToken(ctx context.Context) error

AuthorizeAdminToken checks to make sure that the provided admin token is valid and is authorized to make admin-level requests.

func (*Auth) AuthorizePluginToken

func (a *Auth) AuthorizePluginToken(ctx context.Context) error

AuthorizePluginToken checks to make sure that the provided plugin token is valid and is authorized to make plugin-level requests.

func (*Auth) CreateAdminToken

func (a *Auth) CreateAdminToken(ctx context.Context) (string, error)

CreateAdminToken returns a persistent token that is authorized to not only the same requests that plugins can make, but also register or unregister plugins.

func (*Auth) Handler

func (a *Auth) Handler(next http.Handler) http.Handler

Handler returns a handler that serves cross-origin requests and pulls authentication data from incoming requests.

func (*Auth) RemovePlugin

func (a *Auth) RemovePlugin(ctx context.Context, apiToken string) (bool, error)

RemovePlugin unregisters the plugin corresponding to this specific apiToken. It will return success even if the apiToken is no longer registered, provided that this token is still a valid token. If all plugins corresponding to a particular origin are removed, this origin will no longer be allowed in the CORS mechanism.

type InitPayloadGetter

type InitPayloadGetter func(context.Context) transport.InitPayload

InitPayloadGetter provides an alternate method of retrieving credentials for when the token cannot be sent via HTTP headers (basically the case of websockets)

type MapHandler

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

MapHandler serves requests for map images. It will attempt to serve them from disk first, downloading from xivapi if necessary. Users are subject to Client IP based rate limiting.

Usage:
GET /maps/{map_id} -> Returns an image with content type image/png or
image/jpg

Example:
GET /maps/123 -> 200 OK, image/png
GET /maps/1234 -> 404 Not Found

func NewMapHandler

func NewMapHandler(prefix string, c config.Config, l *zap.Logger) *MapHandler

NewMapHandler creates a new MapHandler

prefix is the path to this handler.

func (*MapHandler) ServeHTTP

func (h *MapHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves maps for the handler

Jump to

Keyboard shortcuts

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