-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.go
252 lines (187 loc) · 7.73 KB
/
database.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package db
import (
"github.com/erikbos/gatekeeper/pkg/types"
)
type (
// Database is our overall database interface
Database struct {
Listener
Route
Cluster
Organization
Developer
DeveloperApp
Key
Company
APIProduct
OAuth
User
Role
Audit
}
// Listener is the listener information storage interface
Listener interface {
// GetAll retrieves all listeners
GetAll() (types.Listeners, types.Error)
// Get retrieves a listener
Get(listener string) (*types.Listener, types.Error)
// Update updates a listener
Update(listener *types.Listener) types.Error
// Delete deletes a listener
Delete(listenerToDelete string) types.Error
}
// Route the route information storage interface
Route interface {
// GetAll retrieves all routes
GetAll() (types.Routes, types.Error)
// Get retrieves a route from database
Get(routeName string) (*types.Route, types.Error)
// Update UPSERTs an route
Update(route *types.Route) types.Error
// Delete deletes a route
Delete(routeToDelete string) types.Error
}
// Cluster the cluster information storage interface
Cluster interface {
// GetAll retrieves all clusters
GetAll() (types.Clusters, types.Error)
// Get retrieves a cluster from database
Get(clusterName string) (*types.Cluster, types.Error)
// Update UPSERTs an cluster in database
Update(c *types.Cluster) types.Error
// Update UPSERTs an cluster in database
Delete(clusterToDelete string) types.Error
}
Organization interface {
// GetAll retrieves all users
GetAll() (types.Organizations, types.Error)
// Get retrieves a user from database
Get(userName string) (*types.Organization, types.Error)
// Update UPSERTs an user in database
Update(c *types.Organization) types.Error
// Update UPSERTs an user in database
Delete(organizationToDelete string) types.Error
}
// Developer the developer information storage interface
Developer interface {
// GetAll retrieves all developer
GetAll(organizationName string) (types.Developers, types.Error)
// GetByEmail retrieves a developer
GetByEmail(organizationName, developerEmail string) (*types.Developer, types.Error)
// GetByID retrieves a developer
GetByID(organizationName, developerID string) (*types.Developer, types.Error)
// Update UPSERTs a developer
Update(organizationName string, dev *types.Developer) types.Error
// DeleteByID deletes a developer
DeleteByID(organizationName, developerID string) types.Error
}
// DeveloperApp the developer app information storage interface
DeveloperApp interface {
// GetAll retrieves all developer apps
GetAll(organizationName string) (types.DeveloperApps, types.Error)
// GetAllByDeveloperID retrieves all developer apps from one developer
GetAllByDeveloperID(organizationName, developerID string) (types.DeveloperApps, types.Error)
// GetByName returns a developer app
GetByName(organizationName, developerEmail, developerAppName string) (*types.DeveloperApp, types.Error)
// GetByID returns a developer app
GetByID(organizationName, developerAppID string) (*types.DeveloperApp, types.Error)
// GetCountByDeveloperID retrieves number of apps belonging to a developer
GetCountByDeveloperID(organizationName, developerID string) (int, types.Error)
// UpdateByName UPSERTs a developer app
Update(organizationName string, app *types.DeveloperApp) types.Error
// DeleteByID deletes a developer app
DeleteByID(organizationName, developerAppID string) types.Error
}
// Key the key information storage interface
Key interface {
// GetByKey returns details of a single apikey
GetByKey(organizationName, key *string) (*types.Key, types.Error)
// GetCountByAPIProductName returns number of keys that has apiproduct assigned
GetCountByAPIProductName(organizationName, apiProductName string) (int, types.Error)
// GetByDeveloperAppID returns an array with apikey details of a developer app
GetByDeveloperAppID(organizationName, developerAppID string) (types.Keys, types.Error)
// UpdateByKey UPSERTs key
UpdateByKey(organizationName string, c *types.Key) types.Error
// DeleteByKey deletes key
DeleteByKey(organizationName, consumerKey string) types.Error
}
// Company the company information storage interface
Company interface {
GetAll(organizationName string) (types.Companies, types.Error)
Get(organizationName, companyName string) (*types.Company, types.Error)
Update(organizationName string, c *types.Company) types.Error
Delete(organizationName, company string) types.Error
}
// APIProduct the apiproduct information storage interface
APIProduct interface {
// GetAll retrieves all api products
GetAll(organizationName string) (types.APIProducts, types.Error)
// Get returns an apiproduct
Get(organizationName, apiproductName string) (*types.APIProduct, types.Error)
// Update UPSERTs an apiproduct in database
Update(organizationName string, p *types.APIProduct) types.Error
// Delete deletes an apiproduct
Delete(organizationName, apiProduct string) types.Error
}
// OAuth the oauth information storage interface
OAuth interface {
// OAuthAccessTokenGetByAccess retrieves an access token
OAuthAccessTokenGetByAccess(accessToken string) (*types.OAuthAccessToken, error)
// OAuthAccessTokenGetByCode retrieves token by code
OAuthAccessTokenGetByCode(code string) (*types.OAuthAccessToken, error)
// OAuthAccessTokenGetByRefresh retrieves token by refreshcode
OAuthAccessTokenGetByRefresh(refresh string) (*types.OAuthAccessToken, error)
// OAuthAccessTokenCreate creates an access token
OAuthAccessTokenCreate(t *types.OAuthAccessToken) error
// OAuthAccessTokenRemoveByAccess deletes an access token
OAuthAccessTokenRemoveByAccess(accessTokenToDelete string) error
// OAuthAccessTokenRemoveByCode deletes an access token
OAuthAccessTokenRemoveByCode(codeToDelete string) error
// OAuthAccessTokenRemoveByRefresh deletes an access token
OAuthAccessTokenRemoveByRefresh(refreshToDelete string) error
}
// User the user information storage interface
User interface {
// GetAll retrieves all users
GetAll() (types.Users, types.Error)
// Get retrieves a user from database
Get(userName string) (*types.User, types.Error)
// Update UPSERTs an user in database
Update(c *types.User) types.Error
// Update UPSERTs an user in database
Delete(userToDelete string) types.Error
}
// Role the role information storage interface
Role interface {
// GetAll retrieves all roles
GetAll() (types.Roles, types.Error)
// Get retrieves a role
Get(roleName string) (*types.Role, types.Error)
// Update UPSERTs a role
Update(c *types.Role) types.Error
// Delete removes a role
Delete(roleToDelete string) types.Error
}
Audit interface {
// GetOrganization retrieves audit records of an organization
GetOrganization(organizationName string, params AuditFilterParams) (types.Audits, types.Error)
// GetAPIProduct retrieves audit records of an apiproduct
GetAPIProduct(organizationName, apiproductName string, params AuditFilterParams) (types.Audits, types.Error)
// GetDeveloper retrieves audit records of a developer
GetDeveloper(organizationName, developerID string, params AuditFilterParams) (types.Audits, types.Error)
// GetApplication retrieves audit records of an application
GetApplication(organizationName, developerID, appID string, params AuditFilterParams) (types.Audits, types.Error)
// GetUser retrieves audit records of a user
GetUser(auditName string, params AuditFilterParams) (types.Audits, types.Error)
// Write inserts an audit record
Write(l *types.Audit) types.Error
}
AuditFilterParams struct {
// Start timestamp in epoch milliseconds
StartTime int64
// End timestamp in epoch milliseconds
EndTime int64
// Maximum number of entities to return
Count int64
}
)