client_get_secret.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 ovh
  14. import (
  15. "context"
  16. "errors"
  17. "fmt"
  18. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  19. )
  20. // GetSecret retrieves a single secret from the provider.
  21. // The created secret will store the entire secret value under the specified key.
  22. // You can specify a key, a property and a version.
  23. func (cl *ovhClient) GetSecret(ctx context.Context, ref esv1.ExternalSecretDataRemoteRef) ([]byte, error) {
  24. // Retrieve the KMS secret using the OVH SDK.
  25. secretData, _, err := cl.getSecretWithOvhSDK(ctx, cl.okmsID, ref)
  26. if err != nil {
  27. if errors.Is(err, esv1.NoSecretErr) {
  28. return []byte{}, err
  29. }
  30. return []byte{}, fmt.Errorf("failed to retrieve secret at path %q: %w", ref.Key, err)
  31. }
  32. return secretData, nil
  33. }