From 3fb51d8f84dba015524d671581c7362e3152fbd9 Mon Sep 17 00:00:00 2001 From: schulze Date: Mon, 17 Apr 2023 15:21:06 +0200 Subject: [PATCH] misc --- config.default.yaml | 2 +- main.go | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/config.default.yaml b/config.default.yaml index 4420f39..77240ff 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -1,5 +1,5 @@ mtd: - services: [] + services: {} aws: regions: [] credentials_path: ./mtdaws/.credentials diff --git a/main.go b/main.go index 473b76e..774efbd 100644 --- a/main.go +++ b/main.go @@ -26,9 +26,11 @@ func main() { config = indexAllInstances(config) + state.SaveConf(ConfigPath, config) //TODO: figure out migration (MTD) config = movingTargetDefense(config) + state.SaveConf(ConfigPath, config) //TODO: proxy commands } @@ -54,13 +56,9 @@ func indexAllInstances(config state.Config) state.Config { fmt.Println("Error converting ip:\t", err) continue } - newService, found := indexInstance(config, cloudID, ip) - if !found { - fmt.Println("New instance found:\t", newService.CloudID) - config.MTD.Services = append(config.MTD.Services, newService) - state.SaveConf(ConfigPath, config) - awsNewInstanceCounter++ - } + var found bool + config, found = indexInstance(config, cloudID, ip) + if !found {awsNewInstanceCounter++} awsInstanceCounter++ } // TODO: Purge instances in config that are not found in the cloud @@ -70,7 +68,7 @@ func indexAllInstances(config state.Config) state.Config { return config } -func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (state.Service, bool) { +func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (state.Config, bool) { found := false for _, service := range config.MTD.Services { if service.CloudID == cloudID { @@ -78,10 +76,13 @@ func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (s break; } } - u := uuid.New() - newService := state.Service{ - ID: state.CustomUUID(u), - CloudID: cloudID, - ServiceIP: serviceIP} - return newService, found + + if !found { + fmt.Println("New instance found:\t", cloudID) + u := uuid.New() + config.MTD.Services[state.CustomUUID(u)] = state.Service{CloudID: cloudID, ServiceIP: serviceIP} + state.SaveConf(ConfigPath, config) + + } + return config, found }