sync

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package sync contains tools to provide bump propagation.

Index

Constants

View Source
const (
	// SortAsc const.
	SortAsc = "asc"
	// SortDesc const.
	SortDesc = "desc"
)

Variables

View Source
var InventoryExcluded = []string{
	".git",
	".plasma",
	".plasmactl",
	".gitlab-ci.yml",
	"ansible_collections",
	"scripts/ci/.gitlab-ci.platform.yaml",
	"venv",
	"__pycache__",
}

InventoryExcluded is list of excluded files and folders from inventory.

View Source
var Kinds = map[string]struct{}{
	"applications": {},
	"services":     {},
	"softwares":    {},
	"executors":    {},
	"flows":        {},
	"skills":       {},
	"functions":    {},
	"libraries":    {},
	"entities":     {},
}

Kinds are list of resources kinds which version can be propagated.

Functions

func ConvertMRNtoPath

func ConvertMRNtoPath(mrn string) (string, error)

ConvertMRNtoPath transforms machine resource name to templated path to resource.

func GatherDependentKeys

func GatherDependentKeys(vd *VariableDependency, result map[string]map[string]bool)

GatherDependentKeys recursively gathers dependent keys and stores them in the result map.

func GetMetaVersion

func GetMetaVersion(meta map[string]any) string

GetMetaVersion searches for version in meta data.

func IsUpdatableKind

func IsUpdatableKind(kind string) bool

IsUpdatableKind checks if resource kind is in Kinds range.

func IsVaultFile

func IsVaultFile(path string) bool

IsVaultFile is helper to determine if file is vault file.

func LoadVariablesFile

func LoadVariablesFile(path, vaultPassword string, isVault bool) (map[string]any, []string, error)

LoadVariablesFile loads vars yaml file from path.

func LoadVariablesFileFromBytes

func LoadVariablesFileFromBytes(input []byte, path string, vaultPassword string, isVault bool) (map[string]any, []string, error)

LoadVariablesFileFromBytes loads vars yaml file from bytes input.

func LoadYamlFileFromBytes

func LoadYamlFileFromBytes(input []byte) (map[string]any, error)

LoadYamlFileFromBytes loads yaml file from bytes input.

func PrepareMachineResourceName

func PrepareMachineResourceName(platform, kind, role string) string

PrepareMachineResourceName concatenates resource platform, kind and role via specific template. It allows to have common resource names.

func ProcessResourcePath

func ProcessResourcePath(path string) (string, string, string, error)

ProcessResourcePath splits resource path onto platform, kind and role.

func SortTimeline

func SortTimeline(list []TimelineItem, order string)

SortTimeline sorts timeline items in slice.

func UnmarshallFixDuplicates

func UnmarshallFixDuplicates(data []byte) (map[string]any, map[string]bool, []string, error)

UnmarshallFixDuplicates handles duplicated values in yaml instead throwing error.

Types

type FilesCrawler

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

FilesCrawler is a type that represents a crawler for resources in a given directory.

func NewFilesCrawler

func NewFilesCrawler(directory string) *FilesCrawler

NewFilesCrawler creates a new instance of FilesCrawler with initialized taskSources and templateSources maps.

func (*FilesCrawler) FindResourcesFiles

func (cr *FilesCrawler) FindResourcesFiles(platform string) (map[string][]string, error)

FindResourcesFiles return list of resources files in platform. If platform is empty, search across all.

func (*FilesCrawler) FindVarsFiles

func (cr *FilesCrawler) FindVarsFiles(platform string) (map[string][]string, error)

FindVarsFiles return list of variables files in platform. If platform is empty, search across all.

type Inventory

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

Inventory represents the inventory used in the application to search and collect resources and variable resources.

func NewInventory

func NewInventory(sourceDir string, log *launchr.Logger) (*Inventory, error)

NewInventory creates a new instance of Inventory with the provided vault password. It then calls the Init method of the Inventory to build the resources graph and returns the initialized Inventory or any error that occurred during initialization.

func (*Inventory) CalculateResourcesUsage

