Commit 32658058 authored by lukasburgey's avatar lukasburgey
Browse files

Merge branch 'indentation' into dev

parents 351ac327 d9d90a76
package indent
import (
"bytes"
"encoding/json"
)
var (
prefix = ""
indent = " "
)
// Indent indents a json string if possible
// if unsuccessful it just returns src
func Indent(src []byte) (ds []byte) {
buf := new(bytes.Buffer)
err := json.Indent(buf, src, prefix, indent)
if err != nil {
return src
}
ds = buf.Bytes()
return
}
......@@ -14,6 +14,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
scripts "git.scc.kit.edu/feudal/feudalScripts/v2"
)
......@@ -121,43 +122,31 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) {
stdin.Write(iBytes)
stdin.Close()
// decode json output
var outputBytes, logOutputBytes []byte
outputBytes, err = ioutil.ReadAll(stdout)
if err != nil {
return
}
// read stdout / stderr
var stdoutBytes, stderrBytes []byte
logOutputBytes, err = ioutil.ReadAll(stderr)
stdoutBytes, err = ioutil.ReadAll(stdout)
if err != nil {
return
}
if sink.Config.Debug.Scripts {
if len(logOutputBytes) > 0 {
dep.Log("Logs:\n%s", logOutputBytes)
stderrBytes, _ = ioutil.ReadAll(stderr)
if sink.Config.Debug.Scripts && len(stderrBytes) > 0 {
dep.Log("Logs:\n%s", stderrBytes)
dep.Log("End of Logs")
}
}
// waits for command execution and pipe reading
err = cmd.Wait()
if err != nil {
return
}
if sink.Config.Debug.Scripts {
var indented = new(bytes.Buffer)
err = json.Indent(indented, outputBytes, " ", " ")
if err != nil {
dep.Log("Output (unable to indent: %s):\n%s", err, outputBytes)
} else {
dep.Log("Output:\n%s", indented.String())
}
dep.Log("Output: %s", indent.Indent(stdoutBytes))
}
err = json.Unmarshal(outputBytes, &output)
err = json.Unmarshal(stdoutBytes, &output)
if err != nil {
if len(outputBytes) > 0 {
dep.Log("Raw output: %s", outputBytes)
}
return
}
......
package amqp
import (
"bytes"
"encoding/json"
"fmt"
"log"
......@@ -9,6 +8,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
"github.com/streadway/amqp"
)
......@@ -119,12 +119,7 @@ func (src *Source) connect() (deliveries <-chan amqp.Delivery, closed <-chan *am
func (src *Source) consume(sink chan<- deps.Dep, deliveries <-chan amqp.Delivery) {
consumeWrapper := func(del amqp.Delivery) {
if src.Config.Debug.Backend {
indented := new(bytes.Buffer)
if err := json.Indent(indented, del.Body, " ", " "); err != nil {
log.Printf("[AMQP] Received (unable to indent: %v):\n%s", err, del.Body)
} else {
log.Printf("[AMQP] Received:\n%s", indented)
}
log.Printf("[AMQP] Received: %s", indent.Indent(del.Body))
}
var newDep deps.Dep
......
package rest
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
......@@ -11,6 +10,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
)
type (
......@@ -70,13 +70,7 @@ func (src Source) fetchDeps(sink chan<- deps.Dep) (err error) {
}
if src.Config.Debug.Backend {
indented := new(bytes.Buffer)
indentErr := json.Indent(indented, body, "", " ")
if indentErr != nil {
log.Printf("[HTTP] Fetched (unable to indent: %v):\n%s", err, body)
} else {
log.Printf("[HTTP] Fetched:\n%s", indented)
}
log.Printf("[HTTP] Fetched: %s", indent.Indent(body))
}
go func() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment