core

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MPL-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package core exposes a high-level API for the expected operations of the project. This can be consumed by the CLI, web APIs, etc. This is the safest set of APIs to use.

The entrypoint for core is Project initialized with NewProject. All further APIs and operations hang off of this struct. For example, to initiate a build for an app in a project you could use Project.App.Build().

Eventually this package will also contain UI abstractions or hooks so that you can build a more responsive UI around the long-running operations of this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestFactory

func TestFactory(t testing.T, typ component.Type) *factory.Factory

TestFactory creates a factory for the given component type.

func TestFactoryRegister

func TestFactoryRegister(t testing.T, f *factory.Factory, n string, v interface{})

TestFactoryRegister registers a singleton value to be returned for the factory for the name n.

func TestFactorySingle

func TestFactorySingle(t testing.T, typ component.Type, n string) (*factory.Factory, *mock.Mock)

TestFactorySingle creates a factory for the given component type and registers a single implementation and returns that mock. This is useful to create a factory for the WithFactory option that returns a mocked value that can be tested against.

Types

type App

type App struct {
	Builder  component.Builder
	Registry component.Registry
	Platform component.Platform
	Releaser component.ReleaseManager

	// UI is the UI that should be used for any output that is specific
	// to this app vs the project UI.
	UI terminal.UI
	// contains filtered or unexported fields
}

App represents a single application and exposes all the operations that can be performed on an application.

An App is only valid if it was returned by Project.App. The behavior of App if constructed in any other way is undefined and likely to result in crashes.

func TestApp

func TestApp(t testing.T, p *Project, n string) *App

TestApp returns the app named n in the project.

func (*App) Auth

func (a *App) Auth(ctx context.Context, c interface{}) (*component.AuthResult, error)

Auth authenticates a component. This will return an error if the component doesn't support auth. If this returns nil, then the auth function succeeded but the component itself may still not be authenticated. You must check again with ValidateAuth.

func (*App) Build

func (a *App) Build(ctx context.Context, optFuncs ...BuildOption) (
	*pb.Build,
	*pb.PushedArtifact,
	error,
)

Build builds the artifact from source for this app. TODO(mitchellh): test

func (*App) CanAuth

func (a *App) CanAuth(comp interface{}) bool

CanAuth returns true if the provided component supports authenticating and validating authentication for plugins

func (*App) CanDestroyDeploy

func (a *App) CanDestroyDeploy() bool

CanDestroyDeploy returns true if this app supports destroying deployments.

func (*App) CanDestroyRelease

func (a *App) CanDestroyRelease() bool

CanDestroyRelease returns true if this app supports destroying releases.

func (*App) Close

func (a *App) Close() error

Close is called to clean up any resources. This should be called whenever the app is done being used. This will be called by Project.Close.

func (*App) ComponentProto

func (a *App) ComponentProto(c interface{}) *pb.Component

ComponentProto returns the proto info for a component. The passed component must be part of the app or nil will be returned.

func (*App) Components

func (a *App) Components() []interface{}

Components returns the list of components that were initilized for this app.

func (*App) Deploy

func (a *App) Deploy(ctx context.Context, push *pb.PushedArtifact) (*pb.Deployment, error)

Deploy deploys the given artifact. TODO(mitchellh): test

func (*App) Destroy

func (a *App) Destroy(ctx context.Context) error

Destroy will destroy all the physical resources for this app in the current configured workspace. If this returns an error, it is possible that the destroy is in a partial state.

func (*App) DestroyDeploy

func (a *App) DestroyDeploy(ctx context.Context, d *pb.Deployment) error

DestroyDeploy destroyes a specific deployment.

func (*App) DestroyRelease

func (a *App) DestroyRelease(ctx context.Context, d *pb.Release) error

DestroyRelease destroyes a specific release.

func (*App) PushBuild

func (a *App) PushBuild(ctx context.Context, optFuncs ...PushBuildOption) (*pb.PushedArtifact, error)

Push pushes the given build to the configured registry. This requires that the build artifact be available, which we leave up to the caller. Therefore, please note that this generally can't be called on separate machines, long after a build is done (because the person may have deleted the physical artifact, etc.).

TODO(mitchellh): test

func (*App) Ref

