Fully implement local and container MRVA
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package common
|
||||
|
||||
type JobInfo struct {
|
||||
QueryLanguage string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
|
||||
QueryLanguage string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
SkippedRepositories SkippedRepositories
|
||||
}
|
||||
|
||||
@@ -16,8 +15,8 @@ type SkippedRepositories struct {
|
||||
}
|
||||
|
||||
type AccessMismatchRepos struct {
|
||||
RepositoryCount int `json:"repository_count"`
|
||||
Repositories []string `json:"repositories"`
|
||||
RepositoryCount int `json:"repository_count"`
|
||||
Repositories []Repository `json:"repositories"`
|
||||
}
|
||||
|
||||
type NotFoundRepos struct {
|
||||
@@ -26,13 +25,13 @@ type NotFoundRepos struct {
|
||||
}
|
||||
|
||||
type NoCodeqlDBRepos struct {
|
||||
RepositoryCount int `json:"repository_count"`
|
||||
Repositories []string `json:"repositories"`
|
||||
RepositoryCount int `json:"repository_count"`
|
||||
Repositories []Repository `json:"repositories"`
|
||||
}
|
||||
|
||||
type OverLimitRepos struct {
|
||||
RepositoryCount int `json:"repository_count"`
|
||||
Repositories []string `json:"repositories"`
|
||||
RepositoryCount int `json:"repository_count"`
|
||||
Repositories []Repository `json:"repositories"`
|
||||
}
|
||||
|
||||
type StatusResponse struct {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package common
|
||||
|
||||
type Common interface {
|
||||
}
|
||||
29
pkg/common/jobspec.go
Normal file
29
pkg/common/jobspec.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// EncodeJobSpec encodes a JobSpec into a base64-encoded string.
|
||||
func EncodeJobSpec(jobSpec JobSpec) (string, error) {
|
||||
data, err := json.Marshal(jobSpec)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.URLEncoding.EncodeToString(data), nil
|
||||
}
|
||||
|
||||
// DecodeJobSpec decodes a base64-encoded string into a JobSpec.
|
||||
func DecodeJobSpec(encoded string) (JobSpec, error) {
|
||||
data, err := base64.URLEncoding.DecodeString(encoded)
|
||||
if err != nil {
|
||||
return JobSpec{}, err
|
||||
}
|
||||
var jobSpec JobSpec
|
||||
err = json.Unmarshal(data, &jobSpec)
|
||||
if err != nil {
|
||||
return JobSpec{}, err
|
||||
}
|
||||
return jobSpec, nil
|
||||
}
|
||||
38
pkg/common/minio.go
Normal file
38
pkg/common/minio.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
func CreateMinIOBucketIfNotExists(client *minio.Client, bucketName string) error {
|
||||
ctx := context.Background()
|
||||
|
||||
exists, err := client.BucketExists(ctx, bucketName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
slog.Info("Creating bucket", "name", bucketName)
|
||||
err = client.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{})
|
||||
if err != nil {
|
||||
// The bucket might already exist at this stage if another component created it concurrently.
|
||||
// For example, the server might have attempted to create it at the same time as the agent.
|
||||
if err.(minio.ErrorResponse).Code == "BucketAlreadyOwnedByYou" {
|
||||
slog.Info("Failed to create bucket because it already exists", "name", bucketName)
|
||||
return nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
slog.Info("Bucket created successfully", "name", bucketName)
|
||||
}
|
||||
} else {
|
||||
slog.Info("Bucket already exists", "name", bucketName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -6,26 +6,6 @@ type NameWithOwner struct {
|
||||
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 {
|
||||
RequestId int // json:"request_id"
|
||||
QueryPackId int // json:"query_pack_id"
|
||||
QueryPackURL string // json:"query_pack_url"
|
||||
QueryLanguage string // json:"query_language"
|
||||
NWO NameWithOwner // json:"nwo"
|
||||
}
|
||||
|
||||
// AnalyzeResult represents the result of an analysis job.
|
||||
// This is the message format that the agent sends to the queue.
|
||||
// Status will only ever be StatusSuccess or StatusError when sent in a result.
|
||||
type AnalyzeResult struct {
|
||||
Status Status // json:"status"
|
||||
RequestId int // json:"request_id"
|
||||
ResultCount int // json:"result_count"
|
||||
ResultArchiveURL string // json:"result_archive_url"
|
||||
}
|
||||
|
||||
// Status represents the status of a job.
|
||||
type Status int
|
||||
|
||||
@@ -55,6 +35,6 @@ func (s Status) ToExternalString() string {
|
||||
}
|
||||
|
||||
type JobSpec struct {
|
||||
JobID int
|
||||
SessionID int
|
||||
NameWithOwner
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user