store

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: BSD-3-Clause Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateFileStoreToSqlite

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

MigrateFileStoreToSqlite migrates the file store to the SQLite store.

Types

type Engine

type Engine string
const (
	FileStoreEngine     Engine = "jsonfile"
	SqliteStoreEngine   Engine = "sqlite"
	PostgresStoreEngine Engine = "postgres"
)

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() Engine

GetStoreEngine returns FileStoreEngine

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.
)

type SqlStore

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

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

func NewPostgresqlStore

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

NewPostgresqlStore creates a new Postgres store.

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 Engine, metrics telemetry.AppMetrics) (*SqlStore, error)

NewSqlStore creates a new SqlStore instance.

func NewSqliteStore

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

NewSqliteStore creates a new SQLite store.

func NewSqliteStoreFromFileStore

func NewSqliteStoreFromFileStore(ctx context.Context, fileStore *FileStore, dataDir string, metrics telemetry.AppMetrics) (*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) AcquireReadLockByUID

func (s *SqlStore) AcquireReadLockByUID(ctx context.Context, uniqueID string) (unlock func())

AcquireReadLockByUID acquires an ID lock for writing to a resource and returns a function that releases the lock

func (*SqlStore) AcquireWriteLockByUID

func (s *SqlStore) AcquireWriteLockByUID(ctx context.Context, uniqueID string) (unlock func())

AcquireWriteLockByUID acquires an ID lock for writing to a resource 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 string, peerId string, groupID string) error

AddPeerToGroup adds a peer to a group. Method always needs to run in a transaction

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) Close

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

Close closes the underlying DB connection

func (*SqlStore) CreatePolicy

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

func (*SqlStore) DeleteAccount

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

func (*SqlStore) DeleteGroup

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

DeleteGroup deletes a group from the database.

func (*SqlStore) DeleteGroups

func (s *SqlStore) DeleteGroups(ctx context.Context, strength LockingStrength, 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, lockStrength LockingStrength, accountID, nsGroupID string) error

DeleteNameServerGroup deletes a name server group from the database.

func (*SqlStore) DeleteNetwork

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

func (*SqlStore) DeleteNetworkResource

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

func (*SqlStore) DeleteNetworkRouter

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

func (*SqlStore) DeletePolicy

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

func (*SqlStore) DeletePostureChecks

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

DeletePostureChecks deletes a posture checks from the database.

func (*SqlStore) DeleteSetupKey

func (s *SqlStore) DeleteSetupKey(ctx context.Context, lockStrength LockingStrength, 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) 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) 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) GetAccountGroups

func (s *SqlStore) GetAccountGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Group, 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(userID string) (string, 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) 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) GetAccountUsers

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

func (*SqlStore) GetAllAccounts

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

func (*SqlStore) GetDB

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

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) 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) GetPeerByPeerPubKey

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

func (*SqlStore) GetPeerLabelsInAccount

func (s *SqlStore) GetPeerLabelsInAccount(ctx context.Context, lockStrength LockingStrength, accountID string) ([]string, 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) 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, routeID string, accountID 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() 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) GetUserByTokenID

func (s *SqlStore) GetUserByTokenID(ctx context.Context, tokenID string) (*types.User, error)

func (*SqlStore) GetUserByUserID

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

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) IncrementNetworkSerial

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

func (*SqlStore) IncrementSetupKeyUsage

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

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

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

func (*SqlStore) SaveDNSSettings

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

SaveDNSSettings saves the DNS settings to the store.

func (*SqlStore) SaveGroup

func (s *SqlStore) SaveGroup(ctx context.Context, lockStrength LockingStrength, group *types.Group) error

SaveGroup saves a group to the store.

func (*SqlStore) SaveGroups

func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength, groups []*types.Group) error

SaveGroups saves the given list of groups to the database.

func (*SqlStore) SaveInstallationID

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

func (*SqlStore) SaveNameServerGroup

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

SaveNameServerGroup saves a name server group to the database.

func (*SqlStore) SaveNetwork

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

func (*SqlStore) SaveNetworkResource

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

func (*SqlStore) SaveNetworkRouter

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

func (*SqlStore) SavePeer

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

func (*SqlStore) SavePeerLocation

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

func (*SqlStore) SavePeerStatus

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

func (*SqlStore) SavePolicy

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

SavePolicy saves a policy to the database.

