provider.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package delinea
  14. import (
  15. "encoding/json"
  16. "github.com/DelineaXPM/dsv-sdk-go/v2/vault"
  17. "github.com/external-secrets/external-secrets-e2e/framework"
  18. "github.com/onsi/gomega"
  19. )
  20. type secretStoreProvider struct {
  21. api *vault.Vault
  22. cfg *config
  23. }
  24. func (p *secretStoreProvider) init(cfg *config) {
  25. p.cfg = cfg
  26. dsvClient, err := vault.New(vault.Configuration{
  27. Credentials: vault.ClientCredential{
  28. ClientID: cfg.clientID,
  29. ClientSecret: cfg.clientSecret,
  30. },
  31. Tenant: cfg.tenant,
  32. URLTemplate: cfg.urlTemplate,
  33. TLD: cfg.tld,
  34. })
  35. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  36. p.api = dsvClient
  37. }
  38. func (p *secretStoreProvider) CreateSecret(key string, val framework.SecretEntry) {
  39. var data map[string]any
  40. err := json.Unmarshal([]byte(val.Value), &data)
  41. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  42. _, err = p.api.CreateSecret(key, &vault.SecretCreateRequest{
  43. Data: data,
  44. })
  45. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  46. }
  47. func (p *secretStoreProvider) DeleteSecret(key string) {
  48. err := p.api.DeleteSecret(key)
  49. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  50. }