func (i *Inventory) CalculateResourcesUsage() error

CalculateResourcesUsage parse platform playbooks and determine resources used in platform.

func (*Inventory) CalculateVariablesUsage

func (i *Inventory) CalculateVariablesUsage(vaultpass string) error

CalculateVariablesUsage precalculates all variables dependencies across platform.

func (*Inventory) GetDependsOnMap

func (i *Inventory) GetDependsOnMap() map[string]*OrderedMap[bool]

GetDependsOnMap returns the map, which represents the 'depends on' dependencies between resources in the Inventory.

func (*Inventory) GetDependsOnResources

func (i *Inventory) GetDependsOnResources(resourceName string, depth int8) map[string]bool

GetDependsOnResources returns list of resources which are used by argument resource (directly or not).

func (*Inventory) GetRequiredByMap

func (i *Inventory) GetRequiredByMap() map[string]*OrderedMap[bool]

GetRequiredByMap returns the required by map, which represents the `required by` dependencies between resources in the Inventory.

func (*Inventory) GetRequiredByResources

func (i *Inventory) GetRequiredByResources(resourceName string, depth int8) map[string]bool

GetRequiredByResources returns list of resources which depend on argument resource (directly or not).

func (*Inventory) GetResourcesMap

func (i *Inventory) GetResourcesMap() *OrderedMap[*Resource]

GetResourcesMap returns map of all resources found in source dir.

func (*Inventory) GetResourcesOrder

func (i *Inventory) GetResourcesOrder() []string

GetResourcesOrder returns the order of resources in the inventory.

func (*Inventory) GetUsedResources

func (i *Inventory) GetUsedResources() map[string]bool

GetUsedResources returns list of used resources.

func (*Inventory) GetVariableResources

func (i *Inventory) GetVariableResources(variableName, variablePlatform string) []string

GetVariableResources returns list of resources which depends on variable.

func (*Inventory) Init

func (i *Inventory) Init() error

Init initializes the Inventory by building the resources graph. It returns an error if there was an issue while building the graph.

func (*Inventory) IsUsedVariable

func (i *Inventory) IsUsedVariable(checkResourcesUsage bool, variableName, variablePlatform string) bool

IsUsedVariable checks if variable used in any resource. checkResourcesUsage adds additional check if resources are used in platform.

type MultiPrinter

type MultiPrinter struct {
	IsActive    bool
	Writer      io.Writer
	UpdateDelay time.Duration
	// contains filtered or unexported fields
}

MultiPrinter overrides pterm.MultiPrinter to properly set area writer. @todo remove when it will be fixed in pterm.

func NewMultiPrinter

func NewMultiPrinter(areaWriter *launchr.Out) *MultiPrinter

NewMultiPrinter creates and initializes a new MultiPrinter instance with the provided output writer.

func (MultiPrinter) GenericStart

func (p MultiPrinter) GenericStart() (*pterm.LivePrinter, error)

GenericStart runs Start, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Start instead of this in your program.

func (MultiPrinter) GenericStop

func (p MultiPrinter) GenericStop() (*pterm.LivePrinter, error)

GenericStop runs Stop, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Stop instead of this in your program.

func (*MultiPrinter) NewWriter

func (p *MultiPrinter) NewWriter() io.Writer

NewWriter creates new multiWriter buffer.

func (*MultiPrinter) SetWriter

func (p *MultiPrinter) SetWriter(writer io.Writer)

SetWriter sets the writer for the AreaPrinter.

func (*MultiPrinter) Start

func (p *MultiPrinter) Start() (*MultiPrinter, error)

Start activates the MultiPrinter, initializes printers, and schedules periodic updates for the area content.

func (*MultiPrinter) Stop

func (p *MultiPrinter) Stop() (*MultiPrinter, error)

Stop deactivates the MultiPrinter, stops all associated printers, updates the area content, and terminates the area.

func (MultiPrinter) WithUpdateDelay

func (p MultiPrinter) WithUpdateDelay(delay time.Duration) *MultiPrinter

