Documentation ¶
Overview ¶
Package store defines the interfaces implemented by Identity Server store implementations.
Index ¶
- Variables
- func LimitAndOffsetFromContext(ctx context.Context) (limit, offset uint32)
- func OrderFromContext(ctx context.Context, table, defaultTableField, defaultOrder string) string
- func SetTotal(ctx context.Context, total uint64)
- func WithOrder(ctx context.Context, spec string) context.Context
- func WithPagination(ctx context.Context, limit, page uint32, total *uint64) context.Context
- func WithSoftDeleted(ctx context.Context, onlyDeleted bool) context.Context
- func WithSoftDeletedBetween(ctx context.Context, deletedAfter, deletedBefore *time.Time) context.Context
- type APIKeyStore
- type ApplicationStore
- type ClientStore
- type ContactInfoStore
- type DeletedOptions
- type EUIStore
- type EndDeviceStore
- type EntitySearch
- type FieldMask
- type GatewayStore
- type InvitationStore
- type LoginTokenStore
- type MembershipChain
- type MembershipChains
- type MembershipStore
- type NotificationStore
- type OAuthStore
- type OrderOptions
- type OrganizationStore
- type PaginationOptions
- type Store
- type TransactionalStore
- type UserSessionStore
- type UserStore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIDTaken is returned when an entity can not be created because the ID is already taken. ErrIDTaken = errors.DefineAlreadyExists("id_taken", "ID already taken, choose a different one and try again") // ErrEUITaken is returned when an entity can not be created because the EUI is already taken. ErrEUITaken = errors.DefineAlreadyExists("eui_taken", "EUI already taken") )
Functions ¶
func LimitAndOffsetFromContext ¶ added in v3.17.2
LimitAndOffsetFromContext gets the limit and offset from the context.
func OrderFromContext ¶ added in v3.17.2
OrderFromContext returns the ordering string (field and direction) for the query. If the context contains ordering options, those are used. Otherwise, the default field and order are used.
func SetTotal ¶ added in v3.17.2
SetTotal sets the total number of results into the destination set by SetTotalCount if not already set.
func WithOrder ¶
WithOrder instructs the store to sort the results by the given field. If the field is prefixed with a minus, the order is reversed.
func WithPagination ¶
WithPagination instructs the store to paginate the results, and set the total number of results into total.
func WithSoftDeleted ¶ added in v3.12.0
WithSoftDeleted returns a context that tells the store to include (only) deleted entities.
Types ¶
type APIKeyStore ¶
type APIKeyStore interface { // Create a new API key for the given entity. CreateAPIKey( ctx context.Context, entityID *ttnpb.EntityIdentifiers, key *ttnpb.APIKey, ) (*ttnpb.APIKey, error) // Find API keys of the given entity. FindAPIKeys( ctx context.Context, entityID *ttnpb.EntityIdentifiers, ) ([]*ttnpb.APIKey, error) // Get an API key. GetAPIKey( ctx context.Context, entityID *ttnpb.EntityIdentifiers, id string, ) (*ttnpb.APIKey, error) // Get an API key by its ID. GetAPIKeyByID( ctx context.Context, id string, ) (*ttnpb.EntityIdentifiers, *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.EntityIdentifiers, key *ttnpb.APIKey, fieldMask FieldMask, ) (*ttnpb.APIKey, error) // Delete api keys deletes all api keys tied to an entity. Used when purging entities. DeleteEntityAPIKeys(ctx context.Context, entityID *ttnpb.EntityIdentifiers) error }
APIKeyStore interface for storing API keys for entities (applications, clients, gateways, organizations or users).
type ApplicationStore ¶
type ApplicationStore interface { CreateApplication(ctx context.Context, app *ttnpb.Application) (*ttnpb.Application, error) FindApplications( ctx context.Context, ids []*ttnpb.ApplicationIdentifiers, fieldMask FieldMask, ) ([]*ttnpb.Application, error) GetApplication( ctx context.Context, id *ttnpb.ApplicationIdentifiers, fieldMask FieldMask, ) (*ttnpb.Application, error) UpdateApplication( ctx context.Context, app *ttnpb.Application, fieldMask FieldMask, ) (*ttnpb.Application, error) DeleteApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error RestoreApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error PurgeApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error }
ApplicationStore interface for storing Applications.
All functions assume the input and fieldMask to be validated, and assume sufficient rights to perform the action.
type ClientStore ¶
type ClientStore interface { CreateClient(ctx context.Context, cli *ttnpb.Client) (*ttnpb.Client, error) FindClients( ctx context.Context, ids []*ttnpb.ClientIdentifiers, fieldMask FieldMask, ) ([]*ttnpb.Client, error) GetClient( ctx context.Context, id *ttnpb.ClientIdentifiers, fieldMask FieldMask, ) (*ttnpb.Client, error) UpdateClient( ctx context.Context, cli *ttnpb.Client, fieldMask FieldMask, ) (*ttnpb.Client, error) DeleteClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error RestoreClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error PurgeClient(ctx context.Context, id *ttnpb.ClientIdentifiers) 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 ContactInfoStore ¶
type ContactInfoStore interface { GetContactInfo( ctx context.Context, entityID ttnpb.IDStringer, ) ([]*ttnpb.ContactInfo, error) SetContactInfo( ctx context.Context, entityID ttnpb.IDStringer, 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.IDStringer) error }
ContactInfoStore interface for contact info validation.
type DeletedOptions ¶ added in v3.17.2
type DeletedOptions struct { IncludeDeleted bool OnlyDeleted bool DeletedBefore *time.Time DeletedAfter *time.Time }
DeletedOptions stores the options for selecting deleted entities.
func SoftDeletedFromContext ¶ added in v3.17.2
func SoftDeletedFromContext(ctx context.Context) *DeletedOptions
SoftDeletedFromContext returns the DeletedOptions from the context if present.
type EUIStore ¶ added in v3.13.0
type EUIStore interface { CreateEUIBlock( ctx context.Context, configPrefix types.EUI64Prefix, initCounter int64, euiType string, ) error IssueDevEUIForApplication( ctx context.Context, id *ttnpb.ApplicationIdentifiers, applicationLimit int, ) (*types.EUI64, error) }
EUIStore interface for assigning DevEUI blocks and addresses.
type EndDeviceStore ¶
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 FieldMask, ) ([]*ttnpb.EndDevice, error) FindEndDevices( ctx context.Context, ids []*ttnpb.EndDeviceIdentifiers, fieldMask FieldMask, ) ([]*ttnpb.EndDevice, error) GetEndDevice( ctx context.Context, id *ttnpb.EndDeviceIdentifiers, fieldMask FieldMask, ) (*ttnpb.EndDevice, error) UpdateEndDevice( ctx context.Context, dev *ttnpb.EndDevice, fieldMask FieldMask, ) (*ttnpb.EndDevice, error) DeleteEndDevice(ctx context.Context, id *ttnpb.EndDeviceIdentifiers) error BatchUpdateEndDeviceLastSeen( ctx context.Context, devsLastSeen []*ttnpb.BatchUpdateEndDeviceLastSeenRequest_EndDeviceLastSeenUpdate, ) 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 EntitySearch ¶
type EntitySearch interface { SearchApplications( ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchApplicationsRequest, ) ([]*ttnpb.ApplicationIdentifiers, error) SearchClients( ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchClientsRequest, ) ([]*ttnpb.ClientIdentifiers, error) SearchEndDevices( ctx context.Context, req *ttnpb.SearchEndDevicesRequest, ) ([]*ttnpb.EndDeviceIdentifiers, error) SearchGateways( ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchGatewaysRequest, ) ([]*ttnpb.GatewayIdentifiers, error) SearchOrganizations( ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchOrganizationsRequest, ) ([]*ttnpb.OrganizationIdentifiers, error) SearchUsers( ctx context.Context, req *ttnpb.SearchUsersRequest, ) ([]*ttnpb.UserIdentifiers, error) }
EntitySearch interface for searching entities.
type FieldMask ¶ added in v3.18.1
type FieldMask []string
FieldMask is used to specify applicable fields in SELECT or UPDATE queries.
type GatewayStore ¶
type GatewayStore interface { CreateGateway(ctx context.Context, gtw *ttnpb.Gateway) (*ttnpb.Gateway, error) FindGateways( ctx context.Context, ids []*ttnpb.GatewayIdentifiers, fieldMask FieldMask, ) ([]*ttnpb.Gateway, error) GetGateway( ctx context.Context, id *ttnpb.GatewayIdentifiers, fieldMask FieldMask, ) (*ttnpb.Gateway, error) UpdateGateway( ctx context.Context, gtw *ttnpb.Gateway, fieldMask FieldMask, ) (*ttnpb.Gateway, error) DeleteGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error RestoreGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error PurgeGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) 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 InvitationStore ¶
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 }
InvitationStore interface for storing user invitations.
type LoginTokenStore ¶ added in v3.12.0
type LoginTokenStore interface { FindActiveLoginTokens(ctx context.Context, userIDs *ttnpb.UserIdentifiers) ([]*ttnpb.LoginToken, error) CreateLoginToken(ctx context.Context, token *ttnpb.LoginToken) (*ttnpb.LoginToken, error) ConsumeLoginToken(ctx context.Context, token string) (*ttnpb.LoginToken, error) }
LoginTokenStore interface for storing user login tokens.
type MembershipChain ¶ added in v3.15.2
type MembershipChain struct { UserIdentifiers *ttnpb.UserIdentifiers RightsOnOrganization *ttnpb.Rights OrganizationIdentifiers *ttnpb.OrganizationIdentifiers RightsOnEntity *ttnpb.Rights EntityIdentifiers *ttnpb.EntityIdentifiers }
MembershipChain is a User -> (Membership -> Organization) -> Membership -> Entity chain.
func (*MembershipChain) GetRights ¶ added in v3.15.2
func (m *MembershipChain) GetRights() *ttnpb.Rights
GetRights returns the intersected rights.
type MembershipChains ¶ added in v3.15.2
type MembershipChains []*MembershipChain
MembershipChains is a list of membership chains.
func (MembershipChains) GetRights ¶ added in v3.15.2
func (c MembershipChains) GetRights( member *ttnpb.OrganizationOrUserIdentifiers, entityID ttnpb.IDStringer, ) *ttnpb.Rights
GetRights returns the rights of the member on the entity.
type MembershipStore ¶
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.EntityIdentifiers, error) // Find memberships (through organizations) between the user and entity. FindAccountMembershipChains( ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, entityType string, entityIDs ...string, ) ([]*MembershipChain, error) // Find direct members and rights of the given entity. FindMembers( ctx context.Context, entityID *ttnpb.EntityIdentifiers, ) (map[*ttnpb.OrganizationOrUserIdentifiers]*ttnpb.Rights, error) // Get direct member rights on an entity. GetMember( ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers, entityID *ttnpb.EntityIdentifiers, ) (*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.EntityIdentifiers, rights *ttnpb.Rights, ) error // Delete all member rights on an entity. Used for purging entities. DeleteEntityMembers(ctx context.Context, entityID *ttnpb.EntityIdentifiers) error // Delete all user rights for an entity. DeleteAccountMembers(ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers) 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 NotificationStore ¶ added in v3.19.0
type NotificationStore interface { CreateNotification( ctx context.Context, notification *ttnpb.Notification, receiverIDs []*ttnpb.UserIdentifiers, ) (*ttnpb.Notification, error) ListNotifications( ctx context.Context, receiverIDs *ttnpb.UserIdentifiers, statuses []ttnpb.NotificationStatus, ) ([]*ttnpb.Notification, error) UpdateNotificationStatus( ctx context.Context, receiverIDs *ttnpb.UserIdentifiers, notificationIDs []string, status ttnpb.NotificationStatus, ) error }
NotificationStore interface for notifications.
type OAuthStore ¶
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 DeleteClientAuthorizations(ctx context.Context, clientIDs *ttnpb.ClientIdentifiers) error CreateAuthorizationCode( ctx context.Context, code *ttnpb.OAuthAuthorizationCode, ) (*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, ) (*ttnpb.OAuthAccessToken, 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 }
OAuthStore interface for the OAuth server.
For internal use (by the OAuth server) only.
type OrderOptions ¶ added in v3.17.2
type OrderOptions struct {
// contains filtered or unexported fields
}
OrderOptions stores the ordering options that are propagated in the context.
type OrganizationStore ¶
type OrganizationStore interface { CreateOrganization( ctx context.Context, org *ttnpb.Organization, ) (*ttnpb.Organization, error) FindOrganizations( ctx context.Context, ids []*ttnpb.OrganizationIdentifiers, fieldMask FieldMask, ) ([]*ttnpb.Organization, error) GetOrganization( ctx context.Context, id *ttnpb.OrganizationIdentifiers, fieldMask FieldMask, ) (*ttnpb.Organization, error) UpdateOrganization( ctx context.Context, org *ttnpb.Organization, fieldMask FieldMask, ) (*ttnpb.Organization, error) DeleteOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) error RestoreOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) error PurgeOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) 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 PaginationOptions ¶ added in v3.17.2
type PaginationOptions struct {
// contains filtered or unexported fields
}
PaginationOptions stores the pagination options that are propagated in the context.
type Store ¶ added in v3.18.1
type Store interface { ApplicationStore ClientStore EndDeviceStore GatewayStore OrganizationStore UserStore UserSessionStore MembershipStore APIKeyStore OAuthStore InvitationStore LoginTokenStore ContactInfoStore EUIStore NotificationStore EntitySearch }
Store interface combines the interfaces of all individual stores.
type TransactionalStore ¶ added in v3.18.1
type TransactionalStore interface { Store Transact(ctx context.Context, fc func(context.Context, Store) error) error }
TransactionalStore is Store, but with a method that uses a transaction.
type UserSessionStore ¶
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) DeleteSession(ctx context.Context, userIDs *ttnpb.UserIdentifiers, sessionID string) error DeleteAllUserSessions(ctx context.Context, userIDs *ttnpb.UserIdentifiers) error }
UserSessionStore interface for storing User sessions.
For internal use (by the OAuth server) only.
type UserStore ¶
type UserStore interface { CreateUser(ctx context.Context, usr *ttnpb.User) (*ttnpb.User, error) FindUsers( ctx context.Context, ids []*ttnpb.UserIdentifiers, fieldMask FieldMask, ) ([]*ttnpb.User, error) ListAdmins(ctx context.Context, fieldMask FieldMask) ([]*ttnpb.User, error) GetUser( ctx context.Context, id *ttnpb.UserIdentifiers, fieldMask FieldMask, ) (*ttnpb.User, error) GetUserByPrimaryEmailAddress( ctx context.Context, email string, fieldMask FieldMask, ) (*ttnpb.User, error) UpdateUser( ctx context.Context, usr *ttnpb.User, fieldMask FieldMask, ) (*ttnpb.User, error) DeleteUser(ctx context.Context, id *ttnpb.UserIdentifiers) error RestoreUser(ctx context.Context, id *ttnpb.UserIdentifiers) error PurgeUser(ctx context.Context, id *ttnpb.UserIdentifiers) error }
UserStore interface for storing Users.
All functions assume the input and fieldMask to be validated, and assume sufficient rights to perform the action.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package migrations contains Identity Server store migrations.
|
Package migrations contains Identity Server store migrations. |