templates

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package templates provides stack templates (#33, #34, ADR-0051): a built-in catalog, catalogs from registry.json URLs, and templates users saved. A template is a compose file, an .env.example whose comments describe its variables, and a description.

Index

Constants

View Source
const (
	SourceBuiltin = "builtin"
	SourceCustom  = "custom"
)

Sources of templates besides registry URLs.

View Source
const MaxFile = 256 << 10

MaxFile is the largest compose file or .env.example of a template.

Variables

This section is empty.

Functions

This section is empty.

Types

type Input

type Input struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Compose     string `json:"compose"`
	Env         string `json:"env"`
}

Input creates or changes a custom template. Keep in sync with api/openapi.yaml.

type Registries

type Registries struct {
	Client *http.Client
	Now    func() time.Time
	// contains filtered or unexported fields
}

Registries reads registry.json files over HTTP and caches them.

func (*Registries) Forget

func (r *Registries) Forget()

Forget empties the cache.

func (*Registries) Get

func (r *Registries) Get(ctx context.Context, source, id string) (Template, error)

Get returns a template of a registry with its files, fetching them when they are linked.

func (*Registries) List

func (r *Registries) List(ctx context.Context, source string) ([]Summary, error)

List returns the templates of a registry.

type Service

type Service struct {
	Store    Store
	Registry *Registries
	Now      func() time.Time
}

Service lists and fetches templates.

func (*Service) Create

func (s *Service) Create(ctx context.Context, in Input, user string) (Template, error)

Create saves a custom template.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id string) error

Delete removes a custom template.

func (*Service) Get

func (s *Service) Get(ctx context.Context, source, id string) (Template, error)

Get returns a template with its files.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]Summary, []SourceError, error)

List returns every template: built-in, custom and from the registries. A registry that cannot be read is reported and skipped.

func (*Service) RegistryURLs

func (s *Service) RegistryURLs(ctx context.Context) ([]string, error)

RegistryURLs returns the configured registry URLs.

func (*Service) SetRegistryURLs

func (s *Service) SetRegistryURLs(ctx context.Context, urls []string) ([]string, error)

SetRegistryURLs replaces the registry URLs.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id string, in Input) (Template, error)

Update changes a custom template.

type SourceError

type SourceError struct {
	Source string `json:"source"`
	Error  string `json:"error"`
}

SourceError is a registry that could not be read.

type Store

type Store interface {
	ListStackTemplates(ctx context.Context) ([]db.StackTemplate, error)
	GetStackTemplate(ctx context.Context, id int64) (db.StackTemplate, error)
	CreateStackTemplate(ctx context.Context, arg db.CreateStackTemplateParams) (db.StackTemplate, error)
	UpdateStackTemplate(ctx context.Context, arg db.UpdateStackTemplateParams) (db.StackTemplate, error)
	DeleteStackTemplate(ctx context.Context, id int64) (int64, error)
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, arg db.SetSettingParams) error
}

Store is the database; *db.Queries implements it.

type Summary

type Summary struct {
	// Source is builtin, custom or the URL of a registry.
	Source        string     `json:"source"`
	ID            string     `json:"id"`
	Name          string     `json:"name"`
	Description   string     `json:"description,omitempty"`
	Categories    []string   `json:"categories,omitempty"`
	Documentation string     `json:"documentation,omitempty"`
	UpdatedAt     *time.Time `json:"updatedAt,omitempty"`
}

Summary describes a template in a catalog. Keep in sync with api/openapi.yaml.

type Template

type Template struct {
	Summary
	Compose   string     `json:"compose"`
	Env       string     `json:"env"`
	Variables []Variable `json:"variables"`
}

Template is a template with its files and variables. Keep in sync with api/openapi.yaml.

func Builtin

func Builtin() []Template

Builtin returns the built-in templates sorted by name.

type Variable

type Variable struct {
	Name        string `json:"name"`
	Default     string `json:"default"`
	Description string `json:"description,omitempty"`
	// Secret is guessed from the name (password, secret, token, key).
	Secret bool `json:"secret"`
}

Variable is a variable of .env.example. Keep in sync with api/openapi.yaml.

func ParseEnv

func ParseEnv(env string) []Variable

ParseEnv reads the variables of an .env.example: KEY=default lines, each described by the comment lines right above it.

Jump to

Keyboard shortcuts

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