WithUpdateDelay returns a fork of the MultiPrinter with a new update delay.

func (MultiPrinter) WithWriter

func (p MultiPrinter) WithWriter(writer io.Writer) *MultiPrinter

WithWriter returns a fork of the MultiPrinter with a new writer.

type OrderedMap

type OrderedMap[T any] struct {
	// contains filtered or unexported fields
}

OrderedMap represents generic struct with map and order keys.

func NewOrderedMap

func NewOrderedMap[T any]() *OrderedMap[T]

NewOrderedMap returns a new instance of OrderedMap.

func (*OrderedMap[T]) Get

func (m *OrderedMap[T]) Get(key string) (T, bool)

Get a value from the OrderedMap.

func (*OrderedMap[T]) Keys

func (m *OrderedMap[T]) Keys() []string

Keys returns the ordered keys from the OrderedMap.

func (*OrderedMap[T]) Len

func (m *OrderedMap[T]) Len() int

Len returns the length of the OrderedMap.

func (*OrderedMap[T]) OrderBy

func (m *OrderedMap[T]) OrderBy(orderList []string)

OrderBy updates the order of keys in the OrderedMap based on the orderList.

func (*OrderedMap[T]) Set

func (m *OrderedMap[T]) Set(key string, value T)

Set a value in the OrderedMap.

func (*OrderedMap[T]) SortKeysAlphabetically

func (m *OrderedMap[T]) SortKeysAlphabetically()

SortKeysAlphabetically sorts internal keys alphabetically.

func (*OrderedMap[T]) ToDict

func (m *OrderedMap[T]) ToDict() map[string]T

ToDict returns copy of OrderedMap dictionary.

func (*OrderedMap[T]) ToList

func (m *OrderedMap[T]) ToList() []T

ToList converts map to ordered list OrderedMap.

func (*OrderedMap[T]) Unset

func (m *OrderedMap[T]) Unset(key string)

Unset a value from the OrderedMap.

type Resource

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

Resource represents a platform resource

func BuildResourceFromPath

func BuildResourceFromPath(path, pathPrefix string) *Resource

BuildResourceFromPath builds a new instance of Resource from the given path.

func NewResource

func NewResource(mrn, prefix string) *Resource

NewResource returns new Resource instance.

func (*Resource) BuildMetaPath

func (r *Resource) BuildMetaPath() string

BuildMetaPath returns common path to resource meta.

func (*Resource) GetBaseVersion

func (r *Resource) GetBaseVersion() (string, string, []string, error)

GetBaseVersion returns resource version without `-` if any.

func (*Resource) GetKind

func (r *Resource) GetKind() string

GetKind returns a resource kind.

func (*Resource) GetName

func (r *Resource) GetName() string

GetName returns a machine resource name.

func (*Resource) GetPlatform

func (r *Resource) GetPlatform() string

GetPlatform returns a resource platform.

func (*Resource) GetRole

func (r *Resource) GetRole() string

GetRole returns a resource name.

func (*Resource) GetVersion

func (r *Resource) GetVersion() (string, []string, error)

GetVersion retrieves the version of the resource from the plasma.yaml

func (*Resource) IsValidResource

func (r *Resource) IsValidResource() bool

IsValidResource checks if resource has meta file.

func (*Resource) UpdateVersion

func (r *Resource) UpdateVersion(version string) ([]string, error)

UpdateVersion updates the version of the resource in the plasma.yaml file

type TimelineItem

type TimelineItem interface {
	GetCommit() string
	GetVersion() string
	GetDate() time.Time
	Merge(item TimelineItem)
	Print()
}

TimelineItem is interface for storing commit, date and version of propagated items. Storing such items in slice allows us to propagate items in the same order they were changed.

func AddToTimeline

func AddToTimeline(list []TimelineItem, item TimelineItem) []TimelineItem

AddToTimeline inserts items into timeline slice.

func CreateTimeline

func CreateTimeline() []TimelineItem

CreateTimeline returns fresh timeline slice.

type TimelineResourcesItem

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

