List file names in log when request/response bodies are pk zip archives
This commit is contained in:
committed by
=Michael Hohn
parent
70768469d6
commit
45f184d061
30
README.org
30
README.org
@@ -195,7 +195,7 @@
|
|||||||
./gh-mrva -h
|
./gh-mrva -h
|
||||||
|
|
||||||
# In log-submit-the-mrva-job.log after edit
|
# In log-submit-the-mrva-job.log after edit
|
||||||
SN=14
|
SN=11
|
||||||
./gh-mrva submit --language cpp --session mirva-session-$SN \
|
./gh-mrva submit --language cpp --session mirva-session-$SN \
|
||||||
--list mirva-list \
|
--list mirva-list \
|
||||||
--query /Users/hohn/local/gh-mrva/FlatBuffersFunc.ql >& log-$SN.out &
|
--query /Users/hohn/local/gh-mrva/FlatBuffersFunc.ql >& log-$SN.out &
|
||||||
@@ -208,7 +208,8 @@
|
|||||||
./gh-mrva download --session mirva-session-$SN \
|
./gh-mrva download --session mirva-session-$SN \
|
||||||
--download-dbs \
|
--download-dbs \
|
||||||
--output-dir mirva-session-$SN-sarif \
|
--output-dir mirva-session-$SN-sarif \
|
||||||
|& tee log-download.log
|
>& log-download-$SN.log &
|
||||||
|
echo log-download-$SN.log
|
||||||
# 2024/02/08 15:33:39 >> Response body is
|
# 2024/02/08 15:33:39 >> Response body is
|
||||||
# Zip archive data, at least v1.0 to extract, compression method=deflate
|
# Zip archive data, at least v1.0 to extract, compression method=deflate
|
||||||
# 0:$ unzip -v foo
|
# 0:$ unzip -v foo
|
||||||
@@ -238,4 +239,29 @@
|
|||||||
# Type 'help' for list of commands.
|
# Type 'help' for list of commands.
|
||||||
# (dlv) c
|
# (dlv) c
|
||||||
|
|
||||||
|
dlv debug -- download --session mirva-session-$SN \
|
||||||
|
--download-dbs \
|
||||||
|
--output-dir mirva-session-$SN-sarif \
|
||||||
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
** VS Code Debugger Configuration
|
||||||
|
launch.json
|
||||||
|
#+begin_src javascript
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Launch Package",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}",
|
||||||
|
"buildFlags": [],
|
||||||
|
"args": ["download", "--session", "mirva-session-11", "--download-dbs", "--output-dir","mirva-session-11-sarif"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|||||||
52
main.go
52
main.go
@@ -22,6 +22,7 @@ THE SOFTWARE.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -48,15 +49,11 @@ func main() {
|
|||||||
|
|
||||||
func LogRequestDump(req *http.Request) {
|
func LogRequestDump(req *http.Request) {
|
||||||
log.Printf(">> %s %s", req.Method, req.URL)
|
log.Printf(">> %s %s", req.Method, req.URL)
|
||||||
|
|
||||||
// TODO: show index for pk zip archives
|
|
||||||
// TODO: show json ?toc? for
|
|
||||||
// 2024/02/08 14:54:14 >> Request body: {"repositories":["google/flatbuffers"],
|
|
||||||
// "language":"cpp","query_pack":"H4sIAAAA...","action_repo_ref":"main"}
|
|
||||||
req.Body = LogBody(req.Body, "request")
|
req.Body = LogBody(req.Body, "request")
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogBody(body io.ReadCloser, from string) io.ReadCloser {
|
func LogBody(body io.ReadCloser, from string) io.ReadCloser {
|
||||||
|
|
||||||
if body != nil {
|
if body != nil {
|
||||||
buf, err := io.ReadAll(body)
|
buf, err := io.ReadAll(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -65,7 +62,50 @@ func LogBody(body io.ReadCloser, from string) io.ReadCloser {
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Printf(">> %s body: %v", from, string(buf))
|
|
||||||
|
IsZipFile := func() bool {
|
||||||
|
if len(buf) >= 4 {
|
||||||
|
// The header is []byte{ 0x50, 0x4b, 0x03, 0x04 }
|
||||||
|
magic := []byte{0x50, 0x4b, 0x03, 0x04}
|
||||||
|
if bytes.Equal(buf[0:4], magic) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsZipFile() {
|
||||||
|
// Show index for pk zip archives
|
||||||
|
buf1 := make([]byte, len(buf))
|
||||||
|
copy(buf1, buf)
|
||||||
|
|
||||||
|
r, err := zip.NewReader(bytes.NewReader(buf1), int64(len(buf1)))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
// defer r.Close()
|
||||||
|
|
||||||
|
// Print the archive index
|
||||||
|
log.Printf(">> %s body:\n", from)
|
||||||
|
log.Printf("zip file, contents:\n")
|
||||||
|
|
||||||
|
for _, f := range r.File {
|
||||||
|
log.Printf("\t%s\n", f.Name)
|
||||||
|
}
|
||||||
|
} else if false {
|
||||||
|
// TODO: show json ?toc? for
|
||||||
|
// 2024/02/08 14:54:14 >> Request body: {"repositories":["google/flatbuffers"],
|
||||||
|
// "language":"cpp","query_pack":"H4sIAAAA...","action_repo_ref":"main"}
|
||||||
|
// 54:0:$ base64 -d < foo1 | gunzip | tar t|head -20
|
||||||
|
// base64 has no magic number.
|
||||||
|
// We have to decode enough to check the gzip magic number, 0x1f 0x8b
|
||||||
|
// 4 chars in base64 yield 3 bytes.
|
||||||
|
} else {
|
||||||
|
log.Printf(">> %s body: %v", from, string(buf))
|
||||||
|
}
|
||||||
|
|
||||||
reader := io.NopCloser(bytes.NewBuffer(buf))
|
reader := io.NopCloser(bytes.NewBuffer(buf))
|
||||||
return reader
|
return reader
|
||||||
|
|||||||
Reference in New Issue
Block a user