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 {
fmt.Println("Indexing instances")
for _, service := range config.MTD.Services {
service.Active = false
}
//index AWS instances
awsNewInstanceCounter := 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) {
found := false
for _, service := range config.MTD.Services {
var foundUUID state.CustomUUID
for u, service := range config.MTD.Services {
if service.CloudID == cloudID {
found = true
foundUUID = u
break;
}
}
@ -87,9 +93,12 @@ func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (s
if !found {
fmt.Println("New instance found:\t", cloudID)
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)
} else {
config.MTD.Services[foundUUID] = state.Service{Active: true}
state.SaveConf(ConfigPath, config)
}
return config, found
}

View File

@ -68,16 +68,16 @@ func AWSMoveInstance(config state.Config) (state.Config) {
return config
}
if !isInstanceRunning(realInstance) {
fmt.Println("Error, Instance is not running!")
return config
}
if instance.AdminDisabled {
if !instance.AdminEnabled {
fmt.Println("Error, Service is Disabled!")
return config
}
if instance.Inactive {
fmt.Println("Error, Service is Inactive!")
if !instance.Active {
fmt.Println("Error, Service is not active!")
return config
}
if !isInstanceRunning(realInstance) {
fmt.Println("Error, Instance is not running!")
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
type Service struct {
CloudID string `yaml:"cloud_id"`
AdminDisabled bool `yaml:"admin_disabled"`
Inactive bool `yaml:"inactive"`
AdminEnabled bool `yaml:"admin_enabled"`
Active bool `yaml:"active"`
EntryIP netip.Addr `yaml:"entry_ip"`
EntryPort uint16 `yaml:"entry_port"`
ServiceIP netip.Addr `yaml:"service_ip"`