| 56 | } |
| 57 | |
| 58 | func (m *DatabasesModule) PrintDatabases(outputDirectory string, verbosity int) { |
| 59 | // These struct values are used by the output module |
| 60 | m.output.Verbosity = verbosity |
| 61 | m.output.Directory = outputDirectory |
| 62 | m.output.CallingModule = "databases" |
| 63 | m.modLog = internal.TxtLog.WithFields(logrus.Fields{ |
| 64 | "module": m.output.CallingModule, |
| 65 | }) |
| 66 | if m.AWSProfile == "" { |
| 67 | m.AWSProfile = internal.BuildAWSPath(m.Caller) |
| 68 | } |
| 69 | |
| 70 | fmt.Printf("[%s][%s] Enumerating databases for account %s.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), aws.ToString(m.Caller.Account)) |
| 71 | fmt.Printf("[%s][%s] Supported Services: RDS, Redshift, DynamoDB, DocumentDB, Neptune\n", cyan(m.output.CallingModule), cyan(m.AWSProfile)) |
| 72 | |
| 73 | wg := new(sync.WaitGroup) |
| 74 | semaphore := make(chan struct{}, m.Goroutines) |
| 75 | // Create a channel to signal the spinner aka task status goroutine to finish |
| 76 | spinnerDone := make(chan bool) |
| 77 | //fire up the task status spinner/updated |
| 78 | go internal.SpinUntil(m.output.CallingModule, &m.CommandCounter, spinnerDone, "tasks") |
| 79 | |
| 80 | //create a channel to receive the objects |
| 81 | dataReceiver := make(chan Database) |
| 82 | |
| 83 | // Create a channel to signal to stop |
| 84 | receiverDone := make(chan bool) |
| 85 | |
| 86 | go m.Receiver(dataReceiver, receiverDone) |
| 87 | |
| 88 | //execute regional checks |
| 89 | for _, region := range m.AWSRegions { |
| 90 | wg.Add(1) |
| 91 | go m.executeChecks(region, wg, semaphore, dataReceiver) |
| 92 | } |
| 93 | |
| 94 | wg.Wait() |
| 95 | |
| 96 | // Send a message to the spinner goroutine to close the channel and stop |
| 97 | spinnerDone <- true |
| 98 | <-spinnerDone |
| 99 | receiverDone <- true |
| 100 | <-receiverDone |
| 101 | |
| 102 | sort.Slice(m.Databases, func(i, j int) bool { |
| 103 | return m.Databases[i].AWSService < m.Databases[j].AWSService |
| 104 | }) |
| 105 | |
| 106 | m.output.Headers = []string{ |
| 107 | "Account", |
| 108 | "Service", |
| 109 | "Engine", |
| 110 | "Region", |
| 111 | "Name", |
| 112 | "Size", |
| 113 | "UserName", |
| 114 | "Endpoint", |
| 115 | "Port", |