/
interfaces.go
189 lines (176 loc) · 9.63 KB
/
interfaces.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
package dao
import (
m "github.com/RedHatInsights/sources-api-go/model"
"github.com/RedHatInsights/sources-api-go/util"
"github.com/redhatinsights/platform-go-middlewares/identity"
)
type SourceDao interface {
// List lists all the sources from a given tenant, which should be specified in the request.
List(limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
// ListInternal lists all the existing sources.
ListInternal(limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
GetById(id *int64) (*m.Source, error)
Create(src *m.Source) error
Update(src *m.Source) error
Delete(id *int64) (*m.Source, error)
Tenant() *int64
User() *int64
NameExistsInCurrentTenant(name string) bool
GetByIdWithPreload(id *int64, preloads ...string) (*m.Source, error)
// ListForRhcConnection gets all the sources that are related to a given rhcConnection id.
ListForRhcConnection(rhcConnectionId *int64, limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
BulkMessage(resource util.Resource) (map[string]interface{}, error)
FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
ToEventJSON(resource util.Resource) ([]byte, error)
// Pause pauses the given source and all its dependant applications.
Pause(id int64) error
// Unpause resumes the given source and all its dependant applications.
Unpause(id int64) error
IsSuperkey(id int64) bool
// DeleteCascade deletes the source along with all its related sub resources. It returns all the deleted
// sub resources and the source itself.
DeleteCascade(sourceId int64) ([]m.ApplicationAuthentication, []m.Application, []m.Endpoint, []m.RhcConnection, *m.Source, error)
// Exists returns true if the source exists.
Exists(sourceId int64) (bool, error)
}
type ApplicationDao interface {
List(limit, offset int, filters []util.Filter) ([]m.Application, int64, error)
SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.Application, int64, error)
GetById(id *int64) (*m.Application, error)
Create(src *m.Application) error
Update(src *m.Application) error
Delete(id *int64) (*m.Application, error)
Tenant() *int64
User() *int64
BulkMessage(resource util.Resource) (map[string]interface{}, error)
FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
ToEventJSON(resource util.Resource) ([]byte, error)
// Pause pauses the application.
Pause(id int64) error
// Unpause resumes the application.
Unpause(id int64) error
GetByIdWithPreload(id *int64, preloads ...string) (*m.Application, error)
IsSuperkey(id int64) bool
// DeleteCascade deletes the application along with all its related application authentications.
DeleteCascade(applicationId int64) ([]m.ApplicationAuthentication, *m.Application, error)
// Exists returns true if the application exists.
Exists(applicationId int64) (bool, error)
}
type AuthenticationDao interface {
List(limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
GetById(id string) (*m.Authentication, error)
ListForSource(sourceID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
ListForApplication(applicationID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
ListForApplicationAuthentication(appAuthID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
ListForEndpoint(endpointID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
Create(src *m.Authentication) error
BulkCreate(src *m.Authentication) error
Update(src *m.Authentication) error
Delete(id string) (*m.Authentication, error)
Tenant() *int64
AuthenticationsByResource(authentication *m.Authentication) ([]m.Authentication, error)
BulkMessage(resource util.Resource) (map[string]interface{}, error)
FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
ToEventJSON(resource util.Resource) ([]byte, error)
// ListIdsForResource fetches all the authentication IDs for the given resource. The rest of the fields will be
// either nil or default values.
ListIdsForResource(resourceType string, resourceIds []int64) ([]m.Authentication, error)
// BulkDelete deletes all the authentications given as a list, and returns the ones that were deleted.
BulkDelete(authentications []m.Authentication) ([]m.Authentication, error)
}
type ApplicationAuthenticationDao interface {
List(limit, offset int, filters []util.Filter) ([]m.ApplicationAuthentication, int64, error)
GetById(id *int64) (*m.ApplicationAuthentication, error)
Create(src *m.ApplicationAuthentication) error
Update(src *m.ApplicationAuthentication) error
Delete(id *int64) (*m.ApplicationAuthentication, error)
Tenant() *int64
ApplicationAuthenticationsByResource(resourceType string, applications []m.Application, authentications []m.Authentication) ([]m.ApplicationAuthentication, error)
}
type ApplicationTypeDao interface {
List(limit, offset int, filters []util.Filter) ([]m.ApplicationType, int64, error)
SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.ApplicationType, int64, error)
GetById(id *int64) (*m.ApplicationType, error)
Create(src *m.ApplicationType) error
Update(src *m.ApplicationType) error
Delete(id *int64) error
ApplicationTypeCompatibleWithSource(typeId, sourceId int64) error
GetSuperKeyResultType(applicationTypeId int64, authType string) (string, error)
ApplicationTypeCompatibleWithSourceType(appTypeId, sourceTypeId int64) error
GetByName(name string) (*m.ApplicationType, error)
}
type EndpointDao interface {
List(limit, offset int, filters []util.Filter) ([]m.Endpoint, int64, error)
SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.Endpoint, int64, error)
GetById(id *int64) (*m.Endpoint, error)
Create(src *m.Endpoint) error
Update(src *m.Endpoint) error
Delete(id *int64) (*m.Endpoint, error)
Tenant() *int64
// CanEndpointBeSetAsDefaultForSource checks if the endpoint can be set as default, by checking if the given source
// id already has another endpoint marked as default.
CanEndpointBeSetAsDefaultForSource(sourceId int64) bool
// IsRoleUniqueForSource checks if the role is unique for the given source ID.
IsRoleUniqueForSource(role string, sourceId int64) bool
// SourceHasEndpoints returns true if the provided source has any associated endpoints.
SourceHasEndpoints(sourceId int64) bool
BulkMessage(resource util.Resource) (map[string]interface{}, error)
FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
ToEventJSON(resource util.Resource) ([]byte, error)
// Exists returns true if the endpoint exists.
Exists(endpointId int64) (bool, error)
}
type MetaDataDao interface {
List(limit, offset int, filters []util.Filter) ([]m.MetaData, int64, error)
SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.MetaData, int64, error)
GetById(id *int64) (*m.MetaData, error)
GetSuperKeySteps(applicationTypeId int64) ([]m.MetaData, error)
GetSuperKeyAccountNumber(applicationTypeId int64) (string, error)
ApplicationOptedIntoRetry(applicationTypeId int64) (bool, error)
}
type SecretDao interface {
Create(src *m.Authentication) error
Delete(id *int64) error
GetById(id *int64) (*m.Authentication, error)
List(limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
NameExistsInCurrentTenant(name string) bool
Update(src *m.Authentication) error
}
type SourceTypeDao interface {
List(limit, offset int, filters []util.Filter) ([]m.SourceType, int64, error)
GetById(id *int64) (*m.SourceType, error)
Create(src *m.SourceType) error
Update(src *m.SourceType) error
Delete(id *int64) error
GetByName(name string) (*m.SourceType, error)
}
type RhcConnectionDao interface {
List(limit, offset int, filters []util.Filter) ([]m.RhcConnection, int64, error)
GetById(id *int64) (*m.RhcConnection, error)
Create(rhcConnection *m.RhcConnection) (*m.RhcConnection, error)
Update(rhcConnection *m.RhcConnection) error
Delete(id *int64) (*m.RhcConnection, error)
// ListForSource gets all the related connections to the given source id.
ListForSource(sourceId *int64, limit, offset int, filters []util.Filter) ([]m.RhcConnection, int64, error)
}
type TenantDao interface {
// GetOrCreateTenant returns the tenant associated with the provided identity. It tries to fetch the tenant by its
// OrgId, and if it is not present, by its EBS account number.
GetOrCreateTenant(identity *identity.Identity) (*m.Tenant, error)
// TenantByIdentity returns the tenant associated to the given identity. It tries to fetch the tenant by its OrgId,
// and if it is not preset, by its EBS account number.
TenantByIdentity(identity *identity.Identity) (*m.Tenant, error)
// GetUntranslatedTenants returns a list of tenants which only have an EBS account number and not a corresponding
// OrgId.
GetUntranslatedTenants() ([]m.Tenant, error)
// TranslateTenants attempts to translate tenants which only have an EBS account number. It takes batches of 100
// tenants and tries to get an "org_id" translation for the "external_tenant" number.
//
// Returns the total number of translatable tenants, number of translated tenants, untranslated tenants and each
// translation operation's results. It doesn't error when a tenant cannot be translated.
TranslateTenants() (int64, uint64, uint64, []m.TenantTranslation, error)
}
type UserDao interface {
FindOrCreate(userID string) (*m.User, error)
}