driver_validators.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package preview
  2. import (
  3. "fmt"
  4. "github.com/mitchellh/mapstructure"
  5. "github.com/porter-dev/switchboard/pkg/types"
  6. )
  7. func commonValidator(resource *types.Resource) (*Source, *Target, error) {
  8. source := &Source{}
  9. err := mapstructure.Decode(resource.Source, source)
  10. if err != nil {
  11. return nil, nil, fmt.Errorf("error parsing source for resource '%s': %w", resource.Name, err)
  12. }
  13. target := &Target{}
  14. err = mapstructure.Decode(resource.Target, target)
  15. if err != nil {
  16. return nil, nil, fmt.Errorf("error parsing target for resource '%s': %w", resource.Name, err)
  17. }
  18. return source, target, nil
  19. }
  20. func deployDriverValidator(resource *types.Resource) error {
  21. _, _, err := commonValidator(resource)
  22. if err != nil {
  23. return err
  24. }
  25. return nil
  26. }
  27. func buildImageDriverValidator(resource *types.Resource) error {
  28. _, _, err := commonValidator(resource)
  29. if err != nil {
  30. return err
  31. }
  32. return nil
  33. }
  34. func pushImageDriverValidator(resource *types.Resource) error {
  35. _, _, err := commonValidator(resource)
  36. if err != nil {
  37. return err
  38. }
  39. return nil
  40. }
  41. func updateConfigDriverValidator(resource *types.Resource) error {
  42. _, _, err := commonValidator(resource)
  43. if err != nil {
  44. return err
  45. }
  46. return nil
  47. }
  48. func randomStringDriverValidator(resource *types.Resource) error {
  49. _, _, err := commonValidator(resource)
  50. if err != nil {
  51. return err
  52. }
  53. driverConfig := &RandomStringDriverConfig{}
  54. err = mapstructure.Decode(resource.Config, driverConfig)
  55. if err != nil {
  56. return fmt.Errorf("error parsing config for resource '%s': %w", resource.Name, err)
  57. }
  58. return nil
  59. }
  60. func envGroupDriverValidator(resource *types.Resource) error {
  61. _, _, err := commonValidator(resource)
  62. if err != nil {
  63. return err
  64. }
  65. return nil
  66. }
  67. func osEnvDriverValidator(resource *types.Resource) error {
  68. return nil
  69. }