remove UUIDs
This commit is contained in:
parent
d0cd4340a5
commit
c6c26bd914
8
main.go
8
main.go
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/thefeli73/polemos/mtdaws"
|
||||
"github.com/thefeli73/polemos/state"
|
||||
)
|
||||
@ -39,6 +38,7 @@ func indexAllInstances(config state.Config) state.Config {
|
||||
|
||||
//index AWS instances
|
||||
awsNewInstanceCounter := 0
|
||||
awsRemovedInstanceCounter := 0
|
||||
awsInstanceCounter := 0
|
||||
awsInstances := mtdaws.GetInstances(config)
|
||||
for _, instance := range awsInstances {
|
||||
@ -57,7 +57,8 @@ func indexAllInstances(config state.Config) state.Config {
|
||||
}
|
||||
awsInstanceCounter++
|
||||
}
|
||||
fmt.Printf("Found %d AWS instances (%d newly added)\n", awsInstanceCounter, awsNewInstanceCounter)
|
||||
// TODO: Purge instances in config that are not found in the cloud
|
||||
fmt.Printf("Found %d AWS instances (%d newly added, %d removed)\n", awsInstanceCounter, awsNewInstanceCounter, awsRemovedInstanceCounter)
|
||||
|
||||
|
||||
return config
|
||||
@ -68,11 +69,10 @@ func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (s
|
||||
for _, service := range config.MTD.Services {
|
||||
if service.CloudID == cloudID {
|
||||
found = true
|
||||
break;
|
||||
}
|
||||
}
|
||||
u := uuid.New()
|
||||
newService := state.Service{
|
||||
ID: state.CustomUUID(u),
|
||||
CloudID: cloudID,
|
||||
ServiceIP: serviceIP}
|
||||
return newService, found
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"net/netip"
|
||||
"os"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@ -22,7 +21,6 @@ type mtdconf struct {
|
||||
|
||||
// Service contains all necessary information about a service to identify it in the cloud as well as configuring a proxy for it
|
||||
type Service struct {
|
||||
ID CustomUUID `yaml:"id"`
|
||||
CloudID string `yaml:"cloud_id"`
|
||||
EntryIP netip.Addr `yaml:"entry_ip"`
|
||||
EntryPort uint16 `yaml:"entry_port"`
|
||||
@ -30,29 +28,11 @@ type Service struct {
|
||||
ServicePort uint16 `yaml:"service_port"`
|
||||
}
|
||||
|
||||
// CustomUUID is an alias for uuid.UUID to enable custom unmarshal function
|
||||
type CustomUUID uuid.UUID
|
||||
|
||||
type aws struct {
|
||||
Regions []string `yaml:"regions"`
|
||||
CredentialsPath string `yaml:"credentials_path"`
|
||||
}
|
||||
|
||||
// UnmarshalYAML parses uuid in yaml to CustomUUID type
|
||||
func (u *CustomUUID) UnmarshalYAML(value *yaml.Node) error {
|
||||
id, err := uuid.Parse(value.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*u = CustomUUID(id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalYAML parses CustomUUID type to uuid string for yaml
|
||||
func (u CustomUUID) MarshalYAML() (interface{}, error) {
|
||||
return uuid.UUID(u).String(), nil
|
||||
}
|
||||
|
||||
// LoadConf loads config from a yaml file
|
||||
func LoadConf(filename string) (Config) {
|
||||
var config Config
|
||||
|
Loading…
Reference in New Issue
Block a user