TimelineResourcesItem implements TimelineItem interface and stores Resource map.

func NewTimelineResourcesItem

func NewTimelineResourcesItem(version, commit string, date time.Time, printer *launchr.Terminal) *TimelineResourcesItem

NewTimelineResourcesItem returns new instance of TimelineResourcesItem

func (*TimelineResourcesItem) AddResource

func (i *TimelineResourcesItem) AddResource(r *Resource)

AddResource pushes Resource into timeline item.

func (*TimelineResourcesItem) GetCommit

func (i *TimelineResourcesItem) GetCommit() string

GetCommit returns timeline item commit.

func (*TimelineResourcesItem) GetDate

func (i *TimelineResourcesItem) GetDate() time.Time

GetDate returns timeline item date.

func (*TimelineResourcesItem) GetResources

func (i *TimelineResourcesItem) GetResources() *OrderedMap[*Resource]

GetResources returns Resource map of timeline.

func (*TimelineResourcesItem) GetVersion

func (i *TimelineResourcesItem) GetVersion() string

GetVersion returns timeline item version to propagate.

func (*TimelineResourcesItem) Merge

func (i *TimelineResourcesItem) Merge(item TimelineItem)

Merge allows to merge other timeline item resources.

func (*TimelineResourcesItem) Print

func (i *TimelineResourcesItem) Print()

Print outputs common item info.

type TimelineVariablesItem

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

TimelineVariablesItem implements TimelineItem interface and stores Variable map.

func NewTimelineVariablesItem

func NewTimelineVariablesItem(version, commit string, date time.Time, printer *launchr.Terminal) *TimelineVariablesItem

NewTimelineVariablesItem returns new instance of TimelineVariablesItem

func (*TimelineVariablesItem) AddVariable

func (i *TimelineVariablesItem) AddVariable(v *Variable)

AddVariable pushes Variable into timeline item.

func (*TimelineVariablesItem) GetCommit

func (i *TimelineVariablesItem) GetCommit() string

GetCommit returns timeline item commit.

func (*TimelineVariablesItem) GetDate

func (i *TimelineVariablesItem) GetDate() time.Time

GetDate returns timeline item date.

func (*TimelineVariablesItem) GetVariables

func (i *TimelineVariablesItem) GetVariables() *OrderedMap[*Variable]

GetVariables returns Variable map of timeline.

func (*TimelineVariablesItem) GetVersion

func (i *TimelineVariablesItem) GetVersion() string

GetVersion returns timeline item version to propagate.

func (*TimelineVariablesItem) Merge

func (i *TimelineVariablesItem) Merge(item TimelineItem)

Merge allows to merge other timeline item variables.

func (*TimelineVariablesItem) Print

func (i *TimelineVariablesItem) Print()

Print outputs common item info.

type Variable

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

Variable represents a variable used in the application.

func NewVariable

func NewVariable(filepath, name string, hash uint64, isVault bool) *Variable

NewVariable returns instance of Variable struct.

func (*Variable) GetHash

func (v *Variable) GetHash() uint64

GetHash returns variable [Variable.hash]

func (*Variable) GetName

func (v *Variable) GetName() string

GetName returns variable name.

func (*Variable) GetPath

func (v *Variable) GetPath() string

GetPath returns path to variable file.

func (*Variable) GetPlatform

func (v *Variable) GetPlatform() string

GetPlatform returns variable platform.

func (*Variable) IsVault

func (v *Variable) IsVault() bool

IsVault tells if variable from vault.

type VariableDependency

type VariableDependency struct {
	Name      string
	Platform  string
	Dependent map[string]map[string]*VariableDependency
}

VariableDependency stores variable name, platform and reference to dependent vars.

func NewVariableDependency

func NewVariableDependency(name, platform string) *VariableDependency

NewVariableDependency creates new instance of VariableDependency

func (*VariableDependency) SetDependent

func (v *VariableDependency) SetDependent(d *VariableDependency)

SetDependent adds new dependent variable to variable.

Jump to

Keyboard shortcuts

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