mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
cc65b4d46a
* [Chore] Remove setting provider from secret service Co-authored-by: Tania B <yalyna.ts@gmail.com> Co-authored-by: Joan López de la Franca Beltran <joanjan14@gmail.com> * Add a ShouldBeRedacted func Co-authored-by: Tania B <yalyna.ts@gmail.com> Co-authored-by: Joan López de la Franca Beltran <joanjan14@gmail.com> * Secrets: Make Migrator extensible Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> Co-authored-by: Tania B <yalyna.ts@gmail.com> * Alerting: Fix tests after refactor Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> Co-authored-by: Tania B <yalyna.ts@gmail.com> * Remove commented code no longer used * Fix Wire bindings Co-authored-by: Tania B <yalyna.ts@gmail.com> * Add constructors to secrets * Linting * Undo undesired change --------- Co-authored-by: gamab <gabi.mabs@gmail.com> Co-authored-by: Tania B <yalyna.ts@gmail.com> Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package manager
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"gopkg.in/ini.v1"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/usagestats"
|
|
encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider"
|
|
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/services/kmsproviders/osskmsproviders"
|
|
"github.com/grafana/grafana/pkg/services/secrets"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
func SetupTestService(tb testing.TB, store secrets.Store) *SecretsService {
|
|
return setupTestService(tb, store, featuremgmt.WithFeatures())
|
|
}
|
|
|
|
func SetupDisabledTestService(tb testing.TB, store secrets.Store) *SecretsService {
|
|
return setupTestService(tb, store, featuremgmt.WithFeatures(featuremgmt.FlagDisableEnvelopeEncryption))
|
|
}
|
|
|
|
func setupTestService(tb testing.TB, store secrets.Store, features *featuremgmt.FeatureManager) *SecretsService {
|
|
tb.Helper()
|
|
defaultKey := "SdlklWklckeLS"
|
|
if len(setting.SecretKey) > 0 {
|
|
defaultKey = setting.SecretKey
|
|
}
|
|
raw, err := ini.Load([]byte(`
|
|
[security]
|
|
secret_key = ` + defaultKey + `
|
|
|
|
[security.encryption]
|
|
data_keys_cache_ttl = 5m
|
|
data_keys_cache_cleanup_interval = 1ns`))
|
|
require.NoError(tb, err)
|
|
|
|
cfg := &setting.Cfg{Raw: raw}
|
|
|
|
encProvider := encryptionprovider.Provider{}
|
|
usageStats := &usagestats.UsageStatsMock{}
|
|
|
|
encryption, err := encryptionservice.ProvideEncryptionService(encProvider, usageStats, cfg)
|
|
require.NoError(tb, err)
|
|
|
|
secretsService, err := ProvideSecretsService(
|
|
store,
|
|
osskmsproviders.ProvideService(encryption, cfg, features),
|
|
encryption,
|
|
cfg,
|
|
features,
|
|
&usagestats.UsageStatsMock{T: tb},
|
|
)
|
|
require.NoError(tb, err)
|
|
|
|
return secretsService
|
|
}
|