wip: add analysis runner / agent, separate Server/Queue/Agent, use New* initializers
This commit is contained in:
committed by
=Michael Hohn
parent
2ab596bf1d
commit
f7155eba50
@@ -29,7 +29,7 @@ func main() {
|
||||
log.Printf("Usage of %s:\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
log.Println("\nExamples:")
|
||||
log.Println(" go run main.go --loglevel=Debug --mode=container")
|
||||
log.Println(" go run main.go --loglevel=debug --mode=container")
|
||||
}
|
||||
|
||||
// Parse the flags
|
||||
@@ -68,16 +68,21 @@ func main() {
|
||||
switch *mode {
|
||||
case "standalone":
|
||||
// Assemble single-process version
|
||||
sq := queue.NewQueueSingle(2) // FIXME take value from configuration
|
||||
sc := server.NewCommanderSingle(nil, sq)
|
||||
sl := logger.NewLoggerSingle()
|
||||
ss := storage.NewStorageSingle(config.Storage.StartingID)
|
||||
sr := agent.NewRunnerSingle(2, sq) // FIXME take value from configuration
|
||||
|
||||
state := server.State{
|
||||
Commander: &server.CommanderSingle{},
|
||||
Logger: &logger.LoggerSingle{},
|
||||
Queue: &queue.QueueSingle{},
|
||||
Storage: &storage.StorageSingle{CurrentID: config.Storage.StartingID},
|
||||
Runner: &agent.RunnerSingle{},
|
||||
Commander: sc,
|
||||
Logger: sl,
|
||||
Queue: sq,
|
||||
Storage: ss,
|
||||
Runner: sr,
|
||||
}
|
||||
main := &server.CommanderSingle{}
|
||||
main.Setup(&state)
|
||||
main.Run()
|
||||
|
||||
sc.Setup(&state) // sc is part of state and dereferences it
|
||||
|
||||
case "container":
|
||||
// Assemble cccontainer
|
||||
|
||||
57
cmd/server/run-analysis.sh
Executable file
57
cmd/server/run-analysis.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash -x -e
|
||||
#* Minimal setup to run analysis using information provided by a request
|
||||
|
||||
#* Take output saved by the server
|
||||
QUERYPACKID=$1
|
||||
shift
|
||||
QUERYLANGUAGE=$1
|
||||
shift
|
||||
|
||||
# and
|
||||
DBOWNER=$1
|
||||
shift
|
||||
DBREPO=$1
|
||||
|
||||
GMSROOT=/Users/hohn/local/ghes-mirva-server
|
||||
|
||||
#* Set up derived paths
|
||||
DBPATH=$GMSROOT/var/codeql/dbs/$DBOWNER/$DBREPO
|
||||
DBZIP=$GMSROOT/codeql/dbs/$DBOWNER/$DBREPO/${DBOWNER}_${DBREPO}_db.zip
|
||||
DBEXTRACT=$GMSROOT/var/codeql/dbs/$DBOWNER/$DBREPO
|
||||
|
||||
QUERYPACK=$GMSROOT/var/codeql/querypacks/qp-$QUERYPACKID.tgz
|
||||
QUERYEXTRACT=$GMSROOT/var/codeql/querypacks/qp-$QUERYPACKID
|
||||
|
||||
QUERYOUTD=$GMSROOT/var/codeql/sarif/localrun/$DBOWNER/$DBREPO
|
||||
QUERYOUTF=$QUERYOUTD/${DBOWNER}_${DBREPO}.sarif
|
||||
|
||||
#* Prep work before running the command
|
||||
|
||||
#** Extract database
|
||||
mkdir -p $DBEXTRACT && cd $DBEXTRACT
|
||||
unzip -o -q $DBZIP
|
||||
DBINFIX=`\ls | head -1` # Could be cpp, codeql_db, or whatever
|
||||
|
||||
# Extract query pack
|
||||
mkdir -p $QUERYEXTRACT && cd $QUERYEXTRACT
|
||||
tar zxf $QUERYPACK
|
||||
|
||||
#** Prepare target directory
|
||||
mkdir -p $QUERYOUTD
|
||||
|
||||
#* run database analyze
|
||||
cd $GMSROOT
|
||||
codeql database analyze --format=sarif-latest --rerun \
|
||||
--output $QUERYOUTF \
|
||||
-j8 \
|
||||
-- $DBPATH/$DBINFIX $QUERYEXTRACT
|
||||
|
||||
#* report result
|
||||
# var/codeql/sarif/localrun/google/flatbuffers/google_flatbuffers.sarif
|
||||
printf "run-analysis-output in %s\n" $QUERYOUTF
|
||||
# TODO Is the bqrs really necessary? It can also be found by the go code at this point.
|
||||
# The name of the query is only found in the query pack itself and would have to be
|
||||
# extracted from there.
|
||||
# var/codeql/dbs/google/flatbuffers/cpp/results/codeql-remote/query/FlatBuffersFunc.bqrs
|
||||
# BQRSPATH=$GMSROOT/var/codeql/dbs/$DBOWNER/$DBREPO/$LANGUAGE/results/codeql-remote/query/
|
||||
# printf "run-analysis-bqrs in %s\n" $QUERYOUTF
|
||||
Reference in New Issue
Block a user