publicapi

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const LegacyAPIPrefix = ""
View Source
const V1APIPrefix = "/api/v1"

Variables

View Source
var DefaultAPIServerConfig = APIServerConfig{
	ReadHeaderTimeout:          10 * time.Second,
	ReadTimeout:                20 * time.Second,
	WriteTimeout:               20 * time.Second,
	RequestHandlerTimeout:      30 * time.Second,
	RequestHandlerTimeoutByURI: map[string]time.Duration{},
	MaxBytesToReadInBody:       10 * datasize.MB,
}
View Source
var LINESOFLOGTOPRINT = 100

Functions

func GenerateHealthData

func GenerateHealthData() types.HealthInfo

func HTTPError added in v0.3.26

func HTTPError(ctx context.Context, res http.ResponseWriter, err error, statusCode int)

func MountUsage

func MountUsage(path string) (disk types.MountStatus)

Function to get disk usage of path/disk

func SignRequest added in v0.3.26

func SignRequest(reqData any) (req signedRequest, err error)

func TailFile

func TailFile(count int, path string) ([]byte, error)

use "-1" as count for just last line

func UnmarshalSigned added in v0.3.26

func UnmarshalSigned[PayloadType ContainsClientID](ctx context.Context, body io.Reader) (PayloadType, error)

Types

type APIClient

type APIClient struct {
	BaseURI        *url.URL
	DefaultHeaders map[string]string

	Client *http.Client
}

APIClient is a utility for interacting with a node's API server against v1 APIs.

func NewAPIClient

func NewAPIClient(host string, port uint16, path ...string) *APIClient

NewAPIClient returns a new client for a node's API server against v1 APIs the client will use /api/v1 path by default is no custom path is defined

func (*APIClient) Alive

func (apiClient *APIClient) Alive(ctx context.Context) (bool, error)

Alive calls the node's API server health check.

func (*APIClient) Post

func (apiClient *APIClient) Post(ctx context.Context, api string, reqData, resData interface{}) error

func (*APIClient) PostSigned added in v0.3.26

func (apiClient *APIClient) PostSigned(ctx context.Context, api string, reqData, resData interface{}) error

func (*APIClient) Version

func (apiClient *APIClient) Version(ctx context.Context) (*model.BuildVersionInfo, error)

type APIServer

type APIServer struct {
	Address string
	Port    uint16
	// contains filtered or unexported fields
}

APIServer configures a node's public REST API.

func NewAPIServer

func NewAPIServer(params APIServerParams) (*APIServer, error)

func (*APIServer) GetURI

func (apiServer *APIServer) GetURI() *url.URL

GetURI returns the HTTP URI that the server is listening on.

func (*APIServer) ListenAndServe

func (apiServer *APIServer) ListenAndServe(ctx context.Context, cm *system.CleanupManager) error
@title			Bacalhau API
@description	This page is the reference of the Bacalhau REST API. Project docs are available at https://docs.bacalhau.org/. Find more information about Bacalhau at https://github.com/bacalhau-project/bacalhau.
@contact.name	Bacalhau Team
@contact.url	https://github.com/bacalhau-project/bacalhau
@contact.email	team@bacalhau.org
@license.name	Apache 2.0
@license.url	https://github.com/bacalhau-project/bacalhau/blob/main/LICENSE
@host			bootstrap.production.bacalhau.org:1234
@BasePath		/
@schemes		http

ListenAndServe listens for and serves HTTP requests against the API server.

func (*APIServer) RegisterHandlers

func (apiServer *APIServer) RegisterHandlers(apiPrefix string, config ...HandlerConfig) error

type APIServerConfig

type APIServerConfig struct {
	// These are TCP connection deadlines and not HTTP timeouts. They don't control the time it takes for our handlers
	// to complete. Deadlines operate on the connection, so our server will fail to return a result only after
	// the handlers try to access connection properties
	ReadHeaderTimeout time.Duration // the amount of time allowed to read request headers
	ReadTimeout       time.Duration // the maximum duration for reading the entire request, including the body
	WriteTimeout      time.Duration // the maximum duration before timing out writes of the response

	// This represents maximum duration for handlers to complete, or else fail the request with 503 error code.
	RequestHandlerTimeout      time.Duration
	RequestHandlerTimeoutByURI map[string]time.Duration

	// MaxBytesToReadInBody is used by safeHandlerFuncWrapper as the max size of body
	MaxBytesToReadInBody datasize.ByteSize
}

type APIServerParams

type APIServerParams struct {
	Address          string
	Port             uint16
	Host             host.Host
	NodeInfoProvider model.NodeInfoProvider
	Config           APIServerConfig
}

type ContainsClientID added in v0.3.26

type ContainsClientID interface {
	GetClientID() string
}

type HandlerConfig

type HandlerConfig struct {
	Path                  string
	Handler               http.Handler
	RequestHandlerTimeout time.Duration
	Raw                   bool // don't wrap the handler with middleware
}

type SignedRequest added in v0.3.26

type SignedRequest[PayloadType ContainsClientID] struct {
	// The data needed to cancel a running job on the network
	Payload PayloadType `json:"payload" validate:"required"`

	// A base64-encoded signature of the data, signed by the client:
	ClientSignature string `json:"signature" validate:"required"`

	// The base64-encoded public key of the client:
	ClientPublicKey string `json:"client_public_key" validate:"required"`
}

A strongly-typed signed request. We use this type only in our documentation to allow clients to understand the correct type of the payload.

type VersionRequest

type VersionRequest struct {
	ClientID string `json:"client_id" example:"ac13188e93c97a9c2e7cf8e86c7313156a73436036f30da1ececc2ce79f9ea51"`
}

type VersionResponse

type VersionResponse struct {
	VersionInfo *model.BuildVersionInfo `json:"build_version_info"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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