mirror of
https://github.com/BishopFox/sj.git
synced 2026-11-07 10:26:01 -10:00
Merge pull request #42 from altperfect/feat/add-curl-command-to-verbose-output
Add curl command in verbose output for 'automate' mode
This commit is contained in:
2 files changed
+10
-2
No files matched your search
@@ -19,6 +19,7 @@ type VerboseResult struct {
|
||||
Preview string `json:"preview"`
|
||||
Status int `json:"status"`
|
||||
Target string `json:"target"`
|
||||
Curl string `json:"curl"`
|
||||
}
|
||||
|
||||
var tempLogger *log.Logger
|
||||
|
||||
+9
-2
@@ -259,11 +259,18 @@ func (s SwaggerRequest) BuildDefinedRequests(client http.Client, method string,
|
||||
accessibleEndpoints = append(accessibleEndpoints, s.URL.String())
|
||||
}
|
||||
if strings.ToLower(outputFormat) != "console" {
|
||||
curlCommand := fmt.Sprintf("curl -X %s -sk %s", method, s.URL.String())
|
||||
if s.BodyData != nil {
|
||||
curlCommand = fmt.Sprintf("%s -d '%s'", curlCommand, string(s.BodyData))
|
||||
}
|
||||
if len(Headers) != 0 {
|
||||
curlCommand = fmt.Sprintf("%s -H '%s'", curlCommand, strings.Join(Headers, "' -H '"))
|
||||
}
|
||||
var result []byte
|
||||
if getAccessibleEndpoints {
|
||||
if sc == 200 {
|
||||
if verbose {
|
||||
result, _ = json.Marshal(VerboseResult{Method: method, Preview: resp[:tempResponsePreviewLength], Status: sc, Target: s.URL.String()})
|
||||
result, _ = json.Marshal(VerboseResult{Method: method, Preview: resp[:tempResponsePreviewLength], Status: sc, Target: s.URL.String(), Curl: curlCommand})
|
||||
} else {
|
||||
result, _ = json.Marshal(Result{Method: method, Status: sc, Target: s.URL.String()})
|
||||
}
|
||||
@@ -275,7 +282,7 @@ func (s SwaggerRequest) BuildDefinedRequests(client http.Client, method string,
|
||||
}
|
||||
} else {
|
||||
if verbose {
|
||||
result, _ = json.Marshal(VerboseResult{Method: method, Preview: resp[:tempResponsePreviewLength], Status: sc, Target: s.URL.String()})
|
||||
result, _ = json.Marshal(VerboseResult{Method: method, Preview: resp[:tempResponsePreviewLength], Status: sc, Target: s.URL.String(), Curl: curlCommand})
|
||||
} else {
|
||||
result, _ = json.Marshal(Result{Method: method, Status: sc, Target: s.URL.String()})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user