api

package
v0.0.0-...-1eb86f4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package api provides the core business logic for func.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	Apply(ctx context.Context, req *ApplyRequest) (*ApplyResponse, error)
}

API is the common interface for the target func api.

type ApplyRequest

type ApplyRequest struct {
	// Project is the project to apply changes to.
	Project string

	// Config is the configuration to apply.
	Config hcl.Body
}

An ApplyRequest is the request to pass to Apply().

type ApplyResponse

type ApplyResponse struct {
	// SourcesRequired is set if source code uploads are required.
	SourcesRequired []*SourceRequest
}

ApplyResponse is returned from applying resources.

The response may contain an UploadRequest, in which case the apply is rejected due to missing source code. The source code should be uploaded and then Apply should be retried.

type Client

type Client struct {
	API    API
	Logger *zap.Logger
	Source SourceProvider
}

Client is a func api client.

func (*Client) Apply

func (c *Client) Apply(ctx context.Context, req *ApplyRequest) error

Apply applies the given hcl configuration.

If source code is needed, source is uploaded. After upload, apply is retried.

type Error

type Error struct {
	Code        ErrorCode
	Message     string
	Diagnostics hcl.Diagnostics
}

An Error is a known error returned from the API.

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode string

An ErrorCode indicates the type of error that occurred.

const (
	ValidationError ErrorCode = "validation"
	Unavailable     ErrorCode = "unavailable"
)

Valid error codes:

type Reconciler

type Reconciler interface {
	Reconcile(ctx context.Context, id, project string, graph reconciler.Graph) error
}

A Reconciler reconciles changes to the graph.

type Registry

type Registry interface {
	Type(typename string) reflect.Type
	Typenames() []string
}

A Registry is used for matching resource type names to resource implementations.

type Server

type Server struct {
	Logger    *zap.Logger
	Registry  Registry
	Source    source.Storage
	Storage   Storage
	Validator Validator

	// If set, reconciliation is done synchronously.
	Reconciler Reconciler
}

Server provides the serverside api implementation.

func (*Server) Apply

func (s *Server) Apply(ctx context.Context, req *ApplyRequest) (*ApplyResponse, error)

Apply applies resource changes.

If any resources require source code, the response will contain source requests. Once the sources have been uploaded, Apply should be retried.

The returned error is always of type *Error.

type SourceProvider

type SourceProvider interface {
	Source(sha string) *bytes.Buffer
}

SourceProvider provides source code for upload.

type SourceRequest

type SourceRequest struct {
	// Key is the key of the source code to upload.
	// The digest maps back to a resource in the ApplyRequest config.
	Key string

	// Url is the destination URL to upload to.
	// The request should be done as a HTTP PUT.
	URL string

	// Headers include the additional headers that must be set on the upload.
	Headers map[string]string
}

An SourceRequest describes a single upload request.

type Storage

type Storage interface {
	PutGraph(ctx context.Context, project string, g *resource.Graph) error
}

Storage persists resolved graphs.

type Validator

type Validator interface {
	Validate(input interface{}, rule string) error
}

A Validator validates user input.

Directories

Path Synopsis
Package httpapi provides a client and server for a remote http api.
Package httpapi provides a client and server for a remote http api.

Jump to

Keyboard shortcuts

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