module

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2015 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const RootName = "root"

RootName is the name of the root tree.

Variables

View Source
var Detectors []Detector

Detectors is the list of detectors that are tried on an invalid URL. This is also the order they're tried (index 0 is first).

View Source
var Getters map[string]Getter

Getters is the mapping of scheme to the Getter implementation that will be used to get a dependency.

Functions

func Detect

func Detect(src string, pwd string) (string, error)

Detect turns a source string into another source string if it is detected to be of a known pattern.

This is safe to be called with an already valid source string: Detect will just return it.

func Get

func Get(dst, src string) error

Get downloads the module specified by src into the folder specified by dst. If dst already exists, Get will attempt to update it.

src is a URL, whereas dst is always just a file path to a folder. This folder doesn't need to exist. It will be created if it doesn't exist.

func GetCopy

func GetCopy(dst, src string) error

GetCopy is the same as Get except that it downloads a copy of the module represented by source.

This copy will omit and dot-prefixed files (such as .git/, .hg/) and can't be updated on its own.

Types

type BitBucketDetector

type BitBucketDetector struct{}

BitBucketDetector implements Detector to detect BitBucket URLs and turn them into URLs that the Git or Hg Getter can understand.

func (*BitBucketDetector) Detect

func (d *BitBucketDetector) Detect(src, _ string) (string, bool, error)

type Detector

type Detector interface {
	// Detect will detect whether the string matches a known pattern to
	// turn it into a proper URL.
	Detect(string, string) (string, bool, error)
}

Detector defines the interface that an invalid URL or a URL with a blank scheme is passed through in order to determine if its shorthand for something else well-known.

type FileDetector

type FileDetector struct{}

FileDetector implements Detector to detect file paths.

func (*FileDetector) Detect

func (d *FileDetector) Detect(src, pwd string) (string, bool, error)

type FileGetter

type FileGetter struct{}

FileGetter is a Getter implementation that will download a module from a file scheme.

func (*FileGetter) Get

func (g *FileGetter) Get(dst string, u *url.URL) error

type FolderStorage

type FolderStorage struct {
	// StorageDir is the directory where the modules will be stored.
	StorageDir string
}

FolderStorage is an implementation of the Storage interface that manages modules on the disk.

func (*FolderStorage) Dir

func (s *FolderStorage) Dir(key string) (d string, e bool, err error)

Dir implements Storage.Dir

func (*FolderStorage) Get

func (s *FolderStorage) Get(key string, source string, update bool) error

Get implements Storage.Get

type GetMode

type GetMode byte

GetMode is an enum that describes how modules are loaded.

GetModeLoad says that modules will not be downloaded or updated, they will only be loaded from the storage.

GetModeGet says that modules can be initially downloaded if they don't exist, but otherwise to just load from the current version in storage.

GetModeUpdate says that modules should be checked for updates and downloaded prior to loading. If there are no updates, we load the version from disk, otherwise we download first and then load.

const (
	GetModeNone GetMode = iota
	GetModeGet
	GetModeUpdate
)

type Getter

type Getter interface {
	// Get downloads the given URL into the given directory. This always
	// assumes that we're updating and gets the latest version that it can.
	//
	// The directory may already exist (if we're updating). If it is in a
	// format that isn't understood, an error should be returned. Get shouldn't
	// simply nuke the directory.
	Get(string, *url.URL) error
}

Getter defines the interface that schemes must implement to download and update modules.

type GitGetter

type GitGetter struct{}

GitGetter is a Getter implementation that will download a module from a git repository.

func (*GitGetter) Get

func (g *GitGetter) Get(dst string, u *url.URL) error

type GitHubDetector

type GitHubDetector struct{}

GitHubDetector implements Detector to detect GitHub URLs and turn them into URLs that the Git Getter can understand.

func (*GitHubDetector) Detect

func (d *GitHubDetector) Detect(src, _ string) (string, bool, error)

type HgGetter

type HgGetter struct{}

HgGetter is a Getter implementation that will download a module from a Mercurial repository.

