provider.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
  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 AWS field in store %s"
  22. )
  23. // GetAWSProvider does the necessary nil checks on the generic store
  24. // it returns the aws provider or an error.
  25. func GetAWSProvider(store esv1alpha1.GenericStore) (*esv1alpha1.AWSProvider, error) {
  26. if store == nil {
  27. return nil, fmt.Errorf(errNilStore)
  28. }
  29. spc := store.GetSpec()
  30. if spc == nil {
  31. return nil, fmt.Errorf(errMissingStoreSpec)
  32. }
  33. if spc.Provider == nil {
  34. return nil, fmt.Errorf(errMissingProvider)
  35. }
  36. prov := spc.Provider.AWS
  37. if prov == nil {
  38. return nil, fmt.Errorf(errInvalidProvider, store.GetObjectMeta().String())
  39. }
  40. return prov, nil
  41. }