disregard inactive instances

This commit is contained in:
schulze 2023-04-18 15:03:34 +02:00
parent 143e839e78
commit 5571b66d52
3 changed files with 20 additions and 11 deletions

13
main.go
View File

@ -51,6 +51,10 @@ func movingTargetDefense(config state.Config) state.Config{
func indexAllInstances(config state.Config) state.Config { func indexAllInstances(config state.Config) state.Config {
fmt.Println("Indexing instances") fmt.Println("Indexing instances")
for _, service := range config.MTD.Services {
service.Active = false
}
//index AWS instances //index AWS instances
awsNewInstanceCounter := 0 awsNewInstanceCounter := 0
awsRemovedInstanceCounter := 0 awsRemovedInstanceCounter := 0
@ -77,9 +81,11 @@ func indexAllInstances(config state.Config) state.Config {
func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (state.Config, bool) { func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (state.Config, bool) {
found := false found := false
for _, service := range config.MTD.Services { var foundUUID state.CustomUUID
for u, service := range config.MTD.Services {
if service.CloudID == cloudID { if service.CloudID == cloudID {
found = true found = true
foundUUID = u
break; break;
} }
} }
@ -87,9 +93,12 @@ func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (s
if !found { if !found {
fmt.Println("New instance found:\t", cloudID) fmt.Println("New instance found:\t", cloudID)
u := uuid.New() u := uuid.New()
config.MTD.Services[state.CustomUUID(u)] = state.Service{CloudID: cloudID, ServiceIP: serviceIP} config.MTD.Services[state.CustomUUID(u)] = state.Service{CloudID: cloudID, ServiceIP: serviceIP, Active: true, AdminEnabled: true}
state.SaveConf(ConfigPath, config) state.SaveConf(ConfigPath, config)
} else {
config.MTD.Services[foundUUID] = state.Service{Active: true}
state.SaveConf(ConfigPath, config)
} }
return config, found return config, found
} }

View File

@ -68,16 +68,16 @@ func AWSMoveInstance(config state.Config) (state.Config) {
return config return config
} }
if !isInstanceRunning(realInstance) { if !instance.AdminEnabled {
fmt.Println("Error, Instance is not running!")
return config
}
if instance.AdminDisabled {
fmt.Println("Error, Service is Disabled!") fmt.Println("Error, Service is Disabled!")
return config return config
} }
if instance.Inactive { if !instance.Active {
fmt.Println("Error, Service is Inactive!") fmt.Println("Error, Service is not active!")
return config
}
if !isInstanceRunning(realInstance) {
fmt.Println("Error, Instance is not running!")
return config return config
} }

View File

@ -24,8 +24,8 @@ 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 // 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 { type Service struct {
CloudID string `yaml:"cloud_id"` CloudID string `yaml:"cloud_id"`
AdminDisabled bool `yaml:"admin_disabled"` AdminEnabled bool `yaml:"admin_enabled"`
Inactive bool `yaml:"inactive"` Active bool `yaml:"active"`
EntryIP netip.Addr `yaml:"entry_ip"` EntryIP netip.Addr `yaml:"entry_ip"`
EntryPort uint16 `yaml:"entry_port"` EntryPort uint16 `yaml:"entry_port"`
ServiceIP netip.Addr `yaml:"service_ip"` ServiceIP netip.Addr `yaml:"service_ip"`