github.com/cloudfoundry/postgres-release/src/acceptance-tests@v0.0.0-20240511030151-872bdd2e0dba/testing/helpers/properties.go (about)

     1  package helpers
     2  
     3  import yaml "gopkg.in/yaml.v2"
     4  
     5  type Properties struct {
     6  	Databases PgProperties `yaml:"databases"`
     7  }
     8  type PgProperties struct {
     9  	Port                  int                   `yaml:"port"`
    10  	Databases             []PgDBProperties      `yaml:"databases,omitempty"`
    11  	Roles                 []PgRoleProperties    `yaml:"roles,omitempty"`
    12  	MaxConnections        int                   `yaml:"max_connections"`
    13  	LogLinePrefix         string                `yaml:"log_line_prefix"`
    14  	CollectStatementStats bool                  `yaml:"collect_statement_statistics"`
    15  	MonitTimeout          int                   `yaml:"monit_timeout,omitempty"`
    16  	AdditionalConfig      PgAdditionalConfigMap `yaml:"additional_config,omitempty"`
    17  	TLS                   PgTLS                 `yaml:"tls,omitempty"`
    18  }
    19  
    20  type PgDBProperties struct {
    21  	CITExt bool   `yaml:"citext"`
    22  	Name   string `yaml:"name"`
    23  }
    24  
    25  type PgRoleProperties struct {
    26  	Name        string   `yaml:"name"`
    27  	Password    string   `yaml:"password"`
    28  	Permissions []string `yaml:"permissions,omitempty"`
    29  }
    30  
    31  type PgTLS struct {
    32  	PrivateKey  string `yaml:"private_key"`
    33  	Certificate string `yaml:"certificate"`
    34  	CA          string `yaml:"ca"`
    35  }
    36  
    37  type PgAdditionalConfig interface{}
    38  type PgAdditionalConfigMap map[string]PgAdditionalConfig
    39  
    40  var defaultPgProperties = PgProperties{
    41  	LogLinePrefix:         "%m: ",
    42  	CollectStatementStats: false,
    43  	MaxConnections:        500,
    44  }
    45  
    46  type ManifestProperties struct {
    47  	ByJob map[string][]Properties
    48  }
    49  
    50  func decodeProperties(yamlData []byte) (Properties, error) {
    51  	var props Properties
    52  	var err error
    53  
    54  	props = Properties{Databases: defaultPgProperties}
    55  	err = yaml.Unmarshal(yamlData, &props)
    56  	if err != nil {
    57  		return Properties{}, err
    58  	}
    59  	return props, nil
    60  }
    61  
    62  func (mp *ManifestProperties) LoadJobProperties(jobName string, yamlData []byte) error {
    63  	props, err := decodeProperties(yamlData)
    64  	if err != nil {
    65  		return err
    66  	}
    67  	if mp.ByJob == nil {
    68  		mp.ByJob = make(map[string][]Properties)
    69  	}
    70  	mp.ByJob[jobName] = append(mp.ByJob[jobName], props)
    71  	return nil
    72  }
    73  
    74  func (mp ManifestProperties) GetJobProperties(jobName string) []Properties {
    75  	result := mp.ByJob[jobName]
    76  	return result
    77  }