github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/config/provider.go (about)

     1  package config
     2  
     3  import (
     4  	"github.com/kyma-project/kyma-environment-broker/internal"
     5  )
     6  
     7  type (
     8  	ConfigReader interface {
     9  		Read(kymaVersion, planName string) (string, error)
    10  	}
    11  
    12  	ConfigValidator interface {
    13  		Validate(cfgString string) error
    14  	}
    15  
    16  	ConfigConverter interface {
    17  		ConvertToStruct(cfgString string) (internal.ConfigForPlan, error)
    18  	}
    19  )
    20  
    21  type ConfigProvider struct {
    22  	Reader    ConfigReader
    23  	Validator ConfigValidator
    24  	Converter ConfigConverter
    25  }
    26  
    27  func NewConfigProvider(reader ConfigReader, validator ConfigValidator, converter ConfigConverter) *ConfigProvider {
    28  	return &ConfigProvider{Reader: reader, Validator: validator, Converter: converter}
    29  }
    30  
    31  func (p *ConfigProvider) ProvideForGivenVersionAndPlan(kymaVersion, planName string) (*internal.ConfigForPlan, error) {
    32  	cfgString, err := p.Reader.Read(kymaVersion, planName)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	if err = p.Validator.Validate(cfgString); err != nil {
    38  		return nil, err
    39  	}
    40  
    41  	cfg, err := p.Converter.ConvertToStruct(cfgString)
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	return &cfg, nil
    47  }