grafana/pkg/services/kmsproviders/defaultprovider/grafana_provider.go
Joan López de la Franca Beltran cc65b4d46a
Secrets: Make the Migrator extensible (#67307)
* [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>
2023-06-19 23:44:01 +02:00

32 lines
857 B
Go

package defaultprovider
import (
"context"
"github.com/grafana/grafana/pkg/services/encryption"
"github.com/grafana/grafana/pkg/services/secrets"
"github.com/grafana/grafana/pkg/setting"
)
type grafanaProvider struct {
cfg *setting.Cfg
encryption encryption.Internal
}
func New(cfg *setting.Cfg, encryption encryption.Internal) secrets.Provider {
return grafanaProvider{
cfg: cfg,
encryption: encryption,
}
}
func (p grafanaProvider) Encrypt(ctx context.Context, blob []byte) ([]byte, error) {
key := p.cfg.SectionWithEnvOverrides("security").Key("secret_key").Value()
return p.encryption.Encrypt(ctx, blob, key)
}
func (p grafanaProvider) Decrypt(ctx context.Context, blob []byte) ([]byte, error) {
key := p.cfg.SectionWithEnvOverrides("security").Key("secret_key").Value()
return p.encryption.Decrypt(ctx, blob, key)
}