2
0

config.go 939 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cloud
  2. import (
  3. "fmt"
  4. )
  5. const Redacted = "REDACTED"
  6. // Config allows for nested configurations which encapsulate their functionality to be validated and compared easily
  7. type Config interface {
  8. Validate() error
  9. Sanitize() Config
  10. Equals(Config) bool
  11. }
  12. // KeyedConfig is a top level Config which uses its public values as a unique identifier allowing duplicates to be identified
  13. type KeyedConfig interface {
  14. Config
  15. Key() string
  16. Provider() string
  17. }
  18. type KeyedConfigWatcher interface {
  19. GetConfigs() []KeyedConfig
  20. }
  21. func GetInterfaceValue[T any](fmap map[string]interface{}, key string) (T, error) {
  22. var value T
  23. interfaceValue, ok := fmap[key]
  24. if !ok {
  25. return value, fmt.Errorf("FromInterface: missing '%s' property", key)
  26. }
  27. typedValue, ok := interfaceValue.(T)
  28. if !ok {
  29. return value, fmt.Errorf("GetInterfaceValue: property '%s' had expected type '%T' but did not match", key, value)
  30. }
  31. return typedValue, nil
  32. }