-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated config handling for list Signed-off-by: Eddie Knight <[email protected]> * Added RaidPkg handler, commented out the Run() logic for this commit Signed-off-by: Eddie Knight <[email protected]> * fixed the busted list command Signed-off-by: Eddie Knight <[email protected]> fixed the busted list command for real this time Signed-off-by: Eddie Knight <[email protected]> * lets go update the raid handlers to use the new config structure, see what happens Signed-off-by: Eddie Knight <[email protected]> * Finalize new config handler logic Signed-off-by: Eddie Knight <[email protected]> * added loglevel flag to plugin args Signed-off-by: Eddie Knight <[email protected]> * cleanup Signed-off-by: Eddie Knight <[email protected]> Update cmd/list.go cleanup Signed-off-by: Eddie Knight <[email protected]> cleanup Signed-off-by: Eddie Knight <[email protected]> fixed bad import Signed-off-by: Eddie Knight <[email protected]> finished debugging SDK Signed-off-by: Eddie Knight <[email protected]> * Updated to import from SDK v0.0.15 Signed-off-by: Eddie Knight <[email protected]> --------- Signed-off-by: Eddie Knight <[email protected]>
- Loading branch information
1 parent
d0c14b2
commit 4833e6a
Showing
12 changed files
with
228 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- [ ] Logger seems to be putting everything from plugins out as DEBUG from the core logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
|
||
hcplugin "github.com/hashicorp/go-plugin" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// RaidError retains an error object and the name of the pack that generated it | ||
type RaidError struct { | ||
Raid string | ||
Err error | ||
} | ||
|
||
// RaidErrors holds a list of errors and an Error() method | ||
// so it adheres to the standard Error interface | ||
type RaidErrors struct { | ||
Errors []RaidError | ||
} | ||
|
||
func (e *RaidErrors) Error() string { | ||
return fmt.Sprintf("Service Pack Errors: %v", e.Errors) | ||
} | ||
|
||
type RaidPkg struct { | ||
Name string | ||
Path string | ||
ServiceTarget string | ||
Command *exec.Cmd | ||
Result string | ||
|
||
Available bool | ||
Requested bool | ||
Error error | ||
} | ||
|
||
func (p *RaidPkg) getBinary() (binaryName string, err error) { | ||
p.Name = filepath.Base(strings.ToLower(p.Name)) // in some cases a filepath may arrive here instead of the base name; overwrite if so | ||
if runtime.GOOS == "windows" && !strings.HasSuffix(p.Name, ".exe") { | ||
p.Name = fmt.Sprintf("%s.exe", p.Name) | ||
} | ||
plugins, _ := hcplugin.Discover(p.Name, viper.GetString("binaries-path")) | ||
if len(plugins) != 1 { | ||
err = fmt.Errorf("failed to locate requested plugin '%s' at path '%s'", p.Name, viper.GetString("binaries-path")) | ||
return | ||
} | ||
binaryName = plugins[0] | ||
|
||
return | ||
} | ||
|
||
func (p *RaidPkg) queueCmd() { | ||
cmd := exec.Command(p.Path) | ||
flags := []string{ | ||
fmt.Sprintf("--config=%s", viper.GetString("config")), | ||
fmt.Sprintf("--loglevel=%s", viper.GetString("loglevel")), | ||
fmt.Sprintf("--service=%s", p.ServiceTarget), | ||
} | ||
for _, flag := range flags { | ||
cmd.Args = append(cmd.Args, flag) | ||
p.Command = cmd | ||
} | ||
} | ||
|
||
func NewRaidPkg(raidName string, serviceName string) *RaidPkg { | ||
raid := &RaidPkg{ | ||
Name: raidName, | ||
} | ||
path, err := raid.getBinary() | ||
if err != nil { | ||
raid.Error = err | ||
} | ||
raid.Path = path | ||
raid.ServiceTarget = serviceName | ||
raid.queueCmd() | ||
return raid | ||
} |
Oops, something went wrong.