remote

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

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFoundRemote is used when no request is defined for a doctype
	ErrNotFoundRemote = errors.New("the doctype has no request defined")
	// ErrInvalidRequest is used when we can't use the request defined by the
	// developer
	ErrInvalidRequest = errors.New("the request is not valid")
	// ErrRequestFailed is used when the connexion to the remote website can't
	// be established
	ErrRequestFailed = errors.New("can't connect to the remote host")
	// ErrInvalidVariables is used when the variables can't be extracted from
	// the request
	ErrInvalidVariables = errors.New("the variables are not valid")
	// ErrMissingVar is used when trying to use a variable that has not been defined
	ErrMissingVar = errors.New("a variable is used in the template, but no value was given")
	// ErrInvalidContentType is used when the response has a content-type that
	// we deny for security reasons
	ErrInvalidContentType = errors.New("the content-type for the response is not authorized")
	// ErrRemoteAssetNotFound is used when the wanted remote asset is not part of
	// our defined list.
	ErrRemoteAssetNotFound = errors.New("wanted remote asset is not part of our asset list")
)

Functions

func ProxyRemoteAsset

func ProxyRemoteAsset(name string, w http.ResponseWriter) error

ProxyRemoteAsset proxy the given http request to fetch an asset from our list of available asset list.

Types

type Doctype

type Doctype struct {
	DocID     string    `json:"_id,omitempty"`
	DocRev    string    `json:"_rev,omitempty"`
	Request   string    `json:"request"`
	UpdatedAt time.Time `json:"updated_at"`
}

Doctype is used to describe a doctype, its request for a remote doctype for example

func (*Doctype) Clone

func (d *Doctype) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Doctype) DocType

func (d *Doctype) DocType() string

DocType implements couchdb.Doc

func (*Doctype) ID

func (d *Doctype) ID() string

ID is used to implement the couchdb.Doc interface

func (*Doctype) Rev

func (d *Doctype) Rev() string

Rev is used to implement the couchdb.Doc interface

func (*Doctype) SetID

func (d *Doctype) SetID(id string)

SetID is used to implement the couchdb.Doc interface

func (*Doctype) SetRev

func (d *Doctype) SetRev(rev string)

SetRev is used to implement the couchdb.Doc interface

type Remote

type Remote struct {
	Doctype string
	Verb    string
	URL     *url.URL
	Headers map[string]string
	Body    string
}

Remote is the struct used to call a remote website for a doctype

func Find

func Find(ins *instance.Instance, doctype string) (*Remote, error)

Find finds the request defined for the given doctype

func ParseRawRequest

func ParseRawRequest(doctype, raw string) (*Remote, error)

ParseRawRequest takes a string and parse it as a remote struct. First line is verb and URL. Then, we have the headers. And for a POST, we have a blank line, and then the body.

func (*Remote) ProxyTo

func (remote *Remote) ProxyTo(ins *instance.Instance, rw http.ResponseWriter, in *http.Request) error

ProxyTo calls the external website and proxy the response

type Request

type Request struct {
	DocID         string            `json:"_id,omitempty"`
	DocRev        string            `json:"_rev,omitempty"`
	RemoteDoctype string            `json:"doctype"`
	Verb          string            `json:"verb"`
	URL           string            `json:"url"`
	ResponseCode  int               `json:"response_code"`
	ContentType   string            `json:"content_type"`
	Variables     map[string]string `json:"variables"`
	CreatedAt     time.Time         `json:"created_at"`
}

Request is used to log in couchdb a call to a remote website

func (*Request) Clone

func (r *Request) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Request) DocType

func (r *Request) DocType() string

DocType implements couchdb.Doc

func (*Request) ID

func (r *Request) ID() string

ID is used to implement the couchdb.Doc interface

func (*Request) Rev

func (r *Request) Rev() string

Rev is used to implement the couchdb.Doc interface

func (*Request) SetID

func (r *Request) SetID(id string)

SetID is used to implement the couchdb.Doc interface

func (*Request) SetRev

func (r *Request) SetRev(rev string)

SetRev is used to implement the couchdb.Doc interface

Jump to

Keyboard shortcuts

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