pm

package
v0.0.0-...-079c800 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTML       string = "html"
	Javascript string = "javascript"
	JSON       string = "json"
	Text       string = "text"
	XML        string = "xml"
)

These constants represent the available raw languages.

Variables

This section is empty.

Functions

func ConvertPostmanToScenarios

func ConvertPostmanToScenarios(
	config *types.Configuration,
	collection *PostmanCollection,
	started time.Time,
	ended time.Time,
) (scenarios []*types.APIScenario)

ConvertPostmanToScenarios builds scenarios from Postman contents

Types

type ListenType

type ListenType string

ListenType defines the kind of script attached to an event.

const (
	// PreRequest script is usually executed before the HTTP request is sent.
	PreRequest ListenType = "prerequest"
	// Test script is usually executed after the actual HTTP request is sent, and the response is received.
	Test ListenType = "test"
)

type PostmanAuth

type PostmanAuth struct {
	Type   types.AuthType      `json:"type,omitempty"`
	APIKey []*PostmanAuthParam `json:"apikey,omitempty"`
	AWSV4  []*PostmanAuthParam `json:"awsv4,omitempty"`
	Basic  []*PostmanAuthParam `json:"basic,omitempty"`
	Bearer []*PostmanAuthParam `json:"bearer,omitempty"`
	Digest []*PostmanAuthParam `json:"digest,omitempty"`
	Hawk   []*PostmanAuthParam `json:"hawk,omitempty"`
	NoAuth []*PostmanAuthParam `json:"noauth,omitempty"`
	OAuth1 []*PostmanAuthParam `json:"oauth1,omitempty"`
	OAuth2 []*PostmanAuthParam `json:"oauth2,omitempty"`
	NTLM   []*PostmanAuthParam `json:"ntlm,omitempty"`
}

PostmanAuth contains the authentication method used and its associated parameters.

func CreateAuth

func CreateAuth(a types.AuthType, params ...*PostmanAuthParam) *PostmanAuth

CreateAuth creates a new PostmanAuth struct with the given parameters.

func (*PostmanAuth) GetParams

func (a *PostmanAuth) GetParams() []*PostmanAuthParam

GetParams returns the parameters related to the authentication method in use.

func (*PostmanAuth) MarshalJSON

func (a *PostmanAuth) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of an PostmanAuth.

func (*PostmanAuth) UnmarshalJSON

func (a *PostmanAuth) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses the JSON-encoded data and create an PostmanAuth from it. Depending on the Postman PostmanCollection version, an auth property can either be an array or an object.

  • v2.1.0 : Array
  • v2.0.0 : Object

type PostmanAuthParam

type PostmanAuthParam struct {
	Key   string      `json:"key,omitempty"`
	Value interface{} `json:"value,omitempty"`
	Type  string      `json:"type,omitempty"`
}

PostmanAuthParam represents an attribute for any authentication method provided by Postman. For example "username" and "password" are set as auth attributes for Basic Authentication method.

func CreateAuthParam

func CreateAuthParam(key string, value string) *PostmanAuthParam

CreateAuthParam creates a new PostmanAuthParam of type string.

type PostmanCollection

type PostmanCollection struct {
	Auth      *PostmanAuth       `json:"auth,omitempty"`
	Info      PostmanInfo        `json:"info"`
	Items     []*PostmanItems    `json:"item"`
	Events    []*PostmanEvent    `json:"event,omitempty"`
	Variables []*PostmanVariable `json:"variable,omitempty"`
}

PostmanCollection represents a Postman PostmanCollection.

func ConvertScenariosToPostman

func ConvertScenariosToPostman(
	name string,
	scenarios ...*types.APIScenario,
) (c *PostmanCollection)

ConvertScenariosToPostman builds Postman contents

func CreateCollection

func CreateCollection(name string, desc string) *PostmanCollection

CreateCollection returns a new PostmanCollection.

func ParseCollection

func ParseCollection(r io.Reader) (c *PostmanCollection, err error)

ParseCollection parses the content of the provided data stream into a PostmanCollection object.

func (*PostmanCollection) AddItem

func (c *PostmanCollection) AddItem(item *PostmanItems)

