-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added callback context in action execution result
- Loading branch information
1 parent
06a8538
commit da0c30c
Showing
9 changed files
with
185 additions
and
54 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
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
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,42 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package runbook | ||
|
||
import ( | ||
"fmt" | ||
"github.com/sirupsen/logrus" | ||
"io" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
var CallbackContextReaderFunc = CallbackContextReader | ||
var CreatePipeFunc = CreatePipe | ||
|
||
func CreatePipe(pipePath string) interface{} { | ||
err := syscall.Mkfifo(pipePath, 0666) | ||
if err != nil { | ||
logrus.Debugf("Could not create named pipe with name %s. Error: %s", pipePath, err.Error()) | ||
} | ||
return pipePath | ||
} | ||
|
||
func CallbackContextReader(contextBuffer []byte, pipeListener interface{}) { | ||
pipePath, ok := pipeListener.(string) | ||
if !ok { | ||
logrus.Debug("Invalid type for pipeListener, could not retrieve pipePath.") | ||
return | ||
} | ||
file, err := os.OpenFile(pipePath, os.O_RDONLY, os.ModeNamedPipe) | ||
if err != nil { | ||
logrus.Debugf("Could not open named pipe. Error: %s", err.Error()) | ||
} | ||
defer file.Close() | ||
|
||
data, err := io.ReadAll(file) | ||
_ = copy(contextBuffer, data) | ||
if err != nil { | ||
fmt.Println("Error reading from the named pipe:", err) | ||
} | ||
} |
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,41 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package runbook | ||
|
||
import ( | ||
winio "github.com/Microsoft/go-winio" | ||
"github.com/sirupsen/logrus" | ||
"net" | ||
) | ||
|
||
var CallbackContextReaderFunc = CallbackContextReaderForWindows | ||
var CreatePipeFunc = CreatePipeForWindows | ||
|
||
func CreatePipeForWindows(pipePath string) interface{} { | ||
listener, err := winio.ListenPipe(pipePath, nil) | ||
if err != nil { | ||
logrus.Debugf("Could not create named pipe: %s Error: %s", pipePath, err.Error()) | ||
} | ||
return listener | ||
} | ||
|
||
func CallbackContextReaderForWindows(contextBuffer []byte, pipeListener interface{}) { | ||
listener, ok := pipeListener.(net.Listener) | ||
if !ok { | ||
logrus.Debug("Invalid pipeListener type for windows.") | ||
return | ||
} | ||
defer listener.Close() | ||
|
||
pipe, err := listener.Accept() | ||
if err != nil { | ||
logrus.Debugf("Could not accept connection from pipe. Error: %s", err.Error()) | ||
} | ||
defer pipe.Close() | ||
|
||
_, err = pipe.Read(contextBuffer) | ||
if err != nil { | ||
logrus.Debugf("Could not read data from pipe. Error: %s", err.Error()) | ||
} | ||
} |
Oops, something went wrong.