brokerpak

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package brokerpak implements the "pak" command and other things

Index

Examples

Constants

View Source
const (
	// BuiltinPakLocation is the file-system location to load brokerpaks from to
	// make them look builtin.
	BuiltinPakLocation = "./"
)
View Source
const ManifestName = "manifest.yml"

Variables

This section is empty.

Functions

func Docs

func Docs(pack string) error

Docs generates the markdown usage docs for the given pack and writes them to stdout.

func Info

func Info(pack string) error

Info writes out human-readable information about the brokerpak.

func Init

func Init(directory string) error

Init initializes a new brokerpak in the given directory with an example manifest and service definition.

func ListBrokerpaks

func ListBrokerpaks(directory string) ([]string, error)

ListBrokerpaks gets all brokerpaks in a given directory.

func Pack

func Pack(directory string, cachePath string, includeSource, compress bool, target platform.Platform) (string, error)

Pack creates a new brokerpak from the given directory which MUST contain a manifest.yml file. If the pack was successful, the returned string will be the path to the created brokerpak.

func RegisterAll

func RegisterAll(registry broker.BrokerRegistry) error

RegisterAll fetches all brokerpaks from the settings file and registers them with the given registry.

func RunExamples

func RunExamples(pack string)

RunExamples executes the examples from a brokerpak.

func Validate

func Validate(pack string) error

Validate checks the brokerpak for syntactic and limited semantic errors.

Example
pk, err := fakeBrokerpak()
defer os.Remove(pk)

if err != nil {
	panic(err)
}

if err := Validate(pk); err != nil {
	panic(err)
} else {
	fmt.Println("ok!")
}
Output:

ok!

Types

type BrokerpakSourceConfig

type BrokerpakSourceConfig struct {
	// BrokerpakURI holds the URI for loading the Brokerpak.
	BrokerpakURI string `json:"uri"`
	// ServicePrefix holds an optional prefix that will be prepended to every service name.
	ServicePrefix string `json:"service_prefix"`
	// ExcludedServices holds a newline delimited list of service UUIDs that will be excluded at registration time.
	ExcludedServices string `json:"excluded_services"`
	// Config holds the configuration options for the Brokerpak as a JSON object.
	Config string `json:"config"`
	// Notes holds user-defined notes about the Brokerpak and shouldn't be used programatically.
	Notes string `json:"notes"`
}

BrokerpakSourceConfig represents a single configuration of a brokerpak.

func NewBrokerpakSourceConfigFromPath

func NewBrokerpakSourceConfigFromPath(path string) BrokerpakSourceConfig

NewBrokerpakSourceConfigFromPath creates a new BrokerpakSourceConfig from a path.

func (*BrokerpakSourceConfig) ExcludedServicesSlice

func (b *BrokerpakSourceConfig) ExcludedServicesSlice() []string

ExcludedServicesSlice gets the ExcludedServices as a slice of UUIDs.

Example
cfg := BrokerpakSourceConfig{ExcludedServices: "FOO\nBAR"}

fmt.Println(cfg.ExcludedServicesSlice())
Output:

[FOO BAR]

func (*BrokerpakSourceConfig) SetExcludedServices

func (b *BrokerpakSourceConfig) SetExcludedServices(services []string)

SetExcludedServices sets the ExcludedServices from a slice of UUIDs.

Example
cfg := BrokerpakSourceConfig{}
cfg.SetExcludedServices([]string{"plan1", "plan2"})

fmt.Println("slice:", cfg.ExcludedServicesSlice())
fmt.Println("text:", cfg.ExcludedServices)
Output:

slice: [plan1 plan2]
text: plan1
plan2

func (*BrokerpakSourceConfig) Validate

func (b *BrokerpakSourceConfig) Validate() (errs *validation.FieldError)

Validate implements validation.Validatable.

type Registrar

type Registrar struct {
	// contains filtered or unexported fields
}

Registrar is responsible for registering brokerpaks with BrokerRegistries subject to the settings provided by a ServerConfig like injecting environment variables and skipping certain services.

func NewRegistrar

func NewRegistrar(sc *ServerConfig) *Registrar

NewRegistrar constructs a new registrar with the given configuration. Registrar expects to become the owner of the configuration afterwards.

func (*Registrar) Register

func (r *Registrar) Register(registry broker.BrokerRegistry) error

Register fetches the brokerpaks and registers them with the given registry.

type ServerConfig

type ServerConfig struct {
	// Config holds global configuration options for the Brokerpak as a JSON object.
	Config string

	// Brokerpaks holds list of brokerpaks to load.
	Brokerpaks map[string]BrokerpakSourceConfig
}

ServerConfig holds the Brokerpak configuration for the server.

func NewServerConfigFromEnv

func NewServerConfigFromEnv() (*ServerConfig, error)

NewServerConfigFromEnv loads the global Brokerpak config from Viper.

Example
viper.Set("brokerpak.sources", `{"good-key":{"uri":"file://path/to/brokerpak", "config":"{}"}}`)
viper.Set("brokerpak.config", `{}`)
defer viper.Reset() // cleanup

cfg, err := NewServerConfigFromEnv()
if err != nil {
	panic(err)
}

fmt.Println("global config:", cfg.Config)
fmt.Println("num services:", len(cfg.Brokerpaks))
Output:

global config: {}
num services: 1
Example (CustomBuiltin)
viper.Set("brokerpak.sources", `{}`)
viper.Set("brokerpak.config", `{}`)
viper.Set(brokerpakBuiltinPathKey, "testdata/dummy-brokerpaks")
viper.Set("compatibility.enable-builtin-brokerpaks", "true")
defer viper.Reset() // cleanup

cfg, err := NewServerConfigFromEnv()
if err != nil {
	panic(err)
}

fmt.Println("num services:", len(cfg.Brokerpaks))
Output:

num services: 2

func (*ServerConfig) GetGlobalLabels added in v0.19.0

func (cfg *ServerConfig) GetGlobalLabels() (map[string]string, error)

func (*ServerConfig) Validate

func (cfg *ServerConfig) Validate() (errs *validation.FieldError)

Validate returns an error if the configuration is invalid.

Jump to

Keyboard shortcuts

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