project

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigFilePattern = "^project.y[a]{0,1}ml$"

ConfigFilePattern name of required project config file.

View Source
const OutputLinkType = "outputMarkers"

Variables

View Source
var BackendsFactories = map[string]BackendsFactory{}

BackendsFactories map of backend providers factories. Use BackendsFactories["prov_name"].New() to create backend of provider 'prov_name'

View Source
var SecretDriversMap = map[string]SecretDriver{}
View Source
var TemplateDriversMap map[string]TemplateDriver = map[string]TemplateDriver{}
View Source
var UnitFactoriesMap = map[string]UnitFactory{}

Functions

func BcryptString

func BcryptString(pwd []byte) (string, error)

func ConvertToShellVar

func ConvertToShellVar(name string) string

func ConvertToShellVarName

func ConvertToShellVarName(name string) string

func ConvertToTfVarName

func ConvertToTfVarName(name string) string

func CreateMarker

func CreateMarker(link ULinkT) (string, error)

CreateMarker generate hash string for template markers.

func DependenciesRecursiveIterate

func DependenciesRecursiveIterate(u Unit, f func(Unit) error) error

func DiscoverCdevLastRelease

func DiscoverCdevLastRelease() error

func EscapeForMarkerStr

func EscapeForMarkerStr(in string) (string, error)

EscapeForMarkerStr convert URL to string which can be used as marker.

func InsertYaml

func InsertYaml(data interface{}) (string, error)

InsertYaml function for template. Insert data to yaml in json one line string (supported from a box by yaml unmarshal functions).

func NewStackTemplate

func NewStackTemplate(data []byte) (*stackTemplate, error)

func OutputsReplacer

func OutputsReplacer(data reflect.Value, unit Unit) (reflect.Value, error)

OutputsReplacer - project scanner function, witch process dependencies markers in unit data created by AddRemoteStateMarker template function.

func OutputsScanner

func OutputsScanner(data reflect.Value, unit Unit) (reflect.Value, error)

OutputsScanner - project scanner function, witch process dependencies markers in unit data setted by AddRemoteStateMarker template function.

func ProjectsFilesExists

func ProjectsFilesExists() bool

func RegisterBackendFactory

func RegisterBackendFactory(f BackendsFactory, provider string) error

RegisterBackendFactory - register factory of some provider (like s3) in map.

func RegisterSecretDriver

func RegisterSecretDriver(drv SecretDriver, key string) error

func RegisterTemplateDriver

func RegisterTemplateDriver(drv TemplateDriver)

RegisterTemplateDriver register unit template driver.

func RegisterUnitFactory

func RegisterUnitFactory(f UnitFactory, modType string) error

func RenderUnitPlanningString

func RenderUnitPlanningString(uStatus *UnitPlanningStatus) string

func ScanMarkers

func ScanMarkers(data interface{}, procFunc MarkerScanner, unit Unit) error

ScanMarkers use marker scanner function to replace templated markers.

func StateOutputsReplacer

func StateOutputsReplacer(data reflect.Value, unit Unit) (reflect.Value, error)

StateOutputsReplacer scan state data for outputs markers and replaces them for placeholders with output ref like <output "stack.unit.output" >

Types

type Backend

type Backend interface {
	Name() string
	Provider() string
	GetBackendHCL(string, string) (*hclwrite.File, error)
	GetBackendBytes(string, string) ([]byte, error)
	GetRemoteStateHCL(string, string) ([]byte, error)
	LockState() error
	UnlockState() error
	WriteState(stateData string) error
	ReadState() (string, error)
}

Backend interface for backend provider.

type BackendsFactory

type BackendsFactory interface {
	New([]byte, string, *Project) (Backend, error)
}

BackendsFactory - interface for backend provider factory. New() creates backend.

type ExecSet

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

func NewExecSet

func NewExecSet(planningStatus *ProjectPlanningStatus) *ExecSet

func (*ExecSet) AddUnit

func (e *ExecSet) AddUnit(u *UnitPlanningStatus)

func (*ExecSet) Delete

func (e *ExecSet) Delete(u Unit)

func (*ExecSet) Find

func (e *ExecSet) Find(u Unit) *UnitPlanningStatus

func (*ExecSet) Front

func (e *ExecSet) Front() *UnitPlanningStatus

func (*ExecSet) Index

func (e *ExecSet) Index(u Unit) int

func (*ExecSet) IsEmpty

func (e *ExecSet) IsEmpty() bool

func (*ExecSet) Len

func (e *ExecSet) Len() int

func (*ExecSet) Slice

