rules

package
v0.0.0-...-161c778 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemaURL         = "https://github.com/http-everything/httpe/main/pkg/rules/schema.json"
	RunScript         = "run.script"
	SendEmail         = "send.email"
	AnswerContent     = "answer.content"
	AnswerFile        = "answer.file"
	RedirectPermanent = "redirect.permanent"
	RedirectTemporary = "redirect.temporary"
	ServeDirectory    = "serve.directory"
	RenderButtons     = "render.buttons"
)

Variables

View Source
var ValidPostActions = []string{
	SendEmail,
	RunScript,
}

Functions

func YamlToJSON

func YamlToJSON(yamlFile string) string

Types

type Args

type Args struct {
	Interpreter string `yaml:"interpreter" json:"interpreter"`
	Timeout     int    `yaml:"timeout" json:"timeout"`
	Cwd         string `yaml:"cwd" json:"cwd"`
	Template    string `yaml:"template" json:"template"`
	FileUploads bool   `yaml:"file_uploads" json:"file_uploads"`
	Templating  bool   `yaml:"templating" json:"templating"`
}

type Button

type Button struct {
	Name    string `yaml:"name,omitempty" json:"name,omitempty"`
	URL     string `yaml:"url,omitempty" json:"url,omitempty"`
	Classes string `yaml:"classes" json:"classes"`
}

type Cfg

type Cfg struct {
	Rules []Rule `yaml:"rules" json:"rules"`
}

type Email

type Email struct {
	From    string `yaml:"from,omitempty" json:"from,omitempty"`
	To      string `yaml:"to,omitempty" json:"to,omitempty"`
	Cc      string `yaml:"cc,omitempty" json:"cc,omitempty"`
	Bcc     string `yaml:"bcc,omitempty" json:"bcc,omitempty"`
	Subject string `yaml:"subject,omitempty" json:"subject,omitempty"`
	Body    string `yaml:"body,omitempty" json:"body,omitempty"`
}

type Headers

type Headers map[string]string

type On

type On struct {
	Path    string   `yaml:"path,omitempty" json:"path,omitempty"`
	Methods []string `yaml:"methods,omitempty" json:"methods,omitempty"`
}

type OnError

type OnError struct {
	HTTPStatus int     `yaml:"http_status" json:"http_status"`
	Body       string  `yaml:"body" json:"body"`
	Headers    Headers `yaml:"headers" json:"headers"`
}

type OnSuccess

type OnSuccess struct {
	HTTPStatus int     `yaml:"http_status" json:"http_status"`
	Body       string  `yaml:"body" json:"body"`
	Headers    Headers `yaml:"headers" json:"headers"`
}

type PostAction

type PostAction struct {
	RunScript string `yaml:"run.script,omitempty" json:"run.script,omitempty"`
	SendEmail *Email `yaml:"send.email,omitempty" json:"send.email,omitempty"`
	Args      Args   `yaml:"args" json:"args"`
}

type Respond

type Respond struct {
	OnSuccess OnSuccess `yaml:"on_success" json:"on_success"`
	OnError   OnError   `yaml:"on_error" json:"on_error"`
}

func (*Respond) Headers

func (ruleResp *Respond) Headers(onSuccess bool) map[string]string

type Rule

type Rule struct {
	Name              string      `yaml:"name,omitempty" json:"name,omitempty"`
	On                *On         `yaml:"on" json:"on"`
	RunScript         string      `yaml:"run.script,omitempty" json:"run.script,omitempty"`
	SendEmail         *Email      `yaml:"send.email,omitempty" json:"send.email,omitempty"`
	AnswerContent     string      `yaml:"answer.content,omitempty" json:"answer.content,omitempty"`
	AnswerFile        string      `yaml:"answer.file,omitempty" json:"answer.file,omitempty"`
	RedirectPermanent string      `yaml:"redirect.permanent,omitempty" json:"redirect.permanent,omitempty"`
	RedirectTemporary string      `yaml:"redirect.temporary,omitempty" json:"redirect.temporary,omitempty"`
	ServeDirectory    string      `yaml:"serve.directory,omitempty" json:"serve.directory,omitempty"`
	RenderButtons     []Button    `yaml:"render.buttons,omitempty" json:"render.buttons,omitempty"`
	Args              Args        `yaml:"args" json:"args"`
	With              *With       `yaml:"with" json:"with,omitempty"`
	PostAction        *PostAction `yaml:"postaction" json:"postaction,omitempty"`
	Respond           Respond     `yaml:"respond" json:"respond"`
}

func (*Rule) Action

func (rule *Rule) Action() (action string)

func (*Rule) MatchesURI

func (rule *Rule) MatchesURI(URI string) bool

func (*Rule) MaxRequestBody

func (rule *Rule) MaxRequestBody() string

func (*Rule) PostAct

func (rule *Rule) PostAct() (action string, err error)

type Rules

type Rules struct {
	Rules *[]Rule `yaml:"rules" json:"rules"`
	// contains filtered or unexported fields
}

func Read

func Read(yamlFile string, logger *logger.Logger) (rules *Rules, err error)

Read reads the yaml file containing the rules

func (*Rules) Validate

func (r *Rules) Validate(smtpConfig *config.SMTPConfig) (err error)

type User

type User struct {
	Username string `yaml:"username,omitempty" json:"username,omitempty"`
	Password string `yaml:"password,omitempty" json:"password,omitempty"`
}

type With

type With struct {
	AuthBasic      []User `yaml:"auth_basic,omitempty" json:"auth_basic,omitempty"`
	AuthHashing    string `yaml:"auth_hashing,omitempty" json:"auth_hashing,omitempty"`
	MaxRequestBody string `yaml:"max_request_body,omitempty" json:"max_request_body,omitempty"`
}

Jump to

Keyboard shortcuts

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