Skip to content

Commit

Permalink
add "host" field in json output
Browse files Browse the repository at this point in the history
The "node" field is very inconvenient since a user specifies list of
nodes and then if they wants to parse json output and associate results
with original list of addresses they needs to parse "node" field because
it looks like `[User.Name@ip-address:port]` but a user specified just ip
addresses.

Therefore, we add new field "host" in JSON output which is the same as
specified by user in stdin or in --host flag.
  • Loading branch information
kovetskiy authored and seletskiy committed Jan 28, 2019
1 parent fd7a577 commit 6968584
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type address struct {
user string
domain string
port int

host string
}

func (address address) String() string {
Expand Down Expand Up @@ -58,6 +60,7 @@ func parseAddress(
user: user,
domain: domain,
port: port,
host: host,
}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ func runRemoteExecutionNode(
stdoutBackend = &jsonOutputWriter{
stream: `stdout`,
node: node.String(),
host: node.address.host,

output: os.Stdout,
}

stderrBackend = &jsonOutputWriter{
stream: `stderr`,
node: node.String(),
host: node.address.host,

output: os.Stderr,
}
Expand Down
7 changes: 7 additions & 0 deletions json_output_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type jsonOutputWriter struct {
stream string
node string
host string

output io.Writer
}
Expand All @@ -27,6 +28,12 @@ func (writer *jsonOutputWriter) Write(data []byte) (int, error) {
message["node"] = writer.node
}

if writer.host == "" {
message["host"] = nil
} else {
message["host"] = writer.host
}

message["body"] = string(data)

jsonMessage, err := json.Marshal(message)
Expand Down

0 comments on commit 6968584

Please sign in to comment.