Documentation
¶
Index ¶
- Constants
- func BuildContexts(files, flags []string, format string) (map[string]map[string]any, error)
- func ChdirOrCreate(dir string) error
- func LoadContextFiles(files []string) (map[string]map[string]any, error)
- func MergeContexts(dst, src map[string]map[string]any)
- func ParseContextFlags(flags []string, format string) (map[string]map[string]any, error)
- func RenderTemplate(content string, contexts map[string]map[string]any) (string, error)
- func ShellEscape(cmd string) string
- type Agent
- func (a *Agent) AgentWithCallback(callback func(interface{}), format int) RunOption
- func (a *Agent) AgentWithConfigs(w WorkflowConfig, i InventoryConfig) RunOption
- func (a *Agent) AgentWithContexts(contexts map[string]map[string]any) RunOption
- func (a *Agent) AgentWithFiles(w string, i string) RunOption
- func (a *Agent) Install(args InstallArgs) error
- func (a *Agent) InstallDev(ic InventoryConfig) error
- func (a *Agent) InstallProd(ic InventoryConfig) error
- func (a *Agent) Run(opts ...RunOption) error
- func (a *Agent) Uninstall(args UninstallArgs) error
- type AuthenticateArgs
- type CopyFileArgs
- type Defaults
- type ExecuteArgs
- type ExecuteCommandArgs
- type InstallArgs
- type Inventory
- type InventoryConfig
- type Job
- type JobState
- type RunArgs
- type RunOption
- type Server
- type Ssh
- func (s *Ssh) Authenticate(args AuthenticateArgs) (*ssh.Client, error)
- func (s *Ssh) CopyFile(args CopyFileArgs) error
- func (s *Ssh) CopyTo(client *ssh.Client, source string, destination string) error
- func (s *Ssh) CreateDirectory(sftpClient *sftp.Client, dirPath string) error
- func (s *Ssh) ExecuteCommand(args ExecuteCommandArgs) (string, string, error)
- type State
- type Step
- type StepOutputPlain
- type UninstallArgs
- type Workflow
- func (w *Workflow) Dump(content WorkflowConfig) (*string, error)
- func (w *Workflow) Execute(args ExecuteArgs) error
- func (w *Workflow) Load(file string) (*WorkflowConfig, error)
- func (w *Workflow) Run(opts ...WorkflowRunOptions) error
- func (w *Workflow) WorkflowWithCallback(callback func(any), sot int) WorkflowRunOptions
- func (w *Workflow) WorkflowWithConfig(config WorkflowConfig) WorkflowRunOptions
- func (w *Workflow) WorkflowWithContexts(contexts map[string]map[string]any) WorkflowRunOptions
- func (w *Workflow) WorkflowWithDirectory(directory string) WorkflowRunOptions
- func (w *Workflow) WorkflowWithFile(file string) WorkflowRunOptions
- type WorkflowConfig
- type WorkflowRunArgs
- type WorkflowRunOptions
- type WorkflowStepOutputStruct
Constants ¶
const ( ContextFormatJSON = "json" ContextFormatBase64 = "base64" )
const ( StepOutputTypePlain = iota + 1 StepOutputTypeStruct StepOutputTypeJson )
Variables ¶
This section is empty.
Functions ¶
func BuildContexts ¶
BuildContexts combines context files and inline context flags into a single context map. Files are applied first (providing the base), then inline flags override individual keys.
func ChdirOrCreate ¶
func LoadContextFiles ¶
LoadContextFiles reads context from one or more YAML/JSON files into the nested context map. Because YAML is a superset of JSON, a single YAML parser handles both formats.
Each entry may take one of two forms:
- "path": the file's top-level keys are context names, each mapping to that context's key/value map (a whole-contexts file).
- "name:path": the file holds a single context's key/value map, assigned under "name".
The forms are disambiguated by splitting on the first ":" — if the left part is a bare word (\w+) it is treated as "name:path"; otherwise the whole entry is treated as a "path". Files are merged in order, with later files overriding earlier ones at the key level.
func MergeContexts ¶
MergeContexts merges src into dst at the key level: for each context name in src, keys are copied into the matching context map in dst (created if absent), with src values overriding existing ones.
func ParseContextFlags ¶
ParseContextFlags parses CLI --context flags in "name:value" format into a nested map. Each flag is split on the first ":" only, so JSON values containing colons are handled correctly.
The format parameter controls how the value portion is interpreted:
- "json" (default): value is raw JSON
- "base64": value is a base64-encoded JSON string
func RenderTemplate ¶
RenderTemplate resolves all ${{ context.key }} expressions in content using the provided context maps. Rendering is in-memory only.
func ShellEscape ¶
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func (*Agent) AgentWithCallback ¶
func (*Agent) AgentWithConfigs ¶
func (a *Agent) AgentWithConfigs(w WorkflowConfig, i InventoryConfig) RunOption
func (*Agent) AgentWithContexts ¶
func (*Agent) Install ¶
func (a *Agent) Install(args InstallArgs) error
func (*Agent) InstallDev ¶
func (a *Agent) InstallDev(ic InventoryConfig) error
This is meant for testing locally or in CI
func (*Agent) InstallProd ¶
func (a *Agent) InstallProd(ic InventoryConfig) error
func (*Agent) Uninstall ¶
func (a *Agent) Uninstall(args UninstallArgs) error
type AuthenticateArgs ¶
type CopyFileArgs ¶
type ExecuteArgs ¶
type ExecuteCommandArgs ¶
type InstallArgs ¶
type InstallArgs struct {
If string
Ic InventoryConfig
// Installation mode; options are `dev` or `prod`
Mode string
}
type Inventory ¶
type Inventory struct{}
func NewInventory ¶
func NewInventory() *Inventory
type InventoryConfig ¶
type InventoryConfig struct {
Servers []Server `yaml:"servers"`
}
type RunArgs ¶
type RunArgs struct {
Wf *string
If *string
Wc *WorkflowConfig
Ic *InventoryConfig
Contexts map[string]map[string]any
Callback func(interface{})
StepOutputType int
}
type Server ¶
type Server struct {
Name string `yaml:"name"`
// IP Address or Domain
Host string `yaml:"host"`
// SSH Port, defaults to 22
Port int `yaml:"port,omitempty"`
User string `yaml:"user"`
SudoPassword string `yaml:"sudo-pass"`
SshPassword string `yaml:"ssh-pass"`
// File path to the SSH private key
PrivateSshKey string `yaml:"private-ssh-key"`
}
func (*Server) UnmarshalYAML ¶
Custom UnmarshalYAML to read the private SSH key file
type Ssh ¶
type Ssh struct{}
func (*Ssh) Authenticate ¶
func (s *Ssh) Authenticate(args AuthenticateArgs) (*ssh.Client, error)
func (*Ssh) CopyFile ¶
func (s *Ssh) CopyFile(args CopyFileArgs) error
func (*Ssh) CopyTo ¶
Copy file from local server to remote server
@example
ssh := NewSsh()
sshClient, err := ssh.Authenticate(AuthenticateArgs{
Host: "10.211.55.12",
Port: 22,
User: "ubuntu",
Password: "1234567890",
})
fmt.Println(err)
ssh.CopyTo(sshClient, "./from/one/place.yaml", "/to/another.yaml")
func (*Ssh) CreateDirectory ¶
func (*Ssh) ExecuteCommand ¶
func (s *Ssh) ExecuteCommand(args ExecuteCommandArgs) (string, string, error)
type StepOutputPlain ¶
type StepOutputPlain string
type UninstallArgs ¶
type UninstallArgs struct {
If string
Ic InventoryConfig
}
type Workflow ¶
type Workflow struct{}
func NewWorkflow ¶
func NewWorkflow() *Workflow
func (*Workflow) Execute ¶
func (w *Workflow) Execute(args ExecuteArgs) error
func (*Workflow) Run ¶
func (w *Workflow) Run(opts ...WorkflowRunOptions) error
func (*Workflow) WorkflowWithCallback ¶
func (w *Workflow) WorkflowWithCallback(callback func(any), sot int) WorkflowRunOptions
func (*Workflow) WorkflowWithConfig ¶
func (w *Workflow) WorkflowWithConfig(config WorkflowConfig) WorkflowRunOptions
func (*Workflow) WorkflowWithContexts ¶
func (w *Workflow) WorkflowWithContexts(contexts map[string]map[string]any) WorkflowRunOptions
func (*Workflow) WorkflowWithDirectory ¶
func (w *Workflow) WorkflowWithDirectory(directory string) WorkflowRunOptions
func (*Workflow) WorkflowWithFile ¶
func (w *Workflow) WorkflowWithFile(file string) WorkflowRunOptions
type WorkflowConfig ¶
type WorkflowConfig struct {
Name string `yaml:"name"`
On struct {
Push struct{} `yaml:"push"`
PullRequest struct{} `yaml:"pull-request"`
} `yaml:"on"`
Jobs []Job `yaml:"jobs"`
// Directory to run the workflow from, defaults to the current directory
Directory string `yaml:"directory"`
// Defaults provides global fallbacks applied to every job step, such as
// the shell and directory, unless the step overrides them.
Defaults Defaults `yaml:"defaults,omitempty"`
}
type WorkflowRunArgs ¶
type WorkflowRunOptions ¶
type WorkflowRunOptions func(*WorkflowRunArgs)