Added request/response logger to main for expansion

This commit is contained in:
Michael Hohn
2024-02-08 13:32:14 -08:00
committed by =Michael Hohn
parent d57f9a855f
commit 2a80ff0bc2
2 changed files with 56 additions and 4 deletions

View File

@@ -97,9 +97,10 @@
cd ~/local/gh-mrva
# Build it
go mod edit -replace="github.com/GitHubSecurityLab/gh-mrva=/Users/hohn/local/gh-mrva"
go build
go build .
# Install
gh extension remove mrva
gh extension install .
# Sanity check
@@ -128,7 +129,7 @@
#+BEGIN_SRC sh
gh mrva submit --help
gh mrva submit --language cpp --session mirva-session-1 \
gh mrva submit --language cpp --session mirva-session-4 \
--list mirva-list \
--query /Users/hohn/local/gh-mrva/FlatBuffersFunc.ql
#+END_SRC
@@ -181,4 +182,19 @@
The workflow producing the logs:
https://github.com/github/codeql-variant-analysis-action/blob/main/variant-analysis-workflow.yml
** Compacted Edit-Run-Debug Cycle
With a full [[*Using MRVA][Using MRVA]] cycle done, only these steps are needed in a
edit-run-debug cycle.
#+BEGIN_SRC sh
cd ~/local/gh-mrva
# Build it
go build .
./gh-mrva -h
# Submit the mrva job
./gh-mrva submit --language cpp --session mirva-session-6 \
--list mirva-list \
--query /Users/hohn/local/gh-mrva/FlatBuffersFunc.ql
#+END_SRC

38
main.go
View File

@@ -22,10 +22,46 @@ THE SOFTWARE.
package main
import (
"log"
"net/http"
"time"
"github.com/GitHubSecurityLab/gh-mrva/cmd"
_ "github.com/motemen/go-loghttp/global"
"github.com/motemen/go-loghttp"
"github.com/motemen/go-nuts/roundtime"
)
func main() {
var transport = &loghttp.Transport{
Transport: http.DefaultTransport,
LogRequest: LogRequestDump,
LogResponse: LogResponseDump,
}
http.DefaultTransport = transport
cmd.Execute()
}
// Used if transport.LogRequest is not set.
func LogRequestDump(req *http.Request) {
log.Printf(">> %s %s", req.Method, req.URL)
}
type contextKey struct {
name string
}
var ContextKeyRequestStart = &contextKey{"RequestStart"}
// Used if transport.LogResponse is not set.
func LogResponseDump(resp *http.Response) {
ctx := resp.Request.Context()
if start, ok := ctx.Value(ContextKeyRequestStart).(time.Time); ok {
log.Printf("<< %d %s (%s)", resp.StatusCode, resp.Request.URL,
roundtime.Duration(time.Since(start), 2))
} else {
log.Printf("<< %d %s", resp.StatusCode, resp.Request.URL)
}
}