This commit is contained in:
schulze 2023-04-17 15:21:06 +02:00
parent 61175acc67
commit 3fb51d8f84
2 changed files with 16 additions and 15 deletions

View File

@ -1,5 +1,5 @@
mtd: mtd:
services: [] services: {}
aws: aws:
regions: [] regions: []
credentials_path: ./mtdaws/.credentials credentials_path: ./mtdaws/.credentials

29
main.go
View File

@ -26,9 +26,11 @@ func main() {
config = indexAllInstances(config) config = indexAllInstances(config)
state.SaveConf(ConfigPath, config)
//TODO: figure out migration (MTD) //TODO: figure out migration (MTD)
config = movingTargetDefense(config) config = movingTargetDefense(config)
state.SaveConf(ConfigPath, config)
//TODO: proxy commands //TODO: proxy commands
} }
@ -54,13 +56,9 @@ func indexAllInstances(config state.Config) state.Config {
fmt.Println("Error converting ip:\t", err) fmt.Println("Error converting ip:\t", err)
continue continue
} }
newService, found := indexInstance(config, cloudID, ip) var found bool
if !found { config, found = indexInstance(config, cloudID, ip)
fmt.Println("New instance found:\t", newService.CloudID) if !found {awsNewInstanceCounter++}
config.MTD.Services = append(config.MTD.Services, newService)
state.SaveConf(ConfigPath, config)
awsNewInstanceCounter++
}
awsInstanceCounter++ awsInstanceCounter++
} }
// TODO: Purge instances in config that are not found in the cloud // 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 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 found := false
for _, service := range config.MTD.Services { for _, service := range config.MTD.Services {
if service.CloudID == cloudID { if service.CloudID == cloudID {
@ -78,10 +76,13 @@ func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (s
break; break;
} }
} }
u := uuid.New()
newService := state.Service{ if !found {
ID: state.CustomUUID(u), fmt.Println("New instance found:\t", cloudID)
CloudID: cloudID, u := uuid.New()
ServiceIP: serviceIP} config.MTD.Services[state.CustomUUID(u)] = state.Service{CloudID: cloudID, ServiceIP: serviceIP}
return newService, found state.SaveConf(ConfigPath, config)
}
return config, found
} }