func (e *ExecSet) Slice() []*UnitPlanningStatus

func (*ExecSet) StatusFilter

func (e *ExecSet) StatusFilter(statusList ...ExecutionStatus) *ExecSet

type ExecutionStatus

type ExecutionStatus uint16
const (
	Backlog ExecutionStatus = iota + 1
	ReadyForExec
	InProgress
	Finished
)

type ExtendedFuncMap

type ExtendedFuncMap template.FuncMap

Type for tmpl functions list with additional options, like set path to templated file.

func (*ExtendedFuncMap) Get

func (f *ExtendedFuncMap) Get(path string, s *Stack) template.FuncMap

type GlobalTemplateDriver

type GlobalTemplateDriver struct {
}

func (*GlobalTemplateDriver) AddTemplateFunctions

func (d *GlobalTemplateDriver) AddTemplateFunctions(mp template.FuncMap, p *Project, s *Stack)

func (*GlobalTemplateDriver) Name

func (d *GlobalTemplateDriver) Name() string

type MarkerScanner

type MarkerScanner func(data reflect.Value, unit Unit) (reflect.Value, error)

MarkerScanner type witch describe function for scanning markers in templated and unmarshaled yaml data.

type ObjectData

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

ObjectData simple representation of project object.

type PrinterOutput

type PrinterOutput struct {
	Name   string `json:"name"`
	Output string `json:"output"`
}

type Project

type Project struct {
	SessionId string
	Units     map[string]Unit
	Stacks    map[string]*Stack
	Backends  map[string]Backend
	UnitLinks *UnitLinksT

	CodeCacheDir        string
	StateMutex          sync.Mutex
	InitLock            sync.Mutex
	RuntimeDataset      RuntimeData
	StateBackendName    string
	OwnState            *StateProject
	UUID                string
	ProcessedUnitsCount uint
	HupUnlockChan       chan os.Signal
	NewVersionMessage   string
	// contains filtered or unexported fields
}

Project describes main config with user-defined variables.

func LoadProjectBase

func LoadProjectBase() (*Project, error)

LoadProjectBase read project data in current directory, create base project, and load secrets. stacks, backends and other objects are not loads.

func LoadProjectFull

func LoadProjectFull() (*Project, error)

LoadProjectFull read project data in current directory, create base project, load secrets and all project's objects.

func NewEmptyProject

func NewEmptyProject() *Project

NewEmptyProject creates new empty project. The configuration will not be loaded.

func (*Project) Apply

func (p *Project) Apply() error

Apply all units.

func (*Project) BackupState

func (p *Project) BackupState() error

func (*Project) Build

func (p *Project) Build() error

Build generate all terraform code for project.

func (*Project) CheckContainsMarkers

func (p *Project) CheckContainsMarkers(data string, kinds ...string) bool

CheckContainsMarkers - check if string contains any template markers.

func (*Project) ClearCacheDir

func (p *Project) ClearCacheDir() error

func (*Project) Destroy

func (p *Project) Destroy() error

Destroy all units.

func (*Project) Edit

func (p *Project) Edit(name string) error

func (*Project) ExportEnvs

func (p *Project) ExportEnvs(ex interface{}) error

func (*Project) GetState

func (p *Project) GetState() ([]byte, error)

func (*Project) LoadState

func (p *Project) LoadState() (*StateProject, error)

func (*Project) LockState

func (p *Project) LockState() error

func (*Project) MkBuildDir

func (p *Project) MkBuildDir() error

func (*Project) Name

func (p *Project) Name() string

Name return project name.

func (*Project) NewEmptyState

func (p *Project) NewEmptyState() *StateProject

func (*Project) Plan

func (p *Project) Plan() (*graph, error)

Plan and output result.

func (*Project) PrintInfo

func (p *Project) PrintInfo() error

PrintInfo print project info.

func (*Project) PrintOutputs

func (p *Project) PrintOutputs() (err error)

func (*Project) PrintSecretsList

func (p *Project) PrintSecretsList()

func (*Project) PullState

func (p *Project) PullState() error

func (*Project) SaveState

func (p *Project) SaveState() error

func (*Project) StartSigTrap

func (p *Project) StartSigTrap(stop chan struct{})

func (*Project) StopSigTrap

func (p *Project) StopSigTrap()

func (*Project) TemplateMust

func (p *Project) TemplateMust(data []byte, fileName string) (res []byte, err error)

TemplateMust do template

func (*Project) TemplateTry

func (p *Project) TemplateTry(data []byte, fileName string) (res []byte, warn bool, err error)

TemplateTry do template

