cofu

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const LUA_APP_KEY = "*__COFU_APP__"

Variables

View Source
var (
	Name       = "cofu"
	Version    = "unknown"
	CommitHash = "unknown"
	Usage      = "Minimum configuration management tool."
)
View Source
var BinPath string
View Source
var CommonAttributes = []Attribute{
	&StringAttribute{
		Name: "only_if",
	},
	&StringAttribute{
		Name: "not_if",
	},
	&StringAttribute{
		Name: "user",
	},
	&StringAttribute{
		Name: "cwd",
	},
	&NotifiesAttribute{
		Name:    "notifies",
		Default: nil,
	},
	&StringSliceAttribute{
		Name:    "verify",
		Default: nil,
	},
	&StringAttribute{
		Name: "description",
	},
}

Functions

func CopyDir added in v0.4.0

func CopyDir(src string, dst string) (err error)

func CopyFile added in v0.4.0

func CopyFile(src, dst string) (err error)

func CurrentDir added in v0.9.0

func CurrentDir(L *lua.LState) string

CurrentDir returns a directory path that includes lua source file which is executed now.

func DefaultShowDifferences

func DefaultShowDifferences(r *Resource) error

func GenLogIndent added in v0.10.0

func GenLogIndent(level int) string

func SetNoColor added in v0.12.0

func SetNoColor(b bool)

Types

type App

type App struct {
	LState               *lua.LState
	Logger               Logger
	ResourceTypes        []*ResourceType
	ResourceTypesMap     map[string]*ResourceType
	Resources            []*Resource
	DelayedNotifications []*Notification
	Infra                *infra.Infra
	DryRun               bool
	Tmpdir               string
	Tmpfiles             []string

	Parent         *App
	Level          int
	LogHeader      string
	BuiltinRecipes map[string]string
	Basepath       string
	// contains filtered or unexported fields
}

func GetApp

func GetApp(L *lua.LState) (*App, error)

func NewApp

func NewApp() *App

func (*App) Close

func (app *App) Close()

func (*App) DequeueDelayedNotification added in v0.9.0

func (app *App) DequeueDelayedNotification() *Notification

func (*App) EnqueueDelayedNotification added in v0.9.0

func (app *App) EnqueueDelayedNotification(n *Notification)

func (*App) FindOneResource

func (app *App) FindOneResource(desc string) *Resource

func (*App) Init

func (app *App) Init() error

func (*App) IsRootApp added in v0.9.0

func (app *App) IsRootApp() bool

func (*App) LoadDefinition

func (app *App) LoadDefinition(definition *Definition)

func (*App) LoadRecipe

func (app *App) LoadRecipe(recipeContent string) error

func (*App) LoadRecipeFile

func (app *App) LoadRecipeFile(recipeFile string) error

func (*App) LoadUserResources added in v0.13.0

func (app *App) LoadUserResources() error

func (*App) LoadVariableFromJSON

func (app *App) LoadVariableFromJSON(v string) error

func (*App) LoadVariableFromJSONFile

func (app *App) LoadVariableFromJSONFile(jsonFile string) error

func (*App) LoadVariableFromMap added in v0.9.0

func (app *App) LoadVariableFromMap(m map[string]interface{}) error

func (*App) RegisterResource

func (app *App) RegisterResource(r *Resource)

func (*App) RemoveDuplicateDelayedNotification added in v0.9.0

func (app *App) RemoveDuplicateDelayedNotification()

func (*App) Run

func (app *App) Run(dryRun bool) (err error)

func (*App) SendContentToTempfile

func (app *App) SendContentToTempfile(content []byte) (string, error)

func (*App) SendDirectoryToTempDirectory added in v0.4.0

func (app *App) SendDirectoryToTempDirectory(src string) (string, error)

func (*App) SendFileToTempfile

func (app *App) SendFileToTempfile(file string) (string, error)

type Attribute

