-
Notifications
You must be signed in to change notification settings - Fork 335
/
dal_connection.go
151 lines (117 loc) · 4.61 KB
/
dal_connection.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package types
import (
"database/sql/driver"
"encoding/json"
"time"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/cortezaproject/corteza/server/pkg/geolocation"
"github.com/cortezaproject/corteza/server/pkg/sql"
"github.com/cortezaproject/corteza/server/pkg/filter"
)
type (
DalConnection struct {
ID uint64 `json:"connectionID,string"`
Handle string `json:"handle"`
Type string `json:"type"`
// descriptions, notes, and other user-provided meta-data
Meta ConnectionMeta `json:"meta"`
// collection of configurations for various subsystems that
// use this connection and how it affects their behaviour
Config ConnectionConfig `json:"config"`
Issues []dal.Issue `json:"issues,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
CreatedBy uint64 `json:"createdBy,string" `
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
UpdatedBy uint64 `json:"updatedBy,string,omitempty"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
DeletedBy uint64 `json:"deletedBy,string,omitempty"`
}
// Meta ...................................................................
ConnectionMeta struct {
Name string `json:"name"`
Ownership string `json:"ownership"`
Location geolocation.Full `json:"location"`
Properties ConnectionMetaProperties `json:"properties"`
}
ConnectionMetaProperties struct {
DataAtRestEncryption ConnectionMetaProperty `json:"dataAtRestEncryption"`
DataAtRestProtection ConnectionMetaProperty `json:"dataAtRestProtection"`
DataAtTransitEncryption ConnectionMetaProperty `json:"dataAtTransitEncryption"`
DataRestoration ConnectionMetaProperty `json:"dataRestoration"`
}
ConnectionMetaProperty struct {
Enabled bool `json:"enabled"`
Notes string `json:"notes"`
}
// Config .................................................................
ConnectionConfig struct {
// DAL configuration
// using ptr to allow nil values (when dealing with access-controlled data)
DAL *ConnectionConfigDAL `json:"dal,omitempty"`
// Privacy configuration
Privacy ConnectionConfigPrivacy `json:"privacy"`
}
ConnectionConfigPrivacy struct {
// Sets max-allowed data-sensitivity level for this connection
//
// Fields of the modules using this connection should have equal or
// lower sensitivity level
SensitivityLevelID uint64 `json:"sensitivityLevelID,string,omitempty"`
}
// ConnectionConfigDAL a set of connection parameters
// and model configuration
ConnectionConfigDAL struct {
// type of connection
Type string `json:"type"`
// parameters for the connection
Params map[string]any `json:"params"`
// ident to be used when generating models from modules using this connection
// it can use {{module}} and {{namespace}} as placeholders
ModelIdent string `json:"modelIdent"`
// set of regular-expression strings that will be used to match against
// generated model identifiers
ModelIdentCheck []string `json:"modelIdentCheck"`
}
// ........................................................................
DalConnectionFilter struct {
DalConnectionID []string `json:"connectionID"`
Handle string `json:"handle"`
Type string `json:"type"`
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(*DalConnection) (bool, error) `json:"-"`
// Standard helpers for paging and sorting
filter.Paging
filter.Sorting
}
)
var (
// Used to identify the primary DAL connection instead of an extra flag
DalPrimaryConnectionResourceType = "corteza::system:primary-dal-connection"
DalPrimaryConnectionHandle = "primary-database"
)
func (c DalConnection) HasIssues() bool {
return len(c.Issues) > 0
}
func ParseConnectionConfig(ss []string) (m ConnectionConfig, err error) {
if len(ss) == 0 {
return
}
err = json.Unmarshal([]byte(ss[0]), &m)
return
}
func ParseConnectionMeta(ss []string) (m ConnectionMeta, err error) {
if len(ss) == 0 {
return
}
err = json.Unmarshal([]byte(ss[0]), &m)
return
}
func (nm *ConnectionConfig) Scan(src any) error { return sql.ParseJSON(src, nm) }
func (nm ConnectionConfig) Value() (driver.Value, error) { return json.Marshal(nm) }
func (nm *ConnectionMeta) Scan(src any) error { return sql.ParseJSON(src, nm) }
func (nm ConnectionMeta) Value() (driver.Value, error) { return json.Marshal(nm) }