Documentation
¶
Overview ¶
Package appimport turns a source platform's application inventory into a reviewed, staged import: per-app verdicts, a hostname mapping with a visible diff, preflight checks and a secret-free receipt. It reads from internal/platformimport and never talks to the source itself.
Index ¶
- Constants
- func FindReferences(env []platformimport.Env, hosts []string) map[string]bool
- func ReferencesHost(v, host string) bool
- func Remaining(e Entry, it store.AppImportItem) []string
- func RewriteValue(v string, maps []Mapping) (string, int)
- func ValidateMapping(m Mapping) error
- type AppliedChange
- type Change
- type Check
- type Context
- type DBRef
- type Entry
- type EnvSummary
- type Finding
- type Group
- type HealthEntry
- type Inventory
- type Mapping
- type PreflightInput
- type PreflightResult
- type Receipt
- type ReceiptApp
- type ReceiptInput
- type ReceiptVolume
- type VolumeEntry
Constants ¶
const ( CheckName = "name" CheckDomains = "domains" CheckEnvKeys = "env-keys" CheckDBHosts = "db-hosts" CheckSecrets = "secrets" CheckBuild = "build" CheckDisk = "disk" )
Check ids reported by Preflight.
const ( VerdictReady = "ready" VerdictNotes = "ready-with-notes" VerdictAttention = "needs-attention" VerdictUnsupported = "unsupported" )
Verdicts for one source application or service.
const ( KindApp = "app" KindService = "service" )
Kinds of inventory entries.
const ( SourceGit = "git" SourceImage = "image" SourceCompose = "compose" SourceService = "service" SourceUnknown = "unknown" )
Where an app's code comes from, for display.
const ( MapDockerfile = "dockerfile" MapRailpack = "railpack" MapStatic = "static" MapImage = "image" )
Build methods an app maps to here.
const DefaultDiskMargin = 1.5
DefaultDiskMargin multiplies known volume sizes when comparing to free space.
const ReceiptStatement = "" /* 135-byte string literal not displayed */
ReceiptStatement is printed on every receipt.
Variables ¶
This section is empty.
Functions ¶
func FindReferences ¶
func FindReferences(env []platformimport.Env, hosts []string) map[string]bool
FindReferences lists which of hosts appear in env values, so a caller can tell which databases an app depends on. Values are inspected, not kept.
func ReferencesHost ¶
ReferencesHost reports whether v contains host as a whole hostname token.
func Remaining ¶
func Remaining(e Entry, it store.AppImportItem) []string
Remaining lists what an operator still has to do by hand for one app.
func RewriteValue ¶
RewriteValue replaces every whole-token occurrence of each mapping's source host and returns the new value with the number of replacements.
func ValidateMapping ¶
ValidateMapping checks both sides are plain hostnames.
Types ¶
type AppliedChange ¶
AppliedChange records that a mapping rewrote a variable, without values.
type Change ¶
type Change struct {
App string `json:"app"`
Key string `json:"key"`
Secret bool `json:"secret"`
Count int `json:"count"`
Before string `json:"before"`
After string `json:"after"`
}
Change is one env value a mapping rewrote, in a form safe to show.
func RewriteEnv ¶
func RewriteEnv(app string, env []platformimport.Env, maps []Mapping) ([]platformimport.Env, []Change)
RewriteEnv applies maps to env values and returns the new env with a masked diff. The input slice is not modified.
type Check ¶
type Check struct {
App string `json:"app,omitempty"`
ID string `json:"id"`
Status string `json:"status"`
Detail string `json:"detail"`
Fix string `json:"fix,omitempty"`
}
Check is one preflight result. App is empty for a whole-import check.
type Context ¶
type Context struct {
// Targets maps a lowercased source database name to the database here.
Targets map[string]string
// TargetHost returns the connection host of a database here.
TargetHost func(name string) string
}
Context is what the target platform already holds, used to judge which source databases were migrated and where they went.
type DBRef ¶
type DBRef struct {
SourceID string `json:"source_id"`
Name string `json:"name"`
// Host is the in-network hostname apps on the source use.
Host string `json:"host"`
// Target is the database here the data was moved to, empty when none.
Target string `json:"target,omitempty"`
// TargetHost is the connection host of Target here.
TargetHost string `json:"target_host,omitempty"`
}
DBRef is a database one app's configuration points at.
func DatabaseRefs ¶
func DatabaseRefs(d *platformimport.Discovery, c Context) []DBRef
DatabaseRefs lists every source database with where it went here.
type Entry ¶
type Entry struct {
SourceID string `json:"source_id"`
Name string `json:"name"`
Kind string `json:"kind"`
Project string `json:"project,omitempty"`
Environment string `json:"environment,omitempty"`
Server string `json:"server,omitempty"`
Source string `json:"source"`
Repo string `json:"repo,omitempty"`
Branch string `json:"branch,omitempty"`
Image string `json:"image,omitempty"`
ImageID string `json:"image_id,omitempty"`
HostBuilt bool `json:"host_built,omitempty"`
BuildPack string `json:"build_pack,omitempty"`
MapsTo string `json:"maps_to,omitempty"`
Port int `json:"port,omitempty"`
Domains []string `json:"domains,omitempty"`
Env EnvSummary `json:"env"`
Volumes []VolumeEntry `json:"volumes,omitempty"`
Health *HealthEntry `json:"health,omitempty"`
MemoryBytes int64 `json:"memory_bytes,omitempty"`
NanoCPUs int64 `json:"nano_cpus,omitempty"`
Databases []DBRef `json:"databases,omitempty"`
Verdict string `json:"verdict"`
Findings []Finding `json:"findings,omitempty"`
}
Entry is one row of the inventory.
type EnvSummary ¶
type EnvSummary struct {
Plain int `json:"plain"`
Secret int `json:"secret"`
// Empty counts secrets that came back without a readable value.
Empty int `json:"empty"`
}
EnvSummary counts variables by sensitivity. Values are never included.
type Group ¶
type Group struct {
Project string `json:"project"`
Environment string `json:"environment"`
Entries []Entry `json:"entries"`
}
Group is the entries of one project environment.
type HealthEntry ¶
type HealthEntry struct {
Path string `json:"path"`
IntervalSeconds int `json:"interval_seconds,omitempty"`
TimeoutSeconds int `json:"timeout_seconds,omitempty"`
Retries int `json:"retries,omitempty"`
}
HealthEntry is the source's HTTP probe.
type Inventory ¶
type Inventory struct {
Platform string `json:"platform"`
Groups []Group `json:"groups"`
Databases []DBRef `json:"databases"`
Counts map[string]int `json:"counts"`
}
Inventory is everything read from the source, grouped and judged.
func BuildInventory ¶
func BuildInventory(d *platformimport.Discovery, c Context) Inventory
BuildInventory judges every app and unsupported item of a discovery and groups them by project and environment.
type PreflightInput ¶
type PreflightInput struct {
Inventory Inventory
// Selected lists source ids to import. Nil selects every importable entry.
Selected map[string]bool
// Names maps a source id to its planned name here.
Names map[string]string
// DomainOwners maps a domain to the app here that holds it.
DomainOwners map[string]string
Mappings []Mapping
// Env holds source env per source id, in memory only. Nil skips the
// checks that need values.
Env map[string][]platformimport.Env
// FreeBytes is free disk here, negative when unknown.
FreeBytes int64
DiskMargin float64
}
PreflightInput is everything the checks depend on.
type PreflightResult ¶
type PreflightResult struct {
Checks []Check `json:"checks"`
Diff []Change `json:"diff"`
Failed int `json:"failed"`
Warnings int `json:"warnings"`
// EnvChecked is false when no source values were available.
EnvChecked bool `json:"env_checked"`
CanStage bool `json:"can_stage"`
}
PreflightResult is the outcome of all checks.
func Preflight ¶
func Preflight(in PreflightInput) PreflightResult
Preflight evaluates every selected entry before anything is written.
type Receipt ¶
type Receipt struct {
GeneratedAt string `json:"generated_at"`
SessionID string `json:"session_id"`
Platform string `json:"platform"`
SourceURL string `json:"source_url"`
Statement string `json:"statement"`
Mappings []Mapping `json:"mappings"`
Apps []ReceiptApp `json:"apps"`
Remaining int `json:"remaining_manual_steps"`
}
Receipt is the downloadable record of one import session.
func BuildReceipt ¶
func BuildReceipt(sess store.AppImportSession, items []ReceiptInput, now time.Time) Receipt
BuildReceipt assembles the receipt. It reads only stored state, never source values, so it cannot carry a secret.
type ReceiptApp ¶
type ReceiptApp struct {
SourceID string `json:"source_id"`
SourceName string `json:"source_name"`
Target string `json:"target,omitempty"`
Project string `json:"project,omitempty"`
Environment string `json:"environment,omitempty"`
Verdict string `json:"verdict"`
State string `json:"state"`
Domains []string `json:"domains,omitempty"`
EnvPlain int `json:"env_plain"`
EnvSecret int `json:"env_secret"`
Rewritten []AppliedChange `json:"rewritten,omitempty"`
Volumes []ReceiptVolume `json:"volumes,omitempty"`
Remaining []string `json:"remaining,omitempty"`
}
ReceiptApp is what happened to one source app.
type ReceiptInput ¶
type ReceiptInput struct {
Item store.AppImportItem
Entry Entry
Rewritten []AppliedChange
}
ReceiptInput couples a stored item with its decoded inventory entry.