store

package
v3.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package store implements the Identity Server store interfaces using GORM.

Index

Constants

This section is empty.

Variables

View Source
var ErrTransactionRecovered = errors.DefineInternal("transaction_recovered", "Internal Server Error")

ErrTransactionRecovered is returned when a panic is caught from a SQL transaction.

Functions

func Check

func Check(db *gorm.DB) error

Check that the database contains all tables.

func Clear

func Clear(db *gorm.DB) error

Clear database tables for all registered models. This should be used with caution.

func GetAPIKeyStore

func GetAPIKeyStore(db *gorm.DB) store.APIKeyStore

GetAPIKeyStore returns an APIKeyStore on the given db (or transaction).

func GetApplicationStore

func GetApplicationStore(db *gorm.DB) store.ApplicationStore

GetApplicationStore returns an ApplicationStore on the given db (or transaction).

func GetClientStore

func GetClientStore(db *gorm.DB) store.ClientStore

GetClientStore returns an ClientStore on the given db (or transaction).

func GetContactInfoStore

func GetContactInfoStore(db *gorm.DB) store.ContactInfoStore

GetContactInfoStore returns an ContactInfoStore on the given db (or transaction).

func GetEUIStore

func GetEUIStore(db *gorm.DB) store.EUIStore

GetEUIStore returns an EUIStore on the given db (or transaction).

func GetEndDeviceStore

func GetEndDeviceStore(db *gorm.DB) store.EndDeviceStore

GetEndDeviceStore returns an EndDeviceStore on the given db (or transaction).

func GetEntitySearch

func GetEntitySearch(db *gorm.DB) store.EntitySearch

GetEntitySearch returns an EntitySearch on the given db (or transaction).

func GetGatewayStore

func GetGatewayStore(db *gorm.DB) store.GatewayStore

GetGatewayStore returns an GatewayStore on the given db (or transaction).

func GetInvitationStore

func GetInvitationStore(db *gorm.DB) store.InvitationStore

GetInvitationStore returns an InvitationStore on the given db (or transaction).

func GetLoginTokenStore

func GetLoginTokenStore(db *gorm.DB) store.LoginTokenStore

GetLoginTokenStore returns an LoginTokenStore on the given db (or transaction).

func GetMembershipStore

func GetMembershipStore(db *gorm.DB) store.MembershipStore

GetMembershipStore returns an MembershipStore on the given db (or transaction).

func GetNotificationStore added in v3.19.0

func GetNotificationStore(db *gorm.DB) store.NotificationStore

GetNotificationStore returns an NotificationStore on the given db (or transaction).

func GetOAuthStore

func GetOAuthStore(db *gorm.DB) store.OAuthStore

GetOAuthStore returns an OAuthStore on the given db (or transaction).

func GetOrganizationStore

func GetOrganizationStore(db *gorm.DB) store.OrganizationStore

GetOrganizationStore returns an OrganizationStore on the given db (or transaction).

func GetUserSessionStore

func GetUserSessionStore(db *gorm.DB) store.UserSessionStore

GetUserSessionStore returns an UserSessionStore on the given db (or transaction).

func GetUserStore

func GetUserStore(db *gorm.DB) store.UserStore

GetUserStore returns an UserStore on the given db (or transaction).

func Initialize

func Initialize(db *gorm.DB) error

Initialize initializes the database.

func Migrate added in v3.20.0

func Migrate(ctx context.Context, db *gorm.DB) error

Migrate migrates the database.

func Open

func Open(ctx context.Context, dsn string) (*gorm.DB, error)

Open opens a new database connection.

func SetLogger

func SetLogger(db *gorm.DB, log log.Interface)

SetLogger sets the database logger.

func Transact

func Transact(ctx context.Context, db *gorm.DB, f func(db *gorm.DB) error) (err error)

Transact executes f in a db transaction.

Types

type APIKey

type APIKey struct {
	Model

	APIKeyID string `gorm:"type:VARCHAR;unique_index:api_key_id_index"`

	Key    string `gorm:"type:VARCHAR"`
	Rights Rights `gorm:"type:INT ARRAY"`
	Name   string `gorm:"type:VARCHAR"`

	EntityID   string `gorm:"type:UUID;index:api_key_entity_index;not null"`
	EntityType string `gorm:"type:VARCHAR(32);index:api_key_entity_index;not null"`

	ExpiresAt *time.Time
}

APIKey model.

type AccessToken

type AccessToken struct {
	Model

	Client   *Client
	ClientID string `gorm:"type:UUID;index;not null"`

	User   *User
	UserID string `gorm:"type:UUID;index;not null"`

	UserSessionID *string `gorm:"type:UUID;index"`

	Rights Rights `gorm:"type:INT ARRAY"`

	TokenID string `gorm:"type:VARCHAR;unique_index:access_token_id_index;not null"`

	Previous   *AccessToken `gorm:"foreignkey:PreviousID;association_foreignkey:TokenID"`
	PreviousID string       `gorm:"type:VARCHAR;index:access_token_previous_index"`

	AccessToken  string `gorm:"type:VARCHAR;not null"`
	RefreshToken string `gorm:"type:VARCHAR;not null"`

	ExpiresAt *time.Time
}

AccessToken model.

type Account

type Account struct {
	Model
	SoftDelete

	UID string `gorm:"type:VARCHAR(36);unique_index:account_uid_index"`

	AccountID   string `gorm:"type:UUID;index:account_id_index;not null"`
	AccountType string `gorm:"type:VARCHAR(32);index:account_id_index;not null"` // user or organization

	Memberships []*Membership
}

Account model.

func (Account) OrganizationOrUserIdentifiers

func (a Account) OrganizationOrUserIdentifiers() *ttnpb.OrganizationOrUserIdentifiers

OrganizationOrUserIdentifiers for the account, depending on its type.

type Application

type Application struct {
	Model
	SoftDelete

	// BEGIN common fields
	ApplicationID string `gorm:"unique_index:application_id_index;type:VARCHAR(36);not null"`
	Name          string `gorm:"type:VARCHAR"`
	Description   string `gorm:"type:TEXT"`

	Attributes  []Attribute  `gorm:"polymorphic:Entity;polymorphic_value:application"`
	APIKeys     []APIKey     `gorm:"polymorphic:Entity;polymorphic_value:application"`
	Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:application"`

	AdministrativeContactID *string  `gorm:"type:UUID;index"`
	AdministrativeContact   *Account `gorm:"save_associations:false"`

	TechnicalContactID *string  `gorm:"type:UUID;index"`
	TechnicalContact   *Account `gorm:"save_associations:false"`

	NetworkServerAddress     string `gorm:"type:VARCHAR"`
	ApplicationServerAddress string `gorm:"type:VARCHAR"`
	JoinServerAddress        string `gorm:"type:VARCHAR"`

	DevEUICounter int `gorm:"<-:create;type:INT;default:'0';column:dev_eui_counter"`
}

Application model.

type Attribute

type Attribute struct {
	ID string `gorm:"type:UUID;primary_key;default:gen_random_uuid()"`

	EntityID   string `gorm:"type:UUID;index:attribute_entity_index;not null"`
	EntityType string `gorm:"type:VARCHAR(32);index:attribute_entity_index;not null"`

	Key   string `gorm:"type:VARCHAR"`
	Value string `gorm:"type:VARCHAR"`
}

Attribute model.

type AuthorizationCode

type AuthorizationCode struct {
	Model

	Client   *Client
	ClientID string `gorm:"type:UUID;index;not null"`

	User   *User
	UserID string `gorm:"type:UUID;index;not null"`

	UserSessionID *string `gorm:"type:UUID;index"`

	Rights Rights `gorm:"type:INT ARRAY"`

	Code        string `gorm:"type:VARCHAR;unique_index:authorization_code_code_index;not null"`
	RedirectURI string `gorm:"type:VARCHAR;column:redirect_uri"`
	State       string `gorm:"type:VARCHAR"`
	ExpiresAt   *time.Time
}

AuthorizationCode model.

type Client

type Client struct {
	Model
	SoftDelete

	// BEGIN common fields
	ClientID    string `gorm:"unique_index:client_id_index;type:VARCHAR(36);not null"`
	Name        string `gorm:"type:VARCHAR"`
	Description string `gorm:"type:TEXT"`

	Attributes  []Attribute  `gorm:"polymorphic:Entity;polymorphic_value:client"`
	Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:client"`

	AdministrativeContactID *string  `gorm:"type:UUID;index"`
	AdministrativeContact   *Account `gorm:"save_associations:false"`

	TechnicalContactID *string  `gorm:"type:UUID;index"`
	TechnicalContact   *Account `gorm:"save_associations:false"`

	ClientSecret       string         `gorm:"type:VARCHAR"`
	RedirectURIs       pq.StringArray `gorm:"type:VARCHAR ARRAY;column:redirect_uris"`
	LogoutRedirectURIs pq.StringArray `gorm:"type:VARCHAR ARRAY;column:logout_redirect_uris"`

	State            int    `gorm:"not null"`
	StateDescription string `gorm:"type:VARCHAR"`

	SkipAuthorization bool `gorm:"not null"`
	Endorsed          bool `gorm:"not null"`

	Grants Grants `gorm:"type:INT ARRAY"`
	Rights Rights `gorm:"type:INT ARRAY"`
}

Client model.

type ClientAuthorization

type ClientAuthorization struct {
	Model

	Client   *Client
	ClientID string `gorm:"type:UUID;index;not null"`

	User   *User
	UserID string `gorm:"type:UUID;index;not null"`

	Rights Rights `gorm:"type:INT ARRAY"`
}

ClientAuthorization model. Is also embedded by other OAuth models.

type CombinedStore added in v3.18.1

type CombinedStore struct {
	TxOptions sql.TxOptions
	// contains filtered or unexported fields
}

CombinedStore combines all stores to implement the store.TransactionalStore interface.

func NewCombinedStore added in v3.18.1

func NewCombinedStore(db *gorm.DB) *CombinedStore

NewCombinedStore returns a new store that implements store.TransactionalStore.

func (*CombinedStore) Authorize added in v3.18.1

func (s *CombinedStore) Authorize(
	ctx context.Context, authorization *ttnpb.OAuthClientAuthorization,
) (*ttnpb.OAuthClientAuthorization, error)

func (*CombinedStore) BatchUpdateEndDeviceLastSeen added in v3.19.0

func (s *CombinedStore) BatchUpdateEndDeviceLastSeen(
	ctx context.Context, devsLastSeen []*ttnpb.BatchUpdateEndDeviceLastSeenRequest_EndDeviceLastSeenUpdate,
) error

func (*CombinedStore) ConsumeLoginToken added in v3.18.1

func (s *CombinedStore) ConsumeLoginToken(ctx context.Context, token string) (*ttnpb.LoginToken, error)

func (*CombinedStore) CountEndDevices added in v3.18.1

func (s *CombinedStore) CountEndDevices(
	ctx context.Context, ids *ttnpb.ApplicationIdentifiers,
) (total uint64, err error)

func (*CombinedStore) CreateAPIKey added in v3.18.1

func (s *CombinedStore) CreateAPIKey(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers, key *ttnpb.APIKey,
) (*ttnpb.APIKey, error)

func (*CombinedStore) CreateAccessToken added in v3.18.1

func (s *CombinedStore) CreateAccessToken(
	ctx context.Context, token *ttnpb.OAuthAccessToken, previousID string,
) (*ttnpb.OAuthAccessToken, error)

func (*CombinedStore) CreateApplication added in v3.18.1

func (s *CombinedStore) CreateApplication(ctx context.Context, app *ttnpb.Application) (*ttnpb.Application, error)

func (*CombinedStore) CreateAuthorizationCode added in v3.18.1

func (s *CombinedStore) CreateAuthorizationCode(
	ctx context.Context, code *ttnpb.OAuthAuthorizationCode,
) (*ttnpb.OAuthAuthorizationCode, error)

func (*CombinedStore) CreateClient added in v3.18.1

func (s *CombinedStore) CreateClient(ctx context.Context, cli *ttnpb.Client) (*ttnpb.Client, error)

func (*CombinedStore) CreateEUIBlock added in v3.18.1

func (s *CombinedStore) CreateEUIBlock(
	ctx context.Context, prefix types.EUI64Prefix, initCounter int64, euiType string,
) error

CreateUIBlock creates the block of appropriate type in IS db.

func (*CombinedStore) CreateEndDevice added in v3.18.1

func (s *CombinedStore) CreateEndDevice(ctx context.Context, dev *ttnpb.EndDevice) (*ttnpb.EndDevice, error)

func (*CombinedStore) CreateGateway added in v3.18.1

func (s *CombinedStore) CreateGateway(ctx context.Context, gtw *ttnpb.Gateway) (*ttnpb.Gateway, error)

func (*CombinedStore) CreateInvitation added in v3.18.1

func (s *CombinedStore) CreateInvitation(
	ctx context.Context, invitation *ttnpb.Invitation,
) (*ttnpb.Invitation, error)

func (*CombinedStore) CreateLoginToken added in v3.18.1

func (s *CombinedStore) CreateLoginToken(
	ctx context.Context, loginToken *ttnpb.LoginToken,
) (*ttnpb.LoginToken, error)

func (*CombinedStore) CreateNotification added in v3.19.0

func (s *CombinedStore) CreateNotification(
	ctx context.Context, pb *ttnpb.Notification, receiverIDs []*ttnpb.UserIdentifiers,
) (*ttnpb.Notification, error)

func (*CombinedStore) CreateOrganization added in v3.18.1

func (s *CombinedStore) CreateOrganization(
	ctx context.Context, org *ttnpb.Organization,
) (*ttnpb.Organization, error)

func (*CombinedStore) CreateSession added in v3.18.1

func (s *CombinedStore) CreateSession(ctx context.Context, sess *ttnpb.UserSession) (*ttnpb.UserSession, error)

func (*CombinedStore) CreateUser added in v3.18.1

func (s *CombinedStore) CreateUser(ctx context.Context, usr *ttnpb.User) (*ttnpb.User, error)

func (*CombinedStore) CreateValidation added in v3.18.1

func (s *CombinedStore) CreateValidation(
	ctx context.Context, validation *ttnpb.ContactInfoValidation,
) (*ttnpb.ContactInfoValidation, error)

func (*CombinedStore) DeleteAccessToken added in v3.18.1

func (s *CombinedStore) DeleteAccessToken(ctx context.Context, id string) error

func (*CombinedStore) DeleteAccountMembers added in v3.18.1

func (s *CombinedStore) DeleteAccountMembers(ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers) error

func (*CombinedStore) DeleteAllUserSessions added in v3.18.1

func (s *CombinedStore) DeleteAllUserSessions(ctx context.Context, userIDs *ttnpb.UserIdentifiers) error

func (*CombinedStore) DeleteApplication added in v3.18.1

func (s *CombinedStore) DeleteApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error

func (*CombinedStore) DeleteAuthorization added in v3.18.1

func (s *CombinedStore) DeleteAuthorization(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers,
) error

func (*CombinedStore) DeleteAuthorizationCode added in v3.18.1

func (s *CombinedStore) DeleteAuthorizationCode(ctx context.Context, code string) error

func (*CombinedStore) DeleteClient added in v3.18.1

func (s *CombinedStore) DeleteClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error

func (*CombinedStore) DeleteClientAuthorizations added in v3.18.1

func (s *CombinedStore) DeleteClientAuthorizations(ctx context.Context, clientIDs *ttnpb.ClientIdentifiers) error

func (*CombinedStore) DeleteEndDevice added in v3.18.1

func (s *CombinedStore) DeleteEndDevice(ctx context.Context, id *ttnpb.EndDeviceIdentifiers) error

func (*CombinedStore) DeleteEntityAPIKeys added in v3.18.1

func (s *CombinedStore) DeleteEntityAPIKeys(ctx context.Context, entityID *ttnpb.EntityIdentifiers) error

func (*CombinedStore) DeleteEntityContactInfo added in v3.18.1

func (s *CombinedStore) DeleteEntityContactInfo(ctx context.Context, entityID ttnpb.IDStringer) error

func (*CombinedStore) DeleteEntityMembers added in v3.18.1

func (s *CombinedStore) DeleteEntityMembers(ctx context.Context, entityID *ttnpb.EntityIdentifiers) error

func (*CombinedStore) DeleteGateway added in v3.18.1

func (s *CombinedStore) DeleteGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error

func (*CombinedStore) DeleteInvitation added in v3.18.1

func (s *CombinedStore) DeleteInvitation(ctx context.Context, email string) error

func (*CombinedStore) DeleteOrganization added in v3.18.1

func (s *CombinedStore) DeleteOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) (err error)

func (*CombinedStore) DeleteSession added in v3.18.1

func (s *CombinedStore) DeleteSession(ctx context.Context, userIDs *ttnpb.UserIdentifiers, sessionID string) error

func (*CombinedStore) DeleteUser added in v3.18.1

func (s *CombinedStore) DeleteUser(ctx context.Context, id *ttnpb.UserIdentifiers) (err error)

func (*CombinedStore) DeleteUserAuthorizations added in v3.18.1

func (s *CombinedStore) DeleteUserAuthorizations(ctx context.Context, userIDs *ttnpb.UserIdentifiers) error

func (*CombinedStore) FindAPIKeys added in v3.18.1

func (s *CombinedStore) FindAPIKeys(ctx context.Context, entityID *ttnpb.EntityIdentifiers) ([]*ttnpb.APIKey, error)

func (*CombinedStore) FindAccountMembershipChains added in v3.18.1

func (s *CombinedStore) FindAccountMembershipChains(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, entityType string, entityIDs ...string,
) ([]*store.MembershipChain, error)

func (*CombinedStore) FindActiveLoginTokens added in v3.18.1

func (s *CombinedStore) FindActiveLoginTokens(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers,
) ([]*ttnpb.LoginToken, error)

func (*CombinedStore) FindApplications added in v3.18.1

func (s *CombinedStore) FindApplications(
	ctx context.Context, ids []*ttnpb.ApplicationIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Application, error)

func (*CombinedStore) FindClients added in v3.18.1

func (s *CombinedStore) FindClients(
	ctx context.Context, ids []*ttnpb.ClientIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Client, error)

func (*CombinedStore) FindEndDevices added in v3.18.1

func (s *CombinedStore) FindEndDevices(
	ctx context.Context, ids []*ttnpb.EndDeviceIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.EndDevice, error)

func (*CombinedStore) FindGateways added in v3.18.1

func (s *CombinedStore) FindGateways(
	ctx context.Context, ids []*ttnpb.GatewayIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Gateway, error)

func (*CombinedStore) FindInvitations added in v3.18.1

func (s *CombinedStore) FindInvitations(ctx context.Context) ([]*ttnpb.Invitation, error)

func (*CombinedStore) FindMembers added in v3.18.1

func (s *CombinedStore) FindMembers(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers,
) (map[*ttnpb.OrganizationOrUserIdentifiers]*ttnpb.Rights, error)

func (*CombinedStore) FindMemberships added in v3.18.1

func (s *CombinedStore) FindMemberships(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, entityType string, includeIndirect bool,
) ([]*ttnpb.EntityIdentifiers, error)

func (*CombinedStore) FindOrganizations added in v3.18.1

func (s *CombinedStore) FindOrganizations(
	ctx context.Context, ids []*ttnpb.OrganizationIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Organization, error)

func (*CombinedStore) FindSessions added in v3.18.1

func (s *CombinedStore) FindSessions(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers,
) ([]*ttnpb.UserSession, error)

func (*CombinedStore) FindUsers added in v3.18.1

func (s *CombinedStore) FindUsers(
	ctx context.Context, ids []*ttnpb.UserIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.User, error)

func (*CombinedStore) GetAPIKey added in v3.18.1

func (s *CombinedStore) GetAPIKey(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers, id string,
) (*ttnpb.APIKey, error)

func (*CombinedStore) GetAPIKeyByID added in v3.19.2

func (s *CombinedStore) GetAPIKeyByID(ctx context.Context, id string) (*ttnpb.EntityIdentifiers, *ttnpb.APIKey, error)

func (*CombinedStore) GetAccessToken added in v3.18.1

func (s *CombinedStore) GetAccessToken(ctx context.Context, id string) (*ttnpb.OAuthAccessToken, error)

func (*CombinedStore) GetApplication added in v3.18.1

func (s *CombinedStore) GetApplication(
	ctx context.Context, id *ttnpb.ApplicationIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Application, error)

func (*CombinedStore) GetAuthorization added in v3.18.1

func (s *CombinedStore) GetAuthorization(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers,
) (*ttnpb.OAuthClientAuthorization, error)

func (*CombinedStore) GetAuthorizationCode added in v3.18.1

func (s *CombinedStore) GetAuthorizationCode(ctx context.Context, code string) (*ttnpb.OAuthAuthorizationCode, error)

func (*CombinedStore) GetClient added in v3.18.1

func (s *CombinedStore) GetClient(
	ctx context.Context, id *ttnpb.ClientIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Client, error)

func (*CombinedStore) GetContactInfo added in v3.18.1

func (s *CombinedStore) GetContactInfo(
	ctx context.Context, entityID ttnpb.IDStringer,
) ([]*ttnpb.ContactInfo, error)

func (*CombinedStore) GetEndDevice added in v3.18.1

func (s *CombinedStore) GetEndDevice(
	ctx context.Context, id *ttnpb.EndDeviceIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.EndDevice, error)

func (*CombinedStore) GetGateway added in v3.18.1

func (s *CombinedStore) GetGateway(
	ctx context.Context, id *ttnpb.GatewayIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Gateway, error)

func (*CombinedStore) GetInvitation added in v3.18.1

func (s *CombinedStore) GetInvitation(ctx context.Context, token string) (*ttnpb.Invitation, error)

func (*CombinedStore) GetMember added in v3.18.1

func (s *CombinedStore) GetMember(
	ctx context.Context, id *ttnpb.OrganizationOrUserIdentifiers, entityID *ttnpb.EntityIdentifiers,
) (*ttnpb.Rights, error)

func (*CombinedStore) GetOrganization added in v3.18.1

func (s *CombinedStore) GetOrganization(
	ctx context.Context, id *ttnpb.OrganizationIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Organization, error)

func (*CombinedStore) GetSession added in v3.18.1

func (s *CombinedStore) GetSession(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, sessionID string,
) (*ttnpb.UserSession, error)

func (*CombinedStore) GetSessionByID added in v3.18.1

func (s *CombinedStore) GetSessionByID(ctx context.Context, sessionID string) (*ttnpb.UserSession, error)

func (*CombinedStore) GetUser added in v3.18.1

func (s *CombinedStore) GetUser(
	ctx context.Context, id *ttnpb.UserIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.User, error)

func (*CombinedStore) GetUserByPrimaryEmailAddress added in v3.18.1

func (s *CombinedStore) GetUserByPrimaryEmailAddress(
	ctx context.Context, email string, fieldMask store.FieldMask,
) (*ttnpb.User, error)

func (*CombinedStore) IssueDevEUIForApplication added in v3.18.1

func (s *CombinedStore) IssueDevEUIForApplication(
	ctx context.Context, ids *ttnpb.ApplicationIdentifiers, applicationLimit int,
) (*types.EUI64, error)

IssueDevEUIForApplication issues DevEUI address from the configured DevEUI block.

func (*CombinedStore) ListAccessTokens added in v3.18.1

func (s *CombinedStore) ListAccessTokens(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers,
) ([]*ttnpb.OAuthAccessToken, error)

func (*CombinedStore) ListAdmins added in v3.18.1

func (s *CombinedStore) ListAdmins(ctx context.Context, fieldMask store.FieldMask) ([]*ttnpb.User, error)

func (*CombinedStore) ListAuthorizations added in v3.18.1

func (s *CombinedStore) ListAuthorizations(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers,
) ([]*ttnpb.OAuthClientAuthorization, error)

func (*CombinedStore) ListEndDevices added in v3.18.1

func (s *CombinedStore) ListEndDevices(
	ctx context.Context, ids *ttnpb.ApplicationIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.EndDevice, error)

func (*CombinedStore) ListNotifications added in v3.19.0

func (s *CombinedStore) ListNotifications(
	ctx context.Context, receiverIDs *ttnpb.UserIdentifiers, statuses []ttnpb.NotificationStatus,
) ([]*ttnpb.Notification, error)

func (*CombinedStore) PurgeApplication added in v3.18.1

func (s *CombinedStore) PurgeApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error

func (*CombinedStore) PurgeClient added in v3.18.1

func (s *CombinedStore) PurgeClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error

func (*CombinedStore) PurgeGateway added in v3.18.1

func (s *CombinedStore) PurgeGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error

func (*CombinedStore) PurgeOrganization added in v3.18.1

func (s *CombinedStore) PurgeOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) (err error)

func (*CombinedStore) PurgeUser added in v3.18.1

func (s *CombinedStore) PurgeUser(ctx context.Context, id *ttnpb.UserIdentifiers) (err error)

func (*CombinedStore) RestoreApplication added in v3.18.1

func (s *CombinedStore) RestoreApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error

func (*CombinedStore) RestoreClient added in v3.18.1

func (s *CombinedStore) RestoreClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error

func (*CombinedStore) RestoreGateway added in v3.18.1

func (s *CombinedStore) RestoreGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error

func (*CombinedStore) RestoreOrganization added in v3.18.1

func (s *CombinedStore) RestoreOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) (err error)

func (*CombinedStore) RestoreUser added in v3.18.1

func (s *CombinedStore) RestoreUser(ctx context.Context, id *ttnpb.UserIdentifiers) (err error)

func (*CombinedStore) SearchApplications added in v3.18.1

func (s *CombinedStore) SearchApplications(
	ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchApplicationsRequest,
) ([]*ttnpb.ApplicationIdentifiers, error)

func (*CombinedStore) SearchClients added in v3.18.1

func (s *CombinedStore) SearchClients(
	ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchClientsRequest,
) ([]*ttnpb.ClientIdentifiers, error)

func (*CombinedStore) SearchEndDevices added in v3.18.1

func (s *CombinedStore) SearchEndDevices(
	ctx context.Context, req *ttnpb.SearchEndDevicesRequest,
) ([]*ttnpb.EndDeviceIdentifiers, error)

func (*CombinedStore) SearchGateways added in v3.18.1

func (s *CombinedStore) SearchGateways(
	ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchGatewaysRequest,
) ([]*ttnpb.GatewayIdentifiers, error)

func (*CombinedStore) SearchOrganizations added in v3.18.1

func (s *CombinedStore) SearchOrganizations(
	ctx context.Context, member *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchOrganizationsRequest,
) ([]*ttnpb.OrganizationIdentifiers, error)

func (*CombinedStore) SearchUsers added in v3.18.1

func (s *CombinedStore) SearchUsers(
	ctx context.Context, req *ttnpb.SearchUsersRequest,
) ([]*ttnpb.UserIdentifiers, error)

func (*CombinedStore) SetContactInfo added in v3.18.1

func (s *CombinedStore) SetContactInfo(
	ctx context.Context, entityID ttnpb.IDStringer, pb []*ttnpb.ContactInfo,
) ([]*ttnpb.ContactInfo, error)

func (*CombinedStore) SetInvitationAcceptedBy added in v3.18.1

func (s *CombinedStore) SetInvitationAcceptedBy(
	ctx context.Context, token string, acceptedByID *ttnpb.UserIdentifiers,
) error

func (*CombinedStore) SetMember added in v3.18.1

func (s *CombinedStore) SetMember(
	ctx context.Context,
	id *ttnpb.OrganizationOrUserIdentifiers,
	entityID *ttnpb.EntityIdentifiers,
	rights *ttnpb.Rights,
) error

func (*CombinedStore) Transact added in v3.18.1

func (s *CombinedStore) Transact(ctx context.Context, fc func(context.Context, store.Store) error) (err error)

Transact implements the store.TransactionalStore interface.

func (*CombinedStore) UpdateAPIKey added in v3.18.1

func (s *CombinedStore) UpdateAPIKey(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers, key *ttnpb.APIKey, fieldMask store.FieldMask,
) (*ttnpb.APIKey, error)

func (*CombinedStore) UpdateApplication added in v3.18.1

func (s *CombinedStore) UpdateApplication(
	ctx context.Context, app *ttnpb.Application, fieldMask store.FieldMask,
) (updated *ttnpb.Application, err error)

func (*CombinedStore) UpdateClient added in v3.18.1

func (s *CombinedStore) UpdateClient(
	ctx context.Context, cli *ttnpb.Client, fieldMask store.FieldMask,
) (updated *ttnpb.Client, err error)

func (*CombinedStore) UpdateEndDevice added in v3.18.1

func (s *CombinedStore) UpdateEndDevice(
	ctx context.Context, dev *ttnpb.EndDevice, fieldMask store.FieldMask,
) (updated *ttnpb.EndDevice, err error)

func (*CombinedStore) UpdateGateway added in v3.18.1

func (s *CombinedStore) UpdateGateway(
	ctx context.Context, gtw *ttnpb.Gateway, fieldMask store.FieldMask,
) (updated *ttnpb.Gateway, err error)

func (*CombinedStore) UpdateNotificationStatus added in v3.19.0

func (s *CombinedStore) UpdateNotificationStatus(
	ctx context.Context, receiverIDs *ttnpb.UserIdentifiers, notificationIDs []string, status ttnpb.NotificationStatus,
) error

func (*CombinedStore) UpdateOrganization added in v3.18.1

func (s *CombinedStore) UpdateOrganization(
	ctx context.Context, org *ttnpb.Organization, fieldMask store.FieldMask,
) (updated *ttnpb.Organization, err error)

func (*CombinedStore) UpdateUser added in v3.18.1

func (s *CombinedStore) UpdateUser(
	ctx context.Context, usr *ttnpb.User, fieldMask store.FieldMask,
) (updated *ttnpb.User, err error)

func (*CombinedStore) Validate added in v3.18.1

func (s *CombinedStore) Validate(ctx context.Context, validation *ttnpb.ContactInfoValidation) error

type ContactInfo

type ContactInfo struct {
	ID string `gorm:"type:UUID;primary_key;default:gen_random_uuid()"`

	ContactType   int    `gorm:"not null"`
	ContactMethod int    `gorm:"not null"`
	Value         string `gorm:"type:VARCHAR"`

	Public bool

	ValidatedAt *time.Time

	EntityID   string `gorm:"type:UUID;index:contact_info_entity_index;not null"`
	EntityType string `gorm:"type:VARCHAR(32);index:contact_info_entity_index;not null"`
}

ContactInfo model.

type ContactInfoValidation

type ContactInfoValidation struct {
	Model

	Reference string `gorm:"type:VARCHAR;index:contact_info_validation_id_index"`
	Token     string `gorm:"type:VARCHAR;index:contact_info_validation_id_index"`

	EntityID   string `gorm:"type:UUID;index:contact_info_validation_entity_index;not null"`
	EntityType string `gorm:"type:VARCHAR(32);index:contact_info_validation_entity_index;not null"`

	ContactMethod int    `gorm:"not null"`
	Value         string `gorm:"type:VARCHAR"`

	Used      bool
	ExpiresAt *time.Time
}

ContactInfoValidation model.

type EUI64

type EUI64 types.EUI64

EUI64 adds methods on a types.EUI64 so that it can be stored in an SQL database.

func (*EUI64) Scan

func (eui *EUI64) Scan(src interface{}) error

Scan reads the value from the database into the EUI.

func (EUI64) Value

func (eui EUI64) Value() (driver.Value, error)

Value returns the value to store in the database.

type EUIBlock

type EUIBlock struct {
	Model

	Type           string `gorm:"type:VARCHAR(10);"`
	StartEUI       EUI64  `gorm:"type:VARCHAR(16);column:start_eui"`
	MaxCounter     int64  `gorm:"type:BIGINT;column:end_counter"`
	CurrentCounter int64  `gorm:"type:BIGINT;column:current_counter"`
}

EUIBlock is the model for a block of EUIs.

func (EUIBlock) TableName

func (EUIBlock) TableName() string

TableName returns the table name for the EUIBlock model.

type EndDevice

type EndDevice struct {
	Model

	ApplicationID string `gorm:"unique_index:end_device_id_index;type:VARCHAR(36);not null;index:end_device_application_index"` //nolint:lll
	Application   *Application

	// BEGIN common fields
	DeviceID    string      `gorm:"unique_index:end_device_id_index;type:VARCHAR(36);not null"`
	Name        string      `gorm:"type:VARCHAR"`
	Description string      `gorm:"type:TEXT"`
	Attributes  []Attribute `gorm:"polymorphic:Entity;polymorphic_value:device"`

	JoinEUI *EUI64 `gorm:"unique_index:end_device_eui_index;index:end_device_join_eui_index;type:VARCHAR(16);column:join_eui"` //nolint:lll
	DevEUI  *EUI64 `gorm:"unique_index:end_device_eui_index;index:end_device_dev_eui_index;type:VARCHAR(16);column:dev_eui"`   //nolint:lll

	BrandID         string `gorm:"type:VARCHAR"`
	ModelID         string `gorm:"type:VARCHAR"`
	HardwareVersion string `gorm:"type:VARCHAR"`
	FirmwareVersion string `gorm:"type:VARCHAR"`
	BandID          string `gorm:"type:VARCHAR"`

	NetworkServerAddress     string `gorm:"type:VARCHAR"`
	ApplicationServerAddress string `gorm:"type:VARCHAR"`
	JoinServerAddress        string `gorm:"type:VARCHAR"`

	ServiceProfileID string `gorm:"type:VARCHAR"`

	Locations []EndDeviceLocation

	Picture   *Picture
	PictureID *string `gorm:"type:UUID;index:end_device_picture_index"`

	ActivatedAt *time.Time `gorm:"default:null"`
	LastSeenAt  *time.Time `gorm:"default:null"`
}

EndDevice model.

type EndDeviceLocation

type EndDeviceLocation struct {
	Model

	EndDeviceID string `gorm:"type:UUID;unique_index:end_device_location_id_index;index:end_device_device_index;not null"`
	Service     string `gorm:"unique_index:end_device_location_id_index"`

	Location

	Source int `gorm:"not null"`
}

EndDeviceLocation model.

type Gateway

type Gateway struct {
	Model
	SoftDelete

	GatewayEUI *EUI64 `gorm:"unique_index:gateway_eui_index;type:VARCHAR(16);column:gateway_eui"`

	// BEGIN common fields
	GatewayID   string `gorm:"unique_index:gateway_id_index;type:VARCHAR(36);not null"`
	Name        string `gorm:"type:VARCHAR"`
	Description string `gorm:"type:TEXT"`

	Attributes  []Attribute  `gorm:"polymorphic:Entity;polymorphic_value:gateway"`
	APIKeys     []APIKey     `gorm:"polymorphic:Entity;polymorphic_value:gateway"`
	Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:gateway"`

	AdministrativeContactID *string  `gorm:"type:UUID;index"`
	AdministrativeContact   *Account `gorm:"save_associations:false"`

	TechnicalContactID *string  `gorm:"type:UUID;index"`
	TechnicalContact   *Account `gorm:"save_associations:false"`

	BrandID         string `gorm:"type:VARCHAR"`
	ModelID         string `gorm:"type:VARCHAR"`
	HardwareVersion string `gorm:"type:VARCHAR"`
	FirmwareVersion string `gorm:"type:VARCHAR"`

	GatewayServerAddress string `gorm:"type:VARCHAR"`

	AutoUpdate    bool   `gorm:"not null"`
	UpdateChannel string `gorm:"type:VARCHAR"`

	// Frequency Plan IDs separated by spaces.
	FrequencyPlanID string `gorm:"type:VARCHAR"`

	StatusPublic   bool `gorm:"not null"`
	LocationPublic bool `gorm:"not null"`

	ScheduleDownlinkLate   bool  `gorm:"not null"`
	EnforceDutyCycle       bool  `gorm:"not null"`
	ScheduleAnytimeDelay   int64 `gorm:"default:0 not null"`
	DownlinkPathConstraint int

	UpdateLocationFromStatus bool `gorm:"default:false not null"`

	Antennas []GatewayAntenna

	LBSLNSSecret []byte `gorm:"type:BYTEA;column:lbs_lns_secret"`

	ClaimAuthenticationCodeSecret    []byte `gorm:"type:BYTEA"`
	ClaimAuthenticationCodeValidFrom *time.Time
	ClaimAuthenticationCodeValidTo   *time.Time

	TargetCUPSURI string `gorm:"type:VARCHAR"`
	TargetCUPSKey []byte `gorm:"type:BYTEA"`

	RequireAuthenticatedConnection bool

	SupportsLRFHSS bool `gorm:"default:false not null"`

	DisablePacketBrokerForwarding bool `gorm:"default:false not null"`
}

Gateway model.

func (*Gateway) AfterDelete

func (gtw *Gateway) AfterDelete(db *gorm.DB) error

AfterDelete releases the EUI of a Gateway after it is deleted.

type GatewayAntenna

type GatewayAntenna struct {
	Model

	Gateway   *Gateway
	GatewayID string `gorm:"type:UUID;unique_index:gateway_antenna_id_index;index:gateway_antenna_gateway_index;not null"`
	Index     int    `gorm:"unique_index:gateway_antenna_id_index;not null"`

	Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:gateway"`

	Gain float32

	Location

	Placement int
}

GatewayAntenna model.

type Grants

type Grants []ttnpb.GrantType

Grants adds methods on a []ttnpb.GrantType so that it can be stored in an SQL database.

func (*Grants) Scan

func (g *Grants) Scan(src interface{}) error

Scan reads the value from the database into the Grants.

func (Grants) Value

func (g Grants) Value() (driver.Value, error)

Value returns the value to store in the database.

type Invitation

type Invitation struct {
	Model

	Email     string `gorm:"type:VARCHAR;unique_index:invitation_email_index;not null"`
	Token     string `gorm:"type:VARCHAR;unique_index:invitation_token_index;not null"`
	ExpiresAt *time.Time

	AcceptedBy   *User
	AcceptedByID *string `gorm:"type:UUID"`
	AcceptedAt   *time.Time
}

Invitation model.

type Location

type Location struct {
	Latitude  float64
	Longitude float64
	Altitude  int32
	Accuracy  int32
}

Location can be embedded in other models.

type LoginToken

type LoginToken struct {
	Model

	User   *User
	UserID string `gorm:"type:UUID"`

	Token     string `gorm:"type:VARCHAR;unique_index:login_token_index;not null"`
	ExpiresAt *time.Time
	Used      bool
}

LoginToken model.

type Membership

