Documentation
¶
Overview ¶
Package where finds, for a command run from anywhere inside a repository with nothing typed, what the command line used to spell out: the repository, its infrastructure root, the application layer, the environments the layer pins secrets for, the secret variables the application declares, and, in Google Cloud, the environment project, the secret container and its versions. Each answer is either the one thing found or an error that lists the candidates, so a command can ask a person to choose or say what to pass.
Two layouts are known. In the application layout, the application repository's infrastructure directory is the application's stack itself (its .tf files, README, terraform.tfvars and placement.json), and the application is named by the module at the repository root. In the organization layout, an infrastructure root (the repository root, or its infrastructure directory) holds the layers, 1-org and 3-app, with one application layer per directory under 3-app. Either way the stack's state lives at 3-app/<app>/<env> in the organization's state bucket, the layer's slot there.
Index ¶
- Constants
- func ApplicationDir(repoRoot, infraRoot string) string
- func Applications(infraRoot string) ([]string, error)
- func ContainerByLabels(ctx context.Context, open secret.ClientFunc, project string, ...) (string, error)
- func Environments(infraRoot, application string) ([]string, error)
- func HasApplicationLayers(infraRoot string) bool
- func InfrastructureRoot(repoRoot string) (string, error)
- func Layer(infraRoot, application string) string
- func LayerDir(infraRoot, application string) string
- func LayerEnvironments(layerDir string) ([]string, error)
- func Placement(layerDir string) (*derive.Placement, error)
- func PlacementFile(repoRoot string) string
- func ProjectByLabels(ctx context.Context, open ProjectClientFunc, labels map[string]string) (string, error)
- func Remote(repoRoot string) (owner, name string, err error)
- func RepoRoot(start string) (string, error)
- func SingleApplication(infraRoot string) (string, error)
- func Variables(appDir, layerDir string) ([]string, error)
- type Project
- type ProjectClient
- type ProjectClientFunc
- type SecretVariable
- type VersionInfo
Constants ¶
const (
// Active is the state Cloud Resource Manager reports for a project that is in use.
Active = "ACTIVE"
)
Variables ¶
This section is empty.
Functions ¶
func ApplicationDir ¶
ApplicationDir is the application's source directory when the layout says where it is: the repository root when the infrastructure lives in its infrastructure directory. Otherwise it is unknown, and empty.
func Applications ¶
Applications lists the application layers under the infrastructure root: the directories under 3-app holding a terraform.tfvars, sorted. When the root is an application's stack itself, it is the one application, by the code its placement records.
func ContainerByLabels ¶
func ContainerByLabels(ctx context.Context, open secret.ClientFunc, project string, labels map[string]string, suffix string) (string, error)
ContainerByLabels is the name of the one secret container in the project that carries every label and ends with the suffix (the variable's, from secret.ContainerSuffix). None and several are refused, the several listed, and none lists what the labels did find.
func Environments ¶
Environments lists the environments the application's placement pins secrets for: the keys of secret_versions in its terraform.tfvars, in the file's order.
func HasApplicationLayers ¶
HasApplicationLayers reports whether the infrastructure root holds the application layers' directory (3-app), the organization layout; an application's own stack (the application layout) holds none.
func InfrastructureRoot ¶
InfrastructureRoot is the repository's infrastructure root: the directory holding the layers (1-org and 3-app), the repository root itself or its infrastructure directory; or, in the application layout, the infrastructure directory when it is the application's stack itself, holding a terraform.tfvars or a placement.json and neither layer.
func Layer ¶
Layer is the application's layer relative to the infrastructure root: "." when the root is the application's stack itself, else the application's directory under 3-app.
func LayerDir ¶
LayerDir is the application's layer as a directory: the infrastructure root joined with Layer.
func LayerEnvironments ¶
LayerEnvironments is Environments for a layer named by its directory, when the layer is not the application's own (--layer).
func Placement ¶
Placement is the placement beside the layer (placement.json in the layer's directory), the one render derived the stack from: nil, without an error, when the layer has none.
func PlacementFile ¶
PlacementFile is where an application repository keeps its placement in the application layout: placement.json in its infrastructure directory, the application's stack, where render reads it.
func ProjectByLabels ¶
func ProjectByLabels(ctx context.Context, open ProjectClientFunc, labels map[string]string) (string, error)
ProjectByLabels is the ID of the one active project carrying every label. The search is by the labels, and the answers are checked against them again, so a looser match by the API cannot pass for the one project. None and several are refused, the several listed.
func Remote ¶
Remote is the GitHub repository the repository at root pushes to: the owner and name of its origin remote. A worktree's .git file is followed to the git directory.
func RepoRoot ¶
RepoRoot walks up from start to the directory holding .git (a directory, or the file a worktree carries) and returns it.
func SingleApplication ¶
SingleApplication is the one application layer under the infrastructure root. Several and none are refused, the several listed.
Types ¶
type Project ¶
type Project struct {
// ID is the project ID, what a --project flag takes.
ID string
// DisplayName is the project's name as the console shows it.
DisplayName string
// State is ACTIVE for a project in use, else DELETE_REQUESTED.
State string
// Labels are the project's labels.
Labels map[string]string
}
Project is what Cloud Resource Manager says about one project.
type ProjectClient ¶
type ProjectClient interface {
// SearchProjects lists the projects matching the query, in the API's order.
SearchProjects(ctx context.Context, query string) ([]Project, error)
}
ProjectClient searches the projects the caller can see. The functions here open one per call through a ProjectClientFunc; tests pass a fake.
func NewProjects ¶
func NewProjects(ctx context.Context) (ProjectClient, error)
NewProjects opens the Cloud Resource Manager client with Application Default Credentials; the search is billed to the credentials' own quota project.
type ProjectClientFunc ¶
type ProjectClientFunc func(ctx context.Context) (ProjectClient, error)
ProjectClientFunc opens a ProjectClient. NewProjects is the real one.
type SecretVariable ¶
SecretVariable is one secret variable the application declares: its name, whether its value is the tooling's to make (secret:"generated" or secret:"versioned"), which bedrock secret add and pin refuse and bedrock secret rotate serves, and whether every enabled version of it reaches the processes (secret:"versioned").
func Secrets ¶
func Secrets(appDir, layerDir string) ([]SecretVariable, error)
Secrets lists the secret variables the application declares. With the application's source directory known, they are read from the code the way render reads it: the model derived from the code and the placement beside the layer, and its secrets in declaration order. Without it, or when the code cannot be read that way, they are the entries of the secrets local in the layer's locals.tf, which render wrote from the same model (each entry's generated attribute says which).
func (SecretVariable) Word ¶ added in v0.1.2
func (s SecretVariable) Word() string
Word is the secret tag's word for a secret the tooling makes, which the placement's secret_versions carries for it: versioned, or generated.
type VersionInfo ¶
type VersionInfo struct {
// Name is the version's number, the last segment of its resource name: what a pin
// holds.
Name string
// State is ENABLED when the version can be mounted, else DISABLED or DESTROYED.
State string
}
VersionInfo is one version of a secret container, for choosing among them.
func Versions ¶
func Versions(ctx context.Context, open secret.ClientFunc, project, container string) ([]VersionInfo, error)
Versions lists the versions of the container in the project, newest (the highest number) first.