Compare commits
18 Commits
25dc6225b3
...
v0.5.0
Author | SHA1 | Date | |
---|---|---|---|
291a954e9c | |||
e43eecf383 | |||
ea676fe0da | |||
e73bd9ff3b | |||
fd9426181f | |||
c25edc5d78 | |||
aebfbda64e | |||
5fe0629b0f | |||
7d6acd77b5 | |||
9d646297c7 | |||
bf8d261cf3 | |||
686cd0019a | |||
b7b002bd72 | |||
b8a63f39f5 | |||
feacb83274 | |||
2aeb435167 | |||
51f5084dd0 | |||
cf04e4456a |
@ -1,3 +0,0 @@
|
|||||||
kind: Added
|
|
||||||
body: Lists config can now go in a file. See docs for more information.
|
|
||||||
time: 2024-08-28T14:27:30.427754114-05:00
|
|
@ -1,3 +0,0 @@
|
|||||||
kind: Changed
|
|
||||||
body: GetKnownHosts is now a method of Host
|
|
||||||
time: 2024-05-14T19:58:17.516072381-05:00
|
|
9
.changes/v0.5.0.md
Normal file
9
.changes/v0.5.0.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
## v0.5.0 - 2024-11-19
|
||||||
|
### Added
|
||||||
|
* Lists can now go in a file. See docs for more information.
|
||||||
|
* commands.[name].type: script now opens `scriptEnvFile`.
|
||||||
|
* Hooks for Commands.[name]. Error, success, and final. [#12]
|
||||||
|
### Changed
|
||||||
|
* GetKnownHosts is now a method of Host
|
||||||
|
### Fixed
|
||||||
|
* make command logger be used for errors, not just when running the command
|
@ -1,3 +1,4 @@
|
|||||||
|
version: 2
|
||||||
before:
|
before:
|
||||||
hooks:
|
hooks:
|
||||||
# You may remove this if you don't use go modules.
|
# You may remove this if you don't use go modules.
|
||||||
@ -31,9 +32,9 @@ archives:
|
|||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
snapshot:
|
snapshot:
|
||||||
name_template: "{{ incpatch .Version }}-next"
|
version_template: "{{ incpatch .Version }}-next"
|
||||||
changelog:
|
changelog:
|
||||||
skip: false
|
disable: false
|
||||||
|
|
||||||
gitea_urls:
|
gitea_urls:
|
||||||
api: https://git.andrewnw.xyz/api/v1
|
api: https://git.andrewnw.xyz/api/v1
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# This is an example .goreleaser.yml file with some sensible defaults.
|
# This is an example .goreleaser.yml file with some sensible defaults.
|
||||||
# Make sure to check the documentation at https://goreleaser.com
|
# Make sure to check the documentation at https://goreleaser.com
|
||||||
|
version: 2
|
||||||
before:
|
before:
|
||||||
hooks:
|
hooks:
|
||||||
# You may remove this if you don't use go modules.
|
# You may remove this if you don't use go modules.
|
||||||
@ -32,7 +33,7 @@ archives:
|
|||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
snapshot:
|
snapshot:
|
||||||
name_template: "{{ incpatch .Version }}-next"
|
version_template: "{{ incpatch .Version }}-next"
|
||||||
changelog:
|
changelog:
|
||||||
sort: asc
|
sort: asc
|
||||||
filters:
|
filters:
|
||||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -4,6 +4,9 @@
|
|||||||
"knadh",
|
"knadh",
|
||||||
"koanf",
|
"koanf",
|
||||||
"mattn",
|
"mattn",
|
||||||
|
"maunium",
|
||||||
|
"mautrix",
|
||||||
|
"nikoksr",
|
||||||
"Strs"
|
"Strs"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -7,4 +7,4 @@ steps:
|
|||||||
release:
|
release:
|
||||||
image: golangci/golangci-lint:v1.53.3
|
image: golangci/golangci-lint:v1.53.3
|
||||||
commands:
|
commands:
|
||||||
- golangci-lint run -v
|
- golangci-lint run -v --timeout 5m
|
@ -20,7 +20,7 @@ package cmd
|
|||||||
|
|
||||||
// func config(cmd *cobra.Command, args []string) {
|
// func config(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// opts := backy.NewOpts(cfgFile, backy.UseCron())
|
// opts := backy.NewOpts(cfgFile, backy.cronEnabled())
|
||||||
// opts.InitConfig()
|
// opts.InitConfig()
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
@ -17,7 +17,7 @@ var (
|
|||||||
|
|
||||||
func cron(cmd *cobra.Command, args []string) {
|
func cron(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
opts := backy.NewOpts(cfgFile, backy.UseCron())
|
opts := backy.NewOpts(cfgFile, backy.CronEnabled())
|
||||||
opts.InitConfig()
|
opts.InitConfig()
|
||||||
backy.ReadConfig(opts)
|
backy.ReadConfig(opts)
|
||||||
opts.Cron()
|
opts.Cron()
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
const versionStr = "0.4.0"
|
const versionStr = "0.5.0"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
versionCmd = &cobra.Command{
|
versionCmd = &cobra.Command{
|
||||||
|
@ -110,6 +110,7 @@ Usage:
|
|||||||
backy list [--list=list1,list2,... | -l list1, list2,...] [ -cmd cmd1 cmd2 cmd3...] [flags]
|
backy list [--list=list1,list2,... | -l list1, list2,...] [ -cmd cmd1 cmd2 cmd3...] [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
|
-c, --cmds strings Accepts comma-separated names of commands to list.
|
||||||
-h, --help help for list
|
-h, --help help for list
|
||||||
-l, --lists strings Accepts comma-separated names of command lists to list.
|
-l, --lists strings Accepts comma-separated names of command lists to list.
|
||||||
|
|
||||||
|
@ -9,6 +9,11 @@ Command lists are for executing commands in sequence and getting notifications f
|
|||||||
|
|
||||||
The top-level object key can be anything you want but not the same as another.
|
The top-level object key can be anything you want but not the same as another.
|
||||||
|
|
||||||
|
Lists can go in a separate file. Command lists should be in a separate file if:
|
||||||
|
|
||||||
|
1. key 'cmd-lists.file' is found
|
||||||
|
2. hosts.yml or hosts.yaml is found in the same directory as the backy config file
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
test2:
|
test2:
|
||||||
name: test2
|
name: test2
|
||||||
@ -51,7 +56,7 @@ An array of notification IDs to use on success and failure. Must match any of th
|
|||||||
|
|
||||||
### Name
|
### Name
|
||||||
|
|
||||||
Name is optional for logging. If name is not defined, name will be the object's map key.
|
Name is optional. If name is not defined, name will be the object's map key.
|
||||||
|
|
||||||
### Cron mode
|
### Cron mode
|
||||||
|
|
||||||
|
@ -19,7 +19,14 @@ commands:
|
|||||||
- down
|
- down
|
||||||
# if host is not defined, command will be run locally
|
# if host is not defined, command will be run locally
|
||||||
# The host has to be defined in either the config file or the SSH Config files
|
# The host has to be defined in either the config file or the SSH Config files
|
||||||
host: some-host
|
host: some-host
|
||||||
|
hooks
|
||||||
|
error:
|
||||||
|
- some-other-command-when-failing
|
||||||
|
success:
|
||||||
|
- success-command
|
||||||
|
final:
|
||||||
|
- final-command
|
||||||
backup-docker-container-script:
|
backup-docker-container-script:
|
||||||
cmd: /path/to/local/script
|
cmd: /path/to/local/script
|
||||||
# script file is input as stdin to SSH
|
# script file is input as stdin to SSH
|
||||||
@ -41,6 +48,7 @@ Values available for this section:
|
|||||||
| `host` | If not specified, the command will execute locally. | `string` | no |
|
| `host` | If not specified, the command will execute locally. | `string` | no |
|
||||||
| `scriptEnvFile` | When type is `scriptFile`, the script is appended to this file. | `string` | no |
|
| `scriptEnvFile` | When type is `scriptFile`, the script is appended to this file. | `string` | no |
|
||||||
| `shell` | Only applicable when host is not specified | `string` | no |
|
| `shell` | Only applicable when host is not specified | `string` | no |
|
||||||
|
| `hooks` | Hooks are used at the end of the individual command. Must be another command. | `[]string` | no |
|
||||||
|
|
||||||
#### cmd
|
#### cmd
|
||||||
|
|
||||||
@ -93,9 +101,9 @@ Make sure to escape any shell input.
|
|||||||
|
|
||||||
Path to a file.
|
Path to a file.
|
||||||
|
|
||||||
When type is `scriptFile`, the script is appended to this file.
|
When type is specified, the script is appended to this file.
|
||||||
|
|
||||||
This is useful for specifiing environment variables or other things so they don't have to be included in the script.
|
This is useful for specifying environment variables or other things so they don't have to be included in the script.
|
||||||
|
|
||||||
### type
|
### type
|
||||||
|
|
||||||
@ -103,7 +111,7 @@ May be `scriptFile` or `script`. Runs script from local machine on remote host p
|
|||||||
|
|
||||||
If `type` is `script`, `cmd` is used as the script.
|
If `type` is `script`, `cmd` is used as the script.
|
||||||
|
|
||||||
If `type` is `scriptFile`, cmd must be a file path.
|
If `type` is `scriptFile`, cmd must be a script file.
|
||||||
|
|
||||||
### environment
|
### environment
|
||||||
|
|
||||||
@ -116,3 +124,23 @@ For now, the variables have to be defined in an `.env` file in the same director
|
|||||||
If using it with host specified, the SSH server has to be configured to accept those env variables.
|
If using it with host specified, the SSH server has to be configured to accept those env variables.
|
||||||
|
|
||||||
If the command is run locally, the OS's environment is added.
|
If the command is run locally, the OS's environment is added.
|
||||||
|
|
||||||
|
### hooks
|
||||||
|
|
||||||
|
Hooks are run after the command is run.
|
||||||
|
|
||||||
|
Errors are run if the command errors, success if it returns no error. Final hooks are run regardless of error condition.
|
||||||
|
|
||||||
|
Values for hooks are as follows:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
command:
|
||||||
|
hook:
|
||||||
|
# these commands are defined elsewhere in the file
|
||||||
|
error:
|
||||||
|
- errcommand
|
||||||
|
success:
|
||||||
|
- successcommand
|
||||||
|
final:
|
||||||
|
- donecommand
|
||||||
|
```
|
8
go.mod
8
go.mod
@ -15,7 +15,6 @@ require (
|
|||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/rs/zerolog v1.30.0
|
github.com/rs/zerolog v1.30.0
|
||||||
github.com/spf13/cobra v1.7.0
|
github.com/spf13/cobra v1.7.0
|
||||||
go.mongodb.org/mongo-driver v1.12.1
|
|
||||||
golang.org/x/crypto v0.13.0
|
golang.org/x/crypto v0.13.0
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||||
maunium.net/go/mautrix v0.16.0
|
maunium.net/go/mautrix v0.16.0
|
||||||
@ -27,7 +26,6 @@ require (
|
|||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||||
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
|
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
|
||||||
github.com/google/uuid v1.3.1 // indirect
|
github.com/google/uuid v1.3.1 // indirect
|
||||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
@ -40,14 +38,12 @@ require (
|
|||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible // indirect
|
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible // indirect
|
||||||
github.com/klauspost/compress v1.16.7 // indirect
|
|
||||||
github.com/knadh/koanf/maps v0.1.1 // indirect
|
github.com/knadh/koanf/maps v0.1.1 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
github.com/ryanuber/go-glob v1.0.0 // indirect
|
github.com/ryanuber/go-glob v1.0.0 // indirect
|
||||||
@ -58,10 +54,6 @@ require (
|
|||||||
github.com/tidwall/match v1.1.1 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
github.com/tidwall/pretty v1.2.1 // indirect
|
github.com/tidwall/pretty v1.2.1 // indirect
|
||||||
github.com/tidwall/sjson v1.2.5 // indirect
|
github.com/tidwall/sjson v1.2.5 // indirect
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.1.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
|
||||||
go.mau.fi/util v0.0.0-20230906155759-14bad39a8718 // indirect
|
go.mau.fi/util v0.0.0-20230906155759-14bad39a8718 // indirect
|
||||||
go.uber.org/atomic v1.11.0 // indirect
|
go.uber.org/atomic v1.11.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||||
|
48
go.sum
48
go.sum
@ -19,11 +19,7 @@ github.com/go-jose/go-jose/v3 v3.0.0 h1:s6rrhirfEP/CGIoc6p+PZAeogN2SxKav6Wp7+dyM
|
|||||||
github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
|
github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
|
||||||
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
|
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
|
||||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
|
||||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
@ -61,9 +57,6 @@ github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
|||||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
|
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
|
||||||
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
||||||
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
|
||||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
|
||||||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
|
||||||
github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs=
|
github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs=
|
||||||
github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
|
github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
|
||||||
github.com/knadh/koanf/parsers/yaml v0.1.0 h1:ZZ8/iGfRLvKSaMEECEBPM1HQslrZADk8fP1XFUxVI5w=
|
github.com/knadh/koanf/parsers/yaml v0.1.0 h1:ZZ8/iGfRLvKSaMEECEBPM1HQslrZADk8fP1XFUxVI5w=
|
||||||
@ -100,9 +93,6 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
|
|||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||||
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
|
||||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
|
||||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
|
||||||
github.com/nikoksr/notify v0.41.0 h1:4LGE41GpWdHX5M3Xo6DlWRwS2WLDbOq1Rk7IzY4vjmQ=
|
github.com/nikoksr/notify v0.41.0 h1:4LGE41GpWdHX5M3Xo6DlWRwS2WLDbOq1Rk7IzY4vjmQ=
|
||||||
github.com/nikoksr/notify v0.41.0/go.mod h1:FoE0UVPeopz1Vy5nm9vQZ+JVmYjEIjQgbFstbkw+cRE=
|
github.com/nikoksr/notify v0.41.0/go.mod h1:FoE0UVPeopz1Vy5nm9vQZ+JVmYjEIjQgbFstbkw+cRE=
|
||||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
@ -151,76 +141,38 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
|||||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
|
||||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
|
||||||
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
|
||||||
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
|
|
||||||
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
|
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
|
||||||
go.mau.fi/util v0.0.0-20230906155759-14bad39a8718 h1:hmm5bZqE0M8+Uvys0HJPCSbAIZIwYtTkBKYPjAWHuMM=
|
go.mau.fi/util v0.0.0-20230906155759-14bad39a8718 h1:hmm5bZqE0M8+Uvys0HJPCSbAIZIwYtTkBKYPjAWHuMM=
|
||||||
go.mau.fi/util v0.0.0-20230906155759-14bad39a8718/go.mod h1:AxuJUMCxpzgJ5eV9JbPWKRH8aAJJidxetNdUj7qcb84=
|
go.mau.fi/util v0.0.0-20230906155759-14bad39a8718/go.mod h1:AxuJUMCxpzgJ5eV9JbPWKRH8aAJJidxetNdUj7qcb84=
|
||||||
go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE=
|
|
||||||
go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ=
|
|
||||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
|
||||||
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
||||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
|
||||||
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
||||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
|
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
@ -30,6 +30,8 @@ var Sprintf = fmt.Sprintf
|
|||||||
// The environment of local commands will be the machine's environment plus any extra
|
// The environment of local commands will be the machine's environment plus any extra
|
||||||
// variables specified in the Env file or Environment.
|
// variables specified in the Env file or Environment.
|
||||||
// Dir can also be specified for local commands.
|
// Dir can also be specified for local commands.
|
||||||
|
//
|
||||||
|
// Returns the output as a slice and an error, if any
|
||||||
func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([]string, error) {
|
func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([]string, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -53,9 +55,9 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
command.Type = strings.TrimSpace(command.Type)
|
command.Type = strings.TrimSpace(command.Type)
|
||||||
|
|
||||||
if command.Type != "" {
|
if command.Type != "" {
|
||||||
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running script %s on host %s", command.Cmd, *command.Host)).Send()
|
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running script %s on host %s", command.Name, *command.Host)).Send()
|
||||||
} else {
|
} else {
|
||||||
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s %s on host %s", command.Cmd, ArgsStr, *command.Host)).Send()
|
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s on host %s", command.Name, *command.Host)).Send()
|
||||||
}
|
}
|
||||||
|
|
||||||
if command.RemoteHost.SshClient == nil {
|
if command.RemoteHost.SshClient == nil {
|
||||||
@ -100,15 +102,61 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
// Is command type defined. That is, is it local or not
|
// Is command type defined. That is, is it local or not
|
||||||
if command.Type != "" {
|
if command.Type != "" {
|
||||||
|
|
||||||
|
var (
|
||||||
|
script *bytes.Buffer
|
||||||
|
buffer bytes.Buffer
|
||||||
|
scriptEnvFileBuffer bytes.Buffer
|
||||||
|
scriptFileBuffer bytes.Buffer
|
||||||
|
dirErr error
|
||||||
|
scriptEnvFilePresent bool
|
||||||
|
)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
// did the program panic while writing to the buffer?
|
// did the program panic while writing to the buffer?
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
cmdCtxLogger.Info().Msg(fmt.Sprintf("panic occurred writing to buffer: %x", err))
|
// cmdCtxLogger.Debug().Msg(fmt.Sprintf("script buffer: %v", script))
|
||||||
|
cmdCtxLogger.Info().Msg(fmt.Sprintf("panic occurred writing to buffer: %v", err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if command.Type == "script" {
|
if command.Type == "script" {
|
||||||
script := bytes.NewBufferString(cmd + "\n")
|
|
||||||
|
if command.ScriptEnvFile != "" {
|
||||||
|
|
||||||
|
command.ScriptEnvFile, dirErr = resolveDir(command.ScriptEnvFile)
|
||||||
|
if dirErr != nil {
|
||||||
|
return nil, dirErr
|
||||||
|
}
|
||||||
|
file, err := os.Open(command.ScriptEnvFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
_, err = io.Copy(&scriptEnvFileBuffer, file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bug: writing to buffer triggers panic
|
||||||
|
// why?
|
||||||
|
// use bytes.Buffer instead of pointer to memory (*bytes.Buffer)
|
||||||
|
|
||||||
|
_, err = buffer.WriteString(scriptEnvFileBuffer.String())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// write newline
|
||||||
|
buffer.WriteByte(0x0A)
|
||||||
|
|
||||||
|
_, err = buffer.WriteString(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
script = &buffer
|
||||||
|
|
||||||
|
} else {
|
||||||
|
script = bytes.NewBufferString(cmd + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
commandSession.Stdin = script
|
commandSession.Stdin = script
|
||||||
if err := commandSession.Shell(); err != nil {
|
if err := commandSession.Shell(); err != nil {
|
||||||
@ -119,7 +167,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
outScanner := bufio.NewScanner(&cmdOutBuf)
|
outScanner := bufio.NewScanner(&cmdOutBuf)
|
||||||
for outScanner.Scan() {
|
for outScanner.Scan() {
|
||||||
outMap := make(map[string]interface{})
|
outMap := make(map[string]interface{})
|
||||||
outMap["cmd"] = cmd
|
outMap["cmd"] = command.Name
|
||||||
outMap["output"] = outScanner.Text()
|
outMap["output"] = outScanner.Text()
|
||||||
if str, ok := outMap["output"].(string); ok {
|
if str, ok := outMap["output"].(string); ok {
|
||||||
outputArr = append(outputArr, str)
|
outputArr = append(outputArr, str)
|
||||||
@ -132,7 +180,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
outScanner := bufio.NewScanner(&cmdOutBuf)
|
outScanner := bufio.NewScanner(&cmdOutBuf)
|
||||||
for outScanner.Scan() {
|
for outScanner.Scan() {
|
||||||
outMap := make(map[string]interface{})
|
outMap := make(map[string]interface{})
|
||||||
outMap["cmd"] = cmd
|
outMap["cmd"] = command.Name
|
||||||
outMap["output"] = outScanner.Text()
|
outMap["output"] = outScanner.Text()
|
||||||
if str, ok := outMap["output"].(string); ok {
|
if str, ok := outMap["output"].(string); ok {
|
||||||
outputArr = append(outputArr, str)
|
outputArr = append(outputArr, str)
|
||||||
@ -144,15 +192,8 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
|
|
||||||
if command.Type == "scriptFile" {
|
if command.Type == "scriptFile" {
|
||||||
|
|
||||||
var (
|
|
||||||
buffer bytes.Buffer
|
|
||||||
scriptEnvFileBuffer bytes.Buffer
|
|
||||||
scriptFileBuffer bytes.Buffer
|
|
||||||
dirErr error
|
|
||||||
scriptEnvFilePresent bool
|
|
||||||
)
|
|
||||||
|
|
||||||
if command.ScriptEnvFile != "" {
|
if command.ScriptEnvFile != "" {
|
||||||
|
|
||||||
command.ScriptEnvFile, dirErr = resolveDir(command.ScriptEnvFile)
|
command.ScriptEnvFile, dirErr = resolveDir(command.ScriptEnvFile)
|
||||||
if dirErr != nil {
|
if dirErr != nil {
|
||||||
return nil, dirErr
|
return nil, dirErr
|
||||||
@ -249,7 +290,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
outScanner := bufio.NewScanner(&cmdOutBuf)
|
outScanner := bufio.NewScanner(&cmdOutBuf)
|
||||||
for outScanner.Scan() {
|
for outScanner.Scan() {
|
||||||
outMap := make(map[string]interface{})
|
outMap := make(map[string]interface{})
|
||||||
outMap["cmd"] = cmd
|
outMap["cmd"] = command.Name
|
||||||
outMap["output"] = outScanner.Text()
|
outMap["output"] = outScanner.Text()
|
||||||
if str, ok := outMap["output"].(string); ok {
|
if str, ok := outMap["output"].(string); ok {
|
||||||
outputArr = append(outputArr, str)
|
outputArr = append(outputArr, str)
|
||||||
@ -258,14 +299,14 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmdCtxLogger.Error().Err(fmt.Errorf("error when running cmd: %s: %w", command.Cmd, err)).Send()
|
cmdCtxLogger.Error().Err(fmt.Errorf("error when running cmd: %s: %w", command.Name, err)).Send()
|
||||||
return outputArr, err
|
return outputArr, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if command.Shell != "" {
|
if command.Shell != "" {
|
||||||
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s %s on local machine in %s", command.Cmd, ArgsStr, command.Shell)).Send()
|
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s on local machine in %s", command.Name, command.Shell)).Send()
|
||||||
|
|
||||||
ArgsStr = fmt.Sprintf("%s %s", command.Cmd, ArgsStr)
|
ArgsStr = fmt.Sprintf("%s %s", command.Cmd, ArgsStr)
|
||||||
|
|
||||||
@ -291,7 +332,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
|
|
||||||
for outScanner.Scan() {
|
for outScanner.Scan() {
|
||||||
outMap := make(map[string]interface{})
|
outMap := make(map[string]interface{})
|
||||||
outMap["cmd"] = command.Cmd
|
outMap["cmd"] = command.Name
|
||||||
outMap["output"] = outScanner.Text()
|
outMap["output"] = outScanner.Text()
|
||||||
if str, ok := outMap["output"].(string); ok {
|
if str, ok := outMap["output"].(string); ok {
|
||||||
outputArr = append(outputArr, str)
|
outputArr = append(outputArr, str)
|
||||||
@ -300,13 +341,13 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmdCtxLogger.Error().Err(fmt.Errorf("error when running cmd %s: %w", command.Cmd, err)).Send()
|
cmdCtxLogger.Error().Err(fmt.Errorf("error when running cmd %s: %w", command.Name, err)).Send()
|
||||||
return outputArr, err
|
return outputArr, err
|
||||||
}
|
}
|
||||||
return outputArr, nil
|
return outputArr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s %s on local machine", command.Cmd, ArgsStr)).Send()
|
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s on local machine", command.Name)).Send()
|
||||||
|
|
||||||
localCMD := exec.Command(command.Cmd, command.Args...)
|
localCMD := exec.Command(command.Cmd, command.Args...)
|
||||||
|
|
||||||
@ -340,7 +381,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
cmdCtxLogger.Info().Fields(outMap).Send()
|
cmdCtxLogger.Info().Fields(outMap).Send()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmdCtxLogger.Error().Err(fmt.Errorf("error when running cmd %s: %w", command.Cmd, err)).Send()
|
cmdCtxLogger.Error().Err(fmt.Errorf("error when running cmd %s: %w", command.Name, err)).Send()
|
||||||
return outputArr, err
|
return outputArr, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,42 +390,35 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
|
|
||||||
// cmdListWorker
|
// cmdListWorker
|
||||||
func cmdListWorker(msgTemps *msgTemplates, jobs <-chan *CmdList, results chan<- string, opts *ConfigOpts) {
|
func cmdListWorker(msgTemps *msgTemplates, jobs <-chan *CmdList, results chan<- string, opts *ConfigOpts) {
|
||||||
|
|
||||||
// iterate over list to run
|
// iterate over list to run
|
||||||
|
res := CmdListResults{}
|
||||||
for list := range jobs {
|
for list := range jobs {
|
||||||
fieldsMap := make(map[string]interface{})
|
fieldsMap := make(map[string]interface{})
|
||||||
fieldsMap["list"] = list.Name
|
fieldsMap["list"] = list.Name
|
||||||
|
var cmdLogger zerolog.Logger
|
||||||
cmdLog := opts.Logger.Info()
|
|
||||||
|
|
||||||
var count int // count of how many commands have been executed
|
var count int // count of how many commands have been executed
|
||||||
var cmdsRan []string // store the commands that have been executed
|
var cmdsRan []string // store the commands that have been executed
|
||||||
var outStructArr []outStruct // stores output messages
|
var outStructArr []outStruct // stores output messages
|
||||||
|
|
||||||
for _, cmd := range list.Order {
|
for _, cmd := range list.Order {
|
||||||
currentCmd := opts.Cmds[cmd].Cmd
|
|
||||||
|
|
||||||
fieldsMap["cmd"] = opts.Cmds[cmd].Cmd
|
currentCmd := opts.Cmds[cmd].Name
|
||||||
|
|
||||||
|
fieldsMap["cmd"] = opts.Cmds[cmd].Name
|
||||||
cmdToRun := opts.Cmds[cmd]
|
cmdToRun := opts.Cmds[cmd]
|
||||||
cmdLog.Fields(fieldsMap).Send()
|
|
||||||
|
|
||||||
cmdLogger := opts.Logger.With().
|
cmdLogger = cmdToRun.generateLogger(opts)
|
||||||
Str("backy-cmd", cmd).Str("Host", "local machine").
|
cmdLogger.Info().Fields(fieldsMap).Send()
|
||||||
Logger()
|
|
||||||
|
|
||||||
if cmdToRun.Host != nil {
|
|
||||||
cmdLogger = opts.Logger.With().
|
|
||||||
Str("backy-cmd", cmd).Str("Host", *cmdToRun.Host).
|
|
||||||
Logger()
|
|
||||||
}
|
|
||||||
|
|
||||||
outputArr, runOutErr := cmdToRun.RunCmd(cmdLogger, opts)
|
outputArr, runOutErr := cmdToRun.RunCmd(cmdLogger, opts)
|
||||||
|
|
||||||
if list.NotifyConfig != nil {
|
if list.NotifyConfig != nil {
|
||||||
|
|
||||||
// check if the command output should be included
|
// check if the command output should be included
|
||||||
if cmdToRun.GetOutput || list.GetOutput {
|
if cmdToRun.GetOutput || list.GetOutput {
|
||||||
outputStruct := outStruct{
|
outputStruct := outStruct{
|
||||||
CmdName: cmd,
|
CmdName: cmdToRun.Name,
|
||||||
CmdExecuted: currentCmd,
|
CmdExecuted: currentCmd,
|
||||||
Output: outputArr,
|
Output: outputArr,
|
||||||
}
|
}
|
||||||
@ -395,6 +429,7 @@ func cmdListWorker(msgTemps *msgTemplates, jobs <-chan *CmdList, results chan<-
|
|||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
if runOutErr != nil {
|
if runOutErr != nil {
|
||||||
|
res.ErrCmd = cmd
|
||||||
if list.NotifyConfig != nil {
|
if list.NotifyConfig != nil {
|
||||||
var errMsg bytes.Buffer
|
var errMsg bytes.Buffer
|
||||||
errStruct := make(map[string]interface{})
|
errStruct := make(map[string]interface{})
|
||||||
@ -412,23 +447,24 @@ func cmdListWorker(msgTemps *msgTemplates, jobs <-chan *CmdList, results chan<-
|
|||||||
tmpErr := msgTemps.err.Execute(&errMsg, errStruct)
|
tmpErr := msgTemps.err.Execute(&errMsg, errStruct)
|
||||||
|
|
||||||
if tmpErr != nil {
|
if tmpErr != nil {
|
||||||
opts.Logger.Err(tmpErr).Send()
|
cmdLogger.Err(tmpErr).Send()
|
||||||
}
|
}
|
||||||
|
|
||||||
notifySendErr := list.NotifyConfig.Send(context.Background(), fmt.Sprintf("List %s failed", list.Name), errMsg.String())
|
notifySendErr := list.NotifyConfig.Send(context.Background(), fmt.Sprintf("List %s failed", list.Name), errMsg.String())
|
||||||
|
|
||||||
if notifySendErr != nil {
|
if notifySendErr != nil {
|
||||||
opts.Logger.Err(notifySendErr).Send()
|
cmdLogger.Err(notifySendErr).Send()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Logger.Err(runOutErr).Send()
|
cmdLogger.Err(runOutErr).Send()
|
||||||
|
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
cmdsRan = append(cmdsRan, cmd)
|
||||||
|
|
||||||
if count == len(list.Order) {
|
if count == len(list.Order) {
|
||||||
cmdsRan = append(cmdsRan, cmd)
|
|
||||||
var successMsg bytes.Buffer
|
var successMsg bytes.Buffer
|
||||||
|
|
||||||
// if notification config is not nil, and NotifyOnSuccess is true or GetOuput is true,
|
// if notification config is not nil, and NotifyOnSuccess is true or GetOuput is true,
|
||||||
@ -444,23 +480,21 @@ func cmdListWorker(msgTemps *msgTemplates, jobs <-chan *CmdList, results chan<-
|
|||||||
tmpErr := msgTemps.success.Execute(&successMsg, successStruct)
|
tmpErr := msgTemps.success.Execute(&successMsg, successStruct)
|
||||||
|
|
||||||
if tmpErr != nil {
|
if tmpErr != nil {
|
||||||
opts.Logger.Err(tmpErr).Send()
|
cmdLogger.Err(tmpErr).Send()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
err := list.NotifyConfig.Send(context.Background(), fmt.Sprintf("List %s succeded", list.Name), successMsg.String())
|
err := list.NotifyConfig.Send(context.Background(), fmt.Sprintf("List %s succeeded", list.Name), successMsg.String())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
opts.Logger.Err(err).Send()
|
cmdLogger.Err(err).Send()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cmdsRan = append(cmdsRan, cmd)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
results <- "done"
|
results <- res.ErrCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -496,7 +530,23 @@ func (opts *ConfigOpts) RunListConfig(cron string) {
|
|||||||
close(listChan)
|
close(listChan)
|
||||||
|
|
||||||
for a := 1; a <= configListsLen; a++ {
|
for a := 1; a <= configListsLen; a++ {
|
||||||
<-results
|
l := <-results
|
||||||
|
|
||||||
|
opts.Logger.Debug().Msg(l)
|
||||||
|
|
||||||
|
if l != "" {
|
||||||
|
// execute error hooks
|
||||||
|
opts.Logger.Debug().Msg("hooks are working")
|
||||||
|
opts.Cmds[l].ExecuteHooks("error", opts)
|
||||||
|
} else {
|
||||||
|
// execute success hooks
|
||||||
|
opts.Cmds[l].ExecuteHooks("success", opts)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute final hooks
|
||||||
|
opts.Cmds[l].ExecuteHooks("final", opts)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.closeHostConnections()
|
opts.closeHostConnections()
|
||||||
@ -505,13 +555,18 @@ func (opts *ConfigOpts) RunListConfig(cron string) {
|
|||||||
func (config *ConfigOpts) ExecuteCmds(opts *ConfigOpts) {
|
func (config *ConfigOpts) ExecuteCmds(opts *ConfigOpts) {
|
||||||
for _, cmd := range opts.executeCmds {
|
for _, cmd := range opts.executeCmds {
|
||||||
cmdToRun := opts.Cmds[cmd]
|
cmdToRun := opts.Cmds[cmd]
|
||||||
cmdLogger := opts.Logger.With().
|
cmdLogger := cmdToRun.generateLogger(opts)
|
||||||
Str("backy-cmd", cmd).
|
|
||||||
Logger()
|
|
||||||
_, runErr := cmdToRun.RunCmd(cmdLogger, opts)
|
_, runErr := cmdToRun.RunCmd(cmdLogger, opts)
|
||||||
if runErr != nil {
|
if runErr != nil {
|
||||||
opts.Logger.Err(runErr).Send()
|
opts.Logger.Err(runErr).Send()
|
||||||
|
|
||||||
|
cmdToRun.ExecuteHooks("error", opts)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
cmdToRun.ExecuteHooks("success", opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmdToRun.ExecuteHooks("final", opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.closeHostConnections()
|
opts.closeHostConnections()
|
||||||
@ -554,3 +609,50 @@ func (c *ConfigOpts) closeHostConnections() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cmd *Command) ExecuteHooks(hookType string, opts *ConfigOpts) {
|
||||||
|
if cmd.Hooks == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch hookType {
|
||||||
|
case "error":
|
||||||
|
for _, v := range cmd.Hooks.Error {
|
||||||
|
errCmd := opts.Cmds[v]
|
||||||
|
cmdLogger := opts.Logger.With().
|
||||||
|
Str("backy-cmd", v).
|
||||||
|
Logger()
|
||||||
|
errCmd.RunCmd(cmdLogger, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
case "success":
|
||||||
|
for _, v := range cmd.Hooks.Success {
|
||||||
|
successCmd := opts.Cmds[v]
|
||||||
|
cmdLogger := opts.Logger.With().
|
||||||
|
Str("backy-cmd", v).
|
||||||
|
Logger()
|
||||||
|
successCmd.RunCmd(cmdLogger, opts)
|
||||||
|
}
|
||||||
|
case "final":
|
||||||
|
for _, v := range cmd.Hooks.Final {
|
||||||
|
finalCmd := opts.Cmds[v]
|
||||||
|
cmdLogger := opts.Logger.With().
|
||||||
|
Str("backy-cmd", v).
|
||||||
|
Logger()
|
||||||
|
finalCmd.RunCmd(cmdLogger, opts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *Command) generateLogger(opts *ConfigOpts) zerolog.Logger {
|
||||||
|
cmdLogger := opts.Logger.With().
|
||||||
|
Str("backy-cmd", cmd.Name).Str("Host", "local machine").
|
||||||
|
Logger()
|
||||||
|
|
||||||
|
if cmd.Host != nil {
|
||||||
|
cmdLogger = opts.Logger.With().
|
||||||
|
Str("backy-cmd", cmd.Name).Str("Host", *cmd.Host).
|
||||||
|
Logger()
|
||||||
|
|
||||||
|
}
|
||||||
|
return cmdLogger
|
||||||
|
}
|
||||||
|
@ -22,6 +22,11 @@ var homeDirErr error
|
|||||||
var backyHomeConfDir string
|
var backyHomeConfDir string
|
||||||
var configFiles []string
|
var configFiles []string
|
||||||
|
|
||||||
|
const macroStart string = "%{"
|
||||||
|
const macroEnd string = "}%"
|
||||||
|
const envMacroStart string = "%{env:"
|
||||||
|
const vaultMacroStart string = "%{env:"
|
||||||
|
|
||||||
func (opts *ConfigOpts) InitConfig() {
|
func (opts *ConfigOpts) InitConfig() {
|
||||||
|
|
||||||
homeDir, homeDirErr = os.UserHomeDir()
|
homeDir, homeDirErr = os.UserHomeDir()
|
||||||
@ -240,6 +245,7 @@ func ReadConfig(opts *ConfigOpts) *ConfigOpts {
|
|||||||
|
|
||||||
cmdListFilePath := path.Clean(opts.CmdListFile)
|
cmdListFilePath := path.Clean(opts.CmdListFile)
|
||||||
|
|
||||||
|
// if path is not absolute, check config directory
|
||||||
if !strings.HasPrefix(cmdListFilePath, "/") {
|
if !strings.HasPrefix(cmdListFilePath, "/") {
|
||||||
opts.CmdListFile = path.Join(backyConfigFileDir, cmdListFilePath)
|
opts.CmdListFile = path.Join(backyConfigFileDir, cmdListFilePath)
|
||||||
}
|
}
|
||||||
@ -254,7 +260,7 @@ func ReadConfig(opts *ConfigOpts) *ConfigOpts {
|
|||||||
logging.ExitWithMSG(fmt.Sprintf("error loading config: %v", err), 1, &opts.Logger)
|
logging.ExitWithMSG(fmt.Sprintf("error loading config: %v", err), 1, &opts.Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("lists config file", opts.CmdListFile).Send()
|
log.Info().Str("using lists config file", opts.CmdListFile).Send()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +270,7 @@ func ReadConfig(opts *ConfigOpts) *ConfigOpts {
|
|||||||
|
|
||||||
var cmdNotFoundSliceErr []error
|
var cmdNotFoundSliceErr []error
|
||||||
for cmdListName, cmdList := range opts.CmdConfigLists {
|
for cmdListName, cmdList := range opts.CmdConfigLists {
|
||||||
if opts.useCron {
|
if opts.cronEnabled {
|
||||||
cron := strings.TrimSpace(cmdList.Cron)
|
cron := strings.TrimSpace(cmdList.Cron)
|
||||||
if cron == "" {
|
if cron == "" {
|
||||||
delete(opts.CmdConfigLists, cmdListName)
|
delete(opts.CmdConfigLists, cmdListName)
|
||||||
@ -286,14 +292,13 @@ func ReadConfig(opts *ConfigOpts) *ConfigOpts {
|
|||||||
cmdNotFoundErrorLog.Errs("commands not found", cmdNotFoundSliceErr).Send()
|
cmdNotFoundErrorLog.Errs("commands not found", cmdNotFoundSliceErr).Send()
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.useCron && (len(opts.CmdConfigLists) == 0) {
|
if opts.cronEnabled && (len(opts.CmdConfigLists) == 0) {
|
||||||
logging.ExitWithMSG("No cron fields detected in any command lists", 1, nil)
|
logging.ExitWithMSG("No cron fields detected in any command lists", 1, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
for c := range opts.Cmds {
|
// process commands
|
||||||
if opts.executeCmds != nil && !contains(opts.executeCmds, c) {
|
if err := processCmds(opts); err != nil {
|
||||||
delete(opts.Cmds, c)
|
logging.ExitWithMSG(err.Error(), 1, &opts.Logger)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.executeLists) > 0 {
|
if len(opts.executeLists) > 0 {
|
||||||
@ -312,23 +317,8 @@ func ReadConfig(opts *ConfigOpts) *ConfigOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cmd := range opts.Cmds {
|
|
||||||
if cmd.Host != nil {
|
|
||||||
host, hostFound := opts.Hosts[*cmd.Host]
|
|
||||||
if hostFound {
|
|
||||||
cmd.RemoteHost = host
|
|
||||||
cmd.RemoteHost.Host = host.Host
|
|
||||||
if host.HostName != "" {
|
|
||||||
cmd.RemoteHost.HostName = host.HostName
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
opts.Hosts[*cmd.Host] = &Host{Host: *cmd.Host}
|
|
||||||
cmd.RemoteHost = &Host{Host: *cmd.Host}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
opts.SetupNotify()
|
opts.SetupNotify()
|
||||||
|
|
||||||
if err := opts.setupVault(); err != nil {
|
if err := opts.setupVault(); err != nil {
|
||||||
log.Err(err).Send()
|
log.Err(err).Send()
|
||||||
}
|
}
|
||||||
@ -455,3 +445,88 @@ func GetVaultKey(str string, opts *ConfigOpts, log zerolog.Logger) string {
|
|||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func processCmds(opts *ConfigOpts) error {
|
||||||
|
// process commands
|
||||||
|
for cmdName, cmd := range opts.Cmds {
|
||||||
|
|
||||||
|
if cmd.Name == "" {
|
||||||
|
cmd.Name = cmdName
|
||||||
|
}
|
||||||
|
// println("Cmd.Name = " + cmd.Name)
|
||||||
|
hooks := cmd.Hooks
|
||||||
|
// resolve hooks
|
||||||
|
if hooks != nil {
|
||||||
|
|
||||||
|
processHookSuccess := processHooks(cmd, hooks.Error, opts, "error")
|
||||||
|
if processHookSuccess != nil {
|
||||||
|
return processHookSuccess
|
||||||
|
}
|
||||||
|
processHookSuccess = processHooks(cmd, hooks.Success, opts, "success")
|
||||||
|
if processHookSuccess != nil {
|
||||||
|
return processHookSuccess
|
||||||
|
}
|
||||||
|
processHookSuccess = processHooks(cmd, hooks.Final, opts, "final")
|
||||||
|
if processHookSuccess != nil {
|
||||||
|
return processHookSuccess
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolve hosts
|
||||||
|
if cmd.Host != nil {
|
||||||
|
host, hostFound := opts.Hosts[*cmd.Host]
|
||||||
|
if hostFound {
|
||||||
|
cmd.RemoteHost = host
|
||||||
|
cmd.RemoteHost.Host = host.Host
|
||||||
|
if host.HostName != "" {
|
||||||
|
cmd.RemoteHost.HostName = host.HostName
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
opts.Hosts[*cmd.Host] = &Host{Host: *cmd.Host}
|
||||||
|
cmd.RemoteHost = &Host{Host: *cmd.Host}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// processHooks evaluates if hooks are valid Commands
|
||||||
|
//
|
||||||
|
// Takes the following arguments:
|
||||||
|
//
|
||||||
|
// 1. a []string of hooks
|
||||||
|
// 2. a map of Commands as arguments
|
||||||
|
// 3. a string hookType, must be the hook type
|
||||||
|
//
|
||||||
|
// The cmds.hookRef is modified in this function.
|
||||||
|
//
|
||||||
|
// Returns the following:
|
||||||
|
//
|
||||||
|
// An error, if any, if the command is not found
|
||||||
|
func processHooks(cmd *Command, hooks []string, opts *ConfigOpts, hookType string) error {
|
||||||
|
|
||||||
|
// initialize hook type
|
||||||
|
var hookCmdFound bool
|
||||||
|
cmd.hookRefs = map[string]map[string]*Command{}
|
||||||
|
cmd.hookRefs[hookType] = map[string]*Command{}
|
||||||
|
|
||||||
|
for _, hook := range hooks {
|
||||||
|
|
||||||
|
var hookCmd *Command
|
||||||
|
// TODO: match by Command.Name
|
||||||
|
|
||||||
|
hookCmd, hookCmdFound = opts.Cmds[hook]
|
||||||
|
|
||||||
|
if !hookCmdFound {
|
||||||
|
return fmt.Errorf("error in command %s hook %s list: command %s not found", cmd.Name, hookType, hook)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.hookRefs[hookType][hook] = hookCmd
|
||||||
|
|
||||||
|
// Recursive, decide if this is good
|
||||||
|
// if hookCmd.hookRefs == nil {
|
||||||
|
// }
|
||||||
|
// hookRef[hookType][h] = hookCmd
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ The following commands ran:
|
|||||||
{{end}}
|
{{end}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if .CmdOutput }}{{- range .CmdOutput }}Commad output for {{ .CmdName }}:
|
{{ if .CmdOutput }}{{- range .CmdOutput }}Command output for {{ .CmdName }}:
|
||||||
{{- range .Output}}
|
{{- range .Output}}
|
||||||
{{ . }}
|
{{ . }}
|
||||||
{{ end }}{{ end }}
|
{{ end }}{{ end }}
|
||||||
|
@ -5,7 +5,7 @@ The following commands ran:
|
|||||||
- {{. -}}
|
- {{. -}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if .CmdOutput }}{{- range .CmdOutput }}Commad output for {{ .CmdName }}:
|
{{ if .CmdOutput }}{{- range .CmdOutput }}Command output for {{ .CmdName }}:
|
||||||
{{- range .Output}}
|
{{- range .Output}}
|
||||||
{{ . }}
|
{{ . }}
|
||||||
{{ end }}{{ end }}
|
{{ end }}{{ end }}
|
||||||
|
@ -43,17 +43,24 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Command struct {
|
Command struct {
|
||||||
|
Name string `yaml:"name,omitempty"`
|
||||||
|
|
||||||
// command to run
|
// command to run
|
||||||
Cmd string `yaml:"cmd"`
|
Cmd string `yaml:"cmd"`
|
||||||
|
|
||||||
// Possible values: script, scriptFile
|
// Possible values: script, scriptFile
|
||||||
// If blank, it is regualar command.
|
// If blank, it is regular command.
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type,omitempty"`
|
||||||
|
|
||||||
// host on which to run cmd
|
// host on which to run cmd
|
||||||
Host *string `yaml:"host,omitempty"`
|
Host *string `yaml:"host,omitempty"`
|
||||||
|
|
||||||
|
// Hooks are for running commands on certain events
|
||||||
|
Hooks *Hooks `yaml:"hooks,omitempty"`
|
||||||
|
|
||||||
|
// hook refs are internal references of commands for each hook type
|
||||||
|
hookRefs map[string]map[string]*Command
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Shell specifies which shell to run the command in, if any.
|
Shell specifies which shell to run the command in, if any.
|
||||||
Not applicable when host is defined.
|
Not applicable when host is defined.
|
||||||
@ -123,7 +130,7 @@ type (
|
|||||||
CmdListFile string
|
CmdListFile string
|
||||||
|
|
||||||
// use command lists using cron
|
// use command lists using cron
|
||||||
useCron bool
|
cronEnabled bool
|
||||||
// Holds commands to execute for the exec command
|
// Holds commands to execute for the exec command
|
||||||
executeCmds []string
|
executeCmds []string
|
||||||
// Holds lists to execute for the backup command
|
// Holds lists to execute for the backup command
|
||||||
@ -188,4 +195,17 @@ type (
|
|||||||
Commands []string
|
Commands []string
|
||||||
Hosts []string
|
Hosts []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Hooks struct {
|
||||||
|
Error []string `yaml:"error,omitempty"`
|
||||||
|
Success []string `yaml:"success,omitempty"`
|
||||||
|
Final []string `yaml:"final,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
CmdListResults struct {
|
||||||
|
// name of the list
|
||||||
|
ListName string
|
||||||
|
// command that caused the list to fail
|
||||||
|
ErrCmd string
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
@ -56,10 +56,10 @@ func SetCmdsToSearch(cmds []string) BackyOptionFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseCron enables the execution of command lists at specified times
|
// cronEnabled enables the execution of command lists at specified times
|
||||||
func UseCron() BackyOptionFunc {
|
func CronEnabled() BackyOptionFunc {
|
||||||
return func(bco *ConfigOpts) {
|
return func(bco *ConfigOpts) {
|
||||||
bco.useCron = true
|
bco.cronEnabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,10 +221,15 @@ func expandEnvVars(backyEnv map[string]string, envVars []string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse env variables using new macros
|
||||||
for indx, v := range envVars {
|
for indx, v := range envVars {
|
||||||
if strings.Contains(v, "$") || (strings.Contains(v, "${") && strings.Contains(v, "}")) {
|
if strings.HasPrefix(v, macroStart) && strings.HasSuffix(v, macroEnd) {
|
||||||
out, _ := shell.Expand(v, env)
|
if strings.HasPrefix(v, envMacroStart) {
|
||||||
envVars[indx] = out
|
v = strings.TrimPrefix(v, envMacroStart)
|
||||||
|
v = strings.TrimRight(v, macroEnd)
|
||||||
|
out, _ := shell.Expand(v, env)
|
||||||
|
envVars[indx] = out
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user