-
Notifications
You must be signed in to change notification settings - Fork 7
/
abs.go
269 lines (232 loc) · 9.72 KB
/
abs.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package service
import (
"context"
"github.com/apibrew/apibrew/pkg/abs"
"github.com/apibrew/apibrew/pkg/errors"
"github.com/apibrew/apibrew/pkg/formats/unstructured"
"github.com/apibrew/apibrew/pkg/model"
"github.com/apibrew/apibrew/pkg/resource_model"
"github.com/apibrew/apibrew/pkg/stub"
"github.com/apibrew/apibrew/pkg/util/jwt-model"
"google.golang.org/protobuf/types/known/structpb"
"time"
)
type AuthenticationService interface {
Init(config *model.AppConfig)
Authenticate(ctx context.Context, username string, password string, term model.TokenTerm, minimizeToken bool) (*model.Token, errors.ServiceError)
AuthenticateWithoutPassword(ctx context.Context, username string, term model.TokenTerm) (*model.Token, errors.ServiceError)
RenewToken(ctx context.Context, token string, term model.TokenTerm) (*model.Token, errors.ServiceError)
GetToken(ctx context.Context) (*jwt_model.UserDetails, errors.ServiceError)
ParseAndVerifyToken(token string) (*jwt_model.UserDetails, errors.ServiceError)
AuthenticationDisabled() bool
}
type AuthorizationService interface {
CheckRecordAccess(ctx context.Context, params CheckRecordAccessParams) errors.ServiceError
CheckRecordAccessWithRecordSelector(ctx context.Context, params CheckRecordAccessParams) (*resource_model.BooleanExpression, errors.ServiceError)
CheckIsExtensionController(ctx context.Context) errors.ServiceError
}
type BackendProviderService interface {
abs.BackendRecordsInterface
abs.BackendActionExecutor
DestroyDataSource(ctx context.Context, dataSourceName string) errors.ServiceError
ListEntities(ctx context.Context, dataSourceId string) ([]*model.DataSourceCatalog, errors.ServiceError)
PrepareResourceFromEntity(ctx context.Context, dataSourceName string, catalog, entity string) (*model.Resource, errors.ServiceError)
UpgradeResource(ctx context.Context, dataSourceName string, params abs.UpgradeResourceParams) errors.ServiceError
GetStatus(ctx context.Context, dataSourceId string) (connectionAlreadyInitiated bool, testConnection bool, err errors.ServiceError)
Init(config *model.AppConfig)
SetSchema(schema *abs.Schema)
}
type DataSourceService interface {
Init(config *model.AppConfig)
ListEntities(ctx context.Context, id string) ([]*model.DataSourceCatalog, errors.ServiceError)
GetStatus(ctx context.Context, id string) (connectionAlreadyInitiated bool, testConnection bool, err errors.ServiceError)
PrepareResourceFromEntity(ctx context.Context, dataSourceId string, catalog, entity string) (*model.Resource, errors.ServiceError)
Delete(ctx context.Context, ids []string) errors.ServiceError
}
type RecordService interface {
Init(config *model.AppConfig)
PrepareQuery(resource *model.Resource, queryMap map[string]string) (*model.BooleanExpression, errors.ServiceError)
GetRecord(ctx context.Context, namespace, resourceName, id string, references []string) (*model.Record, errors.ServiceError)
FindBy(ctx context.Context, namespace, resourceName, propertyName string, value string) (*model.Record, errors.ServiceError)
ResolveReferences(ctx context.Context, resource *model.Resource, records []*model.Record, referencesToResolve []string) errors.ServiceError
List(ctx context.Context, params RecordListParams) ([]*model.Record, uint32, errors.ServiceError)
Create(ctx context.Context, params RecordCreateParams) ([]*model.Record, errors.ServiceError)
Update(ctx context.Context, params RecordUpdateParams) ([]*model.Record, errors.ServiceError)
Apply(ctx context.Context, params RecordUpdateParams) ([]*model.Record, errors.ServiceError)
Get(ctx context.Context, params RecordGetParams) (*model.Record, errors.ServiceError)
Delete(ctx context.Context, params RecordDeleteParams) errors.ServiceError
ExecuteAction(ctx context.Context, params ExecuteActionParams) (unstructured.Unstructured, errors.ServiceError)
Load(ctx context.Context, namespace string, name string, properties map[string]*structpb.Value, listParams RecordLoadParams) (*model.Record, errors.ServiceError)
}
type ResourceService interface {
Init(config *model.AppConfig)
GetResourceByName(ctx context.Context, namespace, resource string) (*model.Resource, errors.ServiceError)
GetSystemResourceByName(ctx context.Context, resourceName string) (*model.Resource, errors.ServiceError)
Create(ctx context.Context, resource *model.Resource, doMigration bool, forceMigration bool) (*model.Resource, errors.ServiceError)
Update(ctx context.Context, resource *model.Resource, doMigration bool, forceMigration bool) errors.ServiceError
Delete(ctx context.Context, ids []string, doMigration bool, forceMigration bool) errors.ServiceError
List(ctx context.Context) ([]*model.Resource, errors.ServiceError)
Get(ctx context.Context, id string) (*model.Resource, errors.ServiceError)
GetSchema() *abs.Schema
PrepareResourceMigrationPlan(ctx context.Context, resources []*model.Resource, prepareFromDataSource bool) ([]*model.ResourceMigrationPlan, errors.ServiceError)
LocateReferences(resource *model.Resource, resolve []string) []string
LocateLocalReferences(resource *model.Resource) []string
LocateResourceByReference(resource *model.Resource, reference *model.Reference) *model.Resource
}
type ResourceMigrationService interface {
PreparePlan(ctx context.Context, existingResource *model.Resource, resource *model.Resource) (*model.ResourceMigrationPlan, errors.ServiceError)
}
type MetricsService interface {
Init(config *model.AppConfig)
GetMetrics(req MetricsRequest) ([]MetricsResponseItem, errors.ServiceError)
}
type AuditService interface {
Init(config *model.AppConfig)
}
type StatsService interface {
Init(config *model.AppConfig)
}
type WatchService interface {
Watch(ctx context.Context, params WatchParams) (<-chan *model.Event, errors.ServiceError)
WatchResource(ctx context.Context, params WatchParams) (<-chan *model.Event, errors.ServiceError)
}
type EventChannelService interface {
Exec(ctx context.Context, channelKey string, event *model.Event) (*model.Event, errors.ServiceError)
PollEvents(ctx context.Context, channelKey string) (chan *model.Event, errors.ServiceError)
WriteEvent(ctx context.Context, proto *model.Event) errors.ServiceError
Init(config *model.AppConfig)
}
type ExternalService interface {
Call(ctx context.Context, all resource_model.ExternalCall, event *model.Event) (*model.Event, errors.ServiceError)
}
type ExtensionService interface {
RegisterExtension(*resource_model.Extension)
UnRegisterExtension(*resource_model.Extension)
Init(config *model.AppConfig)
Reload()
}
type CheckRecordAccessParams struct {
Resource *model.Resource
Records *[]*model.Record
Operation resource_model.PermissionOperation
}
type WatchParams struct {
Selector *model.EventSelector
BufferSize int
}
type WatchResourceParams struct {
Selector *model.EventSelector
BufferSize int
}
type RecordListParams struct {
Query *model.BooleanExpression
Namespace string
Resource string
Limit uint32
Offset uint64
UseHistory bool
ResolveReferences []string
ResultChan chan<- *model.Record
PackRecords bool
Filters map[string]string
Aggregation *model.Aggregation
Sorting *model.Sorting
}
type RecordLoadParams struct {
UseHistory bool
ResolveReferences []string
}
func (p RecordListParams) ToRequest() *stub.ListRecordRequest {
return &stub.ListRecordRequest{
Namespace: p.Namespace,
Resource: p.Resource,
Filters: p.Filters,
Limit: p.Limit,
Offset: p.Offset,
UseHistory: p.UseHistory,
ResolveReferences: p.ResolveReferences,
}
}
type RecordCreateParams struct {
Namespace string
Resource string
Records []*model.Record
}
func (p RecordCreateParams) ToRequest() *stub.CreateRecordRequest {
return &stub.CreateRecordRequest{
Namespace: p.Namespace,
Resource: p.Resource,
Records: p.Records,
}
}
type RecordUpdateParams struct {
Namespace string
Resource string
Records []*model.Record
}
func (p RecordUpdateParams) ToRequest() *stub.UpdateRecordRequest {
return &stub.UpdateRecordRequest{
Namespace: p.Namespace,
Resource: p.Resource,
Records: p.Records,
}
}
type RecordGetParams struct {
Namespace string
Resource string
Id string
ResolveReferences []string
}
type RecordDeleteParams struct {
Namespace string
Resource string
Ids []string
}
type ExecuteActionParams struct {
Namespace string
Resource string
Id string
ActionName string
Input unstructured.Unstructured
}
func (p RecordDeleteParams) ToRequest() *stub.DeleteRecordRequest {
return &stub.DeleteRecordRequest{
Namespace: p.Namespace,
Resource: p.Resource,
Ids: p.Ids,
}
}
type MetricsOperation string
const (
MetricsOperationRead MetricsOperation = "read"
MetricsOperationWrite MetricsOperation = "write"
MetricsOperationDelete MetricsOperation = "delete"
)
type MetricsInterval string
const (
MetricsIntervalMinute MetricsInterval = "minute"
MetricsIntervalHour MetricsInterval = "hour"
MetricsIntervalDay MetricsInterval = "day"
MetricsIntervalWeek MetricsInterval = "week"
MetricsIntervalMonth MetricsInterval = "month"
)
type MetricsRequest struct {
Namespace *string `json:"namespace"`
Resource *string `json:"resource"`
Operation *MetricsOperation `json:"operation"`
Interval *MetricsInterval `json:"interval"`
From *time.Time
To *time.Time
}
type MetricsResponseItem struct {
Namespace string `json:"namespace"`
Resource string `json:"resource"`
Interval MetricsInterval `json:"interval"`
Operation MetricsOperation `json:"operation"`
Time time.Time `json:"time"`
Count uint64 `json:"count"`
}
type Module interface {
Init()
}
type ModuleConstructor func(container Container) Module