batproxy

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

batproxy

A HTTP reverse proxy, but connecting to the backend through SSH.

Develop Guidance

  1. Init database by init_db

    # this command will generate sqlite3 db file `batproxy.db`
    $./scripts/init_db.sh sqlite
    
  2. Move batproxy.db file to .batproxy directory

  3. Run program by use make run

Deploy Guidance

  1. Prepare batproxy.db for store reverse proxy rule

  2. Run batproxy by docker_batproxy.sh

Use Guidance

  • As deployer, want to know more deploy options, use batproxy run -h

  • As api user, know more by api.md

Checklist

  • Sqlite
  • Mysql

Documentation

Index

Constants

View Source
const (
	ECONFLICT       = "conflict"
	EINTERNAL       = "internal"
	EINVALID        = "invalid"
	ENOTFOUND       = "not_found"
	ENOTIMPLEMENTED = "not_implemented"
	EUNAUTHORIZED   = "unauthorized"
	EFORBIDDEN      = "forbidden"
	EBADGATEWAY     = "bad_gateway"
)

Application error codes.

NOTE: These are meant to be generic, and they map well to HTTP error codes. Different applications can have very different error code requirements so these should be expanded as needed (or introduce subcodes).

Variables

View Source
var Version = "v0.0.1"

Functions

func ErrorCode

func ErrorCode(err error) string

ErrorCode unwraps an application error and returns its code. Non-application errors always return EINTERNAL.

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage unwraps an application error and returns its message. Non-application errors always return "Internal error".

Types

type CreateProxyOptions

type CreateProxyOptions struct {
	// Suffix will append after uuid
	// Format: <uuid><.suffix>
	// Optional.
	Suffix string `schema:"suffix,omitempty"`
}

type Error

type Error struct {
	// Machine-readable error code.
	Code string

	// Human-readable error message.
	Message string
}

Error represents an application-specific error. Application errors can be unwrapped by the caller to extract out the code & message.

Any non-application error (such as a disk error) should be reported as an EINTERNAL error and the human user should only see "Internal error" as the message. These low-level internal error details should only be logged and reported to the operator of the application (not the end user).

func Errorf

func Errorf(code string, format string, args ...interface{}) *Error

Errorf is a helper function to return an Error with a given code and formatted message.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface. Not used by the application otherwise.

type ListProxiesOptions

type ListProxiesOptions struct {
	// ProxyID unique proxy rule id.
	ProxyID string `schema:"proxy_id,omitempty"`

	// PageSize sets the maximum number of users to be returned.
	// 0 means no maximum; driver implementations should choose a reasonable
	// max. It is guaranteed to be >= 0.
	PageSize int `schema:"page_size,omitempty"`

	// PageToken may be filled in with the NextPageToken from a previous
	// ListUsers call.
	PageToken string `schema:"page_token,omitempty"`
}

type ListProxiesPage

type ListProxiesPage struct {
	Proxies       []*Proxy `json:"proxies" schema:"proxies"`
	NextPageToken string   `json:"next_page_token,omitempty" schema:"next_page_token,omitempty"`
}

type Proxy

type Proxy struct {
	// ID Unique proxy id.
	// Format: <uuid><.suffix>
	// Output only.
	ID string `json:"proxy_id"`

	// User Over SSH login name.
	// Required.
	User string `json:"user"`

	// Host Over SSH login host.
	// Required.
	Host string `json:"host"`

	// PrivateKey Over SSH login private key.
	// Optional.
	PrivateKey string `json:"private_key,omitempty"`

	// Passphrase Over SSH login private key passphrase.
	// Optional.
	Passphrase string `json:"passphrase,omitempty"`

	// Password Over SSH login password.
	// Optional.
	Password string `json:"password,omitempty"`

	// Node Proxy to destination.
	// Required.
	Node string `json:"node"`

	// Port Proxy to destination.
	// Required.
	Port uint16 `json:"port"`

	// CreateTime Create time of this address.
	// Output only.
	CreateTime time.Time `json:"create_time"`

	// UpdateTime Update time of this address.
	// Output only.
	UpdateTime time.Time `json:"update_time"`
}

func (*Proxy) Validate

func (p *Proxy) Validate() error

type ProxyService

type ProxyService interface {
	CreateProxy(ctx context.Context, proxy *Proxy, opts CreateProxyOptions) error
	ListProxies(ctx context.Context, opts ListProxiesOptions) (*ListProxiesPage, error)
	DeleteProxy(ctx context.Context, proxyID string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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