provider.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright © The ESO Authors
  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 secretserver
  14. import (
  15. "encoding/json"
  16. "github.com/DelineaXPM/tss-sdk-go/v3/server"
  17. "github.com/external-secrets/external-secrets-e2e/framework"
  18. "github.com/onsi/gomega"
  19. )
  20. type secretStoreProvider struct {
  21. api *server.Server
  22. cfg *config
  23. framework *framework.Framework
  24. secretID map[string]int
  25. }
  26. func (p *secretStoreProvider) init(cfg *config, f *framework.Framework) {
  27. p.cfg = cfg
  28. p.secretID = make(map[string]int)
  29. p.framework = f
  30. secretserverClient, err := server.New(server.Configuration{
  31. Credentials: server.UserCredential{
  32. Username: cfg.username,
  33. Password: cfg.password,
  34. },
  35. ServerURL: cfg.serverURL,
  36. })
  37. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  38. p.api = secretserverClient
  39. }
  40. func (p *secretStoreProvider) CreateSecret(key string, val framework.SecretEntry) {
  41. var data map[string]interface{}
  42. err := json.Unmarshal([]byte(val.Value), &data)
  43. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  44. fields := make([]server.SecretField, 1)
  45. fields[0].FieldID = 329 // Data
  46. fields[0].ItemValue = val.Value
  47. s, err := p.api.CreateSecret(server.Secret{
  48. SecretTemplateID: 6051, // custom template
  49. SiteID: 1,
  50. FolderID: 10,
  51. Name: key,
  52. Fields: fields,
  53. })
  54. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  55. p.secretID[key] = s.ID
  56. }
  57. func (p *secretStoreProvider) DeleteSecret(key string) {
  58. err := p.api.DeleteSecret(p.secretID[key])
  59. gomega.Expect(err).ToNot(gomega.HaveOccurred())
  60. }