AddItem appends an item (PostmanItem or PostmanItemGroup) to the existing items slice.

func (*PostmanCollection) AddItemGroup

func (c *PostmanCollection) AddItemGroup(name string) (f *PostmanItems)

AddItemGroup creates a new PostmanItemGroup and appends it to the existing items slice.

func (*PostmanCollection) Write

func (c *PostmanCollection) Write(w io.Writer) (err error)

Write encodes the PostmanCollection struct in JSON and writes it into the provided io.Writer.

type PostmanCollectionDescription

type PostmanCollectionDescription struct {
	Content string `json:"content,omitempty"`
	Type    string `json:"type,omitempty"`
	Version string `json:"version,omitempty"`
}

PostmanCollectionDescription contains collection description.

func (PostmanCollectionDescription) MarshalJSON

func (d PostmanCollectionDescription) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of a PostmanCollectionDescription. If the PostmanCollectionDescription only has a content, it is returned as a string.

func (*PostmanCollectionDescription) UnmarshalJSON

func (d *PostmanCollectionDescription) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses the JSON-encoded data and create a PostmanCollectionDescription from it. A PostmanCollectionDescription can be created from an object or a string.

type PostmanConverter

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

PostmanConverter converter

type PostmanCookie

type PostmanCookie struct {
	Domain     string      `json:"domain"`
	Expires    string      `json:"expires,omitempty"`
	MaxAge     string      `json:"maxAge,omitempty"`
	HostOnly   bool        `json:"hostOnly,omitempty"`
	HTTPOnly   bool        `json:"httpOnly,omitempty"`
	Name       string      `json:"name,omitempty"`
	Path       string      `json:"path"`
	Secure     string      `json:"secure,omitempty"`
	Session    bool        `json:"session,omitempty"`
	Value      string      `json:"value,omitempty"`
	Extensions interface{} `json:"extensions,omitempty"`
}

