mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
[management] remove withContext from store methods (#4422)
This commit is contained in:
@@ -914,7 +914,7 @@ func (s *SqlStore) GetAccountByPeerPubKey(ctx context.Context, peerKey string) (
|
|||||||
|
|
||||||
func (s *SqlStore) GetAnyAccountID(ctx context.Context) (string, error) {
|
func (s *SqlStore) GetAnyAccountID(ctx context.Context) (string, error) {
|
||||||
var account types.Account
|
var account types.Account
|
||||||
result := s.db.WithContext(ctx).Select("id").Order("created_at desc").Limit(1).Find(&account)
|
result := s.db.Select("id").Order("created_at desc").Limit(1).Find(&account)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return "", status.NewGetAccountFromStoreError(result.Error)
|
return "", status.NewGetAccountFromStoreError(result.Error)
|
||||||
}
|
}
|
||||||
@@ -1399,7 +1399,7 @@ func (s *SqlStore) AddPeerToGroup(ctx context.Context, accountID, peerID, groupI
|
|||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.db.WithContext(ctx).Clauses(clause.OnConflict{
|
err := s.db.Clauses(clause.OnConflict{
|
||||||
Columns: []clause.Column{{Name: "group_id"}, {Name: "peer_id"}},
|
Columns: []clause.Column{{Name: "group_id"}, {Name: "peer_id"}},
|
||||||
DoNothing: true,
|
DoNothing: true,
|
||||||
}).Create(peer).Error
|
}).Create(peer).Error
|
||||||
@@ -1414,7 +1414,7 @@ func (s *SqlStore) AddPeerToGroup(ctx context.Context, accountID, peerID, groupI
|
|||||||
|
|
||||||
// RemovePeerFromGroup removes a peer from a group
|
// RemovePeerFromGroup removes a peer from a group
|
||||||
func (s *SqlStore) RemovePeerFromGroup(ctx context.Context, peerID string, groupID string) error {
|
func (s *SqlStore) RemovePeerFromGroup(ctx context.Context, peerID string, groupID string) error {
|
||||||
err := s.db.WithContext(ctx).
|
err := s.db.
|
||||||
Delete(&types.GroupPeer{}, "group_id = ? AND peer_id = ?", groupID, peerID).Error
|
Delete(&types.GroupPeer{}, "group_id = ? AND peer_id = ?", groupID, peerID).Error
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1427,7 +1427,7 @@ func (s *SqlStore) RemovePeerFromGroup(ctx context.Context, peerID string, group
|
|||||||
|
|
||||||
// RemovePeerFromAllGroups removes a peer from all groups
|
// RemovePeerFromAllGroups removes a peer from all groups
|
||||||
func (s *SqlStore) RemovePeerFromAllGroups(ctx context.Context, peerID string) error {
|
func (s *SqlStore) RemovePeerFromAllGroups(ctx context.Context, peerID string) error {
|
||||||
err := s.db.WithContext(ctx).
|
err := s.db.
|
||||||
Delete(&types.GroupPeer{}, "peer_id = ?", peerID).Error
|
Delete(&types.GroupPeer{}, "peer_id = ?", peerID).Error
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2015,7 +2015,7 @@ func (s *SqlStore) SavePolicy(ctx context.Context, policy *types.Policy) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) DeletePolicy(ctx context.Context, accountID, policyID string) error {
|
func (s *SqlStore) DeletePolicy(ctx context.Context, accountID, policyID string) error {
|
||||||
return s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
return s.db.Transaction(func(tx *gorm.DB) error {
|
||||||
if err := tx.Where("policy_id = ?", policyID).Delete(&types.PolicyRule{}).Error; err != nil {
|
if err := tx.Where("policy_id = ?", policyID).Delete(&types.PolicyRule{}).Error; err != nil {
|
||||||
return fmt.Errorf("delete policy rules: %w", err)
|
return fmt.Errorf("delete policy rules: %w", err)
|
||||||
}
|
}
|
||||||
@@ -2706,7 +2706,7 @@ func (s *SqlStore) GetPeerByIP(ctx context.Context, lockStrength LockingStrength
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) GetPeerIdByLabel(ctx context.Context, lockStrength LockingStrength, accountID string, hostname string) (string, error) {
|
func (s *SqlStore) GetPeerIdByLabel(ctx context.Context, lockStrength LockingStrength, accountID string, hostname string) (string, error) {
|
||||||
tx := s.db.WithContext(ctx)
|
tx := s.db
|
||||||
if lockStrength != LockingStrengthNone {
|
if lockStrength != LockingStrengthNone {
|
||||||
tx = tx.Clauses(clause.Locking{Strength: string(lockStrength)})
|
tx = tx.Clauses(clause.Locking{Strength: string(lockStrength)})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user