distromux

package
v0.0.0-...-4bdf62d Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 License: GPL-2.0-or-later Imports: 26 Imported by: 0

Documentation

Overview

Package distromux provides implementations the http.ServeMux interface that serve up ipxe configs for a particular distribution using templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DistroVarsMiddleware

func DistroVarsMiddleware(r *mux.Router, vars DistroVars) mux.MiddlewareFunc

func LoadTestCases

func LoadTestCases(testsPath string) (map[string]*DistroTestCase, error)

func NewDistroVarsContext

func NewDistroVarsContext(parentCtx context.Context, vars DistroVars) context.Context

func RedirectInsecure

func RedirectInsecure(h http.Handler) http.Handler

func TemplateJoinWrapper

func TemplateJoinWrapper(data interface{}, sep string) (string, error)

func TemplateNetworkCidrContains

func TemplateNetworkCidrContains(cidr string, ips interface{}) ([]string, error)

Types

type DistroConfig

type DistroConfig struct {
	Endpoints   EndpointConfig  `mapstructure:"endpoints"`
	DataSources api.EndpointMap `mapstructure:"datasources"`
	Test        DistroTestSuite `mapstructure:"test"`
	DistroVars  DistroVars      `mapstructure:"vars"`
}

DistroConfig descibes the configuration of an instance of DistroMux

type DistroMux

type DistroMux struct {
	*mux.Router
	// contains filtered or unexported fields
}

DistroMux configures a gorilla/mux Router that will serve the contents of a folder based on a config file found in either the root of the folder, or in a config subdirectory.

func NewDistroMux

func NewDistroMux(srcpath string, router *mux.Router) (*DistroMux, error)

NewDistroMux returns a new DistroMux that serves the configuration found at the supplied path

func (*DistroMux) Test

func (d *DistroMux) Test() (map[string]*DistroTestResult, error)

type DistroTestCase

type DistroTestCase struct {
	InputRequest     MockHTTPRequest      `mapstructure:"request"`
	MockedData       []MockDataSourceCall `mapstructure:"mocked_data"`
	ExpectedOutput   MockHTTPResponse     `mapstructure:"expected"`
	MockedDistroVars DistroVars           `mapstructure:"vars"`
}

func (*DistroTestCase) Test

func (c *DistroTestCase) Test(mux *DistroMux, endpoints api.EndpointMap) *DistroTestResult

type DistroTestResult

type DistroTestResult struct {
	Failed bool
	Output string
}

type DistroTestSuite

type DistroTestSuite struct {
	Folder string `mapstructure:"folder"`
}

DistroTestConfig describes where to find tests for the distro

type DistroVars

type DistroVars map[string]interface{}

func DistroVarsFromContext

func DistroVarsFromContext(ctx context.Context) (DistroVars, bool)

func (DistroVars) SetContextForRequest

func (v DistroVars) SetContextForRequest(r *http.Request) *http.Request

func (DistroVars) Vars

func (v DistroVars) Vars(_ *http.Request) DistroVars

type Endpoint

type Endpoint interface {
	CreateHandler(string, string, api.EndpointMap) (http.Handler, error)
}

Endpoint describes an interface that configuration structs should implement.

type EndpointConfig

type EndpointConfig struct {
	Template map[string]*TemplateEndpoint `mapstructure:"template"`
	Static   map[string]*StaticEndpoint   `mapstructure:"static"`
	Proxy    map[string]*ProxyEndpoint    `mapstructure:"proxy"`
}

type MockDataSourceCall

type MockDataSourceCall struct {
	DataSource string           `mapstructure:"datasource"`
	Request    MockHTTPRequest  `mapstructure:"request"`
	Response   MockHTTPResponse `mapstructure:"response"`
}

type MockHTTPRequest

type MockHTTPRequest struct {
	Path    string                 `mapstructure:"path"`
	Query   string                 `mapstructure:"query"`
	Body    string                 `mapstructure:"body"`
	Method  string                 `mapstructure:"method"`
	Headers map[string]interface{} `mapstructure:"headers"`
}

func (*MockHTTPRequest) BuildRequest

func (r *MockHTTPRequest) BuildRequest(baseUrl *url.URL) (*http.Request, error)

type MockHTTPResponse

type MockHTTPResponse struct {
	Status int    `mapstructure:"status"`
	Body   string `mapstructure:"body"`
}

type ProxyEndpoint

type ProxyEndpoint struct {
	TargetURL        string
	RedirectInsecure bool `mapstructure:"redirect_insecure"`
}

ProxyEndpoint acts as a reverse proxy to the given TargetURL

func (*ProxyEndpoint) CreateHandler

func (e *ProxyEndpoint) CreateHandler(_ string, pathPrefix string, _ api.EndpointMap) (http.Handler, error)

CreateHandler returns a httputil.ReverseProxy handler

type StaticEndpoint

type StaticEndpoint struct {
	SourcePath       string `mapstructure:"source"`
	RedirectInsecure bool   `mapstructure:"redirect_insecure"`
}

StaticEndpoint describes configuration of endpoints that serve files. The SourcePath is the relative path to the root of the tree to be served.

func (*StaticEndpoint) CreateHandler

func (e *StaticEndpoint) CreateHandler(basepath string, pathPrefix string, _ api.EndpointMap) (http.Handler, error)

CreateHandler ceates a handler to serve the files found at basepath/SourcePath.

type TemplateData

type TemplateData struct {
	BaseURL       string
	DistroVars    DistroVars
	RequestParams map[string]string
	RawQuery      string
}

TemplateData is the struct that will be passed into the template at render time

type TemplateEndpoint

type TemplateEndpoint struct {
	TemplatePath     string   `mapstructure:"template_path"`
	RawContentType   string   `mapstructure:"raw_content_type"`
	ContentType      string   `mapstructure:"content_type"`
	DefaultTemplate  string   `mapstructure:"default_template"`
	PostRender       []string `mapstructure:"post_render"`
	RedirectInsecure bool     `mapstructure:"redirect_insecure"`
}

TemplateEndpoint describes the configuration of an endpoint based on golang templates.

func (*TemplateEndpoint) CreateHandler

func (e *TemplateEndpoint) CreateHandler(basepath string, _ string, dataSources api.EndpointMap) (http.Handler, error)

CreateHandler returns a handler for the endpoint described by this configuration

type TemplateRenderer

type TemplateRenderer struct {
	DefaultTemplate  string
	FileNameTemplate string
	DataSources      api.EndpointMap
}

TemplateRenderer implements the RenderManager interface.

func (*TemplateRenderer) GetData

func (tr *TemplateRenderer) GetData(r *http.Request) (interface{}, error)

GetData returns the node data associated with this request, if any.

func (*TemplateRenderer) TemplateFuncs

func (tr *TemplateRenderer) TemplateFuncs() template.FuncMap

func (*TemplateRenderer) TemplateSelector

func (tr *TemplateRenderer) TemplateSelector(r *http.Request, t *template.Template) (string, error)

TemplateSelector chooses the appropriate template to use for handling the request. Search order: 1. node.Role match 2. DefaultTemplate

Jump to

Keyboard shortcuts

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