/
application_task.go
72 lines (62 loc) · 2.37 KB
/
application_task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Copyright 2021 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package fish
import (
"fmt"
"github.com/google/uuid"
"github.com/adobe/aquarium-fish/lib/log"
"github.com/adobe/aquarium-fish/lib/openapi/types"
"github.com/adobe/aquarium-fish/lib/util"
)
func (f *Fish) ApplicationTaskFindByApplication(uid types.ApplicationUID, filter *string) (at []types.ApplicationTask, err error) {
db := f.db.Where("application_uid = ?", uid)
if filter != nil {
secured_filter, err := util.ExpressionSqlFilter(*filter)
if err != nil {
log.Warn("Fish: SECURITY: weird SQL filter received:", err)
// We do not fail here because we should not give attacker more information
return at, nil
}
// Adding parentheses to be sure we're have `application_uid AND (filter)`
db = db.Where("(" + secured_filter + ")")
}
err = db.Find(&at).Error
return at, err
}
func (f *Fish) ApplicationTaskCreate(at *types.ApplicationTask) error {
if at.ApplicationUID == uuid.Nil {
return fmt.Errorf("Fish: ApplicationUID can't be unset")
}
if at.Task == "" {
return fmt.Errorf("Fish: Task can't be empty")
}
if at.Options == "" {
at.Options = util.UnparsedJson("{}")
}
if at.Result == "" {
at.Result = util.UnparsedJson("{}")
}
at.UID = f.NewUID()
return f.db.Create(at).Error
}
func (f *Fish) ApplicationTaskSave(at *types.ApplicationTask) error {
return f.db.Save(at).Error
}
func (f *Fish) ApplicationTaskGet(uid types.ApplicationTaskUID) (at *types.ApplicationTask, err error) {
at = &types.ApplicationTask{}
err = f.db.First(at, uid).Error
return at, err
}
func (f *Fish) ApplicationTaskListByApplicationAndWhen(app_uid types.ApplicationUID, when types.ApplicationStatus) (at []types.ApplicationTask, err error) {
err = f.db.Where(`application_uid = ? AND "when" = ?`, app_uid, when).Order("created_at desc").Find(&at).Error
return at, err
}