pluginhttp

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

README

http Plugin

This plugin permorms an http request.

Configuration

Fields Description
url destination for the http call, including host, path and query params
method http method (GET/POST/PUT/DELETE)
body a string representing the payload to be sent with the request
headers a list of headers, represented as objects composed of name and value
timeout_seconds an unsigned int representing a custom HTTP client timeout in seconds
auth a single object composed of either a basic object with user and password fields to enable HTTP basic auth, or bearer field to enable Bearer Token Authorization
deny_redirects a boolean representing the policy of redirects
parameters a list of HTTP query parameters, represented as objects composed of key and value
trim_prefix prefix in the response that must be removed before unmarshalling (optional)

Example

An action of type http requires the following kind of configuration:

action:
  type: http
  configuration:
    # mandatory, string
    url: http://example.org/user
    # mandatory, string
    method: POST
    # optional, string as uint16
    timeout_seconds: "5"
    # optional, authentication you can user either basic or bearer auth
    auth:
      basic: 
        user: {{.config.basicAuth.user}}
        password: {{.config.basicAuth.password}}
      bearer: {{.config.auth.token}}
    # optional, string as boolean
    deny_redirects: "false"
    # optional, array of key and value fields
    parameters:
    - key: foo
      value: bar
    # optional, array of name and value fields
    headers:
    - name:  x-request-id
      value: xxx-yyy-zzz
    # optional, string
    body: |
      {
        "name": "pablo"
      }

Requirements

None by default. Sensitive data should be retrieved from configstore and accessed through {{.config.[itemKey]}} rather than hardcoded in your template.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewHTTPClient = defaultHTTPClientFactory

NewHTTPClient is a factory of HTTPClient

View Source
var (
	Plugin = taskplugin.New("http", "0.7", exec,
		taskplugin.WithConfig(validConfig, HTTPConfig{}),
	)
)

the HTTP plugin performs an HTTP call

Functions

func ExecutorMetadata

func ExecutorMetadata() string

ExecutorMetadata generates json schema to validate the metadata returned by the http executor

Types

type Auth added in v1.2.1

type Auth struct {
	Basic  AuthBasic `json:"basic"`
	Bearer string    `json:"bearer"`
}

Auth represents HTTP authentication

type AuthBasic added in v1.2.1

type AuthBasic struct {
	User     string `json:"user"`
	Password string `json:"password"`
}

AuthBasic represents the embedded basic auth inside Auth struct

type HTTPClient added in v1.2.1

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

HTTPClient is an interface for decoupling http.Client

type HTTPClientConfig added in v1.2.1

type HTTPClientConfig struct {
	Timeout       time.Duration
	DenyRedirects bool
}

HTTPClientConfig is a set of options used to initialize a HTTPClient

type HTTPConfig

type HTTPConfig struct {
	URL            string      `json:"url"`
	Method         string      `json:"method"`
	Body           string      `json:"body,omitempty"`
	Headers        []Header    `json:"headers,omitempty"`
	TimeoutSeconds string      `json:"timeout_seconds,omitempty"`
	Auth           Auth        `json:"auth,omitempty"`
	DenyRedirects  string      `json:"deny_redirects,omitempty"`
	Parameters     []Parameter `json:"parameters,omitempty"`
	TrimPrefix     string      `json:"trim_prefix,omitempty"`
}

HTTPConfig is the configuration needed to perform an HTTP call

type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Header represents an HTTP header

type Parameter added in v1.0.1

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

Parameter represents HTTP parameters

Jump to

Keyboard shortcuts

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