command

package
v0.0.0-...-7faa966 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Runner lets us mock exec.Command for testing
	Runner = exec.Command

	// ErrUnknownCommand indicates the type of command is not recognized
	ErrUnknownCommand = fmt.Errorf("unknown command type")
)
View Source
var (
	// GET is a GET request
	GET = "GET"
	// POST is a POST request
	POST = "POST"
	// PUT is a PUT request
	PUT = "PUT"
)
View Source
var (

	// HTTPClient is the client Direct commands use
	HTTPClient = &http.Client{
		Timeout: 30 * time.Second,
	}
)

Functions

This section is empty.

Types

type Command

type Command struct {
	Type      string `json:"type"`
	Commander `json:"-"`
}

Command is an individual command

func (*Command) MarshalJSON

func (c *Command) MarshalJSON() ([]byte, error)

MarshalJSON encodes our Commander as `comamnd`

func (*Command) UnmarshalJSON

func (c *Command) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals our Commander interface to a struct

type Commander

type Commander interface {
	Valid() (err error)
	DeParameterize(params []string) (err error)
	AddCredentials(credentials map[string]string)
	Run() (bdy []byte, err error)
}

Commander outlines methods to run commands

type Curl

type Curl struct {
	Command string `json:"command"`
}

Curl is a cURL command

func (*Curl) AddCredentials

func (c *Curl) AddCredentials(creds map[string]string)

AddCredentials adds the user's OAuth2 credentials (if applicable)

func (*Curl) DeParameterize

func (c *Curl) DeParameterize(params []string) (err error)

DeParameterize replaces parameters in the cURL statement

func (*Curl) Run

func (c *Curl) Run() ([]byte, error)

Run executes a cURL command

func (*Curl) Valid

func (c *Curl) Valid() error

Valid removes potentially harmful characters from a cURL command

type Direct

type Direct struct {
	Client   HTTPClienter `json:"-"`
	Method   string       `json:"method,omitempty"`
	Body     string       `json:"body,omitempty"`
	Provider string       `json:"provider,omitempty"`

	Web
	// contains filtered or unexported fields
}

Direct is a command where each component (method, headers, etc) are separate

func (*Direct) AddCredentials

func (d *Direct) AddCredentials(creds map[string]string)

AddCredentials adds the user's OAuth2 credentials

func (*Direct) DeParameterize

func (d *Direct) DeParameterize(params []string) (err error)

DeParameterize replaces parameters in the url, headers, and body

func (*Direct) Run

func (d *Direct) Run() ([]byte, error)

Run executes a command directly

func (*Direct) Valid

func (d *Direct) Valid() error

Valid validates a Direct command

type HTTPClienter

type HTTPClienter interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClienter allows for mocking the client in tests

type Header struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Header is an HTTP header

type Response

type Response struct {
	Body interface{} `json:"body"`
}

Response is a command response

type Web

type Web struct {
	URL     string   `json:"url"`
	Headers []Header `json:"headers,omitempty"`
	// contains filtered or unexported fields
}

Web executes a command as a headless browser

func (*Web) AddCredentials

func (w *Web) AddCredentials(creds map[string]string)

AddCredentials adds the user's OAuth2 credentials (if applicable)

func (*Web) DeParameterize

func (w *Web) DeParameterize(params []string) (err error)

DeParameterize replaces parameters in the url, headers, and body

func (*Web) Run

func (w *Web) Run() (bdy []byte, err error)

Run executes a command with a headless browser TODO: Set headers, etc...

func (*Web) Valid

func (w *Web) Valid() error

Valid validates a Web command

Jump to

Keyboard shortcuts

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