mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Refactor and Cleanup
Add SecurityCheck
This commit is contained in:
parent
bb7c1005c9
commit
feba722a53
@ -40,7 +40,7 @@ func (r *jobResolver) ConcurrentJobs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if obj.Exclusive != 1 && obj.Duration > 600 {
|
if obj.Exclusive != 1 && obj.Duration > 600 {
|
||||||
return r.Repo.FindConcurrentJobs(obj)
|
return r.Repo.FindConcurrentJobs(ctx, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -293,12 +293,18 @@ func (r *JobRepository) FindById(jobId int64) (*schema.Job, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *JobRepository) FindConcurrentJobs(
|
func (r *JobRepository) FindConcurrentJobs(
|
||||||
|
ctx context.Context,
|
||||||
job *schema.Job) (*model.JobLinkResultList, error) {
|
job *schema.Job) (*model.JobLinkResultList, error) {
|
||||||
if job == nil {
|
if job == nil {
|
||||||
return nil, 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 startTime int64
|
||||||
var stopTime int64
|
var stopTime int64
|
||||||
|
|
||||||
|
@ -86,7 +86,6 @@ func (r *JobRepository) QueryJobs(
|
|||||||
order *model.OrderByInput) ([]*schema.Job, error) {
|
order *model.OrderByInput) ([]*schema.Job, error) {
|
||||||
|
|
||||||
query, qerr := SecurityCheck(ctx, sq.Select(jobColumns...).From("job"))
|
query, qerr := SecurityCheck(ctx, sq.Select(jobColumns...).From("job"))
|
||||||
|
|
||||||
if qerr != nil {
|
if qerr != nil {
|
||||||
return nil, qerr
|
return nil, qerr
|
||||||
}
|
}
|
||||||
@ -223,21 +222,6 @@ func BuildWhereClause(filter *model.JobFilter, query sq.SelectBuilder) sq.Select
|
|||||||
if filter.MemUsedMax != nil {
|
if filter.MemUsedMax != nil {
|
||||||
query = buildFloatCondition("job.mem_used_max", filter.MemUsedMax, query)
|
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
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user