grizzly

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used to signal a missing resource
	ErrNotFound = errors.New("not found")

	// ErrNotImplemented signals a feature that is not supported by a provider
	ErrNotImplemented = errors.New("not implemented")

	// ErrHandlerNotFound indicates that no handler was found for a particular resource Kind.
	ErrHandlerNotFound = errors.New("handler not found")
)
View Source
var Registry registry

Global Handler registry

Functions

func Apply

func Apply(resources Resources) error

Apply pushes resources to endpoints

func ConfigureProviderRegistry

func ConfigureProviderRegistry(providers []Provider)

NewProviderRegistry returns a new registry instance

func Diff

func Diff(resources Resources) error

Diff compares resources to those at the endpoints

func Export

func Export(exportDir string, resources Resources) error

Export renders Jsonnet resources then saves them to a directory

func FindResourceFiles

func FindResourceFiles(resourcePath string) ([]string, error)

func Get

func Get(UID string) error

Get retrieves a resource from a remote endpoint using its UID

func List

func List(resources Resources) error

List outputs the keys resources found in resulting json.

func ListRemote

func ListRemote(opts Opts) error

ListRetmote outputs the keys of remote resources

func Listen

func Listen(UID, filename string) error

Listen waits for remote changes to a resource and saves them to disk

func MarshalYAML

func MarshalYAML(resource Resource, filename string) error

MarshalYAML takes a resource and renders it to a source file as a YAML string

func Preview

func Preview(resources Resources, opts *PreviewOpts) error

Preview pushes resources to endpoints as previews, if supported

func Pull

func Pull(resourcePath string, opts Opts) error

Pulls remote resources

func Show

func Show(resources Resources) error

Show displays resources

func Watch

func Watch(watchDir string, parser WatchParser) error

Watch watches a directory for changes then pushes Jsonnet resource to endpoints when changes are noticed.

Types

type APIErr

type APIErr struct {
	Err  error
	Body []byte
}

APIErr encapsulates an error from the Grafana API

func (APIErr) Error

func (e APIErr) Error() string

type ExtendedImporter

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

ExtendedImporter does stuff

func (*ExtendedImporter) Import

func (i *ExtendedImporter) Import(importedFrom, importedPath string) (contents jsonnet.Contents, foundAt string, err error)

Import implements the functionality offered by the ExtendedImporter

type Handler

type Handler interface {
	APIVersion() string
	Kind() string
	GetExtension() string

	// FindResourceFiles identifies files within a directory that this handler can process
	FindResourceFiles(dir string) ([]string, error)

	// ResourceFilePath returns the location on disk where a resource should be updated
	ResourceFilePath(resource Resource, filetype string) string

	// Parse parses a manifest object into a struct for this resource type
	Parse(m manifest.Manifest) (Resources, error)

	// Unprepare removes unnecessary elements from a remote resource ready for presentation/comparison
	Unprepare(resource Resource) *Resource

	// Prepare gets a resource ready for dispatch to the remote endpoint
	Prepare(existing, resource Resource) *Resource

	// Retrieves a UID for a resource
	GetUID(resource Resource) (string, error)

	// Get retrieves JSON for a resource from an endpoint, by UID
	GetByUID(UID string) (*Resource, error)

	// GetRemote retrieves a remote equivalent of a remote resource
	GetRemote(resource Resource) (*Resource, error)

	// ListRemote retrieves as list of UIDs of all remote resources
	ListRemote() ([]string, error)

	// Add pushes a new resource to the endpoint
	Add(resource Resource) error

	// Update pushes an existing resource to the endpoint
	Update(existing, resource Resource) error

	// Validate gets or build the uid of corresponding resource
	Validate(resource Resource) error
}

Handler describes a handler for a single API resource handled by a single provider

type ListenHandler

type ListenHandler interface {
	// Listen watches a resource and update local file on changes
	Listen(UID, filename string) error
}

ListenHandler describes a handler that has the ability to watch a single resource for changes, and write changes to that resource to a local file

type LoggingOpts

type LoggingOpts struct {
	LogLevel string
}

LoggingOpts contains logging options (used in all commands)

type Opts

type Opts struct {
	LoggingOpts
	Directory    bool
	JsonnetPaths []string
	Targets      []string
}

Opts contains options for most Grizzly commands

type PreviewHandler

type PreviewHandler interface {
	// Preview renders Jsonnet then pushes them to the endpoint if previews are possible
	Preview(resource Resource, opts *PreviewOpts) error
}

PreviewHandler describes a handler that has the ability to render a preview of a resource

type PreviewOpts

type PreviewOpts struct {
	ExpiresSeconds int
}

PreviewOpts contains options to configure a preview

type Provider

type Provider interface {
	Group() string
	Version() string
	APIVersion() string
	GetHandlers() []Handler
}

Provider describes a single Endpoint Provider

type Resource

type Resource map[string]interface{}

Resource represents a single Resource destined for a single endpoint

func NewResource

func NewResource(apiVersion, kind, name string, spec map[string]interface{}) Resource

NewResource returns a new Resource object

func (*Resource) APIVersion

func (r *Resource) APIVersion() string

APIVersion returns the group and version of the provider of the resource

func (*Resource) DeleteSpecKey

func (r *Resource) DeleteSpecKey(key string)

func (*Resource) GetMetadata

func (r *Resource) GetMetadata(key string) string

func (*Resource) GetSpecString

func (r *Resource) GetSpecString(key string) (string, bool)

func (*Resource) GetSpecValue

func (r *Resource) GetSpecValue(key string) interface{}

func (*Resource) HasMetadata

func (r *Resource) HasMetadata(key string) bool

func (*Resource) Key

func (r *Resource) Key() string

Key returns a key that combines kind and uid

func (*Resource) Kind

func (r *Resource) Kind() string

Kind returns the 'kind' of the resource, i.e. the type of the handler

func (*Resource) MatchesTarget

func (r *Resource) MatchesTarget(targets []string) bool

MatchesTarget identifies whether a resource is in a target list

func (*Resource) Name

func (r *Resource) Name() string

func (*Resource) SetMetadata

func (r *Resource) SetMetadata(key, value string)

func (*Resource) SetSpecString

func (r *Resource) SetSpecString(key, value string)

func (*Resource) SetSpecValue

func (r *Resource) SetSpecValue(key string, value interface{})

func (*Resource) Spec

func (r *Resource) Spec() map[string]interface{}

func (*Resource) SpecAsJSON

func (r *Resource) SpecAsJSON() (string, error)

func (Resource) String

func (r Resource) String() string

func (Resource) UID

func (r Resource) UID() string

func (*Resource) YAML

func (r *Resource) YAML() (string, error)

YAML Gets the string representation for this resource

type Resources

type Resources []Resource

Resources represents a set of resources

func Parse

func Parse(resourcePath string, opts Opts) (Resources, error)

func ParseFile

func ParseFile(opts Opts, resourceFile string) (Resources, error)

func ParseJsonnet

func ParseJsonnet(jsonnetFile string, opts Opts) (Resources, error)

ParseJsonnet evaluates a jsonnet file and parses it into an object tree

func ParseYAML

func ParseYAML(yamlFile string, opts Opts) (Resources, error)

ParseYAML evaluates a YAML file and parses it into resources

func (Resources) Len

func (r Resources) Len() int

func (Resources) Less

func (r Resources) Less(i, j int) bool

func (Resources) Swap

func (r Resources) Swap(i, j int)

type WatchParser

type WatchParser interface {
	Name() string
	Parse() (Resources, error)
}

WatchParser encapsulates the action of parsing a resource (jsonnet or otherwise)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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