Skip to content

Commit

Permalink
Use new client interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmannf committed Oct 6, 2022
1 parent a0d4e30 commit 1cd741d
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 38 deletions.
49 changes: 49 additions & 0 deletions pkg/awsclient/awsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ type Client interface {
DescribePendingMaintenanceActionsAll(ctx context.Context) ([]*rds.ResourcePendingMaintenanceActions, error)
DescribeDBInstancesAll(ctx context.Context) ([]*rds.DBInstance, error)

// VPC
DescribeRouteTablesWithContext(ctx context.Context, input *ec2.DescribeRouteTablesInput, opts ...request.Option) (*ec2.DescribeRouteTablesOutput, error)
DescribeVpcsWithContext(ctx context.Context, input *ec2.DescribeVpcsInput, opts ...request.Option) (*ec2.DescribeVpcsOutput, error)
DescribeVpcsPagesWithContext(ctx context.Context, input *ec2.DescribeVpcsInput, fn func(*ec2.DescribeVpcsOutput, bool) bool, opts ...request.Option) error
DescribeSubnetsPagesWithContext(ctx context.Context, input *ec2.DescribeSubnetsInput, fn func(*ec2.DescribeSubnetsOutput, bool) bool, opts ...request.Option) error
DescribeVpcEndpointsPagesWithContext(ctx context.Context, input *ec2.DescribeVpcEndpointsInput, fn func(*ec2.DescribeVpcEndpointsOutput, bool) bool, opts ...request.Option) error
DescribeRouteTablesPagesWithContext(ctx context.Context, input *ec2.DescribeRouteTablesInput, fn func(*ec2.DescribeRouteTablesOutput, bool) bool, opts ...request.Option) error

// Service Quota
GetServiceQuotaWithContext(ctx aws.Context, input *servicequotas.GetServiceQuotaInput, opts ...request.Option) (*servicequotas.GetServiceQuotaOutput, error)
}
Expand Down Expand Up @@ -115,6 +123,47 @@ func (c *awsClient) DescribeDBInstancesAll(ctx context.Context) ([]*rds.DBInstan
return instances, nil
}

// VPC Functions
func (c *awsClient) DescribeRouteTablesWithContext(ctx context.Context, input *ec2.DescribeRouteTablesInput, opts ...request.Option) (*ec2.DescribeRouteTablesOutput, error) {
return c.ec2Client.DescribeRouteTablesWithContext(ctx, input, opts...)
}

func (c *awsClient) DescribeVpcsWithContext(ctx context.Context, input *ec2.DescribeVpcsInput, opts ...request.Option) (*ec2.DescribeVpcsOutput, error) {
return c.ec2Client.DescribeVpcsWithContext(ctx, input, opts...)
}

func (c *awsClient) DescribeVpcsPagesWithContext(ctx context.Context, input *ec2.DescribeVpcsInput, fn func(*ec2.DescribeVpcsOutput, bool) bool, opts ...request.Option) error {
err := c.ec2Client.DescribeVpcsPagesWithContext(ctx, input, fn, opts...)
if err != nil {
AwsExporterMetrics.IncrementErrors()
}
return err
}

func (c *awsClient) DescribeSubnetsPagesWithContext(ctx context.Context, input *ec2.DescribeSubnetsInput, fn func(*ec2.DescribeSubnetsOutput, bool) bool, opts ...request.Option) error {
err := c.ec2Client.DescribeSubnetsPagesWithContext(ctx, input, fn, opts...)
if err != nil {
AwsExporterMetrics.IncrementErrors()
}
return err
}

func (c *awsClient) DescribeVpcEndpointsPagesWithContext(ctx context.Context, input *ec2.DescribeVpcEndpointsInput, fn func(*ec2.DescribeVpcEndpointsOutput, bool) bool, opts ...request.Option) error {
err := c.ec2Client.DescribeVpcEndpointsPagesWithContext(ctx, input, fn, opts...)
if err != nil {
AwsExporterMetrics.IncrementErrors()
}
return err
}

func (c *awsClient) DescribeRouteTablesPagesWithContext(ctx context.Context, input *ec2.DescribeRouteTablesInput, fn func(*ec2.DescribeRouteTablesOutput, bool) bool, opts ...request.Option) error {
err := c.ec2Client.DescribeRouteTablesPagesWithContext(ctx, input, fn, opts...)
if err != nil {
AwsExporterMetrics.IncrementErrors()
}
return err
}

func NewClientFromSession(sess *session.Session) Client {
return &awsClient{
ec2Client: ec2.New(sess),
Expand Down
116 changes: 116 additions & 0 deletions pkg/awsclient/mock/zz_generated.mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1cd741d

Please sign in to comment.