apiserver

package module
v0.0.0-...-58306fc Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 13 Imported by: 3

README

API Server documentation

This documentation is a quick overview of the CRUD operations that take place within plunder, this should be a living document as the various endpoint mature over time.

Using the API Server

The API Server now starts as default and listens on a different port to HTTP services used for deployment, by default the plunder API server will listen on port 60443 however the -p --port flag can be used to specify a specific port. Currently the API server will bind to all interfaces.

Starting the API Server

The below example will start the API server on a custom port.

plunder server -p 12345

Accessing the API Server

The API Endpoints should be accessed using REST methodologies and JSON payloads, the API Endpoints should always be defined in endpoints.go (this may change later).

Current issues

### Server configuration

Currently DHCP can be stopped and started but logging output is buggy, HTTP/TFTP Can be started but can't be stopped or restarted.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EndPointManager []EndPoint

EndPointManager - Contains all of the dynamically created endpoints

Functions

func AddDynamicEndpoint

func AddDynamicEndpoint(endpointPattern, path, description, name, method string, epFunc http.HandlerFunc)

AddDynamicEndpoint - will add an endpoint to the api server and link it back to a function

func BuildEnvironmentFromConfig

func BuildEnvironmentFromConfig(path, urlFlag string) (*url.URL, *http.Client, error)

BuildEnvironmentFromConfig will use the apiserver pkg to parse a configuration file and create a http client with the correct authentication and URL

func FindFunctionEndpoint

func FindFunctionEndpoint(u *url.URL, c *http.Client, f, m string) (*EndPoint, *Response)

FindFunctionEndpoint - will do a look up to find an exposed dynamic endpoint

func FunctionPath

func FunctionPath() string

FunctionPath - this will return the api server path for any external caller using the package

func NotifyManager

func NotifyManager(managerName string, n Notification) error

NotifyManager - This will Notify a Manager that there is a new notification that needs to go to subscribers

func RegisterNotificationManager

func RegisterNotificationManager(managerName, endpoint string) error

RegisterNotificationManager will create a manager and an endpoint

func StartAPIServer

func StartAPIServer(path string, port int, insecure bool) error

StartAPIServer - will parse a configuration file and passed variables and start the API Server

func WriteClientConfig

func WriteClientConfig(path, address string, s *ServerConfig) error

WriteClientConfig - will write out the server configuration for the API Server

func WriteServerConfig

func WriteServerConfig(path, hostname, address string, port int, cert, key []byte) error

WriteServerConfig - will write out the server configuration for the API Server

Types

type ClientConfig

type ClientConfig struct {
	Address    string `json:"address,omitempty"`
	Port       int    `json:"port"`
	ClientCert string `json:"cert"`
}

ClientConfig is the structure of an expected configuration for pldctl

func (*ClientConfig) GetServerAddressURL

func (c *ClientConfig) GetServerAddressURL() *url.URL

GetServerAddressURL will retrieve a parsed URL

func (*ClientConfig) RetrieveClientCert

func (c *ClientConfig) RetrieveClientCert() ([]byte, error)

RetrieveClientCert will decode the base64 certificate

type EndPoint

type EndPoint struct {
	Name         string `json:"name"`
	Path         string `json:"path"`
	FunctionPath string `json:"functionEndpoint"`
	Description  string `json:"description"`
	Method       string `json:"method"`
}

EndPoint is the source of truth for handling all of the endpoints exposed through the API Server it also provides a mechanism to interact with the apiserver to find/create api endpoints

func GetEndpoint

func GetEndpoint(name, method string) *EndPoint

GetEndpoint - will return the details for an endpoint

type Notification

type Notification struct {
	ID      string
	RawData []byte
}

Notification is what will be sent to subscribers of a manager

type Response

type Response struct {
	Warning string `json:"warning,omitempty"` // when it maybe worked
	Error   string `json:"error,omitempty"`   // when it goes wrong
	Success string `json:"success,omitempty"` // when it goes correct

	Payload json.RawMessage `json:"payload,omitempty"`
}

Response - This is the wrapper for responses back to a client, if any errors are created then the payload isn't guarenteed

func ParsePlunderDelete

func ParsePlunderDelete(u *url.URL, c *http.Client) (*Response, error)

ParsePlunderDelete will attempt to retrieve data from the plunder API server

func ParsePlunderGet

func ParsePlunderGet(u *url.URL, c *http.Client) (*Response, error)

ParsePlunderGet will attempt to retrieve data from the plunder API server

func ParsePlunderPatch

func ParsePlunderPatch(u *url.URL, c *http.Client, data []byte) (*Response, error)

ParsePlunderPatch will attempt to retrieve data from the plunder API server

func ParsePlunderPost

func ParsePlunderPost(u *url.URL, c *http.Client, data []byte) (*Response, error)

ParsePlunderPost will attempt to retrieve data from the plunder API server

type ServerConfig

type ServerConfig struct {
	ClientConfig
	ServerKey string `json:"key"`
}

ServerConfig is the structure of an expected configuration for pldctl

func OpenServerConfig

func OpenServerConfig(path string) (*ServerConfig, error)

OpenServerConfig will open and parse a Plunder server configuration file

func (*ServerConfig) RetrieveClientCert

func (s *ServerConfig) RetrieveClientCert() ([]byte, error)

RetrieveClientCert will decode the base64 certificate

func (*ServerConfig) RetrieveKey

func (s *ServerConfig) RetrieveKey() ([]byte, error)

RetrieveKey will decode the base64 certificate

Jump to

Keyboard shortcuts

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