type Attribute interface {
	GetName() string
	IsRequired() bool
	HasDefault() bool
	GetDefault() interface{}
	ToGoValue(v lua.LValue) interface{}
}

type BoolAttribute

type BoolAttribute struct {
	Name     string
	Required bool
	Default  bool
}

BoolAttribute

func (*BoolAttribute) GetDefault

func (attr *BoolAttribute) GetDefault() interface{}

func (*BoolAttribute) GetName

func (attr *BoolAttribute) GetName() string

func (*BoolAttribute) HasDefault

func (attr *BoolAttribute) HasDefault() bool

func (*BoolAttribute) IsRequired

func (attr *BoolAttribute) IsRequired() bool

func (*BoolAttribute) ToGoValue

func (attr *BoolAttribute) ToGoValue(v lua.LValue) interface{}

type ComparableValue

type ComparableValue interface {
	String() string
	Nil() bool
}

type Definition

type Definition struct {
	Name          string
	DefaultParams *lua.LTable
	Func          *lua.LFunction
	// contains filtered or unexported fields
}

func (*Definition) LGFunction

func (definition *Definition) LGFunction() func(L *lua.LState) int

type Integer

type Integer struct {
	V     int
	IsNil bool
}

func (*Integer) Nil

func (i *Integer) Nil() bool

func (*Integer) String

func (i *Integer) String() string

type IntegerAttribute

type IntegerAttribute struct {
	Name     string
	Required bool
	Default  *Integer
}

IntAttribute

func (*IntegerAttribute) GetDefault

func (attr *IntegerAttribute) GetDefault() interface{}

func (*IntegerAttribute) GetName

func (attr *IntegerAttribute) GetName() string

func (*IntegerAttribute) HasDefault

func (attr *IntegerAttribute) HasDefault() bool

func (*IntegerAttribute) IsRequired

func (attr *IntegerAttribute) IsRequired() bool

func (*IntegerAttribute) ToGoValue

func (attr *IntegerAttribute) ToGoValue(lv lua.LValue) interface{}

type LFunctionAttribute

type LFunctionAttribute struct {
	Name     string
	Required bool
	Default  *lua.LFunction
}

LFunctionAttribute

func (*LFunctionAttribute) GetDefault

func (attr *LFunctionAttribute) GetDefault() interface{}

func (*LFunctionAttribute) GetName

func (attr *LFunctionAttribute) GetName() string

func (*LFunctionAttribute) HasDefault

func (attr *LFunctionAttribute) HasDefault() bool

func (*LFunctionAttribute) IsRequired

func (attr *LFunctionAttribute) IsRequired() bool

func (*LFunctionAttribute) ToGoValue

func (attr *LFunctionAttribute) ToGoValue(lv lua.LValue) interface{}

type Logger added in v0.10.0

type Logger interface {
	Output() io.Writer
	SetOutput(w io.Writer)
	Prefix() string
	SetPrefix(p string)
	Level() log.Lvl
	SetLevel(v log.Lvl)
	SetHeader(h string)
	Print(i ...interface{})
	Printf(format string, args ...interface{})
	Printj(j log.JSON)
	Debug(i ...interface{})
	Debugf(format string, args ...interface{})
	Debugj(j log.JSON)
	Info(i ...interface{})
	Infof(format string, args ...interface{})
	Infoj(j log.JSON)
	Warn(i ...interface{})
	Warnf(format string, args ...interface{})
	Warnj(j log.JSON)
	Error(i ...interface{})
	Errorf(format string, args ...interface{})
	Errorj(j log.JSON)
	Fatal(i ...interface{})
	Fatalj(j log.JSON)
	Fatalf(format string, args ...interface{})
	Panic(i ...interface{})
	Panicj(j log.JSON)
	Panicf(format string, args ...interface{})
}

func GetLogger added in v0.10.0

func GetLogger(L *lua.LState) (Logger, error)

type MapAttribute

