Add FindExistingPostureCheck (#2075)

This commit is contained in:
pascal-fischer
2024-05-30 15:22:42 +02:00
committed by GitHub
parent f176807ebe
commit 012235ff12
7 changed files with 207 additions and 143 deletions

View File

@ -1,6 +1,7 @@
package server
import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
@ -538,6 +539,21 @@ func (s *SqlStore) SaveUserLastLogin(accountID, userID string, lastLogin time.Ti
return s.db.Save(user).Error
}
func (s *SqlStore) GetPostureCheckByChecksDefinition(accountID string, checks *posture.ChecksDefinition) (*posture.Checks, error) {
definitionJSON, err := json.Marshal(checks)
if err != nil {
return nil, err
}
var postureCheck posture.Checks
err = s.db.Where("account_id = ? AND checks = ?", accountID, string(definitionJSON)).First(&postureCheck).Error
if err != nil {
return nil, err
}
return &postureCheck, nil
}
// Close closes the underlying DB connection
func (s *SqlStore) Close() error {
sql, err := s.db.DB()