Standardize NameWithOwner and Visible naming

Acronyms are now "NWO" and "Vis" respsectively
This commit is contained in:
Nicolas Will
2024-06-14 12:55:45 +02:00
parent 3218f64bcf
commit c29daab045
12 changed files with 102 additions and 98 deletions

View File

@@ -22,11 +22,11 @@ func main() {
} }
// Migrate the schema: create the 'owner_repo' table from the struct // Migrate the schema: create the 'owner_repo' table from the struct
err = db.AutoMigrate(&common.OwnerRepo{}) err = db.AutoMigrate(&common.NameWithOwner{})
if err != nil { if err != nil {
panic("failed to migrate database") panic("failed to migrate database")
} }
// Create an entry in the database // Create an entry in the database
db.Create(&common.OwnerRepo{Owner: "foo", Repo: "foo/bar"}) db.Create(&common.NameWithOwner{Owner: "foo", Repo: "foo/bar"})
} }

View File

@@ -52,7 +52,7 @@ func (r *RunnerSingle) worker(wid int) {
slog.Debug("Picking up job", "job", job, "worker", wid) slog.Debug("Picking up job", "job", job, "worker", wid)
slog.Debug("Analysis: running", "job", job) slog.Debug("Analysis: running", "job", job)
storage.SetStatus(job.QueryPackId, job.ORepo, common.StatusQueued) storage.SetStatus(job.QueryPackId, job.NWO, common.StatusQueued)
resultFile, err := r.RunAnalysis(job) resultFile, err := r.RunAnalysis(job)
if err != nil { if err != nil {
@@ -66,8 +66,8 @@ func (r *RunnerSingle) worker(wid int) {
RunAnalysisBQRS: "", // FIXME ? RunAnalysisBQRS: "", // FIXME ?
} }
r.queue.Results() <- res r.queue.Results() <- res
storage.SetStatus(job.QueryPackId, job.ORepo, common.StatusSuccess) storage.SetStatus(job.QueryPackId, job.NWO, common.StatusSuccess)
storage.SetResult(job.QueryPackId, job.ORepo, res) storage.SetResult(job.QueryPackId, job.NWO, res)
} }
} }
@@ -75,9 +75,9 @@ func (r *RunnerSingle) worker(wid int) {
func (r *RunnerSingle) RunAnalysis(job common.AnalyzeJob) (string, error) { func (r *RunnerSingle) RunAnalysis(job common.AnalyzeJob) (string, error) {
// TODO Add multi-language tests including queryLanguage // TODO Add multi-language tests including queryLanguage
// queryPackID, queryLanguage, dbOwner, dbRepo := // queryPackID, queryLanguage, dbOwner, dbRepo :=
// job.QueryPackId, job.QueryLanguage, job.ORL.Owner, job.ORL.Repo // job.QueryPackId, job.QueryLanguage, job.NWO.Owner, job.NWO.Repo
queryPackID, dbOwner, dbRepo := queryPackID, dbOwner, dbRepo :=
job.QueryPackId, job.ORepo.Owner, job.ORepo.Repo job.QueryPackId, job.NWO.Owner, job.NWO.Repo
serverRoot := os.Getenv("MRVA_SERVER_ROOT") serverRoot := os.Getenv("MRVA_SERVER_ROOT")
@@ -135,7 +135,7 @@ func (r *RunnerSingle) RunAnalysis(job common.AnalyzeJob) (string, error) {
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
slog.Error("codeql database analyze failed:", "error", err, "job", job) slog.Error("codeql database analyze failed:", "error", err, "job", job)
storage.SetStatus(job.QueryPackId, job.ORepo, common.StatusError) storage.SetStatus(job.QueryPackId, job.NWO, common.StatusError)
return "", err return "", err
} }

View File

@@ -1,24 +1,29 @@
package common package common
type AnalyzeJob struct { // NameWithOwner represents a repository name and its owner name.
MirvaRequestID int type NameWithOwner struct {
QueryPackId int
QueryLanguage string
ORepo OwnerRepo
}
type OwnerRepo struct {
Owner string Owner string
Repo string Repo string
} }
// AnalyzeJob represents a job specifying a repository and a query pack to analyze it with.
// This is the message format that the agent receives from the queue.
type AnalyzeJob struct {
MRVARequestID int
QueryPackId int
QueryPackURL string
QueryLanguage string
NWO NameWithOwner
}
// AnalyzeResult represents the result of an analysis job.
// This is the message format that the agent sends to the queue.
type AnalyzeResult struct { type AnalyzeResult struct {
RunAnalysisSARIF string RunAnalysisSARIF string
RunAnalysisBQRS string RunAnalysisBQRS string
} }
// Status represents the status of a job.
type Status int type Status int
const ( const (
@@ -48,5 +53,5 @@ func (s Status) ToExternalString() string {
type JobSpec struct { type JobSpec struct {
JobID int JobID int
OwnerRepo NameWithOwner
} }

View File

@@ -57,10 +57,10 @@ func (s *StorageContainer) SaveQueryPack(tgz []byte, sessionID int) (storagePath
return "todo:no-path-yet", nil return "todo:no-path-yet", nil
} }
func (s *StorageContainer) FindAvailableDBs(analysisReposRequested []common.OwnerRepo) (notFoundRepos []common.OwnerRepo, analysisRepos *map[common.OwnerRepo]qldbstore.DBLocation) { func (s *StorageContainer) FindAvailableDBs(analysisReposRequested []common.NameWithOwner) (notFoundRepos []common.NameWithOwner, analysisRepos *map[common.NameWithOwner]qldbstore.DBLocation) {
// TODO s.FindAvailableDBs() via postgres // TODO s.FindAvailableDBs() via postgres
analysisRepos = &map[common.OwnerRepo]qldbstore.DBLocation{} analysisRepos = &map[common.NameWithOwner]qldbstore.DBLocation{}
notFoundRepos = []common.OwnerRepo{} notFoundRepos = []common.NameWithOwner{}
return notFoundRepos, analysisRepos return notFoundRepos, analysisRepos
} }

View File

@@ -8,6 +8,6 @@ import (
type Storage interface { type Storage interface {
NextID() int NextID() int
SaveQueryPack(tgz []byte, sessionID int) (storagePath string, error error) SaveQueryPack(tgz []byte, sessionID int) (storagePath string, error error)
FindAvailableDBs(analysisReposRequested []common.OwnerRepo) (not_found_repos []common.OwnerRepo, FindAvailableDBs(analysisReposRequested []common.NameWithOwner) (not_found_repos []common.NameWithOwner,
analysisRepos *map[common.OwnerRepo]qldbstore.DBLocation) analysisRepos *map[common.NameWithOwner]qldbstore.DBLocation)
} }

View File

@@ -8,7 +8,7 @@ import (
type Queue interface { type Queue interface {
Jobs() chan common.AnalyzeJob Jobs() chan common.AnalyzeJob
Results() chan common.AnalyzeResult Results() chan common.AnalyzeResult
StartAnalyses(analysis_repos *map[common.OwnerRepo]storage.DBLocation, StartAnalyses(analysis_repos *map[common.NameWithOwner]storage.DBLocation,
session_id int, session_id int,
session_language string) session_language string)
} }

View File

@@ -14,19 +14,18 @@ func (q *QueueSingle) Results() chan common.AnalyzeResult {
return q.results return q.results
} }
func (q *QueueSingle) StartAnalyses(analysis_repos *map[common.OwnerRepo]storage.DBLocation, session_id int, func (q *QueueSingle) StartAnalyses(analysis_repos *map[common.NameWithOwner]storage.DBLocation, session_id int,
session_language string) { session_language string) {
slog.Debug("Queueing codeql database analyze jobs") slog.Debug("Queueing codeql database analyze jobs")
for orl := range *analysis_repos { for nwo := range *analysis_repos {
info := common.AnalyzeJob{ info := common.AnalyzeJob{
QueryPackId: session_id, QueryPackId: session_id,
QueryLanguage: session_language, QueryLanguage: session_language,
NWO: nwo,
ORepo: orl,
} }
q.jobs <- info q.jobs <- info
storage.SetStatus(session_id, orl, common.StatusQueued) storage.SetStatus(session_id, nwo, common.StatusQueued)
storage.AddJob(session_id, info) storage.AddJob(session_id, info)
} }
} }

View File

@@ -23,33 +23,33 @@ import (
func (c *CommanderSingle) Setup(st *Visibles) { func (c *CommanderSingle) Setup(st *Visibles) {
r := mux.NewRouter() r := mux.NewRouter()
c.st = st c.vis = st
// //
// First are the API endpoints that mirror those used in the github API // First are the API endpoints that mirror those used in the github API
// //
r.HandleFunc("/repos/{owner}/{repo}/code-scanning/codeql/variant-analyses", c.MirvaRequest) r.HandleFunc("/repos/{owner}/{repo}/code-scanning/codeql/variant-analyses", c.MRVARequest)
// /repos/hohn /mirva-controller/code-scanning/codeql/variant-analyses // /repos/hohn /mrva-controller/code-scanning/codeql/variant-analyses
// Or via // Or via
r.HandleFunc("/{repository_id}/code-scanning/codeql/variant-analyses", c.MirvaRequestID) r.HandleFunc("/{repository_id}/code-scanning/codeql/variant-analyses", c.MRVARequestID)
r.HandleFunc("/", c.RootHandler) r.HandleFunc("/", c.RootHandler)
// This is the standalone status request. // This is the standalone status request.
// It's also the first request made when downloading; the difference is on the // It's also the first request made when downloading; the difference is on the
// client side's handling. // client side's handling.
r.HandleFunc("/repos/{owner}/{repo}/code-scanning/codeql/variant-analyses/{codeql_variant_analysis_id}", c.MirvaStatus) r.HandleFunc("/repos/{owner}/{repo}/code-scanning/codeql/variant-analyses/{codeql_variant_analysis_id}", c.MRVAStatus)
r.HandleFunc("/repos/{controller_owner}/{controller_repo}/code-scanning/codeql/variant-analyses/{codeql_variant_analysis_id}/repos/{repo_owner}/{repo_name}", c.MirvaDownloadArtifact) r.HandleFunc("/repos/{controller_owner}/{controller_repo}/code-scanning/codeql/variant-analyses/{codeql_variant_analysis_id}/repos/{repo_owner}/{repo_name}", c.MRVADownloadArtifact)
// Not implemented: // Not implemented:
// r.HandleFunc("/codeql-query-console/codeql-variant-analysis-repo-tasks/{codeql_variant_analysis_id}/{repo_id}/{owner_id}/{controller_repo_id}", MirvaDownLoad3) // r.HandleFunc("/codeql-query-console/codeql-variant-analysis-repo-tasks/{codeql_variant_analysis_id}/{repo_id}/{owner_id}/{controller_repo_id}", MRVADownLoad3)
// r.HandleFunc("/github-codeql-query-console-prod/codeql-variant-analysis-repo-tasks/{codeql_variant_analysis_id}/{repo_id}", MirvaDownLoad4) // r.HandleFunc("/github-codeql-query-console-prod/codeql-variant-analysis-repo-tasks/{codeql_variant_analysis_id}/{repo_id}", MRVADownLoad4)
// //
// Now some support API endpoints // Now some support API endpoints
// //
r.HandleFunc("/download-server/{local_path:.*}", c.MirvaDownloadServe) r.HandleFunc("/download-server/{local_path:.*}", c.MRVADownloadServe)
// //
// Bind to a port and pass our router in // Bind to a port and pass our router in
@@ -64,13 +64,13 @@ func (c *CommanderSingle) StatusResponse(w http.ResponseWriter, js common.JobSpe
all_scanned := []common.ScannedRepo{} all_scanned := []common.ScannedRepo{}
jobs := storage.GetJobList(js.JobID) jobs := storage.GetJobList(js.JobID)
for _, job := range jobs { for _, job := range jobs {
astat := storage.GetStatus(js.JobID, job.ORepo).ToExternalString() astat := storage.GetStatus(js.JobID, job.NWO).ToExternalString()
all_scanned = append(all_scanned, all_scanned = append(all_scanned,
common.ScannedRepo{ common.ScannedRepo{
Repository: common.Repository{ Repository: common.Repository{
ID: 0, ID: 0,
Name: job.ORepo.Repo, Name: job.NWO.Repo,
FullName: fmt.Sprintf("%s/%s", job.ORepo.Owner, job.ORepo.Repo), FullName: fmt.Sprintf("%s/%s", job.NWO.Owner, job.NWO.Repo),
Private: false, Private: false,
StargazersCount: 0, StargazersCount: 0,
UpdatedAt: ji.UpdatedAt, UpdatedAt: ji.UpdatedAt,
@@ -82,7 +82,7 @@ func (c *CommanderSingle) StatusResponse(w http.ResponseWriter, js common.JobSpe
) )
} }
astat := storage.GetStatus(js.JobID, js.OwnerRepo).ToExternalString() astat := storage.GetStatus(js.JobID, js.NameWithOwner).ToExternalString()
status := common.StatusResponse{ status := common.StatusResponse{
SessionId: js.JobID, SessionId: js.JobID,
@@ -116,9 +116,9 @@ func (c *CommanderSingle) RootHandler(w http.ResponseWriter, r *http.Request) {
slog.Info("Request on /") slog.Info("Request on /")
} }
func (c *CommanderSingle) MirvaStatus(w http.ResponseWriter, r *http.Request) { func (c *CommanderSingle) MRVAStatus(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
slog.Info("mrva status request for ", slog.Info("MRVA status request for ",
"owner", vars["owner"], "owner", vars["owner"],
"repo", vars["repo"], "repo", vars["repo"],
"codeql_variant_analysis_id", vars["codeql_variant_analysis_id"]) "codeql_variant_analysis_id", vars["codeql_variant_analysis_id"])
@@ -142,8 +142,8 @@ func (c *CommanderSingle) MirvaStatus(w http.ResponseWriter, r *http.Request) {
job := spec[0] job := spec[0]
js := common.JobSpec{ js := common.JobSpec{
JobID: job.QueryPackId, JobID: job.QueryPackId,
OwnerRepo: job.ORepo, NameWithOwner: job.NWO,
} }
ji := storage.GetJobInfo(js) ji := storage.GetJobInfo(js)
@@ -152,7 +152,7 @@ func (c *CommanderSingle) MirvaStatus(w http.ResponseWriter, r *http.Request) {
} }
// Download artifacts // Download artifacts
func (c *CommanderSingle) MirvaDownloadArtifact(w http.ResponseWriter, r *http.Request) { func (c *CommanderSingle) MRVADownloadArtifact(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
slog.Info("MRVA artifact download", slog.Info("MRVA artifact download",
"controller_owner", vars["controller_owner"], "controller_owner", vars["controller_owner"],
@@ -170,7 +170,7 @@ func (c *CommanderSingle) MirvaDownloadArtifact(w http.ResponseWriter, r *http.R
} }
js := common.JobSpec{ js := common.JobSpec{
JobID: vaid, JobID: vaid,
OwnerRepo: common.OwnerRepo{ NameWithOwner: common.NameWithOwner{
Owner: vars["repo_owner"], Owner: vars["repo_owner"],
Repo: vars["repo_name"], Repo: vars["repo_name"],
}, },
@@ -181,7 +181,7 @@ func (c *CommanderSingle) MirvaDownloadArtifact(w http.ResponseWriter, r *http.R
func (c *CommanderSingle) DownloadResponse(w http.ResponseWriter, js common.JobSpec, vaid int) { func (c *CommanderSingle) DownloadResponse(w http.ResponseWriter, js common.JobSpec, vaid int) {
slog.Debug("Forming download response", "session", vaid, "job", js) slog.Debug("Forming download response", "session", vaid, "job", js)
astat := storage.GetStatus(vaid, js.OwnerRepo) astat := storage.GetStatus(vaid, js.NameWithOwner)
var dlr common.DownloadResponse var dlr common.DownloadResponse
if astat == common.StatusSuccess { if astat == common.StatusSuccess {
@@ -234,7 +234,7 @@ func (c *CommanderSingle) DownloadResponse(w http.ResponseWriter, js common.JobS
} }
func (c *CommanderSingle) MirvaDownloadServe(w http.ResponseWriter, r *http.Request) { func (c *CommanderSingle) MRVADownloadServe(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
slog.Info("File download request", "local_path", vars["local_path"]) slog.Info("File download request", "local_path", vars["local_path"])
@@ -266,16 +266,16 @@ func FileDownload(w http.ResponseWriter, path string) {
} }
func (c *CommanderSingle) MirvaRequestID(w http.ResponseWriter, r *http.Request) { func (c *CommanderSingle) MRVARequestID(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
slog.Info("New mrva using repository_id=%v\n", vars["repository_id"]) slog.Info("New mrva using repository_id=%v\n", vars["repository_id"])
} }
func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) { func (c *CommanderSingle) MRVARequest(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
slog.Info("New mrva run ", "owner", vars["owner"], "repo", vars["repo"]) slog.Info("New mrva run ", "owner", vars["owner"], "repo", vars["repo"])
session_id := c.st.ServerStore.NextID() session_id := c.vis.ServerStore.NextID()
session_owner := vars["owner"] session_owner := vars["owner"]
session_controller_repo := vars["repo"] session_controller_repo := vars["repo"]
slog.Info("new run", "id: ", fmt.Sprint(session_id), session_owner, session_controller_repo) slog.Info("new run", "id: ", fmt.Sprint(session_id), session_owner, session_controller_repo)
@@ -284,9 +284,9 @@ func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) {
return return
} }
not_found_repos, analysisRepos := c.st.ServerStore.FindAvailableDBs(session_repositories) not_found_repos, analysisRepos := c.vis.ServerStore.FindAvailableDBs(session_repositories)
c.st.Queue.StartAnalyses(analysisRepos, session_id, session_language) c.vis.Queue.StartAnalyses(analysisRepos, session_id, session_language)
si := SessionInfo{ si := SessionInfo{
ID: session_id, ID: session_id,
@@ -316,10 +316,10 @@ func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) {
w.Write(submit_response) w.Write(submit_response)
} }
func ORToArr(aor []common.OwnerRepo) ([]string, int) { func nwoToNwoStringArray(nwo []common.NameWithOwner) ([]string, int) {
repos := []string{} repos := []string{}
count := len(aor) count := len(nwo)
for _, repo := range aor { for _, repo := range nwo {
repos = append(repos, fmt.Sprintf("%s/%s", repo.Owner, repo.Repo)) repos = append(repos, fmt.Sprintf("%s/%s", repo.Owner, repo.Repo))
} }
return repos, count return repos, count
@@ -330,17 +330,17 @@ func submit_response(sn SessionInfo) ([]byte, error) {
var m_cr common.ControllerRepo var m_cr common.ControllerRepo
var m_ac common.Actor var m_ac common.Actor
repos, count := ORToArr(sn.NotFoundRepos) repos, count := nwoToNwoStringArray(sn.NotFoundRepos)
r_nfr := common.NotFoundRepos{RepositoryCount: count, RepositoryFullNames: repos} r_nfr := common.NotFoundRepos{RepositoryCount: count, RepositoryFullNames: repos}
repos, count = ORToArr(sn.AccessMismatchRepos) repos, count = nwoToNwoStringArray(sn.AccessMismatchRepos)
r_amr := common.AccessMismatchRepos{RepositoryCount: count, Repositories: repos} r_amr := common.AccessMismatchRepos{RepositoryCount: count, Repositories: repos}
repos, count = ORToArr(sn.NoCodeqlDBRepos) repos, count = nwoToNwoStringArray(sn.NoCodeqlDBRepos)
r_ncd := common.NoCodeqlDBRepos{RepositoryCount: count, Repositories: repos} r_ncd := common.NoCodeqlDBRepos{RepositoryCount: count, Repositories: repos}
// TODO fill these with real values? // TODO fill these with real values?
repos, count = ORToArr(sn.NoCodeqlDBRepos) repos, count = nwoToNwoStringArray(sn.NoCodeqlDBRepos)
r_olr := common.OverLimitRepos{RepositoryCount: count, Repositories: repos} r_olr := common.OverLimitRepos{RepositoryCount: count, Repositories: repos}
m_skip := common.SkippedRepositories{ m_skip := common.SkippedRepositories{
@@ -366,8 +366,8 @@ func submit_response(sn SessionInfo) ([]byte, error) {
for _, job := range joblist { for _, job := range joblist {
storage.SetJobInfo(common.JobSpec{ storage.SetJobInfo(common.JobSpec{
JobID: sn.ID, JobID: sn.ID,
OwnerRepo: job.ORepo, NameWithOwner: job.NWO,
}, common.JobInfo{ }, common.JobInfo{
QueryLanguage: sn.Language, QueryLanguage: sn.Language,
CreatedAt: m_sr.CreatedAt, CreatedAt: m_sr.CreatedAt,
@@ -387,28 +387,28 @@ func submit_response(sn SessionInfo) ([]byte, error) {
} }
func (c *CommanderSingle) collectRequestInfo(w http.ResponseWriter, r *http.Request, sessionId int) (string, []common.OwnerRepo, string, error) { func (c *CommanderSingle) collectRequestInfo(w http.ResponseWriter, r *http.Request, sessionId int) (string, []common.NameWithOwner, string, error) {
slog.Debug("Collecting session info") slog.Debug("Collecting session info")
if r.Body == nil { if r.Body == nil {
err := errors.New("missing request body") err := errors.New("missing request body")
log.Println(err) log.Println(err)
http.Error(w, err.Error(), http.StatusNoContent) http.Error(w, err.Error(), http.StatusNoContent)
return "", []common.OwnerRepo{}, "", err return "", []common.NameWithOwner{}, "", err
} }
buf, err := io.ReadAll(r.Body) buf, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
var w http.ResponseWriter var w http.ResponseWriter
slog.Error("Error reading MRVA submission body", "error", err.Error()) slog.Error("Error reading MRVA submission body", "error", err.Error())
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return "", []common.OwnerRepo{}, "", err return "", []common.NameWithOwner{}, "", err
} }
msg, err := TrySubmitMsg(buf) msg, err := TrySubmitMsg(buf)
if err != nil { if err != nil {
// Unknown message // Unknown message
slog.Error("Unknown MRVA submission body format") slog.Error("Unknown MRVA submission body format")
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return "", []common.OwnerRepo{}, "", err return "", []common.NameWithOwner{}, "", err
} }
// Decompose the SubmitMsg and keep information // Decompose the SubmitMsg and keep information
@@ -417,19 +417,19 @@ func (c *CommanderSingle) collectRequestInfo(w http.ResponseWriter, r *http.Requ
slog.Error("MRVA submission body querypack has invalid format") slog.Error("MRVA submission body querypack has invalid format")
err := errors.New("MRVA submission body querypack has invalid format") err := errors.New("MRVA submission body querypack has invalid format")
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return "", []common.OwnerRepo{}, "", err return "", []common.NameWithOwner{}, "", err
} }
session_tgz_ref, err := c.extract_tgz(msg.QueryPack, sessionId) session_tgz_ref, err := c.extract_tgz(msg.QueryPack, sessionId)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return "", []common.OwnerRepo{}, "", err return "", []common.NameWithOwner{}, "", err
} }
// 2. Save the language // 2. Save the language
session_language := msg.Language session_language := msg.Language
// 3. Save the repositories // 3. Save the repositories
var session_repositories []common.OwnerRepo var session_repositories []common.NameWithOwner
for _, v := range msg.Repositories { for _, v := range msg.Repositories {
t := strings.Split(v, "/") t := strings.Split(v, "/")
@@ -439,7 +439,7 @@ func (c *CommanderSingle) collectRequestInfo(w http.ResponseWriter, r *http.Requ
http.Error(w, err, http.StatusBadRequest) http.Error(w, err, http.StatusBadRequest)
} }
session_repositories = append(session_repositories, session_repositories = append(session_repositories,
common.OwnerRepo{Owner: t[0], Repo: t[1]}) common.NameWithOwner{Owner: t[0], Repo: t[1]})
} }
return session_language, session_repositories, session_tgz_ref, nil return session_language, session_repositories, session_tgz_ref, nil
} }
@@ -492,7 +492,7 @@ func (c *CommanderSingle) extract_tgz(qp string, sessionID int) (string, error)
return "", err return "", err
} }
session_query_pack_tgz_filepath, err := c.st.ServerStore.SaveQueryPack(tgz, sessionID) session_query_pack_tgz_filepath, err := c.vis.ServerStore.SaveQueryPack(tgz, sessionID)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@@ -15,18 +15,18 @@ type SessionInfo struct {
QueryPack string QueryPack string
Language string Language string
Repositories []common.OwnerRepo Repositories []common.NameWithOwner
AccessMismatchRepos []common.OwnerRepo AccessMismatchRepos []common.NameWithOwner
NotFoundRepos []common.OwnerRepo NotFoundRepos []common.NameWithOwner
NoCodeqlDBRepos []common.OwnerRepo NoCodeqlDBRepos []common.NameWithOwner
OverLimitRepos []common.OwnerRepo OverLimitRepos []common.NameWithOwner
AnalysisRepos *map[common.OwnerRepo]storage.DBLocation AnalysisRepos *map[common.NameWithOwner]storage.DBLocation
} }
type CommanderSingle struct { type CommanderSingle struct {
st *Visibles vis *Visibles
} }
func NewCommanderSingle() *CommanderSingle { func NewCommanderSingle() *CommanderSingle {

View File

@@ -24,10 +24,10 @@ func (s *StorageContainer) SaveQueryPack(tgz []byte, sessionID int) (storagePath
return "todo:no-path-yet", nil return "todo:no-path-yet", nil
} }
func (s *StorageContainer) FindAvailableDBs(analysisReposRequested []common.OwnerRepo) (notFoundRepos []common.OwnerRepo, analysisRepos *map[common.OwnerRepo]DBLocation) { func (s *StorageContainer) FindAvailableDBs(analysisReposRequested []common.NameWithOwner) (notFoundRepos []common.NameWithOwner, analysisRepos *map[common.NameWithOwner]DBLocation) {
// TODO s.FindAvailableDBs() via postgres // TODO s.FindAvailableDBs() via postgres
analysisRepos = &map[common.OwnerRepo]DBLocation{} analysisRepos = &map[common.NameWithOwner]DBLocation{}
notFoundRepos = []common.OwnerRepo{} notFoundRepos = []common.NameWithOwner{}
return notFoundRepos, analysisRepos return notFoundRepos, analysisRepos
} }

View File

@@ -5,6 +5,6 @@ import "mrvacommander/pkg/common"
type Storage interface { type Storage interface {
NextID() int NextID() int
SaveQueryPack(tgz []byte, sessionID int) (storagePath string, error error) SaveQueryPack(tgz []byte, sessionID int) (storagePath string, error error)
FindAvailableDBs(analysisReposRequested []common.OwnerRepo) (not_found_repos []common.OwnerRepo, FindAvailableDBs(analysisReposRequested []common.NameWithOwner) (not_found_repos []common.NameWithOwner,
analysisRepos *map[common.OwnerRepo]DBLocation) analysisRepos *map[common.NameWithOwner]DBLocation)
} }

View File

@@ -67,8 +67,8 @@ func (s *StorageSingle) SaveQueryPack(tgz []byte, sessionId int) (string, error)
// Determine for which repositories codeql databases are available. // Determine for which repositories codeql databases are available.
// //
// Those will be the analysis_repos. The rest will be skipped. // Those will be the analysis_repos. The rest will be skipped.
func (s *StorageSingle) FindAvailableDBs(analysisReposRequested []common.OwnerRepo) (not_found_repos []common.OwnerRepo, func (s *StorageSingle) FindAvailableDBs(analysisReposRequested []common.NameWithOwner) (not_found_repos []common.NameWithOwner,
analysisRepos *map[common.OwnerRepo]DBLocation) { analysisRepos *map[common.NameWithOwner]DBLocation) {
slog.Debug("Looking for available CodeQL databases") slog.Debug("Looking for available CodeQL databases")
cwd, err := os.Getwd() cwd, err := os.Getwd()
@@ -77,9 +77,9 @@ func (s *StorageSingle) FindAvailableDBs(analysisReposRequested []common.OwnerRe
return return
} }
analysisRepos = &map[common.OwnerRepo]DBLocation{} analysisRepos = &map[common.NameWithOwner]DBLocation{}
not_found_repos = []common.OwnerRepo{} not_found_repos = []common.NameWithOwner{}
for _, rep := range analysisReposRequested { for _, rep := range analysisReposRequested {
dbPrefix := filepath.Join(cwd, "codeql", "dbs", rep.Owner, rep.Repo) dbPrefix := filepath.Join(cwd, "codeql", "dbs", rep.Owner, rep.Repo)
@@ -110,7 +110,7 @@ func ArtifactURL(js common.JobSpec, vaid int) (string, error) {
return "", nil return "", nil
} }
zfpath, err := PackageResults(ar, js.OwnerRepo, vaid) zfpath, err := PackageResults(ar, js.NameWithOwner, vaid)
if err != nil { if err != nil {
slog.Error("Error packaging results:", "error", err) slog.Error("Error packaging results:", "error", err)
return "", err return "", err
@@ -129,13 +129,13 @@ func GetResult(js common.JobSpec) common.AnalyzeResult {
return ar return ar
} }
func SetResult(sessionid int, orl common.OwnerRepo, ar common.AnalyzeResult) { func SetResult(sessionid int, orl common.NameWithOwner, ar common.AnalyzeResult) {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()
result[common.JobSpec{JobID: sessionid, OwnerRepo: orl}] = ar result[common.JobSpec{JobID: sessionid, NameWithOwner: orl}] = ar
} }
func PackageResults(ar common.AnalyzeResult, owre common.OwnerRepo, vaid int) (zipPath string, e error) { func PackageResults(ar common.AnalyzeResult, owre common.NameWithOwner, vaid int) (zipPath string, e error) {
slog.Debug("Readying zip file with .sarif/.bqrs", "analyze-result", ar) slog.Debug("Readying zip file with .sarif/.bqrs", "analyze-result", ar)
cwd, err := os.Getwd() cwd, err := os.Getwd()
@@ -210,10 +210,10 @@ func SetJobInfo(js common.JobSpec, ji common.JobInfo) {
info[js] = ji info[js] = ji
} }
func GetStatus(sessionid int, orl common.OwnerRepo) common.Status { func GetStatus(sessionid int, orl common.NameWithOwner) common.Status {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()
return status[common.JobSpec{JobID: sessionid, OwnerRepo: orl}] return status[common.JobSpec{JobID: sessionid, NameWithOwner: orl}]
} }
func ResultAsFile(path string) (string, []byte, error) { func ResultAsFile(path string) (string, []byte, error) {
@@ -231,10 +231,10 @@ func ResultAsFile(path string) (string, []byte, error) {
return fpath, file, nil return fpath, file, nil
} }
func SetStatus(sessionid int, orl common.OwnerRepo, s common.Status) { func SetStatus(sessionid int, orl common.NameWithOwner, s common.Status) {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()
status[common.JobSpec{JobID: sessionid, OwnerRepo: orl}] = s status[common.JobSpec{JobID: sessionid, NameWithOwner: orl}] = s
} }
func AddJob(sessionid int, job common.AnalyzeJob) { func AddJob(sessionid int, job common.AnalyzeJob) {