func (a *App) Ref() *pb.Ref_Application

Ref returns the reference to this application for us in API calls.

func (*App) Release

func (a *App) Release(ctx context.Context, target *pb.Deployment) (
	*pb.Release,
	component.Release,
	error,
)

Release releases a set of deploys. TODO(mitchellh): test

func (*App) ValidateAuth

func (a *App) ValidateAuth(ctx context.Context, c interface{}) error

ValidateAuth validates if the component is properly authenticated. This will always return nil if the component doesn't support auth.

type BuildOption

type BuildOption func(*buildOptions) error

BuildOption is used to configure a Build

func BuildWithPush

func BuildWithPush(v bool) BuildOption

BuildWithPush sets whether or not the build will push. The default is for the build to push.

type Option

type Option func(*Project, *options)

Option is used to set options for NewProject.

func WithClient

func WithClient(client pb.WaypointClient) Option

WithClient sets the API client to use.

func WithComponents

func WithComponents(fs map[component.Type]*factory.Factory) Option

WithComponents sets the factories for components.

func WithConfig

func WithConfig(c *config.Config) Option

WithConfig uses the given project configuration for initializing the Project. This configuration must be validated already prior to using this option.

func WithConfigContext

func WithConfigContext(ctx *hcl.EvalContext) Option

WithConfigContext sets an eval context to use for parsing plugin-specific config. It is useful to reuse the same context that was used in parsing the original config here so behavior doesn't change.

func WithDataDir

func WithDataDir(dir *datadir.Project) Option

WithDataDir sets the datadir that will be used for this project.

func WithFactory

func WithFactory(t component.Type, f *factory.Factory) Option

WithFactory sets a factory for a component type. If this isn't set for any component type, then the builtin mapper will be used.

func WithJobInfo

func WithJobInfo(info *component.JobInfo) Option

WithJobInfo sets the base job info used for any executed operations.

func WithLabels

func WithLabels(m map[string]string) Option

WithLabels sets the labels that will override any other labels set.

func WithLogger

func WithLogger(log hclog.Logger) Option

WithLogger sets the logger to use with the project. If this option is not provided, a default logger will be used (`hclog.L()`).

func WithMappers

func WithMappers(m ...*argmapper.Func) Option

WithMappers adds the mappers to the list of mappers.

func WithRootDir

func WithRootDir(dir string) Option

WithRootDir sets the root directory for the project. This is where the root configuration is.

func WithUI

func WithUI(ui terminal.UI) Option

WithUI sets the UI to use. If this isn't set, a BasicUI is used.

func WithWorkspace

func WithWorkspace(ws string) Option

WithWorkspace sets the workspace we'll be working in.

type Project

type Project struct {

	// UI is the terminal UI to use for messages related to the project
	// as a whole. These messages will show up unprefixed for example compared
	// to the app-specific UI.
	UI terminal.UI
	// contains filtered or unexported fields
}

Project represents a project with one or more applications.

The Close function should be called when finished with the project to properly clean up any open resources.

func NewProject

func NewProject(ctx context.Context, os ...Option) (*Project, error)

NewProject creates a new Project with the given options.

func TestProject

func TestProject(t testing.T, opts ...Option) *Project

TestProject returns a fully in-memory and side-effect free Project that can be used for testing. Additional options can be given to provide your own factories, configuration, etc.

func (*Project) App

func (p *Project) App(name string) (*App, error)

App initializes and returns the app with the given name.

func (*Project) Client

func (p *Project) Client() pb.WaypointClient

Client returns the API client for the backend server.

func (*Project) Close

func (p *Project) Close() error

Close is called to clean up resources allocated by the project. This should be called and blocked on to gracefully stop the project.

func (*Project) Ref

func (p *Project) Ref() *pb.Ref_Project

Ref returns the project ref for API calls.

func (*Project) WorkspaceRef

func (p *Project) WorkspaceRef() *pb.Ref_Workspace

WorkspaceRef returns the project ref for API calls.

type PushBuildOption

type PushBuildOption func(*pushBuildOptions) error

PushBuildOption is used to configure a Build

func PushWithBuild

func PushWithBuild(b *pb.Build) PushBuildOption

BuildWithPush sets whether or not the build will push. The default is for the build to push.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