@@ -27,41 +27,58 @@ func (d *Driver) GetDatabases(ctx context.Context) ([]schema.Database, error) {
2727 default :
2828 logger .Info ("Start enumerating RDS ..." )
2929 }
30- client := rds .NewRdsClient (rds .RdsClientBuilder ().
31- WithRegion (region .ValueOf (d .Regions [0 ])). // Maybe need traverse region
32- WithCredential (d .Auth ).
33- Build ())
34- request := & model.ListInstancesRequest {}
35- response , err := client .ListInstances (request )
36- if err != nil {
37- logger .Error ("Enumerate RDS failed." )
38- return list , err
39- }
40- for _ , instance := range * response .Instances {
41- i := reflect .ValueOf (instance .Datastore .Type )
42- engine := i .FieldByName ("value" ).String ()
43- _dbInstance := schema.Database {
44- InstanceId : instance .Id ,
45- Engine : engine ,
46- EngineVersion : instance .Datastore .Version ,
47- Region : instance .Region ,
30+ for _ , r := range d .Regions {
31+ client := newClient (r , d .Auth )
32+ if client == nil {
33+ continue
34+ }
35+ request := & model.ListInstancesRequest {}
36+ resp , err := client .ListInstances (request )
37+ if err != nil {
38+ continue
4839 }
49- if len (instance .PublicIps ) > 0 {
50- addrs := []string {}
51- for _ , ip := range instance .PublicIps {
52- addrs = append (addrs , fmt .Sprintf ("%s:%d" , ip , instance .Port ))
40+
41+ for _ , instance := range * resp .Instances {
42+ i := reflect .ValueOf (instance .Datastore .Type )
43+ engine := i .FieldByName ("value" ).String ()
44+ _dbInstance := schema.Database {
45+ InstanceId : instance .Id ,
46+ Engine : engine ,
47+ EngineVersion : instance .Datastore .Version ,
48+ Region : instance .Region ,
5349 }
54- _dbInstance .Address = strings .Join (addrs , "\n " )
55- } else if len (instance .PrivateIps ) > 0 {
56- addrs := []string {}
57- for _ , ip := range instance .PrivateIps {
58- addrs = append (addrs , fmt .Sprintf ("%s:%d" , ip , instance .Port ))
50+ if len (instance .PublicIps ) > 0 {
51+ addrs := []string {}
52+ for _ , ip := range instance .PublicIps {
53+ addrs = append (addrs , fmt .Sprintf ("%s:%d" , ip , instance .Port ))
54+ }
55+ _dbInstance .Address = strings .Join (addrs , "\n " )
56+ } else if len (instance .PrivateIps ) > 0 {
57+ addrs := []string {}
58+ for _ , ip := range instance .PrivateIps {
59+ addrs = append (addrs , fmt .Sprintf ("%s:%d" , ip , instance .Port ))
60+ }
61+ _dbInstance .Address = strings .Join (addrs , "\n " )
5962 }
60- _dbInstance .Address = strings .Join (addrs , "\n " )
61- }
6263
63- list = append (list , _dbInstance )
64+ list = append (list , _dbInstance )
65+ }
66+ break
6467 }
6568
6669 return list , nil
6770}
71+
72+ func newClient (r string , auth basic.Credentials ) * rds.RdsClient {
73+ defer func () {
74+ if err := recover (); err != nil {
75+ return
76+ }
77+ }()
78+
79+ client := rds .NewRdsClient (rds .RdsClientBuilder ().
80+ WithRegion (region .ValueOf (r )).
81+ WithCredential (auth ).
82+ Build ())
83+ return client
84+ }
0 commit comments