-
Notifications
You must be signed in to change notification settings - Fork 301
/
store_interfaces.go
206 lines (186 loc) · 12 KB
/
store_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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package store
import (
"context"
"github.com/gogo/protobuf/types"
"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
)
// ApplicationStore interface for storing Applications.
//
// All functions assume the input and fieldMask to be validated, and assume
// sufficient rights to perform the action.
type ApplicationStore interface {
CreateApplication(ctx context.Context, app *ttnpb.Application) (*ttnpb.Application, error)
FindApplications(ctx context.Context, ids []*ttnpb.ApplicationIdentifiers, fieldMask *types.FieldMask) ([]*ttnpb.Application, error)
GetApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers, fieldMask *types.FieldMask) (*ttnpb.Application, error)
UpdateApplication(ctx context.Context, app *ttnpb.Application, fieldMask *types.FieldMask) (*ttnpb.Application, error)
DeleteApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error
PurgeApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error
}
// ClientStore interface for storing Clients.
//
// All functions assume the input and fieldMask to be validated, and assume
// sufficient rights to perform the action.
type ClientStore interface {
CreateClient(ctx context.Context, cli *ttnpb.Client) (*ttnpb.Client, error)
FindClients(ctx context.Context, ids []*ttnpb.ClientIdentifiers, fieldMask *types.FieldMask) ([]*ttnpb.Client, error)
GetClient(ctx context.Context, id *ttnpb.ClientIdentifiers, fieldMask *types.FieldMask) (*ttnpb.Client, error)
UpdateClient(ctx context.Context, cli *ttnpb.Client, fieldMask *types.FieldMask) (*ttnpb.Client, error)
DeleteClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error
}
// EndDeviceStore interface for storing EndDevices.
//
// All functions assume the input and fieldMask to be validated, and assume
// sufficient rights to perform the action.
type EndDeviceStore interface {
CreateEndDevice(ctx context.Context, dev *ttnpb.EndDevice) (*ttnpb.EndDevice, error)
CountEndDevices(ctx context.Context, ids *ttnpb.ApplicationIdentifiers) (uint64, error)
ListEndDevices(ctx context.Context, ids *ttnpb.ApplicationIdentifiers, fieldMask *types.FieldMask) ([]*ttnpb.EndDevice, error)
FindEndDevices(ctx context.Context, ids []*ttnpb.EndDeviceIdentifiers, fieldMask *types.FieldMask) ([]*ttnpb.EndDevice, error)
GetEndDevice(ctx context.Context, id *ttnpb.EndDeviceIdentifiers, fieldMask *types.FieldMask) (*ttnpb.EndDevice, error)
UpdateEndDevice(ctx context.Context, dev *ttnpb.EndDevice, fieldMask *types.FieldMask) (*ttnpb.EndDevice, error)
DeleteEndDevice(ctx context.Context, id *ttnpb.EndDeviceIdentifiers) error
}
// GatewayStore interface for storing Gateways.
//
// All functions assume the input and fieldMask to be validated, and assume
// sufficient rights to perform the action.
type GatewayStore interface {
CreateGateway(ctx context.Context, gtw *ttnpb.Gateway) (*ttnpb.Gateway, error)
FindGateways(ctx context.Context, ids []*ttnpb.GatewayIdentifiers, fieldMask *types.FieldMask) ([]*ttnpb.Gateway, error)
GetGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers, fieldMask *types.FieldMask) (*ttnpb.Gateway, error)
UpdateGateway(ctx context.Context, gtw *ttnpb.Gateway, fieldMask *types.FieldMask) (*ttnpb.Gateway, error)
DeleteGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error
PurgeGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error
}
// OrganizationStore interface for storing Organizations.
//
// All functions assume the input and fieldMask to be validated, and assume
// sufficient rights to perform the action.
type OrganizationStore interface {
CreateOrganization(ctx context.Context, org *ttnpb.Organization) (*ttnpb.Organization, error)
FindOrganizations(ctx context.Context, ids []*ttnpb.OrganizationIdentifiers, fieldMask *types.FieldMask) ([]*ttnpb.Organization, error)
GetOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers, fieldMask *types.FieldMask) (*ttnpb.Organization, error)
UpdateOrganization(ctx context.Context, org *ttnpb.Organization, fieldMask *types.FieldMask) (*ttnpb.Organization, error)
DeleteOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) error
PurgeOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) error
}
// UserStore interface for storing Users.
//
// All functions assume the input and fieldMask to be validated, and assume
// sufficient rights to perform the action.
type UserStore interface {
CreateUser(ctx context.Context, usr *ttnpb.User) (*ttnpb.User, error)
FindUsers(ctx context.Context, ids []*ttnpb.UserIdentifiers, fieldMask *types.FieldMask) ([]*ttnpb.User, error)
ListAdmins(ctx context.Context, fieldMask *types.FieldMask) ([]*ttnpb.User, error)
GetUser(ctx context.Context, id *ttnpb.UserIdentifiers, fieldMask *types.FieldMask) (*ttnpb.User, error)
UpdateUser(ctx context.Context, usr *ttnpb.User, fieldMask *types.FieldMask) (*ttnpb.User, error)
DeleteUser(ctx context.Context, id *ttnpb.UserIdentifiers) error
PurgeUser(ctx context.Context, id *ttnpb.UserIdentifiers) error
}
// UserSessionStore interface for storing User sessions.
//
// For internal use (by the OAuth server) only.
type UserSessionStore interface {
CreateSession(ctx context.Context, sess *ttnpb.UserSession) (*ttnpb.UserSession, error)
FindSessions(ctx context.Context, userIDs *ttnpb.UserIdentifiers) ([]*ttnpb.UserSession, error)
GetSession(ctx context.Context, userIDs *ttnpb.UserIdentifiers, sessionID string) (*ttnpb.UserSession, error)
GetSessionByID(ctx context.Context, tokenID string) (*ttnpb.UserSession, error)
UpdateSession(ctx context.Context, sess *ttnpb.UserSession) (*ttnpb.UserSession, error)
DeleteSession(ctx context.Context, userIDs *ttnpb.UserIdentifiers, sessionID string) error
DeleteAllUserSessions(ctx context.Context, userIDs *ttnpb.UserIdentifiers) error
}
// MembershipStore interface for storing membership (collaboration) relations
// between accounts (users or organizations) and entities (applications, clients,
// gateways or organizations).
//
// As the operations in this store may be quite expensive, the results of FindXXX
// operations should typically be cached. The recommended cache behavior is:
type MembershipStore interface {
// Find direct and optionally also indirect memberships of the organization or user.
FindMemberships(ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers, entityType string, includeIndirect bool) ([]ttnpb.Identifiers, error)
// Find indirect memberships (through organizations) between the user and entity.
FindIndirectMemberships(ctx context.Context, userID *ttnpb.UserIdentifiers, entityID ttnpb.Identifiers) ([]IndirectMembership, error)
// Find direct members and rights of the given entity.
FindMembers(ctx context.Context, entityID ttnpb.Identifiers) (map[*ttnpb.OrganizationOrUserIdentifiers]*ttnpb.Rights, error)
// Get direct member rights on an entity.
GetMember(ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers, entityID ttnpb.Identifiers) (*ttnpb.Rights, error)
// Set direct member rights on an entity. Rights can be deleted by not passing any rights.
SetMember(ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers, entityID ttnpb.Identifiers, rights *ttnpb.Rights) error
// Delete all member rights on an entity. Used for purging entities.
DeleteEntityMembers(ctx context.Context, entityID ttnpb.Identifiers) error
// Delete all user rights for an entity.
DeleteAccountMembers(ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers) error
}
// APIKeyStore interface for storing API keys for entities (applications,
// clients, gateways, organizations or users).
type APIKeyStore interface {
// Create a new API key for the given entity.
CreateAPIKey(ctx context.Context, entityID ttnpb.Identifiers, key *ttnpb.APIKey) error
// Find API keys of the given entity.
FindAPIKeys(ctx context.Context, entityID ttnpb.Identifiers) ([]*ttnpb.APIKey, error)
// Get an API key by its ID.
GetAPIKey(ctx context.Context, id string) (ttnpb.Identifiers, *ttnpb.APIKey, error)
// Update key rights on an entity. Rights can be deleted by not passing any rights, in which case the returned API key will be nil.
UpdateAPIKey(ctx context.Context, entityID ttnpb.Identifiers, key *ttnpb.APIKey) (*ttnpb.APIKey, error)
// Delete api keys deletes all api keys tied to an entity. Used when purging entities.
DeleteEntityAPIKeys(ctx context.Context, entityID ttnpb.Identifiers) error
}
// OAuthStore interface for the OAuth server.
//
// For internal use (by the OAuth server) only.
type OAuthStore interface {
ListAuthorizations(ctx context.Context, userIDs *ttnpb.UserIdentifiers) ([]*ttnpb.OAuthClientAuthorization, error)
GetAuthorization(ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers) (*ttnpb.OAuthClientAuthorization, error)
Authorize(ctx context.Context, req *ttnpb.OAuthClientAuthorization) (authorization *ttnpb.OAuthClientAuthorization, err error)
DeleteAuthorization(ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers) error
DeleteUserAuthorizations(ctx context.Context, userIDs *ttnpb.UserIdentifiers) error
CreateAuthorizationCode(ctx context.Context, code *ttnpb.OAuthAuthorizationCode) error
GetAuthorizationCode(ctx context.Context, code string) (*ttnpb.OAuthAuthorizationCode, error)
DeleteAuthorizationCode(ctx context.Context, code string) error
CreateAccessToken(ctx context.Context, token *ttnpb.OAuthAccessToken, previousID string) error
ListAccessTokens(ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers) ([]*ttnpb.OAuthAccessToken, error)
GetAccessToken(ctx context.Context, id string) (*ttnpb.OAuthAccessToken, error)
DeleteAccessToken(ctx context.Context, id string) error
}
// InvitationStore interface for storing user invitations.
type InvitationStore interface {
CreateInvitation(ctx context.Context, invitation *ttnpb.Invitation) (*ttnpb.Invitation, error)
FindInvitations(ctx context.Context) ([]*ttnpb.Invitation, error)
GetInvitation(ctx context.Context, token string) (*ttnpb.Invitation, error)
SetInvitationAcceptedBy(ctx context.Context, token string, accepter *ttnpb.UserIdentifiers) error
DeleteInvitation(ctx context.Context, email string) error
}
// EntitySearch interface for searching entities.
type EntitySearch interface {
FindEntities(ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchEntitiesRequest, entityType string) ([]ttnpb.Identifiers, error)
FindEndDevices(ctx context.Context, req *ttnpb.SearchEndDevicesRequest) ([]*ttnpb.EndDeviceIdentifiers, error)
}
// ContactInfoStore interface for contact info validation.
type ContactInfoStore interface {
GetContactInfo(ctx context.Context, entityID ttnpb.Identifiers) ([]*ttnpb.ContactInfo, error)
SetContactInfo(ctx context.Context, entityID ttnpb.Identifiers, contactInfo []*ttnpb.ContactInfo) ([]*ttnpb.ContactInfo, error)
CreateValidation(ctx context.Context, validation *ttnpb.ContactInfoValidation) (*ttnpb.ContactInfoValidation, error)
// Confirm a validation. Only the ID and Token need to be set.
Validate(ctx context.Context, validation *ttnpb.ContactInfoValidation) error
DeleteEntityContactInfo(ctx context.Context, entityID ttnpb.Identifiers) error
}
// MigrationStore interface for migration history.
type MigrationStore interface {
CreateMigration(ctx context.Context, migration *Migration) error
FindMigrations(ctx context.Context) ([]*Migration, error)
GetMigration(ctx context.Context, id string) (*Migration, error)
DeleteMigration(ctx context.Context, id string) error
}