prepare config for services state
This commit is contained in:
		
							
								
								
									
										15
									
								
								config.yaml
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								config.yaml
									
									
									
									
									
								
							@@ -1,6 +1,19 @@
 | 
			
		||||
mtd:
 | 
			
		||||
  services:
 | 
			
		||||
    - id: 3213a31c-59de-4e14-7648-e9508216e4bc
 | 
			
		||||
      entry_ip: 192.168.1.1
 | 
			
		||||
      entry_port: 8080
 | 
			
		||||
      service_ip: 10.0.1.2
 | 
			
		||||
      service_port: 80
 | 
			
		||||
    - id: 1233a31c-59de-4e14-7648-e9508216e4bc
 | 
			
		||||
      entry_ip: 192.168.1.3
 | 
			
		||||
      entry_port: 8081
 | 
			
		||||
      service_ip: 10.0.1.4
 | 
			
		||||
      service_port: 81
 | 
			
		||||
 | 
			
		||||
aws:
 | 
			
		||||
  regions: 
 | 
			
		||||
    - us-east-1
 | 
			
		||||
    - us-east-2
 | 
			
		||||
#    - us-east-2
 | 
			
		||||
    - us-west-1
 | 
			
		||||
  credentials_path: ./mtd_aws/.credentials
 | 
			
		||||
@@ -2,19 +2,46 @@ package state
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"net/netip"
 | 
			
		||||
 | 
			
		||||
	"github.com/google/uuid"
 | 
			
		||||
	"gopkg.in/yaml.v3"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Config contains all MTD services and cloud provider configs
 | 
			
		||||
type Config struct {
 | 
			
		||||
    AWS struct {
 | 
			
		||||
        Regions          []string `yaml:"regions"`
 | 
			
		||||
        Credentials_path   string `yaml:"credentials_path"`
 | 
			
		||||
    } `yaml:"aws"`
 | 
			
		||||
    MTD             mtdconf     `yaml:"mtd"`
 | 
			
		||||
    AWS             aws         `yaml:"aws"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Load_conf(filename string) (Config, error) {
 | 
			
		||||
type mtdconf struct {
 | 
			
		||||
    Services        []service   `yaml:"services"`
 | 
			
		||||
}
 | 
			
		||||
type service struct {
 | 
			
		||||
    ID              customUUID  `yaml:"id"`
 | 
			
		||||
    ServiceID       string      `yaml:"cloud_id"`
 | 
			
		||||
    EntryIP         netip.Addr  `yaml:"entry_ip"`
 | 
			
		||||
    EntryPort       uint16      `yaml:"entry_port"`
 | 
			
		||||
    ServiceIP       netip.Addr  `yaml:"service_ip"`
 | 
			
		||||
    ServicePort     uint16      `yaml:"service_port"`
 | 
			
		||||
}
 | 
			
		||||
type customUUID uuid.UUID
 | 
			
		||||
type aws struct {
 | 
			
		||||
    Regions         []string    `yaml:"regions"`
 | 
			
		||||
    CredentialsPath string      `yaml:"credentials_path"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *customUUID) UnmarshalYAML(value *yaml.Node) error {
 | 
			
		||||
	id, err := uuid.Parse(value.Value)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	*u = customUUID(id)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LoadConf loads config from a yaml file
 | 
			
		||||
func LoadConf(filename string) (Config, error) {
 | 
			
		||||
    var config Config
 | 
			
		||||
 | 
			
		||||
    data, err := ioutil.ReadFile(filename)
 | 
			
		||||
@@ -22,7 +49,7 @@ func Load_conf(filename string) (Config, error) {
 | 
			
		||||
        return config, err
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    err = yaml.Unmarshal(data, &config)
 | 
			
		||||
    err = yaml.Unmarshal([]byte(data), &config)
 | 
			
		||||
    if err != nil {
 | 
			
		||||
        return config, err
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user