-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from janboll/refactor-aws-client
Refactor aws client
- Loading branch information
Showing
7 changed files
with
303 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// inspired by https://github.com/openshift/aws-account-operator/blob/master/pkg/awsclient/client.go | ||
|
||
package awsclient | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/aws/aws-sdk-go/service/servicequotas" | ||
"github.com/aws/aws-sdk-go/service/servicequotas/servicequotasiface" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/aws/aws-sdk-go/service/ec2/ec2iface" | ||
) | ||
|
||
//go:generate mockgen -source=./awsclient.go -destination=./mock/zz_generated.mock_client.go -package=mock | ||
|
||
// Client is a wrapper object for actual AWS SDK clients to allow for easier testing. | ||
type Client interface { | ||
//EC2 | ||
DescribeTransitGatewaysWithContext(ctx aws.Context, input *ec2.DescribeTransitGatewaysInput, opts ...request.Option) (*ec2.DescribeTransitGatewaysOutput, error) | ||
|
||
// Service Quota | ||
GetServiceQuota(*servicequotas.GetServiceQuotaInput) (*servicequotas.GetServiceQuotaOutput, error) | ||
GetServiceQuotaWithContext(ctx aws.Context, input *servicequotas.GetServiceQuotaInput, opts ...request.Option) (*servicequotas.GetServiceQuotaOutput, error) | ||
RequestServiceQuotaIncrease(*servicequotas.RequestServiceQuotaIncreaseInput) (*servicequotas.RequestServiceQuotaIncreaseOutput, error) | ||
ListRequestedServiceQuotaChangeHistory(*servicequotas.ListRequestedServiceQuotaChangeHistoryInput) (*servicequotas.ListRequestedServiceQuotaChangeHistoryOutput, error) | ||
ListRequestedServiceQuotaChangeHistoryByQuota(*servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaInput) (*servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaOutput, error) | ||
} | ||
|
||
type awsClient struct { | ||
ec2Client ec2iface.EC2API | ||
serviceQuotasClient servicequotasiface.ServiceQuotasAPI | ||
} | ||
|
||
func (c *awsClient) DescribeTransitGatewaysWithContext(ctx aws.Context, input *ec2.DescribeTransitGatewaysInput, opts ...request.Option) (*ec2.DescribeTransitGatewaysOutput, error) { | ||
return c.ec2Client.DescribeTransitGatewaysWithContext(ctx, input, opts...) | ||
} | ||
|
||
func (c *awsClient) DeleteSubnet(input *ec2.DeleteSubnetInput) (*ec2.DeleteSubnetOutput, error) { | ||
return c.ec2Client.DeleteSubnet(input) | ||
} | ||
|
||
func (c *awsClient) GetServiceQuota(input *servicequotas.GetServiceQuotaInput) (*servicequotas.GetServiceQuotaOutput, error) { | ||
return c.serviceQuotasClient.GetServiceQuota(input) | ||
} | ||
|
||
func (c *awsClient) GetServiceQuotaWithContext(ctx aws.Context, input *servicequotas.GetServiceQuotaInput, opts ...request.Option) (*servicequotas.GetServiceQuotaOutput, error) { | ||
return c.serviceQuotasClient.GetServiceQuotaWithContext(ctx, input, opts...) | ||
} | ||
|
||
func (c *awsClient) RequestServiceQuotaIncrease(input *servicequotas.RequestServiceQuotaIncreaseInput) (*servicequotas.RequestServiceQuotaIncreaseOutput, error) { | ||
return c.serviceQuotasClient.RequestServiceQuotaIncrease(input) | ||
} | ||
|
||
func (c *awsClient) ListRequestedServiceQuotaChangeHistory(input *servicequotas.ListRequestedServiceQuotaChangeHistoryInput) (*servicequotas.ListRequestedServiceQuotaChangeHistoryOutput, error) { | ||
return c.serviceQuotasClient.ListRequestedServiceQuotaChangeHistory(input) | ||
} | ||
|
||
func (c *awsClient) ListRequestedServiceQuotaChangeHistoryByQuota(input *servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaInput) (*servicequotas.ListRequestedServiceQuotaChangeHistoryByQuotaOutput, error) { | ||
return c.serviceQuotasClient.ListRequestedServiceQuotaChangeHistoryByQuota(input) | ||
} | ||
|
||
func NewClientFromSession(sess *session.Session) Client { | ||
return &awsClient{ | ||
ec2Client: ec2.New(sess), | ||
serviceQuotasClient: servicequotas.New(sess), | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.