apitypes

package
v0.0.0-...-2bc12df Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package apitypes declares types common to the API client and server.

Index

Constants

View Source
const (
	UnsupportedAction  = "puppetlabs.wash/unsupported-action"
	UnknownError       = "puppetlabs.wash/unknown-error"
	StreamingError     = "puppetlabs.wash/streaming-error"
	EntryNotFound      = "puppetlabs.wash/entry-not-found"
	PluginDoesNotExist = "puppetlabs.wash/plugin-does-not-exist"
	BadRequest         = "puppetlabs.wash/bad-request"
	BadActionRequest   = "puppetlabs.wash/bad-action-request"
	JournalUnavailable = "puppetlabs.wash/journal-unavailable"
	ErroredAction      = "puppetlabs.wash/errored-action"
	DuplicateCName     = "puppetlabs.wash/duplicate-cname"
	RelativePath       = "puppetlabs.wash/relative-path"
	InvalidPaths       = "puppetlabs.wash/invalid-paths"
	OutOfBounds        = "puppetlabs.wash/out-of-bounds"
	NonWashPath        = "puppetlabs.wash/non-wash-path"
	InvalidBool        = "puppetlabs.wash/invalid-bool"
	InvalidInt         = "puppetlabs.wash/invalid-int"
)

Define error kinds returned by the API

Enumerates packet types used by the API.

View Source
const JournalDescHeader = "JournalDesc"

JournalDescHeader is the name of the HTTP Header used to provide a more detailed description of the activity related to that journal entry, to be displayed as part of the history.

View Source
const JournalIDHeader = "JournalID"

JournalIDHeader is the name of the HTTP Header used to provide a journal ID to assocate multiple actions.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity struct {
	Description string    `json:"description"`
	Start       time.Time `json:"start"`
}

Activity describes an activity from wash's `activity.History`.

type Entry

type Entry struct {
	TypeID     string                 `json:"type_id"`
	Path       string                 `json:"path"`
	Actions    []string               `json:"actions"`
	Name       string                 `json:"name"`
	CName      string                 `json:"cname"`
	Attributes plugin.EntryAttributes `json:"attributes"`
	Metadata   plugin.JSONObject      `json:"metadata"`
}

Entry represents a Wash entry as interpreted by the API.

swagger:response

func NewEntry

func NewEntry(e plugin.Entry) Entry

func (*Entry) Supports

func (e *Entry) Supports(action plugin.Action) bool

Supports returns true if e supports the given action, false otherwise.

type EntrySchema

type EntrySchema struct {
	plugin.EntrySchema
	// contains filtered or unexported fields
}

EntrySchema describes an entry's schema, which is what's returned by the /fs/schema endpoint.

swagger:response

func NewEntrySchema

func NewEntrySchema(s *plugin.EntrySchema) *EntrySchema

func (*EntrySchema) Actions

func (s *EntrySchema) Actions() []string

Actions returns the entry's supported actions

func (*EntrySchema) Children

func (s *EntrySchema) Children() []*EntrySchema

Children returns the entry's child schemas

func (*EntrySchema) Description

func (s *EntrySchema) Description() string

Description returns the entry's description

func (*EntrySchema) GetChild

func (s *EntrySchema) GetChild(typeID string) *EntrySchema

GetChild returns the child schema corresponding to typeID

func (*EntrySchema) Label

func (s *EntrySchema) Label() string

Label returns the entry's label

func (EntrySchema) MarshalJSON

func (s EntrySchema) MarshalJSON() ([]byte, error)

MarshalJSON marshals the entry's schema to JSON. It takes a value receiver so that the entry schema's still marshalled when it's referenced as an interface{} object. See https://stackoverflow.com/a/21394657 for more details.

func (*EntrySchema) MetadataSchema

func (s *EntrySchema) MetadataSchema() *plugin.JSONSchema

MetadataSchema returns the entry's metadata schema

func (*EntrySchema) PartialMetadataSchema

func (s *EntrySchema) PartialMetadataSchema() *plugin.JSONSchema

PartialMetadataSchema returns the entry's partial metadata schema

func (*EntrySchema) Path

func (s *EntrySchema) Path() string

Path returns the unique path to this specific entry's schema (relative to the stree root). The path consists of

<root_label>/<parent1_label>/.../<label>

func (*EntrySchema) SetActions

func (s *EntrySchema) SetActions(actions []string) *EntrySchema

SetActions sets the entry's supported actions. This should only be called by the tests.

func (*EntrySchema) SetChildren

func (s *EntrySchema) SetChildren(children []*EntrySchema) *EntrySchema

SetChildren sets the entry's children. This should only be called by the tests.

func (*EntrySchema) SetDescription

func (s *EntrySchema) SetDescription(description string) *EntrySchema

SetDescription sets the entry's description. This should only be called by the tests.

func (*EntrySchema) SetMetadataSchema

func (s *EntrySchema) SetMetadataSchema(schema *plugin.JSONSchema)

SetMetadataSchema sets the entry's metadata schema to s. This should only be called by the tests.

func (*EntrySchema) SetPartialMetadataSchema

func (s *EntrySchema) SetPartialMetadataSchema(schema *plugin.JSONSchema)

SetPartialMetadataSchema sets the entry's meta attribute schema to s. This should only be called by the tests

func (*EntrySchema) SetPath

func (s *EntrySchema) SetPath(path string) *EntrySchema

SetPath sets the entry's schema path. This should only be called by the tests.

