provider.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 conjurutil provides utility functions for working with Conjur providers.
  14. // It contains helper functions for validating and extracting Conjur provider configurations.
  15. package conjurutil
  16. import (
  17. "errors"
  18. "fmt"
  19. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  20. )
  21. const (
  22. errNilStore = "found nil store"
  23. errMissingStoreSpec = "store is missing spec"
  24. errMissingProvider = "storeSpec is missing provider"
  25. errInvalidProvider = "invalid provider spec. Missing Conjur field in store %s"
  26. )
  27. // GetConjurProvider does the necessary nil checks on the generic store
  28. // it returns the conjur provider or an error.
  29. func GetConjurProvider(store esv1.GenericStore) (*esv1.ConjurProvider, error) {
  30. if store == nil {
  31. return nil, errors.New(errNilStore)
  32. }
  33. spec := store.GetSpec()
  34. if spec == nil {
  35. return nil, errors.New(errMissingStoreSpec)
  36. }
  37. if spec.Provider == nil {
  38. return nil, errors.New(errMissingProvider)
  39. }
  40. if spec.Provider.Conjur == nil {
  41. return nil, errors.New(errMissingProvider)
  42. }
  43. prov := spec.Provider.Conjur
  44. if prov == nil {
  45. return nil, fmt.Errorf(errInvalidProvider, store.GetObjectMeta().String())
  46. }
  47. return prov, nil
  48. }