json: JSON messages now have proper status field for all messages
Fixes - #1369
This commit is contained in:
@@ -74,9 +74,10 @@ EXAMPLES:
|
||||
|
||||
// aliasMessage container for content message structure
|
||||
type aliasMessage struct {
|
||||
op string
|
||||
Alias string `json:"alias"`
|
||||
URL string `json:"url,omitempty"`
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
Alias string `json:"alias"`
|
||||
URL string `json:"url,omitempty"`
|
||||
}
|
||||
|
||||
// String colorized alias message
|
||||
@@ -98,6 +99,7 @@ func (a aliasMessage) String() string {
|
||||
|
||||
// JSON jsonified alias message
|
||||
func (a aliasMessage) JSON() string {
|
||||
a.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(a)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ EXAMPLES:
|
||||
// hostMessage container for content message structure
|
||||
type hostMessage struct {
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
Host string `json:"host"`
|
||||
AccessKeyID string `json:"accessKeyId,omitempty"`
|
||||
SecretAccessKey string `json:"secretAccessKey,omitempty"`
|
||||
@@ -91,6 +92,7 @@ func (a hostMessage) String() string {
|
||||
|
||||
// JSON jsonified host message
|
||||
func (a hostMessage) JSON() string {
|
||||
a.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(a)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ EXAMPLES:
|
||||
|
||||
// copyMessage container for file copy messages
|
||||
type copyMessage struct {
|
||||
Status string `json:"status"`
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
Length int64 `json:"length"`
|
||||
@@ -93,6 +94,7 @@ func (c copyMessage) String() string {
|
||||
|
||||
// JSON jsonified copy message
|
||||
func (c copyMessage) JSON() string {
|
||||
c.Status = "success"
|
||||
copyMessageBytes, err := json.Marshal(c)
|
||||
fatalIf(probe.NewError(err), "Failed to marshal copy message.")
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ func checkDiffSyntax(ctx *cli.Context) {
|
||||
|
||||
// diffMessage json container for diff messages
|
||||
type diffMessage struct {
|
||||
Status string `json:"status"`
|
||||
FirstURL string `json:"first"`
|
||||
SecondURL string `json:"second"`
|
||||
Diff string `json:"diff"`
|
||||
@@ -106,6 +107,7 @@ func (d diffMessage) String() string {
|
||||
|
||||
// JSON jsonified diff message
|
||||
func (d diffMessage) JSON() string {
|
||||
d.Status = "success"
|
||||
diffJSONBytes, err := json.Marshal(d)
|
||||
fatalIf(probe.NewError(err),
|
||||
"Unable to marshal diff message ‘"+d.FirstURL+"’, ‘"+d.SecondURL+"’ and ‘"+d.Diff+"’.")
|
||||
|
||||
@@ -24,71 +24,45 @@ import (
|
||||
"github.com/minio/minio-xl/pkg/probe"
|
||||
)
|
||||
|
||||
// ErrorMessage container for error messages
|
||||
type ErrorMessage struct {
|
||||
// causeMessage container for golang error messages
|
||||
type causeMessage struct {
|
||||
Message string `json:"message"`
|
||||
Error error `json:"error"`
|
||||
}
|
||||
|
||||
// errorMessage container for error messages
|
||||
type errorMessage struct {
|
||||
Message string `json:"message"`
|
||||
Cause error `json:"cause"`
|
||||
Cause causeMessage `json:"cause"`
|
||||
Type string `json:"type"`
|
||||
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||
SysInfo map[string]string `json:"sysinfo"`
|
||||
}
|
||||
|
||||
// fatalIfMultiple wrapper function which takes error message map and selectively prints stack frames if available on debug
|
||||
// fatalIfMultiple is implemented to handle multiple argument validation.
|
||||
/*
|
||||
func fatalIfMultiple(errMsgMap map[string]*probe.Error) {
|
||||
if errMsgMap == nil {
|
||||
return
|
||||
}
|
||||
for msg, err := range errMsgMap {
|
||||
if globalJSONFlag {
|
||||
errorMessage := ErrorMessage{
|
||||
Message: msg,
|
||||
Type: "error",
|
||||
Cause: err.ToGoError(),
|
||||
SysInfo: err.SysInfo,
|
||||
}
|
||||
if globalDebugFlag {
|
||||
errorMessage.CallTrace = err.CallTrace
|
||||
}
|
||||
json, err := json.Marshal(struct {
|
||||
Error ErrorMessage `json:"error"`
|
||||
}{
|
||||
Error: errorMessage,
|
||||
})
|
||||
if err != nil {
|
||||
console.Fatalln(probe.NewError(err))
|
||||
}
|
||||
console.Println(string(json))
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
console.Errorln(fmt.Sprintf("%s %s", msg, err.ToGoError()))
|
||||
}
|
||||
console.Errorln(fmt.Sprintf("%s %s", msg, err))
|
||||
}
|
||||
console.Fatalln()
|
||||
}
|
||||
*/
|
||||
|
||||
// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
|
||||
func fatalIf(err *probe.Error, msg string) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := ErrorMessage{
|
||||
errorMsg := errorMessage{
|
||||
Message: msg,
|
||||
Type: "fatal",
|
||||
Cause: err.ToGoError(),
|
||||
Cause: causeMessage{
|
||||
Message: err.ToGoError().Error(),
|
||||
Error: err.ToGoError(),
|
||||
},
|
||||
SysInfo: err.SysInfo,
|
||||
}
|
||||
if globalDebugFlag {
|
||||
errorMessage.CallTrace = err.CallTrace
|
||||
errorMsg.CallTrace = err.CallTrace
|
||||
}
|
||||
json, err := json.Marshal(struct {
|
||||
Error ErrorMessage `json:"error"`
|
||||
Status string `json:"status"`
|
||||
Error errorMessage `json:"error"`
|
||||
}{
|
||||
Error: errorMessage,
|
||||
Status: "error",
|
||||
Error: errorMsg,
|
||||
})
|
||||
if err != nil {
|
||||
console.Fatalln(probe.NewError(err))
|
||||
@@ -108,19 +82,24 @@ func errorIf(err *probe.Error, msg string) {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := ErrorMessage{
|
||||
errorMsg := errorMessage{
|
||||
Message: msg,
|
||||
Type: "error",
|
||||
Cause: err.ToGoError(),
|
||||
Cause: causeMessage{
|
||||
Message: err.ToGoError().Error(),
|
||||
Error: err.ToGoError(),
|
||||
},
|
||||
SysInfo: err.SysInfo,
|
||||
}
|
||||
if globalDebugFlag {
|
||||
errorMessage.CallTrace = err.CallTrace
|
||||
errorMsg.CallTrace = err.CallTrace
|
||||
}
|
||||
json, err := json.Marshal(struct {
|
||||
Error ErrorMessage `json:"error"`
|
||||
Status string `json:"status"`
|
||||
Error errorMessage `json:"error"`
|
||||
}{
|
||||
Error: errorMessage,
|
||||
Status: "error",
|
||||
Error: errorMsg,
|
||||
})
|
||||
if err != nil {
|
||||
console.Fatalln(probe.NewError(err))
|
||||
|
||||
@@ -36,6 +36,7 @@ const (
|
||||
|
||||
// contentMessage container for content message structure.
|
||||
type contentMessage struct {
|
||||
Status string `json:"status"`
|
||||
Filetype string `json:"type"`
|
||||
Time time.Time `json:"lastModified"`
|
||||
Size int64 `json:"size"`
|
||||
@@ -57,6 +58,7 @@ func (c contentMessage) String() string {
|
||||
|
||||
// JSON jsonified content message.
|
||||
func (c contentMessage) JSON() string {
|
||||
c.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(c)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ var (
|
||||
|
||||
// mirrorMessage container for file mirror messages
|
||||
type mirrorMessage struct {
|
||||
Status string `json:"status"`
|
||||
Source string `json:"source"`
|
||||
Targets []string `json:"targets"`
|
||||
}
|
||||
@@ -91,6 +92,7 @@ func (m mirrorMessage) String() string {
|
||||
|
||||
// JSON jsonified mirror message
|
||||
func (m mirrorMessage) JSON() string {
|
||||
m.Status = "success"
|
||||
mirrorMessageBytes, e := json.Marshal(m)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
|
||||
+4
-3
@@ -89,7 +89,8 @@ EXAMPLES:
|
||||
|
||||
// Structured message depending on the type of console.
|
||||
type rmMessage struct {
|
||||
URL string `json:"url"`
|
||||
Status string `json:"status"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// Colorized message for console printing.
|
||||
@@ -170,7 +171,7 @@ func rmAll(url string, isRecursive, isIncomplete, isFake bool) {
|
||||
errorIf(err.Trace(entry.URL.String()), "Unable to remove ‘"+entry.URL.String()+"’.")
|
||||
continue
|
||||
}
|
||||
printMsg(rmMessage{entry.URL.String()})
|
||||
printMsg(rmMessage{Status: "success", URL: entry.URL.String()})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ func mainRm(ctx *cli.Context) {
|
||||
errorIf(err.Trace(url), "Unable to remove ‘"+url+"’.")
|
||||
continue
|
||||
}
|
||||
printMsg(rmMessage{url})
|
||||
printMsg(rmMessage{Status: "success", URL: url})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -85,8 +85,9 @@ type sessionV3Header struct {
|
||||
TotalObjects int `json:"totalObjects"`
|
||||
}
|
||||
|
||||
// SessionMessage container for session messages
|
||||
type SessionMessage struct {
|
||||
// sessionMessage container for session messages
|
||||
type sessionMessage struct {
|
||||
Status string `json:"status"`
|
||||
SessionID string `json:"sessionId"`
|
||||
Time time.Time `json:"time"`
|
||||
CommandType string `json:"commandType"`
|
||||
@@ -122,13 +123,14 @@ func (s sessionV3) String() string {
|
||||
|
||||
// JSON jsonified session message
|
||||
func (s sessionV3) JSON() string {
|
||||
sessionMesage := SessionMessage{
|
||||
sessionMsg := sessionMessage{
|
||||
SessionID: s.SessionID,
|
||||
Time: s.Header.When.Local(),
|
||||
CommandType: s.Header.CommandType,
|
||||
CommandArgs: s.Header.CommandArgs,
|
||||
}
|
||||
sessionBytes, e := json.Marshal(sessionMesage)
|
||||
sessionMsg.Status = "success"
|
||||
sessionBytes, e := json.Marshal(sessionMsg)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(sessionBytes)
|
||||
|
||||
@@ -51,6 +51,7 @@ var (
|
||||
|
||||
// Structured share command message.
|
||||
type shareMesssage struct {
|
||||
Status string `json:"status"`
|
||||
ObjectURL string `json:"url"`
|
||||
ShareURL string `json:"share"`
|
||||
TimeLeft time.Duration `json:"timeLeft"`
|
||||
@@ -74,6 +75,7 @@ func (s shareMesssage) String() string {
|
||||
|
||||
// JSON - JSONified message for scripting.
|
||||
func (s shareMesssage) JSON() string {
|
||||
s.Status = "success"
|
||||
shareMessageBytes, e := json.Marshal(s)
|
||||
fatalIf(probe.NewError(e), "Failed to marshal into JSON.")
|
||||
|
||||
|
||||
+2
-1
@@ -79,6 +79,7 @@ type mcUpdates struct {
|
||||
|
||||
// updateMessage container to hold update messages.
|
||||
type updateMessage struct {
|
||||
Status string `json:"status"`
|
||||
Update bool `json:"update"`
|
||||
Download string `json:"downloadURL"`
|
||||
Version string `json:"version"`
|
||||
@@ -89,7 +90,6 @@ func (u updateMessage) String() string {
|
||||
if !u.Update {
|
||||
return console.Colorize("Update", "You are already running the most recent version of ‘mc’.")
|
||||
}
|
||||
|
||||
var msg string
|
||||
if runtime.GOOS == "windows" {
|
||||
msg = "mc.exe cp " + u.Download + " .\\mc.exe"
|
||||
@@ -103,6 +103,7 @@ func (u updateMessage) String() string {
|
||||
|
||||
// JSON jsonified update message.
|
||||
func (u updateMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
updateMessageJSONBytes, err := json.Marshal(u)
|
||||
fatalIf(probe.NewError(err), "Unable to marshal into JSON.")
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ FLAGS:
|
||||
|
||||
// Structured message depending on the type of console.
|
||||
type versionMessage struct {
|
||||
Status string `json:"status"`
|
||||
Version struct {
|
||||
Value string `json:"value"`
|
||||
Format string `json:"format"`
|
||||
@@ -70,6 +71,7 @@ func (v versionMessage) String() string {
|
||||
|
||||
// JSON'ified message for scripting.
|
||||
func (v versionMessage) JSON() string {
|
||||
v.Status = "success"
|
||||
msgBytes, e := json.Marshal(v)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(msgBytes)
|
||||
|
||||
Reference in New Issue
Block a user