func (*Project) UnLockState

func (p *Project) UnLockState() error

func (*Project) UnitsSlice

func (p *Project) UnitsSlice() []Unit

type ProjectPlanningStatus

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

func (*ProjectPlanningStatus) Add

func (s *ProjectPlanningStatus) Add(u Unit, op UnitOperation, diff string, tainted bool)

func (*ProjectPlanningStatus) AddIfNotExists

func (s *ProjectPlanningStatus) AddIfNotExists(u Unit, op UnitOperation, diff string, tainted bool)

func (*ProjectPlanningStatus) AddOrUpdate

func (s *ProjectPlanningStatus) AddOrUpdate(u Unit, op UnitOperation, diff string, tainted bool)

func (*ProjectPlanningStatus) BuildGraph

func (s *ProjectPlanningStatus) BuildGraph() (*graph, error)

func (*ProjectPlanningStatus) FindUnit

func (s *ProjectPlanningStatus) FindUnit(unit Unit) *UnitPlanningStatus

FindUnit searching unit by pointer, return *UnitPlanningStatus only for same unit

func (*ProjectPlanningStatus) FindUnitByKey

func (s *ProjectPlanningStatus) FindUnitByKey(unit Unit) *UnitPlanningStatus

FindUnit searching unit by pointer, return *UnitPlanningStatus if unit with same key exists (possible to have 2 different units ptr with same key - project/projectState)

func (*ProjectPlanningStatus) HasChanges

func (s *ProjectPlanningStatus) HasChanges() bool

func (*ProjectPlanningStatus) Len

func (s *ProjectPlanningStatus) Len() int

func (*ProjectPlanningStatus) OperationFilter

func (s *ProjectPlanningStatus) OperationFilter(ops ...UnitOperation) *ProjectPlanningStatus

func (*ProjectPlanningStatus) Print

func (s *ProjectPlanningStatus) Print()

func (*ProjectPlanningStatus) Slice

type RuntimeData

type RuntimeData struct {
	UnitsOutputs    map[string]interface{}
	PrintersOutputs []PrinterOutput
}

type Secret

type Secret struct {
	Filename  string
	DriverKey string
	Data      interface{}
}

type SecretDriver

type SecretDriver interface {
	// Read secret from raw yaml data. Return secret name, parsed secret data (for project templateing) and error.
	Read([]byte) (string, interface{}, error)
	// Return secret driver key (sops ...)
	Key() string
	// Edit secret.
	Edit(Secret) error
	// Create secret from files list generated by ui.generator/
	Create(map[string][]byte) error
}

type Stack

type Stack struct {
	ProjectPtr  *Project
	Backend     Backend
	Name        string
	BackendName string
	TemplateSrc string
	TemplateDir string
	Templates   []stackTemplate
	Variables   map[string]interface{}
	ConfigData  map[string]interface{}
}

Stack represent stack object.

func (*Stack) ReadTemplate

func (s *Stack) ReadTemplate(src string) (err error)

ReadTemplate read all templates in src.

func (*Stack) TemplateMust

func (i *Stack) TemplateMust(data []byte, fileName string) (res []byte, err error)

TemplateMust apply stack variables to template data. If template has unresolved variables - function will return an error.

func (*Stack) TemplateTry

func (i *Stack) TemplateTry(data []byte, fileName string) (res []byte, warn bool, err error)

TemplateTry apply values to template data. If template has unresolved variables - warn will be set to true.

type StateProject

type StateProject struct {
	Project
	LoaderProjectPtr *Project
	ChangedUnits     map[string]Unit
}

func (*StateProject) CheckUnitChanges

func (sp *StateProject) CheckUnitChanges(unit Unit) (string, Unit)

func (*StateProject) DeleteUnit

func (sp *StateProject) DeleteUnit(mod Unit)

func (*StateProject) UpdateUnit

func (sp *StateProject) UpdateUnit(unit Unit)

type TemplateDriver

type TemplateDriver interface {
	AddTemplateFunctions(template.FuncMap, *Project, *Stack)
	Name() string
}

type ULinkT

type ULinkT struct {
	Unit            Unit        `json:"-"`
	LinkType        string      `json:"link_type"`
	TargetUnitName  string      `json:"target_unit_name"`
	TargetStackName string      `json:"target_stack_name"`
	OutputName      string      `json:"output_name"`
	OutputData      interface{} `json:"output_data"`
}

ULinkT describe unit link betwen one target unit and multiple cli units, which uses this unit (output or remote state, or custom unit dependency).

func (*ULinkT) InitUnitPtr

