75f3dd141c
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CI and Release / lint-frontend (push) Has been cancelled
CI and Release / dockerfile-scan (push) Has been cancelled
CI and Release / test-frontend (push) Has been cancelled
CI and Release / lint-verification-agent (push) Has been cancelled
CI and Release / test-verification-agent (push) Has been cancelled
CI and Release / e2e-verification-agent (push) Has been cancelled
CI and Release / test-backend (push) Has been cancelled
CI and Release / build-dev-image (push) Has been cancelled
CI and Release / push-dev-image (push) Has been cancelled
CI and Release / build-image (push) Has been cancelled
CI and Release / build-verification-image (push) Has been cancelled
CI and Release / determine-version (push) Has been cancelled
CI and Release / push-image (push) Has been cancelled
CI and Release / push-verification-image (12) (push) Has been cancelled
CI and Release / lint-backend (push) Has been cancelled
CI and Release / push-verification-image (17) (push) Has been cancelled
CI and Release / push-verification-image (18) (push) Has been cancelled
CI and Release / release (push) Has been cancelled
CI and Release / publish-helm-chart (push) Has been cancelled
CI and Release / push-verification-image (13) (push) Has been cancelled
CI and Release / push-verification-image (14) (push) Has been cancelled
CI and Release / push-verification-image (15) (push) Has been cancelled
CI and Release / push-verification-image (16) (push) Has been cancelled
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package storages
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
|
|
local_storage "databasus-backend/internal/features/storages/models/local"
|
|
s3_storage "databasus-backend/internal/features/storages/models/s3"
|
|
"databasus-backend/internal/util/encryption"
|
|
)
|
|
|
|
func SetStorageDatabaseCountersForTest(counters ...StorageDatabaseCounter) {
|
|
storageService.storageDatabaseCounters = counters
|
|
}
|
|
|
|
func CreateTestStorage(workspaceID uuid.UUID) *Storage {
|
|
storage := &Storage{
|
|
WorkspaceID: workspaceID,
|
|
Type: StorageTypeLocal,
|
|
Name: "Test Storage " + uuid.New().String(),
|
|
LocalStorage: &local_storage.LocalStorage{},
|
|
}
|
|
|
|
storage, err := storageRepository.Save(storage)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return storage
|
|
}
|
|
|
|
func CreateTestFlakyS3Storage(workspaceID uuid.UUID, endpoint string) *Storage {
|
|
encryptor := encryption.GetFieldEncryptor()
|
|
|
|
accessKey, err := encryptor.Encrypt("issue-582-access")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
secretKey, err := encryptor.Encrypt("issue-582-secret")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
storage := &Storage{
|
|
WorkspaceID: workspaceID,
|
|
Type: StorageTypeS3,
|
|
Name: "Flaky S3 " + uuid.New().String(),
|
|
S3Storage: &s3_storage.S3Storage{
|
|
S3Bucket: "issue-582-no-such-bucket-" + uuid.New().String(),
|
|
S3Region: "us-east-1",
|
|
S3AccessKey: accessKey,
|
|
S3SecretKey: secretKey,
|
|
S3Endpoint: endpoint,
|
|
},
|
|
}
|
|
|
|
saved, err := storageRepository.Save(storage)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return saved
|
|
}
|
|
|
|
func RemoveTestStorage(id uuid.UUID) {
|
|
storage, err := storageRepository.FindByID(id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = storageRepository.Delete(storage)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|