type MapAttribute struct {
	Name     string
	Required bool
	Default  map[string]interface{}
}

MapAttribute

func (*MapAttribute) GetDefault

func (attr *MapAttribute) GetDefault() interface{}

func (*MapAttribute) GetName

func (attr *MapAttribute) GetName() string

func (*MapAttribute) HasDefault

func (attr *MapAttribute) HasDefault() bool

func (*MapAttribute) IsRequired

func (attr *MapAttribute) IsRequired() bool

func (*MapAttribute) ToGoValue

func (attr *MapAttribute) ToGoValue(v lua.LValue) interface{}

type Notification

type Notification struct {
	DefinedInResource  *Resource
	Action             string
	TargetResourceDesc string
	Timing             string
}

func (*Notification) Delayed

func (n *Notification) Delayed() bool

func (*Notification) Immediately

func (n *Notification) Immediately() bool

func (*Notification) Run

func (n *Notification) Run() error

func (*Notification) Validate

func (n *Notification) Validate() error

type NotifiesAttribute

type NotifiesAttribute struct {
	Name     string
	Required bool
	Default  []*Notification
}

NotifiesAttribute

func (*NotifiesAttribute) GetDefault

func (attr *NotifiesAttribute) GetDefault() interface{}

func (*NotifiesAttribute) GetName

func (attr *NotifiesAttribute) GetName() string

func (*NotifiesAttribute) HasDefault

func (attr *NotifiesAttribute) HasDefault() bool

func (*NotifiesAttribute) IsRequired

func (attr *NotifiesAttribute) IsRequired() bool

func (*NotifiesAttribute) ToGoValue

func (attr *NotifiesAttribute) ToGoValue(lv lua.LValue) interface{}

type Resource

type Resource struct {
	Name string
	// Basepath is a directory path that includes recipe file defines this resource.
	Basepath           string
	Attributes         map[string]interface{}
	AttributesLValues  map[string]lua.LValue
	CurrentAttributes  map[string]interface{}
	FallbackAttributes map[string]interface{}
	Notifications      []*Notification
	ResourceType       *ResourceType
	App                *App
	CurrentAction      string
	Values             map[string]interface{}
	// contains filtered or unexported fields
}

func NewResource

func NewResource(name string, resourceType *ResourceType, app *App) *Resource

func (*Resource) CheckCommand

func (r *Resource) CheckCommand(command string) bool

func (*Resource) Desc

func (r *Resource) Desc() string

Desc returns string like 'resource_type[name]'

func (*Resource) GetBoolAttribute

func (r *Resource) GetBoolAttribute(key string) bool

func (*Resource) GetBoolCurrentAttribute

func (r *Resource) GetBoolCurrentAttribute(key string) bool

func (*Resource) GetIntegerAttribute

func (r *Resource) GetIntegerAttribute(key string) *Integer

func (*Resource) GetIntegerCurrentAttribute

func (r *Resource) GetIntegerCurrentAttribute(key string) *Integer

func (*Resource) GetLFunctionAttribute

func (r *Resource) GetLFunctionAttribute(key string) *lua.LFunction

func (*Resource) GetLFunctionCurrentAttribute

func (r *Resource) GetLFunctionCurrentAttribute(key string) *lua.LFunction

func (*Resource) GetMapAttribute

func (r *Resource) GetMapAttribute(key string) map[string]interface{}

func (*Resource) GetMapCurrentAttribute

func (r *Resource) GetMapCurrentAttribute(key string) map[string]interface{}

func (*Resource) GetRawAttribute

func (r *Resource) GetRawAttribute(key string) interface{}

func (*Resource) GetRawCurrentAttribute

func (r *Resource) GetRawCurrentAttribute(key string) interface{}

func (*Resource) GetStringAttribute

func (r *Resource) GetStringAttribute(key string) string

func (*Resource) GetStringCurrentAttribute

