templatesource

package
v0.8.0-rc1 Latest Latest
Warning

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

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

Documentation

Overview

Package render implements the template rendering related subcommands.

Index

Constants

View Source
const (
	LocTypeLocalGit  = "local_git"
	LocTypeRemoteGit = "remote_git"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DownloadMetadata

type DownloadMetadata struct {
	// A "canonical" location is one that's the same for everybody. When
	// installing a template source like
	// "~/my_downloaded_templates/foo_template", that location is not canonical,
	// because not every has that directory downloaded on their machine. On the
	// other hand, a template location like
	// github.com/abcxyz/gcp-org-terraform-template *is* canonical because
	// everyone everywhere can access it by that name.
	//
	// Canonical template locations are preferred because they make automatic
	// template upgrades easier. Given a destination directory that is the
	// output of a template, we can easily upgrade it if we know the canonical
	// location of the template that created it. We just go look for new git
	// tags at the canonical location.
	//
	// A local template directory is not a canonical location except for one
	// special case: when the template source directory and the destination
	// directory are within the same repo. This supports the case where a single
	// git repo contains templates that are rendered into that repo. Since the
	// relative path between the template directory and the destination
	// directory are the same for everyone who clones the repo, that means the
	// relative path counts as a canonical source.
	//
	// IsCanonical is true if and only if CanonicalSource and LocationType are
	// non-empty.
	IsCanonical     bool
	CanonicalSource string
	LocationType    string

	// Depending on where the template was taken from, there might be a version
	// string associated with it (e.g. a git tag or a git SHA).
	//
	// HasVersion is true if and only if Version is non-empty.
	HasVersion bool
	Version    string

	// Values for template variables like _git_tag and _git_sha.
	Vars DownloaderVars
}

type Downloader

type Downloader interface {
	// Download downloads this template into templateDir. templateDir should be
	// a temporary directory.
	//
	// destDir is the directory that this operation is targeting, from the
	// user's point of view. This is only used to determine whether a template
	// installed from a local directory is canonical or not; it's not written to
	// as part of the download operation. When we're being called as part of
	// `abc templates render`, then this is the render output directory. When
	// we're being called as part of `abc templates upgrade`, this is the
	// directory that the template is installed to, and NOT the temp dir that
	// receives the output of Render().
	Download(ctx context.Context, cwd, templateDir, destDir string) (*DownloadMetadata, error)
}

A Downloader is returned by a sourceParser. It offers the ability to download a template, and provides some metadata.

func ForUpgrade added in v0.6.0

func ForUpgrade(ctx context.Context, f *ForUpgradeParams) (Downloader, error)

ForUpgrade takes a location type and canonical location from a manifest file, and returns a downloader that will download the latest version of that template.

func ParseSource

func ParseSource(ctx context.Context, params *ParseSourceParams) (Downloader, error)

ParseSource maps the input template source to a particular kind of source (e.g. git) and returns a downloader that will download that source.

source is a template location, like "github.com/foo/bar@v1.2.3". protocol is the value of the --protocol flag, like "https".

A list of sourceParsers is accepted as input for the purpose of testing, rather than hardcoding the real list of sourceParsers.

type DownloaderVars added in v0.5.0

type DownloaderVars struct {
	GitTag      string
	GitSHA      string
	GitShortSHA string
}

Values for template variables like _git_tag and _git_sha.

type ForUpgradeParams added in v0.7.0

type ForUpgradeParams struct {
	// InstalledDir is the directory where the template was rendered to, and is
	// now being upgraded.
	InstalledDir string

	// CanonicalLocation is the location of the template source, e.g.
	// github.com/abcxyz/abc/t/foo .
	CanonicalLocation string

	// One of local_git, remote_git, etc.
	LocType string

	// The value of --git-protocol.
	GitProtocol string
}

ForUpgradeParams contains the arguments to ForUpgrade().

type LocalDownloader added in v0.6.0

type LocalDownloader struct {
	// This path uses the OS-native file separator and is an absolute path.
	SrcPath string
}

LocalDownloader implements Downloader.

func (*LocalDownloader) Download added in v0.6.0

func (l *LocalDownloader) Download(ctx context.Context, cwd, templateDir, destDir string) (*DownloadMetadata, error)

installedDir is only used to check for canonical-ness.

type ParseSourceParams

type ParseSourceParams struct {
	// The working directory that we're in. Used to resolve relative paths.
	CWD string

	// Source could be any of the template source types we accept. Examples:
	//  - github.com/foo/bar@latest
	//  - /a/local/path
	//  - a/relative/path
	//
	// In the case where the source is a local filesystem path, it uses native
	// filesystem separators.
	Source string

	// The value of --git-protocol.
	GitProtocol string
}

ParseSourceParams contains the arguments to ParseSource.

Jump to

Keyboard shortcuts

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