provider.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package util
  13. import (
  14. "fmt"
  15. esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  16. )
  17. const (
  18. errNilStore = "found nil store"
  19. errMissingStoreSpec = "store is missing spec"
  20. errMissingProvider = "storeSpec is missing provider"
  21. errInvalidProvider = "invalid provider spec. Missing Conjur field in store %s"
  22. )
  23. // GetConjurProvider does the necessary nil checks on the generic store
  24. // it returns the conjur provider or an error.
  25. func GetConjurProvider(store esv1beta1.GenericStore) (*esv1beta1.ConjurProvider, error) {
  26. if store == nil {
  27. return nil, fmt.Errorf(errNilStore)
  28. }
  29. spec := store.GetSpec()
  30. if spec == nil {
  31. return nil, fmt.Errorf(errMissingStoreSpec)
  32. }
  33. if spec.Provider == nil {
  34. return nil, fmt.Errorf(errMissingProvider)
  35. }
  36. if spec.Provider.Conjur == nil {
  37. return nil, fmt.Errorf(errMissingProvider)
  38. }
  39. prov := spec.Provider.Conjur
  40. if prov == nil {
  41. return nil, fmt.Errorf(errInvalidProvider, store.GetObjectMeta().String())
  42. }
  43. return prov, nil
  44. }