grizzly

package
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is used to signal a missing resource

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented signals a feature that is not supported by a provider

Functions

func Apply

func Apply(config Config, resources Resources) error

Apply pushes resources to endpoints

func Diff

func Diff(config Config, resources Resources) error

Diff compares resources to those at the endpoints

func Export

func Export(config Config, exportDir string, resources Resources) error

Export renders Jsonnet resources then saves them to a directory

func Get

func Get(config Config, UID string) error

Get retrieves a resource from a remote endpoint using its UID

func List

func List(config Config, resources Resources) error

List outputs the keys resources found in resulting json.

func Listen

func Listen(config Config, UID, filename string) error

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

func Preview

func Preview(config Config, resources Resources, opts *PreviewOpts) error

Preview pushes resources to endpoints as previews, if supported

func Show

func Show(config Config, resources Resources) error

Show displays resources

func Watch

func Watch(config Config, watchDir string, parser Parser) 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 Config

type Config struct {
	Registry    Registry
	Notifier    Notifier
	JsonnetPath string
}

Config provides configuration to `grizzly`

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
	GetJSONPaths() []string
	GetExtension() string

	// Parse parses an interface{} object into a struct for this resource type
	Parse(path string, i interface{}) (ResourceList, 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

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

	// GetRepresentation renders Jsonnet to Grizzly resources, rendering as a string
	GetRepresentation(uid string, resource Resource) (string, error)

	// GetRemoteRepresentation retrieves a resource from the endpoint and renders to a string
	GetRemoteRepresentation(uid string) (string, error)

	// GetRemote retrieves a resource as a datastructure
	GetRemote(uid string) (*Resource, 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
}

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(notifier Notifier, 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 MultiResourceHandler

type MultiResourceHandler interface {
	// Diff compares local resources with remote equivalents and output result
	Diff(notifier Notifier, resources ResourceList) error

	// Apply local resources to remote endpoint
	Apply(notifier Notifier, resources ResourceList) error
}

MultiResourceHandler describes a handler that can handle multiple resources in one go. This could be because it needs to see all resources before sending, or because the endpoint API supports batching of resources.

type Notifier

type Notifier struct{}

Notifier provides Handlers terminal agnostic mechanisms to announce results of actions

func (*Notifier) Added

func (n *Notifier) Added(resource Resource)

Added announces that a resource has been added to the remote endpoint

func (*Notifier) Error

func (n *Notifier) Error(resource *Resource, msg string)

Error announces a message in yellow

func (*Notifier) HasChanges

func (n *Notifier) HasChanges(resource Resource, diff string)

HasChanges announces that a resource has changed, and displays the differences

func (*Notifier) Info

func (n *Notifier) Info(resource *Resource, msg string)

Info announces a message in green

func (*Notifier) NoChanges

func (n *Notifier) NoChanges(resource Resource)

NoChanges announces that nothing has changed

func (*Notifier) NotFound

func (n *Notifier) NotFound(resource Resource)

NotFound announces that a resource was not found on the remote endpoint

func (*Notifier) NotSupported

func (n *Notifier) NotSupported(resource Resource, behaviour string)

NotSupported announces that a behaviour is not supported by a handler

func (*Notifier) Updated

func (n *Notifier) Updated(resource Resource)

Updated announces that a resource has been updated at the remote endpoint

func (*Notifier) Warn

func (n *Notifier) Warn(resource *Resource, msg string)

Warn announces a message in yellow

type Parser

type Parser interface {
	Name() string
	Parse(config Config) (Resources, error)
}

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

type PreviewHandler

type PreviewHandler interface {
	// Preview renders Jsonnet then pushes them to the endpoint if previews are possible
	Preview(resource Resource, notifier Notifier, 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 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 Registry

type Registry struct {
	Providers     []Provider
	Handlers      []Handler
	HandlerByName map[string]Handler
	HandlerByPath map[string]Handler
}

Registry records providers

func NewProviderRegistry

func NewProviderRegistry() Registry

NewProviderRegistry returns a new registry instance

func (*Registry) GetHandler

func (r *Registry) GetHandler(path string) (Handler, error)

GetHandler returns a single provider based upon a JSON path

func (*Registry) RegisterProvider

func (r *Registry) RegisterProvider(provider Provider) error

RegisterProvider will register a new provider

type Resource

type Resource struct {
	UID      string      `json:"uid"`
	Filename string      `json:"filename"`
	Handler  Handler     `json:"handler"`
	Detail   interface{} `json:"detail"`
	JSONPath string      `json:"path"`
}

Resource represents a single Resource destined for a single endpoint

func (*Resource) APIVersion

func (r *Resource) APIVersion() string

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

func (*Resource) GetRemoteRepresentation

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

GetRemoteRepresentation Gets the string representation for this resource

func (*Resource) GetRepresentation

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

GetRepresentation Gets the string representation for this resource

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

type ResourceList

type ResourceList map[string]Resource

ResourceList represents a set of named resources

type Resources

type Resources map[Handler]ResourceList

Resources represents a set of resources by handler

func Parse

func Parse(config Config, jsonnetFile string, targets []string) (Resources, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL