store

package
v0.64.4 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 46 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetKeyQueryCondition added in v0.36.0

func GetKeyQueryCondition(s *SqlStore) string

func LoadSQL added in v0.39.0

func LoadSQL(db *gorm.DB, filepath string) error

func MigrateFileStoreToSqlite

func MigrateFileStoreToSqlite(ctx context.Context, dataDir string) error

MigrateFileStoreToSqlite migrates the file store to the SQLite store.

Types

type FileStore

type FileStore struct {
	Accounts                map[string]*types.Account
	SetupKeyID2AccountID    map[string]string `json:"-"`
	PeerKeyID2AccountID     map[string]string `json:"-"`
	PeerID2AccountID        map[string]string `json:"-"`
	UserID2AccountID        map[string]string `json:"-"`
	PrivateDomain2AccountID map[string]string `json:"-"`
	HashedPAT2TokenID       map[string]string `json:"-"`
	TokenID2UserID          map[string]string `json:"-"`
	InstallationID          string
	// contains filtered or unexported fields
}

FileStore represents an account storage backed by a file persisted to disk

func NewFileStore

func NewFileStore(ctx context.Context, dataDir string, metrics telemetry.AppMetrics) (*FileStore, error)

NewFileStore restores a store from the file located in the datadir

func (*FileStore) Close

func (s *FileStore) Close(ctx context.Context) error

Close the FileStore persisting data to disk

func (*FileStore) GetAllAccounts

func (s *FileStore) GetAllAccounts(_ context.Context) (all []*types.Account)

GetAllAccounts returns all accounts

func (*FileStore) GetStoreEngine

func (s *FileStore) GetStoreEngine() types.Engine

GetStoreEngine returns FileStoreEngine

func (*FileStore) SetFieldEncrypt added in v0.62.0

func (s *FileStore) SetFieldEncrypt(_ *crypt.FieldEncrypt)

SetFieldEncrypt is a no-op for FileStore as it doesn't support field encryption.

type LockingStrength

type LockingStrength string
const (
	LockingStrengthUpdate      LockingStrength = "UPDATE"        // Strongest lock, preventing any changes by other transactions until your transaction completes.
	LockingStrengthShare       LockingStrength = "SHARE"         // Allows reading but prevents changes by other transactions.
	LockingStrengthNoKeyUpdate LockingStrength = "NO KEY UPDATE" // Similar to UPDATE but allows changes to related rows.
	LockingStrengthKeyShare    LockingStrength = "KEY SHARE"     // Protects against changes to primary/unique keys but allows other updates.
	LockingStrengthNone        LockingStrength = "NONE"          // No locking, allowing all transactions to proceed without restrictions.
)

type SqlStore

type SqlStore struct {
	// contains filtered or unexported fields
}

SqlStore represents an account storage backed by a Sql DB persisted to disk

func NewMysqlStore added in v0.36.0

func NewMysqlStore(ctx context.Context, dsn string, metrics telemetry.AppMetrics, skipMigration bool) (*SqlStore, error)

NewMysqlStore creates a new MySQL store.

func NewMysqlStoreFromSqlStore added in v0.36.0

func NewMysqlStoreFromSqlStore(ctx context.Context, sqliteStore *SqlStore, dsn string, metrics telemetry.AppMetrics) (*SqlStore, error)

NewMysqlStoreFromSqlStore restores a store from SqlStore and stores MySQL DB.

func NewPostgresqlStore

func NewPostgresqlStore(ctx context.Context, dsn string, metrics telemetry.AppMetrics, skipMigration bool) (*SqlStore, error)

NewPostgresqlStore creates a new Postgres store.

func NewPostgresqlStoreForTests added in v0.59.13

func NewPostgresqlStoreForTests(ctx context.Context, dsn string, metrics telemetry.AppMetrics, skipMigration bool) (*SqlStore, error)

used for tests only

func NewPostgresqlStoreFromSqlStore

func NewPostgresqlStoreFromSqlStore(ctx context.Context, sqliteStore *SqlStore, dsn string, metrics telemetry.AppMetrics) (*SqlStore, error)

NewPostgresqlStoreFromSqlStore restores a store from SqlStore and stores Postgres DB.

func NewSqlStore

func NewSqlStore(ctx context.Context, db *gorm.DB, storeEngine types.Engine, metrics telemetry.AppMetrics, skipMigration bool) (*SqlStore, error)

NewSqlStore creates a new SqlStore instance.

func NewSqliteStore

func NewSqliteStore(ctx context.Context, dataDir string, metrics telemetry.AppMetrics, skipMigration bool) (*SqlStore, error)

NewSqliteStore creates a new SQLite store.

func NewSqliteStoreFromFileStore

func NewSqliteStoreFromFileStore(ctx context.Context, fileStore *FileStore, dataDir string, metrics telemetry.AppMetrics, skipMigration bool) (*SqlStore, error)

NewSqliteStoreFromFileStore restores a store from FileStore and stores SQLite DB in the file located in datadir.

func (*SqlStore) AccountExists

func (s *SqlStore) AccountExists(ctx context.Context, lockStrength LockingStrength, id string) (bool, error)

AccountExists checks whether an account exists by the given ID.

func (*SqlStore) AcquireGlobalLock

func (s *SqlStore) AcquireGlobalLock(ctx context.Context) (unlock func())

AcquireGlobalLock acquires global lock across all the accounts and returns a function that releases the lock

func (*SqlStore) AddPeerToAccount

func (s *SqlStore) AddPeerToAccount(ctx context.Context, peer *nbpeer.Peer) error

func (*SqlStore) AddPeerToAllGroup

func (s *SqlStore) AddPeerToAllGroup(ctx context.Context, accountID string, peerID string) error

AddPeerToAllGroup adds a peer to the 'All' group. Method always needs to run in a transaction

func (*SqlStore) AddPeerToGroup

func (s *SqlStore) AddPeerToGroup(ctx context.Context, accountID, peerID, groupID string) error

AddPeerToGroup adds a peer to a group

func (*SqlStore) AddResourceToGroup

func (s *SqlStore) AddResourceToGroup(ctx context.Context, accountId string, groupID string, resource *types.Resource) error

AddResourceToGroup adds a resource to a group. Method always needs to run n a transaction

func (*SqlStore) ApproveAccountPeers added in v0.60.8

func (s *SqlStore) ApproveAccountPeers(ctx context.Context, accountID string) (int, error)

ApproveAccountPeers marks all peers that currently require approval in the given account as approved.

func (*SqlStore) Close

func (s *SqlStore) Close(_ context.Context) error

Close closes the underlying DB connection

func (*SqlStore) CompletePeerJob added in v0.64.0

func (s *SqlStore) CompletePeerJob(ctx context.Context, job *types.Job) error

func (*SqlStore) CountAccountsByPrivateDomain added in v0.40.0

func (s *SqlStore) CountAccountsByPrivateDomain(ctx context.Context, domain string) (int64, error)

func (*SqlStore) CreateDNSRecord added in v0.63.0

func (s *SqlStore) CreateDNSRecord(ctx context.Context, record *records.Record) error

func (*SqlStore) CreateGroup added in v0.53.0

func (s *SqlStore) CreateGroup(ctx context.Context, group *types.Group) error

CreateGroup creates a group in the store.

func (*SqlStore) CreateGroups added in v0.53.0

func (s *SqlStore) CreateGroups(ctx context.Context, accountID string, groups []*types.Group) error

CreateGroups creates the given list of groups to the database.

func (*SqlStore) CreatePeerJob added in v0.64.0

func (s *SqlStore) CreatePeerJob(ctx context.Context, job *types.Job) error

SaveJob persists a job in DB

func (*SqlStore) CreatePolicy

func (s *SqlStore) CreatePolicy(ctx context.Context, policy *types.Policy) error

func (*SqlStore) CreateZone added in v0.63.0

func (s *SqlStore) CreateZone(ctx context.Context, zone *zones.Zone) error

func (*SqlStore) DeleteAccount

func (s *SqlStore) DeleteAccount(ctx context.Context, account *types.Account) error

func (*SqlStore) DeleteDNSRecord added in v0.63.0

func (s *SqlStore) DeleteDNSRecord(ctx context.Context, accountID, zoneID, recordID string) error

func (*SqlStore) DeleteGroup

func (s *SqlStore) DeleteGroup(ctx context.Context, accountID, groupID string) error

DeleteGroup deletes a group from the database.

func (*SqlStore) DeleteGroups

func (s *SqlStore) DeleteGroups(ctx context.Context, accountID string, groupIDs []string) error

DeleteGroups deletes groups from the database.

func (*SqlStore) DeleteHashedPAT2TokenIDIndex

func (s *SqlStore) DeleteHashedPAT2TokenIDIndex(hashedToken string) error

DeleteHashedPAT2TokenIDIndex is noop in SqlStore

func (*SqlStore) DeleteNameServerGroup

func (s *SqlStore) DeleteNameServerGroup(ctx context.Context, accountID, nsGroupID string) error

DeleteNameServerGroup deletes a name server group from the database.

func (*SqlStore) DeleteNetwork

func (s *SqlStore) DeleteNetwork(ctx context.Context, accountID, networkID string) error

func (*SqlStore) DeleteNetworkResource

func (s *SqlStore) DeleteNetworkResource(ctx context.Context, accountID, resourceID string) error

func (*SqlStore) DeleteNetworkRouter

func (s *SqlStore) DeleteNetworkRouter(ctx context.Context, accountID, routerID string) error

func (*SqlStore) DeletePAT added in v0.37.0

func (s *SqlStore) DeletePAT(ctx context.Context, userID, patID string) error

DeletePAT deletes a personal access token from the database.

func (*SqlStore) DeletePeer added in v0.36.4

func (s *SqlStore) DeletePeer(ctx context.Context, accountID string, peerID string) error

DeletePeer removes a peer from the store.

func (*SqlStore) DeletePolicy

func (s *SqlStore) DeletePolicy(ctx context.Context, accountID, policyID string) error

func (*SqlStore) DeletePostureChecks

func (s *SqlStore) DeletePostureChecks(ctx context.Context, accountID, postureChecksID string) error

DeletePostureChecks deletes a posture checks from the database.

func (*SqlStore) DeleteRoute added in v0.48.0

func (s *SqlStore) DeleteRoute(ctx context.Context, accountID, routeID string) error

DeleteRoute deletes a route from the database.

func (*SqlStore) DeleteSetupKey

func (s *SqlStore) DeleteSetupKey(ctx context.Context, accountID, keyID string) error

DeleteSetupKey deletes a setup key from the database.

func (*SqlStore) DeleteTokenID2UserIDIndex

func (s *SqlStore) DeleteTokenID2UserIDIndex(tokenID string) error

DeleteTokenID2UserIDIndex is noop in SqlStore

func (*SqlStore) DeleteUser added in v0.37.0

func (s *SqlStore) DeleteUser(ctx context.Context, accountID, userID string) error

func (*SqlStore) DeleteUserInvite added in v0.64.2

func (s *SqlStore) DeleteUserInvite(ctx context.Context, inviteID string) error

DeleteUserInvite deletes a user invite by its ID

func (*SqlStore) DeleteZone added in v0.63.0

func (s *SqlStore) DeleteZone(ctx context.Context, accountID, zoneID string) error

func (*SqlStore) DeleteZoneDNSRecords added in v0.63.0

func (s *SqlStore) DeleteZoneDNSRecords(ctx context.Context, accountID, zoneID string) error

func (*SqlStore) ExecuteInTransaction

func (s *SqlStore) ExecuteInTransaction(ctx context.Context, operation func(store Store) error) error

func (*SqlStore) GetAccount

func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Account, error)

func (*SqlStore) GetAccountByPeerID

func (s *SqlStore) GetAccountByPeerID(ctx context.Context, peerID string) (*types.Account, error)

func (*SqlStore) GetAccountByPeerPubKey

func (s *SqlStore) GetAccountByPeerPubKey(ctx context.Context, peerKey string) (*types.Account, error)

func (*SqlStore) GetAccountByPrivateDomain

func (s *SqlStore) GetAccountByPrivateDomain(ctx context.Context, domain string) (*types.Account, error)

func (*SqlStore) GetAccountBySetupKey

func (s *SqlStore) GetAccountBySetupKey(ctx context.Context, setupKey string) (*types.Account, error)

func (*SqlStore) GetAccountByUser

func (s *SqlStore) GetAccountByUser(ctx context.Context, userID string) (*types.Account, error)

func (*SqlStore) GetAccountCreatedBy added in v0.37.0

func (s *SqlStore) GetAccountCreatedBy(ctx context.Context, lockStrength LockingStrength, accountID string) (string, error)

func (*SqlStore) GetAccountDNSSettings

func (s *SqlStore) GetAccountDNSSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.DNSSettings, error)

func (*SqlStore) GetAccountDomainAndCategory

func (s *SqlStore) GetAccountDomainAndCategory(ctx context.Context, lockStrength LockingStrength, accountID string) (string, string, error)

GetAccountDomainAndCategory retrieves the Domain and DomainCategory fields for an account based on the given accountID.

func (*SqlStore) GetAccountGroupPeers added in v0.53.0

func (s *SqlStore) GetAccountGroupPeers(ctx context.Context, lockStrength LockingStrength, accountID string) (map[string]map[string]struct{}, error)

func (*SqlStore) GetAccountGroups

func (s *SqlStore) GetAccountGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Group, error)

func (*SqlStore) GetAccountIDByPeerID added in v0.36.4

func (s *SqlStore) GetAccountIDByPeerID(ctx context.Context, lockStrength LockingStrength, peerID string) (string, error)

func (*SqlStore) GetAccountIDByPeerPubKey

func (s *SqlStore) GetAccountIDByPeerPubKey(ctx context.Context, peerKey string) (string, error)

func (*SqlStore) GetAccountIDByPrivateDomain

func (s *SqlStore) GetAccountIDByPrivateDomain(ctx context.Context, lockStrength LockingStrength, domain string) (string, error)

func (*SqlStore) GetAccountIDBySetupKey

func (s *SqlStore) GetAccountIDBySetupKey(ctx context.Context, setupKey string) (string, error)

func (*SqlStore) GetAccountIDByUserID

func (s *SqlStore) GetAccountIDByUserID(ctx context.Context, lockStrength LockingStrength, userID string) (string, error)

func (*SqlStore) GetAccountMeta added in v0.42.0

func (s *SqlStore) GetAccountMeta(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.AccountMeta, error)

func (*SqlStore) GetAccountNameServerGroups

func (s *SqlStore) GetAccountNameServerGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*nbdns.NameServerGroup, error)

GetAccountNameServerGroups retrieves name server groups for an account.

func (*SqlStore) GetAccountNetwork

func (s *SqlStore) GetAccountNetwork(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.Network, error)

func (*SqlStore) GetAccountNetworks

func (s *SqlStore) GetAccountNetworks(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*networkTypes.Network, error)

func (*SqlStore) GetAccountOnboarding added in v0.50.0

func (s *SqlStore) GetAccountOnboarding(ctx context.Context, accountID string) (*types.AccountOnboarding, error)

GetAccountOnboarding retrieves the onboarding information for a specific account.

func (*SqlStore) GetAccountOwner added in v0.40.0

func (s *SqlStore) GetAccountOwner(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.User, error)

func (*SqlStore) GetAccountPeers added in v0.36.4

func (s *SqlStore) GetAccountPeers(ctx context.Context, lockStrength LockingStrength, accountID, nameFilter, ipFilter string) ([]*nbpeer.Peer, error)

GetAccountPeers retrieves peers for an account.

func (*SqlStore) GetAccountPeersWithExpiration added in v0.36.4

func (s *SqlStore) GetAccountPeersWithExpiration(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*nbpeer.Peer, error)

GetAccountPeersWithExpiration retrieves a list of peers that have login expiration enabled and added by a user.

func (*SqlStore) GetAccountPeersWithInactivity added in v0.36.4

func (s *SqlStore) GetAccountPeersWithInactivity(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*nbpeer.Peer, error)

GetAccountPeersWithInactivity retrieves a list of peers that have login expiration enabled and added by a user.

func (*SqlStore) GetAccountPolicies

func (s *SqlStore) GetAccountPolicies(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Policy, error)

GetAccountPolicies retrieves policies for an account.

func (*SqlStore) GetAccountPostureChecks

func (s *SqlStore) GetAccountPostureChecks(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*posture.Checks, error)

GetAccountPostureChecks retrieves posture checks for an account.

func (*SqlStore) GetAccountRoutes

func (s *SqlStore) GetAccountRoutes(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*route.Route, error)

GetAccountRoutes retrieves network routes for an account.

func (*SqlStore) GetAccountSettings

func (s *SqlStore) GetAccountSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.Settings, error)

func (*SqlStore) GetAccountSetupKeys

func (s *SqlStore) GetAccountSetupKeys(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.SetupKey, error)

GetAccountSetupKeys retrieves setup keys for an account.

func (*SqlStore) GetAccountUserInvites added in v0.64.2

func (s *SqlStore) GetAccountUserInvites(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.UserInviteRecord, error)

GetAccountUserInvites retrieves all user invites for an account

func (*SqlStore) GetAccountUsers

func (s *SqlStore) GetAccountUsers(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.User, error)

func (*SqlStore) GetAccountZones added in v0.63.0

func (s *SqlStore) GetAccountZones(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*zones.Zone, error)

func (*SqlStore) GetAccountsCounter added in v0.37.1

func (s *SqlStore) GetAccountsCounter(ctx context.Context) (int64, error)

func (*SqlStore) GetAllAccounts

func (s *SqlStore) GetAllAccounts(ctx context.Context) (all []*types.Account)

func (*SqlStore) GetAllEphemeralPeers added in v0.36.4

func (s *SqlStore) GetAllEphemeralPeers(ctx context.Context, lockStrength LockingStrength) ([]*nbpeer.Peer, error)

GetAllEphemeralPeers retrieves all peers with Ephemeral set to true across all accounts, optimized for batch processing.

func (*SqlStore) GetAnyAccountID added in v0.43.1

func (s *SqlStore) GetAnyAccountID(ctx context.Context) (string, error)

func (*SqlStore) GetDB

func (s *SqlStore) GetDB() *gorm.DB

func (*SqlStore) GetDNSRecordByID added in v0.63.0

func (s *SqlStore) GetDNSRecordByID(ctx context.Context, lockStrength LockingStrength, accountID, zoneID, recordID string) (*records.Record, error)

func (*SqlStore) GetGroupByID

func (s *SqlStore) GetGroupByID(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) (*types.Group, error)

GetGroupByID retrieves a group by ID and account ID.

func (*SqlStore) GetGroupByName

func (s *SqlStore) GetGroupByName(ctx context.Context, lockStrength LockingStrength, accountID, groupName string) (*types.Group, error)

GetGroupByName retrieves a group by name and account ID.

func (*SqlStore) GetGroupsByIDs

func (s *SqlStore) GetGroupsByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, groupIDs []string) (map[string]*types.Group, error)

GetGroupsByIDs retrieves groups by their IDs and account ID.

func (*SqlStore) GetInstallationID

func (s *SqlStore) GetInstallationID() string

func (*SqlStore) GetNameServerGroupByID

func (s *SqlStore) GetNameServerGroupByID(ctx context.Context, lockStrength LockingStrength, accountID, nsGroupID string) (*nbdns.NameServerGroup, error)

GetNameServerGroupByID retrieves a name server group by its ID and account ID.

func (*SqlStore) GetNetworkByID

func (s *SqlStore) GetNetworkByID(ctx context.Context, lockStrength LockingStrength, accountID, networkID string) (*networkTypes.Network, error)

func (*SqlStore) GetNetworkResourceByID

func (s *SqlStore) GetNetworkResourceByID(ctx context.Context, lockStrength LockingStrength, accountID, resourceID string) (*resourceTypes.NetworkResource, error)

func (*SqlStore) GetNetworkResourceByName

func (s *SqlStore) GetNetworkResourceByName(ctx context.Context, lockStrength LockingStrength, accountID, resourceName string) (*resourceTypes.NetworkResource, error)

func (*SqlStore) GetNetworkResourcesByAccountID

func (s *SqlStore) GetNetworkResourcesByAccountID(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*resourceTypes.NetworkResource, error)

func (*SqlStore) GetNetworkResourcesByNetID

func (s *SqlStore) GetNetworkResourcesByNetID(ctx context.Context, lockStrength LockingStrength, accountID, networkID string) ([]*resourceTypes.NetworkResource, error)

func (*SqlStore) GetNetworkRouterByID

func (s *SqlStore) GetNetworkRouterByID(ctx context.Context, lockStrength LockingStrength, accountID, routerID string) (*routerTypes.NetworkRouter, error)

func (*SqlStore) GetNetworkRoutersByAccountID

func (s *SqlStore) GetNetworkRoutersByAccountID(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*routerTypes.NetworkRouter, error)

func (*SqlStore) GetNetworkRoutersByNetID

func (s *SqlStore) GetNetworkRoutersByNetID(ctx context.Context, lockStrength LockingStrength, accountID, netID string) ([]*routerTypes.NetworkRouter, error)

func (*SqlStore) GetPATByHashedToken added in v0.37.0

func (s *SqlStore) GetPATByHashedToken(ctx context.Context, lockStrength LockingStrength, hashedToken string) (*types.PersonalAccessToken, error)

GetPATByHashedToken returns a PersonalAccessToken by its hashed token.

func (*SqlStore) GetPATByID added in v0.37.0

func (s *SqlStore) GetPATByID(ctx context.Context, lockStrength LockingStrength, userID string, patID string) (*types.PersonalAccessToken, error)

GetPATByID retrieves a personal access token by its ID and user ID.

func (*SqlStore) GetPeerByID

func (s *SqlStore) GetPeerByID(ctx context.Context, lockStrength LockingStrength, accountID, peerID string) (*nbpeer.Peer, error)

GetPeerByID retrieves a peer by its ID and account ID.

func (*SqlStore) GetPeerByIP added in v0.39.0

func (s *SqlStore) GetPeerByIP(ctx context.Context, lockStrength LockingStrength, accountID string, ip net.IP) (*nbpeer.Peer, error)

func (*SqlStore) GetPeerByPeerPubKey

func (s *SqlStore) GetPeerByPeerPubKey(ctx context.Context, lockStrength LockingStrength, peerKey string) (*nbpeer.Peer, error)

func (*SqlStore) GetPeerGroupIDs added in v0.53.0

func (s *SqlStore) GetPeerGroupIDs(ctx context.Context, lockStrength LockingStrength, accountId string, peerId string) ([]string, error)

GetPeerGroupIDs retrieves all group IDs assigned to a specific peer in a given account.

func (*SqlStore) GetPeerGroups added in v0.36.4

func (s *SqlStore) GetPeerGroups(ctx context.Context, lockStrength LockingStrength, accountId string, peerId string) ([]*types.Group, error)

GetPeerGroups retrieves all groups assigned to a specific peer in a given account.

func (*SqlStore) GetPeerIDByKey added in v0.64.0

func (s *SqlStore) GetPeerIDByKey(ctx context.Context, lockStrength LockingStrength, key string) (string, error)

func (*SqlStore) GetPeerIdByLabel added in v0.50.0

func (s *SqlStore) GetPeerIdByLabel(ctx context.Context, lockStrength LockingStrength, accountID string, hostname string) (string, error)

func (*SqlStore) GetPeerJobByID added in v0.64.0

func (s *SqlStore) GetPeerJobByID(ctx context.Context, accountID, jobID string) (*types.Job, error)

GetJobByID fetches job by ID

func (*SqlStore) GetPeerJobs added in v0.64.0

func (s *SqlStore) GetPeerJobs(ctx context.Context, accountID, peerID string) ([]*types.Job, error)

get all jobs

func (*SqlStore) GetPeerLabelsInAccount

func (s *SqlStore) GetPeerLabelsInAccount(ctx context.Context, lockStrength LockingStrength, accountID string, dnsLabel string) ([]string, error)

func (*SqlStore) GetPeersByGroupIDs added in v0.56.1

func (s *SqlStore) GetPeersByGroupIDs(ctx context.Context, accountID string, groupIDs []string) ([]*nbpeer.Peer, error)

func (*SqlStore) GetPeersByIDs

func (s *SqlStore) GetPeersByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, peerIDs []string) (map[string]*nbpeer.Peer, error)

GetPeersByIDs retrieves peers by their IDs and account ID.

func (*SqlStore) GetPolicyByID

func (s *SqlStore) GetPolicyByID(ctx context.Context, lockStrength LockingStrength, accountID, policyID string) (*types.Policy, error)

GetPolicyByID retrieves a policy by its ID and account ID.

func (*SqlStore) GetPolicyRulesByResourceID added in v0.59.0

func (s *SqlStore) GetPolicyRulesByResourceID(ctx context.Context, lockStrength LockingStrength, accountID string, resourceID string) ([]*types.PolicyRule, error)

func (*SqlStore) GetPostureCheckByChecksDefinition

func (s *SqlStore) GetPostureCheckByChecksDefinition(accountID string, checks *posture.ChecksDefinition) (*posture.Checks, error)

func (*SqlStore) GetPostureChecksByID

func (s *SqlStore) GetPostureChecksByID(ctx context.Context, lockStrength LockingStrength, accountID, postureChecksID string) (*posture.Checks, error)

GetPostureChecksByID retrieves posture checks by their ID and account ID.

func (*SqlStore) GetPostureChecksByIDs

func (s *SqlStore) GetPostureChecksByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, postureChecksIDs []string) (map[string]*posture.Checks, error)

GetPostureChecksByIDs retrieves posture checks by their IDs and account ID.

func (*SqlStore) GetResourceGroups

func (s *SqlStore) GetResourceGroups(ctx context.Context, lockStrength LockingStrength, accountID, resourceID string) ([]*types.Group, error)

func (*SqlStore) GetRouteByID

func (s *SqlStore) GetRouteByID(ctx context.Context, lockStrength LockingStrength, accountID string, routeID string) (*route.Route, error)

GetRouteByID retrieves a route by its ID and account ID.

func (*SqlStore) GetSetupKeyByID

func (s *SqlStore) GetSetupKeyByID(ctx context.Context, lockStrength LockingStrength, accountID, setupKeyID string) (*types.SetupKey, error)

GetSetupKeyByID retrieves a setup key by its ID and account ID.

func (*SqlStore) GetSetupKeyBySecret

func (s *SqlStore) GetSetupKeyBySecret(ctx context.Context, lockStrength LockingStrength, key string) (*types.SetupKey, error)

func (*SqlStore) GetStoreEngine

func (s *SqlStore) GetStoreEngine() types.Engine

GetStoreEngine returns underlying store engine

func (*SqlStore) GetTakenIPs

func (s *SqlStore) GetTakenIPs(ctx context.Context, lockStrength LockingStrength, accountID string) ([]net.IP, error)

func (*SqlStore) GetTokenIDByHashedToken

func (s *SqlStore) GetTokenIDByHashedToken(ctx context.Context, hashedToken string) (string, error)

func (*SqlStore) GetUserByPATID added in v0.37.0

func (s *SqlStore) GetUserByPATID(ctx context.Context, lockStrength LockingStrength, patID string) (*types.User, error)

func (*SqlStore) GetUserByUserID

func (s *SqlStore) GetUserByUserID(ctx context.Context, lockStrength LockingStrength, userID string) (*types.User, error)

func (*SqlStore) GetUserIDByPeerKey added in v0.61.1

func (s *SqlStore) GetUserIDByPeerKey(ctx context.Context, lockStrength LockingStrength, peerKey string) (string, error)

func (*SqlStore) GetUserInviteByEmail added in v0.64.2

func (s *SqlStore) GetUserInviteByEmail(ctx context.Context, lockStrength LockingStrength, accountID, email string) (*types.UserInviteRecord, error)

GetUserInviteByEmail retrieves a user invite by account ID and email. Since email is encrypted with random IVs, we fetch all invites for the account and compare emails in memory after decryption.

func (*SqlStore) GetUserInviteByHashedToken added in v0.64.2

func (s *SqlStore) GetUserInviteByHashedToken(ctx context.Context, lockStrength LockingStrength, hashedToken string) (*types.UserInviteRecord, error)

GetUserInviteByHashedToken retrieves a user invite by its hashed token

func (*SqlStore) GetUserInviteByID added in v0.64.2

func (s *SqlStore) GetUserInviteByID(ctx context.Context, lockStrength LockingStrength, accountID, inviteID string) (*types.UserInviteRecord, error)

GetUserInviteByID retrieves a user invite by its ID and account ID

func (*SqlStore) GetUserPATs added in v0.37.0

func (s *SqlStore) GetUserPATs(ctx context.Context, lockStrength LockingStrength, userID string) ([]*types.PersonalAccessToken, error)

GetUserPATs retrieves personal access tokens for a user.

func (*SqlStore) GetUserPeers

func (s *SqlStore) GetUserPeers(ctx context.Context, lockStrength LockingStrength, accountID, userID string) ([]*nbpeer.Peer, error)

GetUserPeers retrieves peers for a user.

func (*SqlStore) GetZoneByDomain added in v0.63.0

func (s *SqlStore) GetZoneByDomain(ctx context.Context, accountID, domain string) (*zones.Zone, error)

func (*SqlStore) GetZoneByID added in v0.63.0

func (s *SqlStore) GetZoneByID(ctx context.Context, lockStrength LockingStrength, accountID, zoneID string) (*zones.Zone, error)

func (*SqlStore) GetZoneDNSRecords added in v0.63.0

func (s *SqlStore) GetZoneDNSRecords(ctx context.Context, lockStrength LockingStrength, accountID, zoneID string) ([]*records.Record, error)

func (*SqlStore) GetZoneDNSRecordsByName added in v0.63.0

func (s *SqlStore) GetZoneDNSRecordsByName(ctx context.Context, lockStrength LockingStrength, accountID, zoneID, name string) ([]*records.Record, error)

func (*SqlStore) IncrementNetworkSerial

func (s *SqlStore) IncrementNetworkSerial(ctx context.Context, accountId string) error

func (*SqlStore) IncrementSetupKeyUsage

func (s *SqlStore) IncrementSetupKeyUsage(ctx context.Context, setupKeyID string) error

func (*SqlStore) IsPrimaryAccount added in v0.55.0

func (s *SqlStore) IsPrimaryAccount(ctx context.Context, accountID string) (bool, string, error)

func (*SqlStore) MarkAccountPrimary added in v0.55.0

func (s *SqlStore) MarkAccountPrimary(ctx context.Context, accountID string) error

func (*SqlStore) MarkAllPendingJobsAsFailed added in v0.64.0

func (s *SqlStore) MarkAllPendingJobsAsFailed(ctx context.Context, accountID, peerID, reason string) error

job was pending for too long and has been cancelled

func (*SqlStore) MarkPATUsed added in v0.37.0

func (s *SqlStore) MarkPATUsed(ctx context.Context, patID string) error

MarkPATUsed marks a personal access token as used.

func (*SqlStore) MarkPendingJobsAsFailed added in v0.64.0

func (s *SqlStore) MarkPendingJobsAsFailed(ctx context.Context, accountID, peerID, jobID, reason string) error

job was pending for too long and has been cancelled

func (*SqlStore) RemovePeerFromAllGroups added in v0.53.0

func (s *SqlStore) RemovePeerFromAllGroups(ctx context.Context, peerID string) error

RemovePeerFromAllGroups removes a peer from all groups

func (*SqlStore) RemovePeerFromGroup added in v0.53.0

func (s *SqlStore) RemovePeerFromGroup(ctx context.Context, peerID string, groupID string) error

RemovePeerFromGroup removes a peer from a group

func (*SqlStore) RemoveResourceFromGroup

func (s *SqlStore) RemoveResourceFromGroup(ctx context.Context, accountId string, groupID string, resourceID string) error

RemoveResourceFromGroup removes a resource from a group. Method always needs to run in a transaction

func (*SqlStore) SaveAccount deprecated

func (s *SqlStore) SaveAccount(ctx context.Context, account *types.Account) error

Deprecated: Full account operations are no longer supported

func (*SqlStore) SaveAccountOnboarding added in v0.50.0

func (s *SqlStore) SaveAccountOnboarding(ctx context.Context, onboarding *types.AccountOnboarding) error

SaveAccountOnboarding updates the onboarding information for a specific account.

func (*SqlStore) SaveAccountSettings added in v0.47.0

func (s *SqlStore) SaveAccountSettings(ctx context.Context, accountID string, settings *types.Settings) error

SaveAccountSettings stores the account settings in DB.

func (*SqlStore) SaveDNSSettings

func (s *SqlStore) SaveDNSSettings(ctx context.Context, accountID string, settings *types.DNSSettings) error

SaveDNSSettings saves the DNS settings to the store.

func (*SqlStore) SaveInstallationID

func (s *SqlStore) SaveInstallationID(_ context.Context, ID string) error

func (*SqlStore) SaveNameServerGroup

func (s *SqlStore) SaveNameServerGroup(ctx context.Context, nameServerGroup *nbdns.NameServerGroup) error

SaveNameServerGroup saves a name server group to the database.

func (*SqlStore) SaveNetwork

func (s *SqlStore) SaveNetwork(ctx context.Context, network *networkTypes.Network) error

func (*SqlStore) SaveNetworkResource

func (s *SqlStore) SaveNetworkResource(ctx context.Context, resource *resourceTypes.NetworkResource) error

func (*SqlStore) SaveNetworkRouter

func (s *SqlStore) SaveNetworkRouter(ctx context.Context, router *routerTypes.NetworkRouter) error

func (*SqlStore) SavePAT added in v0.37.0

func (s *SqlStore) SavePAT(ctx context.Context, pat *types.PersonalAccessToken) error

SavePAT saves a personal access token to the database.

func (*SqlStore) SavePeer

func (s *SqlStore) SavePeer(ctx context.Context, accountID string, peer *nbpeer.Peer) error

func (*SqlStore) SavePeerLocation

func (s *SqlStore) SavePeerLocation(ctx context.Context, accountID string, peerWithLocation *nbpeer.Peer) error

func (*SqlStore) SavePeerStatus

func (s *SqlStore) SavePeerStatus(ctx context.Context, accountID, peerID string, peerStatus nbpeer.PeerStatus) error

func (*SqlStore) SavePolicy

func (s *SqlStore) SavePolicy(ctx context.Context, policy *types.Policy) error

SavePolicy saves a policy to the database.

func (*SqlStore) SavePostureChecks

func (s *SqlStore) SavePostureChecks(ctx context.Context, postureCheck *posture.Checks) error

SavePostureChecks saves a posture checks to the database.

func (*SqlStore) SaveRoute added in v0.48.0

func (s *SqlStore) SaveRoute(ctx context.Context, route *route.Route) error

SaveRoute saves a route to the database.

func (*SqlStore) SaveSetupKey

func (s *SqlStore) SaveSetupKey(ctx context.Context, setupKey *types.SetupKey) error

SaveSetupKey saves a setup key to the database.

func (*SqlStore) SaveUser

func (s *SqlStore) SaveUser(ctx context.Context, user *types.User) error

SaveUser saves the given user to the database.

func (*SqlStore) SaveUserInvite added in v0.64.2

func (s *SqlStore) SaveUserInvite(ctx context.Context, invite *types.UserInviteRecord) error

SaveUserInvite saves a user invite to the database

func (*SqlStore) SaveUserLastLogin

func (s *SqlStore) SaveUserLastLogin(ctx context.Context, accountID, userID string, lastLogin time.Time) error

SaveUserLastLogin stores the last login time for a user in DB.

func (*SqlStore) SaveUsers

func (s *SqlStore) SaveUsers(ctx context.Context, users []*types.User) error

SaveUsers saves the given list of users to the database.

func (*SqlStore) SetFieldEncrypt added in v0.62.0

func (s *SqlStore) SetFieldEncrypt(enc *crypt.FieldEncrypt)

SetFieldEncrypt sets the field encryptor for encrypting sensitive user data.

func (*SqlStore) UpdateAccountDomainAttributes

func (s *SqlStore) UpdateAccountDomainAttributes(ctx context.Context, accountID string, domain string, category string, isPrimaryDomain bool) error

func (*SqlStore) UpdateAccountNetwork added in v0.55.0

func (s *SqlStore) UpdateAccountNetwork(ctx context.Context, accountID string, ipNet net.IPNet) error

func (*SqlStore) UpdateDNSRecord added in v0.63.0

func (s *SqlStore) UpdateDNSRecord(ctx context.Context, record *records.Record) error

func (*SqlStore) UpdateGroup added in v0.53.0

func (s *SqlStore) UpdateGroup(ctx context.Context, group *types.Group) error

UpdateGroup updates a group in the store.

func (*SqlStore) UpdateGroups added in v0.53.0

func (s *SqlStore) UpdateGroups(ctx context.Context, accountID string, groups []*types.Group) error

UpdateGroups updates the given list of groups to the database.

func (*SqlStore) UpdateZone added in v0.63.0

func (s *SqlStore) UpdateZone(ctx context.Context, zone *zones.Zone) error

type Store

type Store interface {
	GetAccountsCounter(ctx context.Context) (int64, error)
	GetAllAccounts(ctx context.Context) []*types.Account
	GetAccount(ctx context.Context, accountID string) (*types.Account, error)
	GetAccountMeta(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.AccountMeta, error)
	GetAccountOnboarding(ctx context.Context, accountID string) (*types.AccountOnboarding, error)
	AccountExists(ctx context.Context, lockStrength LockingStrength, id string) (bool, error)
	GetAccountDomainAndCategory(ctx context.Context, lockStrength LockingStrength, accountID string) (string, string, error)
	GetAccountByUser(ctx context.Context, userID string) (*types.Account, error)
	GetAccountByPeerPubKey(ctx context.Context, peerKey string) (*types.Account, error)
	GetAnyAccountID(ctx context.Context) (string, error)
	GetAccountIDByPeerPubKey(ctx context.Context, peerKey string) (string, error)
	GetAccountIDByUserID(ctx context.Context, lockStrength LockingStrength, userID string) (string, error)
	GetAccountIDBySetupKey(ctx context.Context, peerKey string) (string, error)
	GetAccountIDByPeerID(ctx context.Context, lockStrength LockingStrength, peerID string) (string, error)
	GetAccountByPeerID(ctx context.Context, peerID string) (*types.Account, error)
	GetAccountBySetupKey(ctx context.Context, setupKey string) (*types.Account, error) // todo use key hash later
	GetAccountByPrivateDomain(ctx context.Context, domain string) (*types.Account, error)
	GetAccountIDByPrivateDomain(ctx context.Context, lockStrength LockingStrength, domain string) (string, error)
	GetAccountSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.Settings, error)
	GetAccountDNSSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.DNSSettings, error)
	GetAccountCreatedBy(ctx context.Context, lockStrength LockingStrength, accountID string) (string, error)
	SaveAccount(ctx context.Context, account *types.Account) error
	DeleteAccount(ctx context.Context, account *types.Account) error
	UpdateAccountDomainAttributes(ctx context.Context, accountID string, domain string, category string, isPrimaryDomain bool) error
	SaveDNSSettings(ctx context.Context, accountID string, settings *types.DNSSettings) error
	SaveAccountSettings(ctx context.Context, accountID string, settings *types.Settings) error
	CountAccountsByPrivateDomain(ctx context.Context, domain string) (int64, error)
	SaveAccountOnboarding(ctx context.Context, onboarding *types.AccountOnboarding) error

	GetUserByPATID(ctx context.Context, lockStrength LockingStrength, patID string) (*types.User, error)
	GetUserByUserID(ctx context.Context, lockStrength LockingStrength, userID string) (*types.User, error)
	GetAccountUsers(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.User, error)
	GetAccountOwner(ctx context.Context, lockStrength LockingStrength, accountID string) (*types.User, error)
	SaveUsers(ctx context.Context, users []*types.User) error
	SaveUser(ctx context.Context, user *types.User) error
	SaveUserLastLogin(ctx context.Context, accountID, userID string, lastLogin time.Time) error
	DeleteUser(ctx context.Context, accountID, userID string) error
	GetTokenIDByHashedToken(ctx context.Context, secret string) (string, error)
	DeleteHashedPAT2TokenIDIndex(hashedToken string) error
	DeleteTokenID2UserIDIndex(tokenID string) error

	SaveUserInvite(ctx context.Context, invite *types.UserInviteRecord) error
	GetUserInviteByID(ctx context.Context, lockStrength LockingStrength, accountID, inviteID string) (*types.UserInviteRecord, error)
	GetUserInviteByHashedToken(ctx context.Context, lockStrength LockingStrength, hashedToken string) (*types.UserInviteRecord, error)
	GetUserInviteByEmail(ctx context.Context, lockStrength LockingStrength, accountID, email string) (*types.UserInviteRecord, error)
	GetAccountUserInvites(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.UserInviteRecord, error)
	DeleteUserInvite(ctx context.Context, inviteID string) error

	GetPATByID(ctx context.Context, lockStrength LockingStrength, userID, patID string) (*types.PersonalAccessToken, error)
	GetUserPATs(ctx context.Context, lockStrength LockingStrength, userID string) ([]*types.PersonalAccessToken, error)
	GetPATByHashedToken(ctx context.Context, lockStrength LockingStrength, hashedToken string) (*types.PersonalAccessToken, error)
	MarkPATUsed(ctx context.Context, patID string) error
	SavePAT(ctx context.Context, pat *types.PersonalAccessToken) error
	DeletePAT(ctx context.Context, userID, patID string) error

	GetAccountGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Group, error)
	GetResourceGroups(ctx context.Context, lockStrength LockingStrength, accountID, resourceID string) ([]*types.Group, error)
	GetGroupByID(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) (*types.Group, error)
	GetGroupByName(ctx context.Context, lockStrength LockingStrength, groupName, accountID string) (*types.Group, error)
	GetGroupsByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, groupIDs []string) (map[string]*types.Group, error)
	CreateGroups(ctx context.Context, accountID string, groups []*types.Group) error
	UpdateGroups(ctx context.Context, accountID string, groups []*types.Group) error
	CreateGroup(ctx context.Context, group *types.Group) error
	UpdateGroup(ctx context.Context, group *types.Group) error
	DeleteGroup(ctx context.Context, accountID, groupID string) error
	DeleteGroups(ctx context.Context, accountID string, groupIDs []string) error

	GetAccountPolicies(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Policy, error)
	GetPolicyByID(ctx context.Context, lockStrength LockingStrength, accountID, policyID string) (*types.Policy, error)
	CreatePolicy(ctx context.Context, policy *types.Policy) error
	SavePolicy(ctx context.Context, policy *types.Policy) error
	DeletePolicy(ctx context.Context, accountID, policyID string) error

	GetPostureCheckByChecksDefinition(accountID string, checks *posture.ChecksDefinition) (*posture.Checks, error)
	GetAccountPostureChecks(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*posture.Checks, error)
	GetPostureChecksByID(ctx context.Context, lockStrength LockingStrength, accountID, postureCheckID string) (*posture.Checks, error)
	GetPostureChecksByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, postureChecksIDs []string) (map[string]*posture.Checks, error)
	SavePostureChecks(ctx context.Context, postureCheck *posture.Checks) error
	DeletePostureChecks(ctx context.Context, accountID, postureChecksID string) error

	GetPeerLabelsInAccount(ctx context.Context, lockStrength LockingStrength, accountId string, hostname string) ([]string, error)
	AddPeerToAllGroup(ctx context.Context, accountID string, peerID string) error
	AddPeerToGroup(ctx context.Context, accountID, peerId string, groupID string) error
	RemovePeerFromGroup(ctx context.Context, peerID string, groupID string) error
	RemovePeerFromAllGroups(ctx context.Context, peerID string) error
	GetPeerGroups(ctx context.Context, lockStrength LockingStrength, accountId string, peerId string) ([]*types.Group, error)
	GetPeerGroupIDs(ctx context.Context, lockStrength LockingStrength, accountId string, peerId string) ([]string, error)
	AddResourceToGroup(ctx context.Context, accountId string, groupID string, resource *types.Resource) error
	RemoveResourceFromGroup(ctx context.Context, accountId string, groupID string, resourceID string) error
	AddPeerToAccount(ctx context.Context, peer *nbpeer.Peer) error
	GetPeerByPeerPubKey(ctx context.Context, lockStrength LockingStrength, peerKey string) (*nbpeer.Peer, error)
	GetAccountPeers(ctx context.Context, lockStrength LockingStrength, accountID, nameFilter, ipFilter string) ([]*nbpeer.Peer, error)
	GetUserPeers(ctx context.Context, lockStrength LockingStrength, accountID, userID string) ([]*nbpeer.Peer, error)
	GetPeerByID(ctx context.Context, lockStrength LockingStrength, accountID string, peerID string) (*nbpeer.Peer, error)
	GetPeersByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, peerIDs []string) (map[string]*nbpeer.Peer, error)
	GetPeersByGroupIDs(ctx context.Context, accountID string, groupIDs []string) ([]*nbpeer.Peer, error)
	GetAccountPeersWithExpiration(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*nbpeer.Peer, error)
	GetAccountPeersWithInactivity(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*nbpeer.Peer, error)
	GetAllEphemeralPeers(ctx context.Context, lockStrength LockingStrength) ([]*nbpeer.Peer, error)
	SavePeer(ctx context.Context, accountID string, peer *nbpeer.Peer) error
	SavePeerStatus(ctx context.Context, accountID, peerID string, status nbpeer.PeerStatus) error
	SavePeerLocation(ctx context.Context, accountID string, peer *nbpeer.Peer) error
	ApproveAccountPeers(ctx context.Context, accountID string) (int, error)
	DeletePeer(ctx context.Context, accountID string, peerID string) error

	GetSetupKeyBySecret(ctx context.Context, lockStrength LockingStrength, key string) (*types.SetupKey, error)
	IncrementSetupKeyUsage(ctx context.Context, setupKeyID string) error
	GetAccountSetupKeys(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.SetupKey, error)
	GetSetupKeyByID(ctx context.Context, lockStrength LockingStrength, accountID, setupKeyID string) (*types.SetupKey, error)
	SaveSetupKey(ctx context.Context, setupKey *types.SetupKey) error
	DeleteSetupKey(ctx context.Context, accountID, keyID string) error

	GetAccountRoutes(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*route.Route, error)
	GetRouteByID(ctx context.Context, lockStrength LockingStrength, accountID, routeID string) (*route.Route, error)
	SaveRoute(ctx context.Context, route *route.Route) error
	DeleteRoute(ctx context.Context, accountID, routeID string) error

	GetAccountNameServerGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*dns.NameServerGroup, error)
	GetNameServerGroupByID(ctx context.Context, lockStrength LockingStrength, nameServerGroupID string, accountID string) (*dns.NameServerGroup, error)
	SaveNameServerGroup(ctx context.Context, nameServerGroup *dns.NameServerGroup) error
	DeleteNameServerGroup(ctx context.Context, accountID, nameServerGroupID string) error

	GetTakenIPs(ctx context.Context, lockStrength LockingStrength, accountId string) ([]net.IP, error)
	IncrementNetworkSerial(ctx context.Context, accountId string) error
	GetAccountNetwork(ctx context.Context, lockStrength LockingStrength, accountId string) (*types.Network, error)

	GetInstallationID() string
	SaveInstallationID(ctx context.Context, ID string) error

	// AcquireGlobalLock should attempt to acquire a global lock and return a function that releases the lock
	AcquireGlobalLock(ctx context.Context) func()

	// Close should close the store persisting all unsaved data.
	Close(ctx context.Context) error
	// GetStoreEngine should return Engine of the current store implementation.
	// This is also a method of metrics.DataSource interface.
	GetStoreEngine() types.Engine
	ExecuteInTransaction(ctx context.Context, f func(store Store) error) error

	GetAccountNetworks(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*networkTypes.Network, error)
	GetNetworkByID(ctx context.Context, lockStrength LockingStrength, accountID, networkID string) (*networkTypes.Network, error)
	SaveNetwork(ctx context.Context, network *networkTypes.Network) error
	DeleteNetwork(ctx context.Context, accountID, networkID string) error

	GetNetworkRoutersByNetID(ctx context.Context, lockStrength LockingStrength, accountID, netID string) ([]*routerTypes.NetworkRouter, error)
	GetNetworkRoutersByAccountID(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*routerTypes.NetworkRouter, error)
	GetNetworkRouterByID(ctx context.Context, lockStrength LockingStrength, accountID, routerID string) (*routerTypes.NetworkRouter, error)
	SaveNetworkRouter(ctx context.Context, router *routerTypes.NetworkRouter) error
	DeleteNetworkRouter(ctx context.Context, accountID, routerID string) error

	GetNetworkResourcesByNetID(ctx context.Context, lockStrength LockingStrength, accountID, netID string) ([]*resourceTypes.NetworkResource, error)
	GetNetworkResourcesByAccountID(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*resourceTypes.NetworkResource, error)
	GetNetworkResourceByID(ctx context.Context, lockStrength LockingStrength, accountID, resourceID string) (*resourceTypes.NetworkResource, error)
	GetNetworkResourceByName(ctx context.Context, lockStrength LockingStrength, accountID, resourceName string) (*resourceTypes.NetworkResource, error)
	SaveNetworkResource(ctx context.Context, resource *resourceTypes.NetworkResource) error
	DeleteNetworkResource(ctx context.Context, accountID, resourceID string) error
	GetPeerByIP(ctx context.Context, lockStrength LockingStrength, accountID string, ip net.IP) (*nbpeer.Peer, error)
	GetPeerIdByLabel(ctx context.Context, lockStrength LockingStrength, accountID string, hostname string) (string, error)
	GetAccountGroupPeers(ctx context.Context, lockStrength LockingStrength, accountID string) (map[string]map[string]struct{}, error)
	IsPrimaryAccount(ctx context.Context, accountID string) (bool, string, error)
	MarkAccountPrimary(ctx context.Context, accountID string) error
	UpdateAccountNetwork(ctx context.Context, accountID string, ipNet net.IPNet) error
	GetPolicyRulesByResourceID(ctx context.Context, lockStrength LockingStrength, accountID string, peerID string) ([]*types.PolicyRule, error)

	// SetFieldEncrypt sets the field encryptor for encrypting sensitive user data.
	SetFieldEncrypt(enc *crypt.FieldEncrypt)
	GetUserIDByPeerKey(ctx context.Context, lockStrength LockingStrength, peerKey string) (string, error)

	CreateZone(ctx context.Context, zone *zones.Zone) error
	UpdateZone(ctx context.Context, zone *zones.Zone) error
	DeleteZone(ctx context.Context, accountID, zoneID string) error
	GetZoneByID(ctx context.Context, lockStrength LockingStrength, accountID, zoneID string) (*zones.Zone, error)
	GetZoneByDomain(ctx context.Context, accountID, domain string) (*zones.Zone, error)
	GetAccountZones(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*zones.Zone, error)

	CreateDNSRecord(ctx context.Context, record *records.Record) error
	UpdateDNSRecord(ctx context.Context, record *records.Record) error
	DeleteDNSRecord(ctx context.Context, accountID, zoneID, recordID string) error
	GetDNSRecordByID(ctx context.Context, lockStrength LockingStrength, accountID, zoneID, recordID string) (*records.Record, error)
	GetZoneDNSRecords(ctx context.Context, lockStrength LockingStrength, accountID, zoneID string) ([]*records.Record, error)
	GetZoneDNSRecordsByName(ctx context.Context, lockStrength LockingStrength, accountID, zoneID, name string) ([]*records.Record, error)
	DeleteZoneDNSRecords(ctx context.Context, accountID, zoneID string) error
	CreatePeerJob(ctx context.Context, job *types.Job) error
	CompletePeerJob(ctx context.Context, job *types.Job) error
	GetPeerJobByID(ctx context.Context, accountID, jobID string) (*types.Job, error)
	GetPeerJobs(ctx context.Context, accountID, peerID string) ([]*types.Job, error)
	MarkPendingJobsAsFailed(ctx context.Context, accountID, peerID, jobID, reason string) error
	MarkAllPendingJobsAsFailed(ctx context.Context, accountID, peerID, reason string) error
	GetPeerIDByKey(ctx context.Context, lockStrength LockingStrength, key string) (string, error)
}

func NewStore

func NewStore(ctx context.Context, kind types.Engine, dataDir string, metrics telemetry.AppMetrics, skipMigration bool) (Store, error)

NewStore creates a new store based on the provided engine type, data directory, and telemetry metrics

func NewTestStoreFromSQL

func NewTestStoreFromSQL(ctx context.Context, filename string, dataDir string) (Store, func(), error)

NewTestStoreFromSQL is only used in tests. It will create a test database base of the store engine set in env. Optionally it can load a SQL file to the database. If the filename is empty it will return an empty database

Jump to

Keyboard shortcuts

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