-
Notifications
You must be signed in to change notification settings - Fork 335
/
applications.go
104 lines (81 loc) · 2.73 KB
/
applications.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package types
import (
"database/sql/driver"
"encoding/json"
"time"
"github.com/cortezaproject/corteza/server/pkg/sql"
"github.com/cortezaproject/corteza/server/pkg/filter"
)
type (
Application struct {
ID uint64 `json:"applicationID,string"`
Name string `json:"name"`
OwnerID uint64 `json:"ownerID"`
Enabled bool `json:"enabled"`
Weight int `json:"weight"`
Unify *ApplicationUnify `json:"unify,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Flags []string `json:"flags,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
ApplicationUnify struct {
Name string `json:"name,omitempty"`
Listed bool `json:"listed"`
Url string `json:"url"`
Config string `json:"config"`
// Temporary icon & logo URLs
// @todo rework this when we rework attachment management
Icon string `json:"icon,omitempty"`
IconID uint64 `json:"iconID,string"`
Logo string `json:"logo,omitempty"`
LogoID uint64 `json:"logoID,string"`
}
ApplicationFilter struct {
ApplicationID []string `json:"applicationID"`
Name string `json:"name"`
Query string `json:"query"`
LabeledIDs []uint64 `json:"-"`
Labels map[string]string `json:"labels,omitempty"`
FlaggedIDs []uint64 `json:"-"`
Flags []string `json:"flags,omitempty"`
IncFlags uint `json:"-"`
Deleted filter.State `json:"deleted"`
// Check fn is called by store backend for each resource found function can
// modify the resource and return false if store should not return it
//
// Store then loads additional resources to satisfy the paging parameters
Check func(*Application) (bool, error) `json:"-"`
// Standard helpers for paging and sorting
filter.Sorting
filter.Paging
}
ApplicationMetrics struct {
Total uint `json:"total"`
Deleted uint `json:"deleted"`
Valid uint `json:"valid"`
}
)
func (a *Application) Valid() bool {
return a.ID > 0 && a.DeletedAt == nil
}
func (au *ApplicationUnify) Scan(src any) error { return sql.ParseJSON(src, au) }
func (au ApplicationUnify) Value() (driver.Value, error) { return json.Marshal(au) }
// // // These will get generated later on
// SetFlags adds new label to label map
func (a *Application) SetFlags(flags []string) {
a.Flags = flags
}
// GetFlags returns current flags on the resource
func (a *Application) GetFlags() []string {
return a.Flags
}
// FlagResourceKind returns the resource kind for the flag
func (*Application) FlagResourceKind() string {
return "system:application"
}
// GetLabels adds new label to label map
func (a *Application) FlagResourceID() uint64 {
return a.ID
}