func (u *ULinkT) InitUnitPtr(p *Project) (err error)

func (*ULinkT) LinkPath

func (u *ULinkT) LinkPath() (res string)

func (*ULinkT) UnitKey

func (u *ULinkT) UnitKey() (res string)

type Unit

type Unit interface {
	Name() string
	Stack() *Stack
	Project() *Project
	Backend() Backend
	Prepare() error // Prepare scan all markers in unit, and build project unit links, and unit dependencies.
	Dependencies() *UnitLinksT
	Build() error
	Init() error
	Apply() error
	Plan() error
	Destroy() error
	Key() string
	GetState() Unit
	GetDiffData() interface{}
	GetStateDiffData() interface{}
	LoadState(interface{}, string, *StateProject) error
	KindKey() string
	CodeDir() string
	UpdateProjectRuntimeData(p *Project) error
	WasApplied() bool
	ForceApply() bool
	Mux() *sync.Mutex
	IsTainted() bool
	SetTainted(newValue bool, err error)
	SetExecStatus(ExecutionStatus)
	GetExecStatus() ExecutionStatus
	ExecError() error
}

Unit interface for unit drivers.

func NewUnit

func NewUnit(spec map[string]interface{}, stack *Stack) (Unit, error)

NewUnit creates and return unit with needed driver.

func NewUnitFromState

func NewUnitFromState(state map[string]interface{}, name string, p *StateProject) (Unit, error)

NewUnitFromState creates unit from saved state.

type UnitDriver

type UnitDriver interface {
	AddTemplateFunctions(projectPtr *Project) error
	GetScanners() []MarkerScanner
}

type UnitFactory

type UnitFactory interface {
	New(map[string]interface{}, *Stack) (Unit, error)
	NewFromState(map[string]interface{}, string, *StateProject) (Unit, error)
}

type UnitLinksT

type UnitLinksT struct {
	LinksList map[string]*ULinkT `json:"unit_links_list,omitempty"`
	MapMutex  sync.RWMutex
}

UnitLinksT describe a set of links (dependencies) betwen units inside project.

func NewUnitLinksT

func NewUnitLinksT() *UnitLinksT

func (*UnitLinksT) ByLinkTypes

func (o *UnitLinksT) ByLinkTypes(outputType ...string) (res *UnitLinksT)

ByLinkTypes returns sublist with unit link types == any of outputType slice. Returns full list if outputType is empty.

func (*UnitLinksT) ByTargetUnit

func (o *UnitLinksT) ByTargetUnit(unit Unit) (res *UnitLinksT)

func (*UnitLinksT) Delete

func (o *UnitLinksT) Delete(marker string) (err error)

func (*UnitLinksT) Get

func (o *UnitLinksT) Get(key string) (res *ULinkT)

func (*UnitLinksT) Insert

func (o *UnitLinksT) Insert(key string, l *ULinkT)

Insert insert element to map, override if exists

func (*UnitLinksT) InsertTry

func (o *UnitLinksT) InsertTry(key string, l *ULinkT) error

Insert insert element to map, return error if exists

func (*UnitLinksT) IsEmpty

func (o *UnitLinksT) IsEmpty() bool

func (*UnitLinksT) Join

func (o *UnitLinksT) Join(l *UnitLinksT) error

func (*UnitLinksT) JoinWithDataReplace

func (o *UnitLinksT) JoinWithDataReplace(source *UnitLinksT) error

JoinWithDataReplace join source links into o. If link exists - only copy output data.

func (*UnitLinksT) Map

func (o *UnitLinksT) Map() (res map[string]*ULinkT)

func (*UnitLinksT) Set

func (o *UnitLinksT) Set(l *ULinkT) (string, error)

func (*UnitLinksT) Size

func (o *UnitLinksT) Size() int

func (*UnitLinksT) Slice

func (o *UnitLinksT) Slice() (res []*ULinkT)

func (*UnitLinksT) UniqUnits

func (o *UnitLinksT) UniqUnits() map[string]Unit

UniqUnits return list of uniq links units.

type UnitOperation

type UnitOperation uint16
const (
	Apply UnitOperation = iota + 1
	Destroy
	Update
	NotChanged
)

func (UnitOperation) HasChanges

func (u UnitOperation) HasChanges() bool

func (UnitOperation) String

func (u UnitOperation) String() string

type UnitPlanningStatus

type UnitPlanningStatus struct {
	UnitPtr   Unit
	Diff      string
	Operation UnitOperation
	IsTainted bool
	Index     int
}

type UnitState

type UnitState interface {
	GetType() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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