func (*EntrySchema) SetSignals

func (s *EntrySchema) SetSignals(signals []SignalSchema) *EntrySchema

SetSignals sets the entry's supported signals. This should only be called by the tests.

func (*EntrySchema) SetTypeID

func (s *EntrySchema) SetTypeID(typeID string) *EntrySchema

SetTypeID sets the entry's type ID. This should only be called by the tests.

func (*EntrySchema) Signals

func (s *EntrySchema) Signals() []SignalSchema

Signals returns the entry's supported signals

func (*EntrySchema) Singleton

func (s *EntrySchema) Singleton() bool

Singleton returns true if the entry's a singleton, false otherwise.

func (*EntrySchema) ToMap

func (s *EntrySchema) ToMap() map[string][]string

ToMap returns a map of <path> => <childPaths...>. It is useful for testing.

func (*EntrySchema) TypeID

func (s *EntrySchema) TypeID() string

TypeID returns the entry's type ID.

func (*EntrySchema) UnmarshalJSON

func (s *EntrySchema) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the entry's schema from JSON. EntrySchemas are unmarshalled into their stree representation. Specifically, given stree output like

docker ├── containers │   └── [container] │   ├── log │   ├── metadata.json │   └── fs │   ├── [dir] │   │   ├── [dir] │   │   └── [file] │   └── [file] └── volumes

└── [volume]
    ├── [dir]
    │   ├── [dir]
    │   └── [file]
    └── [file]

The unmarshalled graph will have nodes "containers", "container", "log", "metadata.json", "fs", "dir", "file", "file" to mirror the first half of the tree (the second "file" node represents "fs"' "file" child while the first "file" node represents "dir"'s "file" child). The second half of the tree is captured by nodes "volumes", "volume", "dir", "file", "file" (here, the second "file" node represents "volume"'s "file" child while the first "file" node represents "dir"'s "file" child). The stree's root is the "docker" node.

Unmarshalling the graph this way makes things symmetric with what a user sees via stree. It also simplifies the implementation of some `wash find` primaries.

NOTE: One way to think about this representation is as follows. Consider a node A. Let R-B-A and R-C-D-A be two possible paths from the stree root R to A. Then the unmarshalled graph will have two different "A" nodes -- one for the path "R-B-A", and another for the path "R-C-D-A". Thus, the unmarshalled graph represents all possible paths from the stree root R (the starting entry) to its descendants (the other nodes). This is the precise definition of an entry's stree.

NOTE: The type ID uniquely identifies a specific class of entries. The path identifies a specific kind of entries. For example in the above stree output, docker/containers/container/fs/dir and docker/volumes/volume/dir both share a common "volumeDir" class. However, the former represents entries that are directories in a Docker container's enumerated filesystem while the latter represents entries that are directories inside a Docker volume.

NOTE: The above "path" => "kind" analogy is not always correct. For example, "docker/containers/container/fs/file" and "docker/containers/container/fs/dir/file" represent the same kind of entry (a file inside a Docker container). However, the analogy is good enough for most cases.

type ErrorFields

type ErrorFields = map[string]interface{}

ErrorFields represents the fields of an ErrorObj

type ErrorObj

type ErrorObj struct {
	// Identifies the kind of error.
	Kind string `json:"kind"`
	// A description of what failed.
	Msg string `json:"msg"`
	// Additional structured data that may be useful in responding to the error.
	Fields ErrorFields `json:"fields"`
}

ErrorObj represents an API error object

func (*ErrorObj) Error

func (e *ErrorObj) Error() string

Provides a nicely formatted string representation of the error. Omits Fields. If you want to use fields, either access them directly or serialize the whole thing to JSON as part of a larger set of JSON output.

type ExecBody

type ExecBody struct {
	// Name of the executable to invoke
	Cmd string `json:"cmd"`
	// Array of arguments to the executable
	Args []string `json:"args"`
	// Additional execution options
	Opts ExecOptions `json:"opts"`
}

ExecBody encapsulates the payload for a call to a plugin's Exec function

type ExecOptions

type ExecOptions struct {
	// Input to pass on stdin when executing the command
	Input string `json:"input"`
}

ExecOptions are options that can be passed as part of an Exec call. These are not identical to plugin.ExecOptions because initially the API only supports receiving a string of input, not a reader.

type ExecPacket

type ExecPacket struct {
	TypeField plugin.ExecPacketType `json:"type"`
	Timestamp time.Time             `json:"timestamp"`
	Data      interface{}           `json:"data"`
	Err       *ErrorObj             `json:"error"`
}

ExecPacket is a single packet of results from an exec. If TypeField is Stdout or Stderr, Data will be a string. If TypeField is Exitcode, Data will be an int (or float64 if deserialized from JSON).

swagger:response

type HistoryResponse

type HistoryResponse struct {
	// in: body
	Activities []Activity
}

HistoryResponse describes the result returned by the `/history` endpoint.

swagger:response

type ScreenviewBody

type ScreenviewBody struct {
	Name   string           `json:"name"`
	Params analytics.Params `json:"params"`
}

ScreenviewBody encapsulates the payload for a call to analytics.Client#Screenview

type SignalBody

type SignalBody struct {
	// Name of the signal that's to be sent
	Signal string `json:"signal"`
}

SignalBody encapsulates the payload for a call to a plugin's Signal function

type SignalSchema

type SignalSchema = plugin.SignalSchema

SignalSchema represents a signal's schema

Jump to

Keyboard shortcuts

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