func (r *Resource) GetStringCurrentAttribute(key string) string

func (*Resource) GetStringSliceAttribute

func (r *Resource) GetStringSliceAttribute(key string) []string

func (*Resource) GetStringSliceCurrentAttribute

func (r *Resource) GetStringSliceCurrentAttribute(key string) []string

func (*Resource) Infra

func (r *Resource) Infra() *infra.Infra

func (*Resource) IsDifferentFiles

func (r *Resource) IsDifferentFiles(from, to string) bool

func (*Resource) IsDifferentFilesRecursively added in v0.4.0

func (r *Resource) IsDifferentFilesRecursively(from, to string) bool

func (Resource) IsUpdated

func (r Resource) IsUpdated() bool

func (*Resource) MustRunCommand

func (r *Resource) MustRunCommand(command string) *backend.CommandResult

func (*Resource) Run

func (r *Resource) Run(specificAction string) error

func (*Resource) RunCommand

func (r *Resource) RunCommand(command string) *backend.CommandResult

func (*Resource) SendContentToTempfile

func (r *Resource) SendContentToTempfile(content []byte) (string, error)

func (*Resource) SendDirectoryToTempDirectory added in v0.4.0

func (r *Resource) SendDirectoryToTempDirectory(src string) (string, error)

func (*Resource) SendFileToTempfile

func (r *Resource) SendFileToTempfile(file string) (string, error)

func (*Resource) ShowContentDiff

func (r *Resource) ShowContentDiff(from, to string)

func (*Resource) ShowContentDiffRecursively added in v0.4.0

func (r *Resource) ShowContentDiffRecursively(from, to string)

func (*Resource) Update

func (r *Resource) Update()

type ResourceAction

type ResourceAction func(*Resource) error

type ResourceType

type ResourceType struct {
	Name                     string
	Attributes               []Attribute
	PreAction                ResourceAction
	SetCurrentAttributesFunc ResourceAction
	Actions                  map[string]ResourceAction
	ShowDifferences          ResourceAction
	UseFallbackAttributes    bool
	// contains filtered or unexported fields
}

func (*ResourceType) LGFunction

func (resourceType *ResourceType) LGFunction() func(L *lua.LState) int

type StringAttribute

type StringAttribute struct {
	Name     string
	Required bool
	Default  string
	// If DefaultName is true, it uses name as default value.
	DefaultName bool
}

StringAttribute

func (*StringAttribute) GetDefault

func (attr *StringAttribute) GetDefault() interface{}

func (*StringAttribute) GetName

func (attr *StringAttribute) GetName() string

func (*StringAttribute) HasDefault

func (attr *StringAttribute) HasDefault() bool

func (*StringAttribute) IsDefaultName

func (attr *StringAttribute) IsDefaultName() bool

func (*StringAttribute) IsRequired

func (attr *StringAttribute) IsRequired() bool

func (*StringAttribute) ToGoValue

func (attr *StringAttribute) ToGoValue(lv lua.LValue) interface{}

type StringSliceAttribute

type StringSliceAttribute struct {
	Name     string
	Required bool
	Default  []string
	// If DefaultName is true, it uses name as default value.
	DefaultName bool
}

StringSliceAttribute

func (*StringSliceAttribute) GetDefault

func (attr *StringSliceAttribute) GetDefault() interface{}

func (*StringSliceAttribute) GetName

func (attr *StringSliceAttribute) GetName() string

func (*StringSliceAttribute) HasDefault

func (attr *StringSliceAttribute) HasDefault() bool

func (*StringSliceAttribute) IsDefaultName

func (attr *StringSliceAttribute) IsDefaultName() bool

func (*StringSliceAttribute) IsRequired

func (attr *StringSliceAttribute) IsRequired() bool

func (*StringSliceAttribute) ToGoValue

func (attr *StringSliceAttribute) ToGoValue(v lua.LValue) interface{}

Jump to

Keyboard shortcuts

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