type Membership struct {
	Model

	Account    *Account
	AccountID  string `gorm:"type:UUID;index:membership_account_index;not null"`
	Rights     Rights `gorm:"type:INT ARRAY"`
	EntityID   string `gorm:"type:UUID;index:membership_entity_index;not null"`
	EntityType string `gorm:"type:VARCHAR(32);index:membership_entity_index;not null"`
}

Membership model.

type Model

type Model struct {
	ID        string    `gorm:"type:UUID;primary_key;default:gen_random_uuid()"`
	CreatedAt time.Time `gorm:"not null"`
	UpdatedAt time.Time `gorm:"not null"`
	// contains filtered or unexported fields
}

Model is the base of database models.

func (Model) PrimaryKey

func (m Model) PrimaryKey() string

PrimaryKey returns the primary key of the model.

func (*Model) SetContext

func (m *Model) SetContext(ctx context.Context)

SetContext needs to be called before creating models.

type Notification added in v3.19.0

type Notification struct {
	Model

	EntityID   string `gorm:"type:UUID;index:notification_entity_index;not null"`
	EntityType string `gorm:"type:VARCHAR(32);index:notification_entity_index;not null"`

	// EntityUID is a copy of the human-readable entity ID, so that we can keep notifications for deleted entities.
	EntityUID string `gorm:"type:VARCHAR(36);not null"`

	NotificationType string `gorm:"not null"`

	Data postgres.Jsonb `gorm:"type:JSONB"`

	SenderID *string `gorm:"type:UUID;index:notification_sender_index"`

	// SenderUID is a copy of the human-readable sender ID, so that we can keep notifications for deleted senders.
	SenderUID string `gorm:"type:VARCHAR(36);not null"`

	Receivers pq.Int32Array `gorm:"type:INT ARRAY"`

	Email bool `gorm:"not null"`
}

Notification model.

type NotificationReceiver added in v3.19.0

type NotificationReceiver struct {
	Notification   *Notification
	NotificationID string `gorm:"type:UUID;unique_index:notification_receiver_index;index:notification_receiver_notification_id_index;not null"` //nolint:lll

	Receiver   *User
	ReceiverID string `gorm:"type:UUID;unique_index:notification_receiver_index;index:notification_receiver_user_index;not null"` //nolint:lll

	Status          int32     `gorm:"not null"`
	StatusUpdatedAt time.Time `gorm:"not null"`
}

NotificationReceiver model.

type Organization

type Organization struct {
	Model
	SoftDelete

	Account Account `gorm:"polymorphic:Account;polymorphic_value:organization"`

	// BEGIN common fields
	Name        string `gorm:"type:VARCHAR"`
	Description string `gorm:"type:TEXT"`

	Attributes  []Attribute  `gorm:"polymorphic:Entity;polymorphic_value:organization"`
	APIKeys     []APIKey     `gorm:"polymorphic:Entity;polymorphic_value:organization"`
	Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:organization"`

	AdministrativeContactID *string  `gorm:"type:UUID;index"`
	AdministrativeContact   *Account `gorm:"save_associations:false"`

	TechnicalContactID *string  `gorm:"type:UUID;index"`
	TechnicalContact   *Account `gorm:"save_associations:false"`
}

Organization model.

func (*Organization) SetContext

func (org *Organization) SetContext(ctx context.Context)

SetContext sets the context on the organization model and the embedded account model.

type Picture

type Picture struct {
	Model
	SoftDelete // Filter on deleted_at not being NULL to clean up storage bucket.

	Data []byte `gorm:"type:BYTEA"`
}

Picture model.

type Rights

type Rights ttnpb.Rights

Rights adds methods on a ttnpb.Rights so that it can be stored in an SQL database.

func (*Rights) Scan

func (r *Rights) Scan(src interface{}) error

Scan reads the value from the database into the Rights.

func (Rights) Value

func (r Rights) Value() (driver.Value, error)

Value returns the value to store in the database.

type SoftDelete

type SoftDelete struct {
	DeletedAt *time.Time `gorm:"index"`
}

SoftDelete makes a Delete operation set a DeletedAt instead of actually deleting the model.

type User

type User struct {
	Model
	SoftDelete

	Account Account `gorm:"polymorphic:Account;polymorphic_value:user"`

	// BEGIN common fields
	Name        string      `gorm:"type:VARCHAR"`
	Description string      `gorm:"type:TEXT"`
	Attributes  []Attribute `gorm:"polymorphic:Entity;polymorphic_value:user"`
	APIKeys     []APIKey    `gorm:"polymorphic:Entity;polymorphic_value:user"`

	Sessions []*UserSession

	PrimaryEmailAddress            string     `gorm:"type:VARCHAR;not null;unique_index"`
	PrimaryEmailAddressValidatedAt *time.Time // should be cleared when email changes

	Password              string    `gorm:"type:VARCHAR;not null"` // this is the hash
	PasswordUpdatedAt     time.Time `gorm:"not null"`
	RequirePasswordUpdate bool      `gorm:"not null"`

	State            int    `gorm:"not null"`
	StateDescription string `gorm:"type:VARCHAR"`

	Admin bool `gorm:"not null"`

	TemporaryPassword          string `gorm:"type:VARCHAR"`
	TemporaryPasswordCreatedAt *time.Time
	TemporaryPasswordExpiresAt *time.Time

	ProfilePicture   *Picture
	ProfilePictureID *string `gorm:"type:UUID;index:user_profile_picture_index"`
}

User model.

func (*User) SetContext

func (usr *User) SetContext(ctx context.Context)

SetContext sets the context on both the Model and Account.

type UserSession

type UserSession struct {
	Model

	User          *User
	UserID        string `gorm:"type:UUID;index:user_session_user_index;not null"`
	SessionSecret string `gorm:"type:VARCHAR"`

	ExpiresAt *time.Time
}

UserSession is the session of a logged in user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL