httpguard

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: MIT Imports: 17 Imported by: 0

README

Go-HTTPGuard

Prepare:

git clone git@gitlab.com:Laisky/configs.git /opt/config

Run:

go run entrypoints/main.go --config=/etc/go-httpguard/settings --debug --dry

Settings.yml:

addr: "0.0.0.0:24215"
audit: "http://xxx/httpguard/logs"
backend: "http://xxx"
secret: "123456"
users:
  - username: "readonly"
    password: "readonly"
    permissions:
      get:
        - "/"
      head:
        - "/"
  - username: "laisky"
    permissions:
      get:
        - "/"
      head:
        - "/"
      post:
        - "/"

token:

{
  "exp": 4701978061,
  "uid": "jiudian-ai"
}

Each request should has the Cookie named token:

demo

You can try with readonly token:

eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjQ3MDE5NzgwNjEsInVpZCI6InJlYWRvbmx5In0.PRDnh3tpfxd2G4TDj29HW3QA5dZKq068AYaLSTpA2LQFuAZD-luXvorUfvIXGKY1ESkHVPbkvWEZaX7tTh2E8w

(You can generate HS512 token at https://jwt.io/)

generate

Documentation

Index

Constants

View Source
const (
	Username  = "username"
	ExpiresAt = "expires_at"
)

Variables

View Source
var Config = &ConfigType{}

Functions

This section is empty.

Types

type Audit

type Audit struct{}

func NewAudit

func NewAudit() *Audit

func (*Audit) Entrypoint

func (a *Audit) Entrypoint(c *chaining.Chain) (interface{}, error)

func (*Audit) PushAuditRecord

func (a *Audit) PushAuditRecord(data map[string]interface{})

type Auth

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

func NewAuth

func NewAuth(plugins ...AuthPlugin) *Auth

func (*Auth) Entrypoint

func (a *Auth) Entrypoint(c *chaining.Chain) (interface{}, error)

type AuthPlugin

type AuthPlugin interface {
	// contains filtered or unexported methods
}

type AwsAuthPlugin

type AwsAuthPlugin struct {
}

func NewAwsAuthPlugin

func NewAwsAuthPlugin() *AwsAuthPlugin

type Backend

type Backend struct{}

func NewBackend

func NewBackend() *Backend

func (*Backend) Entrypoint

func (b *Backend) Entrypoint(c *chaining.Chain) (ret interface{}, err error)

func (*Backend) RequestBackend

func (b *Backend) RequestBackend(ctx *fasthttp.RequestCtx, url string) (err error)

RequestBackend request backend by internal http client

type BasicAuthPlugin

type BasicAuthPlugin struct {
}

func NewBasicAuthPlugin

func NewBasicAuthPlugin() *BasicAuthPlugin

type ConfigType

type ConfigType struct {
	Runtime   runtimeConfig         `mapstructure:"-"`
	Listen    string                `mapstructure:"listen"`
	Backend   string                `mapstructure:"backend"`
	JWTSecret string                `mapstructure:"jwt_secret"`
	Users     []configUser          `mapstructure:"users"`
	UsersMap  map[string]configUser `mapstructure:"-"`
}

func (*ConfigType) Init

func (c *ConfigType) Init() *ConfigType

type Controllor

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

func NewController

func NewController(middlewares ...Middleware) *Controllor

func (*Controllor) MiddlewareChain

func (c *Controllor) MiddlewareChain(chain *chaining.Chain) *chaining.Chain

func (*Controllor) Run

func (c *Controllor) Run(ctx context.Context) (err error)

type CtxMeta

type CtxMeta struct {
	Ctx  *fasthttp.RequestCtx
	Meta map[string]interface{}
}

type JwtAuthPlugin

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

func NewJwtAuthPlugin

func NewJwtAuthPlugin(secret string) *JwtAuthPlugin

type Middleware

type Middleware interface {
	Entrypoint(c *chaining.Chain) (interface{}, error)
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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