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

     1  package avs
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	kebError "github.com/kyma-project/kyma-environment-broker/internal/error"
     8  	"gopkg.in/yaml.v3"
     9  )
    10  
    11  type Config struct {
    12  	OauthTokenEndpoint                              string
    13  	OauthUsername                                   string
    14  	OauthPassword                                   string
    15  	OauthClientId                                   string
    16  	ApiEndpoint                                     string
    17  	DefinitionType                                  string `envconfig:"default=BASIC"`
    18  	Disabled                                        bool   `envconfig:"default=false"`
    19  	InternalTesterAccessId                          int64
    20  	InternalTesterService                           string `envconfig:"optional"`
    21  	GroupId                                         int64
    22  	ExternalTesterDisabled                          bool
    23  	ExternalTesterAccessId                          int64
    24  	ExternalTesterService                           string `envconfig:"optional"`
    25  	ParentId                                        int64
    26  	InstanceIdTagClassId                            int
    27  	ShootNameTagClassId                             int
    28  	RegionTagClassId                                int
    29  	GlobalAccountIdTagClassId                       int
    30  	SubAccountIdTagClassId                          int
    31  	LandscapeTagClassId                             int
    32  	ProviderTagClassId                              int
    33  	TrialInternalTesterAccessId                     int64    `envconfig:"optional"`
    34  	TrialParentId                                   int64    `envconfig:"optional"`
    35  	TrialGroupId                                    int64    `envconfig:"optional"`
    36  	MaintenanceModeDuringUpgradeDisabled            bool     `envconfig:"default=false"`
    37  	MaintenanceModeDuringUpgradeAlwaysDisabledGAIDs []string `envconfig:"-"`
    38  }
    39  
    40  func (c *Config) IsTrialConfigured() bool {
    41  	return c.TrialInternalTesterAccessId != 0 && c.TrialParentId != 0 && c.TrialGroupId != 0
    42  }
    43  
    44  func (c *Config) ReadMaintenanceModeDuringUpgradeAlwaysDisabledGAIDsFromYaml(yamlFilePath string) error {
    45  	yamlData, err := os.ReadFile(yamlFilePath)
    46  	if err != nil {
    47  		return fmt.Errorf("while reading YAML file with GA IDs: %w", err)
    48  	}
    49  	var gaIDs struct {
    50  		MaintenanceModeDuringUpgradeAlwaysDisabledGAIDs []string `yaml:"maintenanceModeDuringUpgradeAlwaysDisabledGAIDs"`
    51  	}
    52  	err = yaml.Unmarshal(yamlData, &gaIDs)
    53  	if err != nil {
    54  		return fmt.Errorf("while unmarshalling YAML file with GA IDs: %w", err)
    55  	}
    56  
    57  	c.MaintenanceModeDuringUpgradeAlwaysDisabledGAIDs = append(
    58  		c.MaintenanceModeDuringUpgradeAlwaysDisabledGAIDs,
    59  		gaIDs.MaintenanceModeDuringUpgradeAlwaysDisabledGAIDs...)
    60  
    61  	return nil
    62  }
    63  
    64  type avsError struct {
    65  	message string
    66  }
    67  
    68  func (e avsError) Error() string {
    69  	return e.message
    70  }
    71  
    72  func (e avsError) Component() kebError.ErrComponent {
    73  	return kebError.ErrAVS
    74  }
    75  
    76  func (e avsError) Reason() kebError.ErrReason {
    77  	return kebError.ErrHttpStatusCode
    78  }
    79  
    80  func NewAvsError(format string, args ...interface{}) kebError.ErrorReporter {
    81  	return avsError{message: fmt.Sprintf(format, args...)}
    82  }