func (*SqlStore) SavePostureChecks

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

SavePostureChecks saves a posture checks to the database.

func (*SqlStore) SaveSetupKey

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

SaveSetupKey saves a setup key to the database.

func (*SqlStore) SaveUser

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

SaveUser saves the given user 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(accountID string, users map[string]*types.User) error

SaveUsers saves the given list of users to the database. It updates existing users if a conflict occurs.

func (*SqlStore) UpdateAccountDomainAttributes

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

type Store

type Store interface {
	GetAllAccounts(ctx context.Context) []*types.Account
	GetAccount(ctx context.Context, accountID string) (*types.Account, 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)
	GetAccountIDByPeerPubKey(ctx context.Context, peerKey string) (string, error)
	GetAccountIDByUserID(userID string) (string, error)
	GetAccountIDBySetupKey(ctx context.Context, peerKey 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)
	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, lockStrength LockingStrength, accountID string, settings *types.DNSSettings) error

	GetUserByTokenID(ctx context.Context, tokenID 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)
	SaveUsers(accountID string, users map[string]*types.User) error
	SaveUser(ctx context.Context, lockStrength LockingStrength, user *types.User) error
	SaveUserLastLogin(ctx context.Context, accountID, userID string, lastLogin time.Time) error
	GetTokenIDByHashedToken(ctx context.Context, secret string) (string, error)
	DeleteHashedPAT2TokenIDIndex(hashedToken string) error
	DeleteTokenID2UserIDIndex(tokenID 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)
	SaveGroups(ctx context.Context, lockStrength LockingStrength, groups []*types.Group) error
	SaveGroup(ctx context.Context, lockStrength LockingStrength, group *types.Group) error
	DeleteGroup(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) error
	DeleteGroups(ctx context.Context, strength LockingStrength, 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, lockStrength LockingStrength, policy *types.Policy) error
	SavePolicy(ctx context.Context, lockStrength LockingStrength, policy *types.Policy) error
	DeletePolicy(ctx context.Context, lockStrength LockingStrength, 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, lockStrength LockingStrength, postureCheck *posture.Checks) error
	DeletePostureChecks(ctx context.Context, lockStrength LockingStrength, accountID, postureChecksID string) error

	GetPeerLabelsInAccount(ctx context.Context, lockStrength LockingStrength, accountId string) ([]string, error)
	AddPeerToAllGroup(ctx context.Context, accountID string, peerID string) error
	AddPeerToGroup(ctx context.Context, accountId string, peerId string, groupID 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)
	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)
	SavePeer(ctx context.Context, accountID string, peer *nbpeer.Peer) error
	SavePeerStatus(accountID, peerID string, status nbpeer.PeerStatus) error
	SavePeerLocation(accountID string, peer *nbpeer.Peer) 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, lockStrength LockingStrength, setupKey *types.SetupKey) error
	DeleteSetupKey(ctx context.Context, lockStrength LockingStrength, accountID, keyID string) error

	GetAccountRoutes(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*route.Route, error)
	GetRouteByID(ctx context.Context, lockStrength LockingStrength, routeID string, accountID string) (*route.Route, 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, lockStrength LockingStrength, nameServerGroup *dns.NameServerGroup) error
	DeleteNameServerGroup(ctx context.Context, lockStrength LockingStrength, accountID, nameServerGroupID string) error

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

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

	// AcquireWriteLockByUID should attempt to acquire a lock for write purposes and return a function that releases the lock
	AcquireWriteLockByUID(ctx context.Context, uniqueID string) func()
	// AcquireReadLockByUID should attempt to acquire lock for read purposes and return a function that releases the lock
	AcquireReadLockByUID(ctx context.Context, uniqueID string) func()
	// 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() 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, lockStrength LockingStrength, network *networkTypes.Network) error
	DeleteNetwork(ctx context.Context, lockStrength LockingStrength, 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, lockStrength LockingStrength, router *routerTypes.NetworkRouter) error
	DeleteNetworkRouter(ctx context.Context, lockStrength LockingStrength, 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, lockStrength LockingStrength, resource *resourceTypes.NetworkResource) error
	DeleteNetworkResource(ctx context.Context, lockStrength LockingStrength, accountID, resourceID string) error
}

func NewStore

func NewStore(ctx context.Context, kind Engine, dataDir string, metrics telemetry.AppMetrics) (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