config

package
v0.0.0-...-678bb0e Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package config is a library to access the luci-config service.

There are three backends for the interface presented in the interface.go.

One backend talks directly to the luci-config service, another reads from the local filesystem, and the third one reads from memory struct.

Usually, you should use the remote backend in production, the filesystem backend when developing, and the memory backend from unit tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConfig = errors.New("no such config")

ErrNoConfig is returned if requested config does not exist.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ConfigSet is the config set name (e.g. "projects/<id>") this config
	// belongs to.
	// May be the empty string if this is unknown.
	ConfigSet string `json:"configSet,omitempty"`

	// Path is the filename relative to the root of the config set,
	// without leading slash, e.g. "luci-cron.cfg".
	// May be the empty string if this is unknown.
	Path string

	// Error is not nil if there where troubles fetching this config. Used only
	// by functions that operate with multiple configs at once, such as
	// GetProjectConfigs and GetRefConfigs.
	Error error `json:"error,omitempty"`

	// Content is the actual body of the config file.
	Content string `json:"content,omitempty"`

	// ContentHash can be used to quickly check that content didn't change.
	ContentHash string `json:"contentHash,omitempty"`

	// Revision is git SHA1 of a repository the config was fetched from.
	Revision string `json:"revision,omitempty"`
}

Config is a configuration entry in the luci-config service.

type Interface

type Interface interface {
	// GetConfig returns a config at a path in a config set or ErrNoConfig
	// if missing. If hashOnly is true, returned Config struct has Content set
	// to "" (and the call is faster).
	GetConfig(ctx context.Context, configSet, path string, hashOnly bool) (*Config, error)

	// GetConfigByHash returns the contents of a config, as identified by its
	// content hash, or ErrNoConfig if missing.
	GetConfigByHash(ctx context.Context, contentHash string) (string, error)

	// GetConfigSetLocation returns the URL location of a config set.
	GetConfigSetLocation(ctx context.Context, configSet string) (*url.URL, error)

	// GetProjectConfigs returns all the configs at the given path in all
	// projects that have such config. If hashesOnly is true, returned Config
	// structs have Content set to "" (and the call is faster).
	GetProjectConfigs(ctx context.Context, path string, hashesOnly bool) ([]Config, error)

	// GetProjects returns all the registered projects in the configuration
	// service.
	GetProjects(ctx context.Context) ([]Project, error)

	// GetRefConfigs returns the config at the given path in all refs of all
	// projects that have such config. If hashesOnly is true, returned Config
	// structs have Content set to "" (and the call is faster).
	GetRefConfigs(ctx context.Context, path string, hashesOnly bool) ([]Config, error)

	// GetRefs returns the list of refs for a project.
	GetRefs(ctx context.Context, projectID string) ([]string, error)
}

Interface represents luci-config service API.

All methods accept context.Context they use for deadlines and for passing to callbacks (if the implementation uses any). Contexts here don't necessary relate to a "global" package context (used by GetImplementation and SetImplementation), though very often they are the same (as is the case when using package-level functions like GetConfig).

For example, unit tests may instantiate an implementation of Interface directly and don't bother registering it in the context with SetImplementation(...).

Transient errors are wrapped in errors.Transient. See common/errors.

type Project

type Project struct {
	// ID is unique project identifier.
	ID string

	// Name is a short friendly display name of the project.
	Name string

	// RepoType specifies in what kind of storage projects configs are stored.
	RepoType RepoType

	// RepoUrl is the location of this project code repository. May be nil if
	// unknown or cannot be parsed.
	RepoURL *url.URL
}

Project is a project registered in the luci-config service.

type RepoType

type RepoType string

RepoType is the type of the repo the Project is stored in.

const (
	// GitilesRepo means a repo is backed by the Gitiles service.
	GitilesRepo RepoType = "GITILES"

	// UnknownRepo means a repo is backed by an unknown service.
	// It may be an invalid repo.
	UnknownRepo RepoType = "UNKNOWN"
)

Directories

Path Synopsis
impl
filesystem
Package filesystem implements a file system backend for the config client.
Package filesystem implements a file system backend for the config client.
memory
Package memory implements in-memory backend for the config client.
Package memory implements in-memory backend for the config client.
Package validation provides a helper for performing config validations.
Package validation provides a helper for performing config validations.

Jump to

Keyboard shortcuts

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