Documentation
¶
Overview ¶
Package distromux provides implementations the http.ServeMux interface that serve up ipxe configs for a particular distribution using templates.
Index ¶
- func DistroVarsMiddleware(r *mux.Router, vars DistroVars) mux.MiddlewareFunc
- func LoadTestCases(testsPath string) (map[string]*DistroTestCase, error)
- func NewDistroVarsContext(parentCtx context.Context, vars DistroVars) context.Context
- func RedirectInsecure(h http.Handler) http.Handler
- func TemplateJoinWrapper(data interface{}, sep string) (string, error)
- func TemplateNetworkCidrContains(cidr string, ips interface{}) ([]string, error)
- type DistroConfig
- type DistroMux
- type DistroTestCase
- type DistroTestResult
- type DistroTestSuite
- type DistroVars
- type Endpoint
- type EndpointConfig
- type MockDataSourceCall
- type MockHTTPRequest
- type MockHTTPResponse
- type ProxyEndpoint
- type StaticEndpoint
- type TemplateData
- type TemplateEndpoint
- type TemplateRenderer
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 TemplateJoinWrapper ¶
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 ¶
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 ¶
NewDistroMux returns a new DistroMux that serves the configuration found at the supplied path
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 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 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 ¶
type MockHTTPResponse ¶
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 ¶
TemplateSelector chooses the appropriate template to use for handling the request. Search order: 1. node.Role match 2. DefaultTemplate