3
3
package awsclient
4
4
5
5
import (
6
+ "context"
7
+
6
8
"github.com/aws/aws-sdk-go/aws/request"
9
+ "github.com/aws/aws-sdk-go/service/rds"
7
10
"github.com/aws/aws-sdk-go/service/servicequotas"
8
11
"github.com/aws/aws-sdk-go/service/servicequotas/servicequotasiface"
9
12
@@ -20,50 +23,102 @@ type Client interface {
20
23
//EC2
21
24
DescribeTransitGatewaysWithContext (ctx aws.Context , input * ec2.DescribeTransitGatewaysInput , opts ... request.Option ) (* ec2.DescribeTransitGatewaysOutput , error )
22
25
26
+ //RDS
27
+ DescribeDBInstancesPagesWithContext (ctx aws.Context , input * rds.DescribeDBInstancesInput , fn func (* rds.DescribeDBInstancesOutput , bool ) bool , opts ... request.Option ) error
28
+ DescribeDBLogFilesPagesWithContext (ctx aws.Context , input * rds.DescribeDBLogFilesInput , fn func (* rds.DescribeDBLogFilesOutput , bool ) bool , opts ... request.Option ) error
29
+ DescribePendingMaintenanceActionsPagesWithContext (ctx aws.Context , input * rds.DescribePendingMaintenanceActionsInput , fn func (* rds.DescribePendingMaintenanceActionsOutput , bool ) bool , opts ... request.Option ) error
30
+ DescribeDBLogFilesAll (ctx context.Context , instanceId string ) ([]* rds.DescribeDBLogFilesOutput , error )
31
+ DescribePendingMaintenanceActionsAll (ctx context.Context ) ([]* rds.ResourcePendingMaintenanceActions , error )
32
+ DescribeDBInstancesAll (ctx context.Context ) ([]* rds.DBInstance , error )
33
+
23
34
// Service Quota
24
- GetServiceQuota (* servicequotas.GetServiceQuotaInput ) (* servicequotas.GetServiceQuotaOutput , error )
25
35
GetServiceQuotaWithContext (ctx aws.Context , input * servicequotas.GetServiceQuotaInput , opts ... request.Option ) (* servicequotas.GetServiceQuotaOutput , error )
26
- RequestServiceQuotaIncrease (* servicequotas.RequestServiceQuotaIncreaseInput ) (* servicequotas.RequestServiceQuotaIncreaseOutput , error )
27
- ListRequestedServiceQuotaChangeHistory (* servicequotas.ListRequestedServiceQuotaChangeHistoryInput ) (* servicequotas.ListRequestedServiceQuotaChangeHistoryOutput , error )
28
- ListRequestedServiceQuotaChangeHistoryByQuota (* servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaInput ) (* servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaOutput , error )
29
36
}
30
37
31
38
type awsClient struct {
32
39
ec2Client ec2iface.EC2API
40
+ rdsClient rds.RDS
33
41
serviceQuotasClient servicequotasiface.ServiceQuotasAPI
34
42
}
35
43
36
44
func (c * awsClient ) DescribeTransitGatewaysWithContext (ctx aws.Context , input * ec2.DescribeTransitGatewaysInput , opts ... request.Option ) (* ec2.DescribeTransitGatewaysOutput , error ) {
37
45
return c .ec2Client .DescribeTransitGatewaysWithContext (ctx , input , opts ... )
38
46
}
39
47
40
- func (c * awsClient ) DeleteSubnet (input * ec2.DeleteSubnetInput ) (* ec2.DeleteSubnetOutput , error ) {
41
- return c .ec2Client .DeleteSubnet (input )
48
+ func (c * awsClient ) DescribeDBLogFilesPagesWithContext (ctx aws.Context , input * rds.DescribeDBLogFilesInput , fn func (* rds.DescribeDBLogFilesOutput , bool ) bool , opts ... request.Option ) error {
49
+ return c .rdsClient .DescribeDBLogFilesPagesWithContext (ctx , input , fn , opts ... )
50
+ }
51
+
52
+ func (c * awsClient ) DescribeDBInstancesPagesWithContext (ctx aws.Context , input * rds.DescribeDBInstancesInput , fn func (* rds.DescribeDBInstancesOutput , bool ) bool , opts ... request.Option ) error {
53
+ return c .rdsClient .DescribeDBInstancesPagesWithContext (ctx , input , fn , opts ... )
42
54
}
43
55
44
- func (c * awsClient ) GetServiceQuota ( input * servicequotas. GetServiceQuotaInput ) ( * servicequotas. GetServiceQuotaOutput , error ) {
45
- return c .serviceQuotasClient . GetServiceQuota ( input )
56
+ func (c * awsClient ) DescribePendingMaintenanceActionsPagesWithContext ( ctx aws. Context , input * rds. DescribePendingMaintenanceActionsInput , fn func ( * rds. DescribePendingMaintenanceActionsOutput , bool ) bool , opts ... request. Option ) error {
57
+ return c .rdsClient . DescribePendingMaintenanceActionsPagesWithContext ( ctx , input , fn , opts ... )
46
58
}
47
59
48
60
func (c * awsClient ) GetServiceQuotaWithContext (ctx aws.Context , input * servicequotas.GetServiceQuotaInput , opts ... request.Option ) (* servicequotas.GetServiceQuotaOutput , error ) {
49
61
return c .serviceQuotasClient .GetServiceQuotaWithContext (ctx , input , opts ... )
50
62
}
51
63
52
- func (c * awsClient ) RequestServiceQuotaIncrease (input * servicequotas.RequestServiceQuotaIncreaseInput ) (* servicequotas.RequestServiceQuotaIncreaseOutput , error ) {
53
- return c .serviceQuotasClient .RequestServiceQuotaIncrease (input )
64
+ func (c * awsClient ) DescribeDBLogFilesAll (ctx context.Context , instanceId string ) ([]* rds.DescribeDBLogFilesOutput , error ) {
65
+ input := & rds.DescribeDBLogFilesInput {
66
+ DBInstanceIdentifier : & instanceId ,
67
+ }
68
+
69
+ var logOutPuts []* rds.DescribeDBLogFilesOutput
70
+ err := c .DescribeDBLogFilesPagesWithContext (ctx , input , func (ddlo * rds.DescribeDBLogFilesOutput , b bool ) bool {
71
+ AwsExporterMetrics .IncrementRequests ()
72
+ logOutPuts = append (logOutPuts , ddlo )
73
+ return true
74
+ })
75
+
76
+ if err != nil {
77
+ AwsExporterMetrics .IncrementErrors ()
78
+ return nil , err
79
+ }
80
+
81
+ return logOutPuts , nil
54
82
}
55
83
56
- func (c * awsClient ) ListRequestedServiceQuotaChangeHistory (input * servicequotas.ListRequestedServiceQuotaChangeHistoryInput ) (* servicequotas.ListRequestedServiceQuotaChangeHistoryOutput , error ) {
57
- return c .serviceQuotasClient .ListRequestedServiceQuotaChangeHistory (input )
84
+ func (c * awsClient ) DescribePendingMaintenanceActionsAll (ctx context.Context ) ([]* rds.ResourcePendingMaintenanceActions , error ) {
85
+ describePendingMaintInput := & rds.DescribePendingMaintenanceActionsInput {}
86
+
87
+ var instancesPendMaintActionsData []* rds.ResourcePendingMaintenanceActions
88
+ err := c .DescribePendingMaintenanceActionsPagesWithContext (ctx , describePendingMaintInput , func (dpm * rds.DescribePendingMaintenanceActionsOutput , b bool ) bool {
89
+ AwsExporterMetrics .IncrementRequests ()
90
+ instancesPendMaintActionsData = append (instancesPendMaintActionsData , dpm .PendingMaintenanceActions ... )
91
+ return true
92
+ })
93
+
94
+ if err != nil {
95
+ AwsExporterMetrics .IncrementErrors ()
96
+ return nil , err
97
+ }
98
+
99
+ return instancesPendMaintActionsData , nil
58
100
}
59
101
60
- func (c * awsClient ) ListRequestedServiceQuotaChangeHistoryByQuota (input * servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaInput ) (* servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaOutput , error ) {
61
- return c .serviceQuotasClient .ListRequestedServiceQuotaChangeHistoryByQuota (input )
102
+ func (c * awsClient ) DescribeDBInstancesAll (ctx context.Context ) ([]* rds.DBInstance , error ) {
103
+ input := & rds.DescribeDBInstancesInput {}
104
+
105
+ var instances []* rds.DBInstance
106
+ err := c .DescribeDBInstancesPagesWithContext (ctx , input , func (ddo * rds.DescribeDBInstancesOutput , b bool ) bool {
107
+ AwsExporterMetrics .IncrementRequests ()
108
+ instances = append (instances , ddo .DBInstances ... )
109
+ return true
110
+ })
111
+ if err != nil {
112
+ AwsExporterMetrics .IncrementErrors ()
113
+ return nil , err
114
+ }
115
+ return instances , nil
62
116
}
63
117
64
118
func NewClientFromSession (sess * session.Session ) Client {
65
119
return & awsClient {
66
120
ec2Client : ec2 .New (sess ),
67
121
serviceQuotasClient : servicequotas .New (sess ),
122
+ rdsClient : * rds .New (sess ),
68
123
}
69
124
}
0 commit comments