From feba722a539c8d8063ce139889db4923cb0c70f0 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Thu, 22 Jun 2023 06:26:19 +0200 Subject: [PATCH] Refactor and Cleanup Add SecurityCheck --- internal/graph/schema.resolvers.go | 2 +- internal/repository/job.go | 8 +++++++- internal/repository/query.go | 16 ---------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/internal/graph/schema.resolvers.go b/internal/graph/schema.resolvers.go index 03e74df..571a8b9 100644 --- a/internal/graph/schema.resolvers.go +++ b/internal/graph/schema.resolvers.go @@ -40,7 +40,7 @@ func (r *jobResolver) ConcurrentJobs( } if obj.Exclusive != 1 && obj.Duration > 600 { - return r.Repo.FindConcurrentJobs(obj) + return r.Repo.FindConcurrentJobs(ctx, obj) } return nil, nil diff --git a/internal/repository/job.go b/internal/repository/job.go index 922db07..c58748b 100644 --- a/internal/repository/job.go +++ b/internal/repository/job.go @@ -293,12 +293,18 @@ func (r *JobRepository) FindById(jobId int64) (*schema.Job, error) { } func (r *JobRepository) FindConcurrentJobs( + ctx context.Context, job *schema.Job) (*model.JobLinkResultList, error) { if job == nil { return nil, nil } - query := sq.Select("job.id", "job.job_id").From("job").Where("cluster = ?", job.Cluster) + query, qerr := SecurityCheck(ctx, sq.Select("job.id", "job.job_id").From("job")) + if qerr != nil { + return nil, qerr + } + + query = query.Where("cluster = ?", job.Cluster) var startTime int64 var stopTime int64 diff --git a/internal/repository/query.go b/internal/repository/query.go index f047da2..dd43dd7 100644 --- a/internal/repository/query.go +++ b/internal/repository/query.go @@ -86,7 +86,6 @@ func (r *JobRepository) QueryJobs( order *model.OrderByInput) ([]*schema.Job, error) { query, qerr := SecurityCheck(ctx, sq.Select(jobColumns...).From("job")) - if qerr != nil { return nil, qerr } @@ -223,21 +222,6 @@ func BuildWhereClause(filter *model.JobFilter, query sq.SelectBuilder) sq.Select if filter.MemUsedMax != nil { query = buildFloatCondition("job.mem_used_max", filter.MemUsedMax, query) } - // Shared Jobs Query - if filter.Exclusive != nil { - query = query.Where("job.exclusive = ?", *filter.Exclusive) - } - if filter.SharedNode != nil { - query = buildStringCondition("job.resources", filter.SharedNode, query) - } - if filter.SelfJobID != nil { - query = buildStringCondition("job.job_id", filter.SelfJobID, query) - } - if filter.SelfStartTime != nil && filter.SelfDuration != nil { - start := filter.SelfStartTime.Unix() + 10 // There does not seem to be a portable way to get the current unix timestamp accross different DBs. - end := start + int64(*filter.SelfDuration) - 20 - query = query.Where("((job.start_time BETWEEN ? AND ?) OR ((job.start_time + job.duration) BETWEEN ? AND ?))", start, end, start, end) - } return query }