PostmanCookie represents a cookie that follows the Google Chrome format (https://developer.chrome.com/extensions/cookies)

type PostmanEvent

type PostmanEvent struct {
	ID       string         `json:"id,omitempty"`
	Listen   ListenType     `json:"listen,omitempty"`
	Script   *PostmanScript `json:"script,omitempty"`
	Disabled bool           `json:"disabled,omitempty"`
}

An PostmanEvent defines a script associated with an associated event name.

func CreatePostmanEvent

func CreatePostmanEvent(listenType ListenType, script []string) *PostmanEvent

CreatePostmanEvent creates a new PostmanEvent of type text/javascript.

type PostmanHeader

type PostmanHeader struct {
	Key         string `json:"key"`
	Value       string `json:"value"`
	Disabled    bool   `json:"disabled,omitempty"`
	Description string `json:"description,omitempty"`
}

PostmanHeader represents an HTTP PostmanHeader.

type PostmanHeaderList

type PostmanHeaderList struct {
	Headers []*PostmanHeader
}

PostmanHeaderList contains a list of headers.

func (PostmanHeaderList) MarshalJSON

func (hl PostmanHeaderList) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of a PostmanHeaderList.

func (*PostmanHeaderList) UnmarshalJSON

func (hl *PostmanHeaderList) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses the JSON-encoded data and create a PostmanHeaderList from it. A PostmanHeaderList can be created from an array or a string.

type PostmanInfo

type PostmanInfo struct {
	Name        string                       `json:"name"`
	Description PostmanCollectionDescription `json:"description"`
	Version     string                       `json:"version"`
	Schema      string                       `json:"schema"`
}

PostmanInfo stores data about the collection.

type PostmanItem

type PostmanItem struct {
	Name                    string             `json:"name"`
	Description             string             `json:"description,omitempty"`
	Variables               []*PostmanVariable `json:"variable,omitempty"`
	Events                  []*PostmanEvent    `json:"event,omitempty"`
	ProtocolProfileBehavior interface{}        `json:"protocolProfileBehavior,omitempty"`
	ID                      string             `json:"id,omitempty"`
	Request                 *PostmanRequest    `json:"request,omitempty"`
	Responses               []*PostmanResponse `json:"response,omitempty"`
}

An PostmanItem is an entity which contain an actual HTTP request, and sample responses attached to it.

type PostmanItemGroup

type PostmanItemGroup struct {
	Name                    string             `json:"name"`
	Description             string             `json:"description,omitempty"`
	Variables               []*PostmanVariable `json:"variable,omitempty"`
	Events                  []*PostmanEvent    `json:"event,omitempty"`
	ProtocolProfileBehavior interface{}        `json:"protocolProfileBehavior,omitempty"`
	Items                   []*PostmanItems    `json:"item"`
	Auth                    *PostmanAuth       `json:"auth,omitempty"`
}

A PostmanItemGroup is an ordered set of requests.

type PostmanItems

type PostmanItems struct {
	// Common fields.
	Name                    string             `json:"name"`
	Description             string             `json:"description,omitempty"`
	Variables               []*PostmanVariable `json:"variable,omitempty"`
	Events                  []*PostmanEvent    `json:"event,omitempty"`
	ProtocolProfileBehavior interface{}        `json:"protocolProfileBehavior,omitempty"`
	// Fields specific to PostmanItem
	ID        string             `json:"id,omitempty"`
	Request   *PostmanRequest    `json:"request,omitempty"`
	Responses []*PostmanResponse `json:"response,omitempty"`
	// Fields specific to PostmanItemGroup
	Items []*PostmanItems `json:"item"`
	Auth  *PostmanAuth    `json:"auth,omitempty"`
}

PostmanItems are the basic unit for a Postman collection. It can either be a request (PostmanItem) or a folder (PostmanItemGroup).

func CreatePostmanItem

func CreatePostmanItem(i PostmanItem) *PostmanItems

CreatePostmanItem is a helper to create a new PostmanItem.

func CreatePostmanItemGroup

func CreatePostmanItemGroup(ig PostmanItemGroup) *PostmanItems

CreatePostmanItemGroup is a helper to create a new PostmanItemGroup.

func (*PostmanItems) AddItem

func (i *PostmanItems) AddItem(item *PostmanItems)

AddItem appends an item to the existing items slice.

func (*PostmanItems) AddItemGroup

func (i *PostmanItems) AddItemGroup(name string) (f *PostmanItems)

AddItemGroup creates a new PostmanItem folder and appends it to the existing items slice.

func (PostmanItems) IsGroup

func (i PostmanItems) IsGroup() bool

IsGroup returns false as an PostmanItem is not a group.

func (PostmanItems) MarshalJSON

func (i PostmanItems) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of an PostmanItem/PostmanItemGroup.

type PostmanQueryParam

type PostmanQueryParam struct {
	Key         string  `json:"key"`
	Value       string  `json:"value"`
	Description *string `json:"description"`
}

PostmanQueryParam param for query

type PostmanRequest

type PostmanRequest struct {
	URL         *PostmanURL         `json:"url"`
	Auth        *PostmanAuth        `json:"auth,omitempty"`
	Proxy       interface{}         `json:"proxy,omitempty"`
	Certificate interface{}         `json:"certificate,omitempty"`
	Method      types.MethodType    `json:"method"`
	Description interface{}         `json:"description,omitempty"`
	Header      []*PostmanHeader    `json:"header,omitempty"`
	Body        *PostmanRequestBody `json:"body,omitempty"`
}

A PostmanRequest represents an HTTP request.

func (*PostmanRequest) MarshalJSON

func (r *PostmanRequest) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of a PostmanRequest. If the PostmanRequest only contains an PostmanURL with the Get HTTP method, it is returned as a string.

func (*PostmanRequest) UnmarshalJSON

func (r *PostmanRequest) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses the JSON-encoded data and create a PostmanRequest from it. A PostmanRequest can be created from an object or a string. If a string, the string is assumed to be the request PostmanURL and the method is assumed to be 'GET'.

type PostmanRequestBody

type PostmanRequestBody struct {
	Mode       string                     `json:"mode"`
	Raw        string                     `json:"raw,omitempty"`
	URLEncoded interface{}                `json:"urlencoded,omitempty"`
	FormData   interface{}                `json:"formdata,omitempty"`
	File       interface{}                `json:"file,omitempty"`
	GraphQL    interface{}                `json:"graphql,omitempty"`
	Disabled   bool                       `json:"disabled,omitempty"`
	Options    *PostmanRequestBodyOptions `json:"options,omitempty"`
}

PostmanRequestBody represents the data usually contained in the request body.

type PostmanRequestBodyOptions

type PostmanRequestBodyOptions struct {
	Raw PostmanRequestBodyOptionsRaw `json:"raw,omitempty"`
}

PostmanRequestBodyOptions holds body options.

type PostmanRequestBodyOptionsRaw

type PostmanRequestBodyOptionsRaw struct {
	Language string `json:"language,omitempty"`
}

PostmanRequestBodyOptionsRaw represents the acutal language to use in postman. (See possible options in the cost above)

type PostmanResponse

type PostmanResponse struct {
	ID              string             `json:"id,omitempty"`
	OriginalRequest *PostmanRequest    `json:"originalRequest,omitempty"`
	ResponseTime    interface{}        `json:"responseTime,omitempty"`
	Timings         interface{}        `json:"timings,omitempty"`
	Headers         *PostmanHeaderList `json:"header,omitempty"`
	Cookies         []*PostmanCookie   `json:"cookie,omitempty"`
	Body            string             `json:"body,omitempty"`
	Status          string             `json:"status,omitempty"`
	Code            int                `json:"code,omitempty"`
	Name            string             `json:"name,omitempty"`
	PreviewLanguage string             `json:"_postman_previewlanguage,omitempty"`
}

A PostmanResponse represents an HTTP response.

type PostmanScript

type PostmanScript struct {
	ID   string      `json:"id,omitempty"`
	Type string      `json:"type,omitempty"`
	Exec []string    `json:"exec,omitempty"`
	Src  *PostmanURL `json:"src,omitempty"`
	Name string      `json:"name,omitempty"`
}

A PostmanScript is a snippet of Javascript code that can be used to to perform setup or teardown operations on a particular response.

type PostmanURL

type PostmanURL struct {
	Raw       string               `json:"raw"`
	Protocol  string               `json:"protocol,omitempty"`
	Host      []string             `json:"host,omitempty"`
	Path      []string             `json:"path,omitempty"`
	Port      string               `json:"port,omitempty"`
	Query     []*PostmanQueryParam `json:"query,omitempty"`
	Hash      string               `json:"hash,omitempty"`
	Variables []*PostmanVariable   `json:"variable,omitempty" mapstructure:"variable"`
}

PostmanURL is a struct that contains an PostmanURL in a "broken-down way". Raw contains the complete PostmanURL.

func UnmarshalURLJSON

func UnmarshalURLJSON(b []byte) (u *PostmanURL, err error)

UnmarshalURLJSON parses the JSON-encoded data and create an PostmanURL from it. An PostmanURL can be created from an object or a string. If a string, the value is assumed to be the Raw attribute of the PostmanURL.

func (*PostmanURL) MarshalJSON

func (u *PostmanURL) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of an PostmanURL. It encodes the PostmanURL as a string if it does not contain any variable. In case it contains any variable, it gets encoded as an object.

func (*PostmanURL) String

func (u *PostmanURL) String() string

String returns the raw version of the PostmanURL.

type PostmanVariable

type PostmanVariable struct {
	ID          string `json:"id,omitempty"`
	Key         string `json:"key,omitempty"`
	Type        string `json:"type,omitempty"`
	Name        string `json:"name,omitempty"`
	Value       string `json:"value,omitempty"`
	Description string `json:"description,omitempty"`
	System      bool   `json:"system,omitempty"`
	Disabled    bool   `json:"disabled,omitempty"`
}

A PostmanVariable allows you to store and reuse values in your requests and scripts.

func CreatePostmanVariable

func CreatePostmanVariable(name string, value string) *PostmanVariable

CreatePostmanVariable creates a new PostmanVariable of type string.

func (*PostmanVariable) KeyName

func (v *PostmanVariable) KeyName() string

KeyName accessor

Jump to

Keyboard shortcuts

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