func (*HgGetter) Get

func (g *HgGetter) Get(dst string, u *url.URL) error

type HttpGetter

type HttpGetter struct{}

HttpGetter is a Getter implementation that will download a module from an HTTP endpoint. The protocol for downloading a module from an HTTP endpoing is as follows:

An HTTP GET request is made to the URL with the additional GET parameter "terraform-get=1". This lets you handle that scenario specially if you wish. The response must be a 2xx.

First, a header is looked for "X-Terraform-Get" which should contain a source URL to download.

If the header is not present, then a meta tag is searched for named "terraform-get" and the content should be a source URL.

The source URL, whether from the header or meta tag, must be a fully formed URL. The shorthand syntax of "github.com/foo/bar" or relative paths are not allowed.

func (*HttpGetter) Get

func (g *HttpGetter) Get(dst string, u *url.URL) error

type Module

type Module struct {
	Name   string
	Source string
}

Module represents the metadata for a single module.

type Storage

type Storage interface {
	// Dir returns the directory on local disk where the modulue source
	// can be loaded from.
	Dir(string) (string, bool, error)

	// Get will download and optionally update the given module.
	Get(string, string, bool) error
}

Storage is an interface that knows how to lookup downloaded modules as well as download and update modules from their sources into the proper location.

type Tree

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

Tree represents the module import tree of configurations.

This Tree structure can be used to get (download) new modules, load all the modules without getting, flatten the tree into something Terraform can use, etc.

func NewTree

func NewTree(name string, c *config.Config) *Tree

NewTree returns a new Tree for the given config structure.

func NewTreeModule

func NewTreeModule(name, dir string) (*Tree, error)

NewTreeModule is like NewTree except it parses the configuration in the directory and gives it a specific name. Use a blank name "" to specify the root module.

func (*Tree) Child

func (t *Tree) Child(path []string) *Tree

Child returns the child with the given path (by name).

func (*Tree) Children

func (t *Tree) Children() map[string]*Tree

Children returns the children of this tree (the modules that are imported by this root).

This will only return a non-nil value after Load is called.

func (*Tree) Config

func (t *Tree) Config() *config.Config

Config returns the configuration for this module.

func (*Tree) GobDecode

func (t *Tree) GobDecode(bs []byte) error

func (*Tree) GobEncode

func (t *Tree) GobEncode() ([]byte, error)

func (*Tree) Load

func (t *Tree) Load(s Storage, mode GetMode) error

Load loads the configuration of the entire tree.

The parameters are used to tell the tree where to find modules and whether it can download/update modules along the way.

Calling this multiple times will reload the tree.

Various semantic-like checks are made along the way of loading since module trees inherently require the configuration to be in a reasonably sane state: no circular dependencies, proper module sources, etc. A full suite of validations can be done by running Validate (after loading).

func (*Tree) Loaded

func (t *Tree) Loaded() bool

Loaded says whether or not this tree has been loaded or not yet.

func (*Tree) Modules

func (t *Tree) Modules() []*Module

Modules returns the list of modules that this tree imports.

This is only the imports of _this_ level of the tree. To retrieve the full nested imports, you'll have to traverse the tree.

func (*Tree) Name

func (t *Tree) Name() string

Name returns the name of the tree. This will be "<root>" for the root tree and then the module name given for any children.

func (*Tree) Path added in v0.4.1

func (t *Tree) Path() []string

Path is the full path to this tree.

func (*Tree) String

func (t *Tree) String() string

String gives a nice output to describe the tree.

func (*Tree) Validate

func (t *Tree) Validate() error

Validate does semantic checks on the entire tree of configurations.

This will call the respective config.Config.Validate() functions as well as verifying things such as parameters/outputs between the various modules.

Load must be called prior to calling Validate or an error will be returned.

type TreeError

type TreeError struct {
	Name []string
	Err  error
}

TreeError is an error returned by Tree.Validate if an error occurs with validation.

func (*TreeError) Error

func (e *TreeError) Error() string

Jump to

Keyboard shortcuts

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