raws

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2019 License: MIT Imports: 39 Imported by: 0

README

Raws: AWS Reader Build Status Coverage Status

What is Raws?

Raws is a golang project helping to get information from AWS.

It currently provides simplicity - one package vs multitude in AWS - as well as multi-region management - all calls are done for each selected region(s). Region's parameter also supports globbing, thus allowing to fetch data from all eu with: 'eu-*' or all eu-west with 'eu-west-*'

Currently only a couple of the most used information is gathered, but adding extra calls should not be complicated, as they all have the same logic.

Any contributions are welcome!

IMPORTANT we are still experimenting the usage of this library, hence the public interface isn't stable as we have to see that the methods signatures fulfill the main goal of the library which is to simplify the AWS SDK to gather information. Because of this, the repo contains tags which define each version using Semantic Versioning convention.

Getting started

Import the library

To get started, you can download/include the library to your code and use it like so:

func main() {
  var config *aws.Config = nil
  var accessKey string = "xxxxxxxxxxxxxxx"
  var secretKey string = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
  var region []string = []string{"eu-*"}
  var ctx = context.Background()

  // Create a reader
  c, err := raws.NewAWSReader(ctx, accessKey, secretKey, region, config)
  if err != nil {
    fmt.Printf("Error while getting NewConnector: %s\n", err.Error())
    return
  }

  // Start making calls
  // Errors are intentionally ignored in this example,
  // no inputs are provided to those calls, even though one could.
  elbs, _ := c.GetLoadBalancersV2(ctx, nil)
  fmt.Println(elbs)

  instances, _ := c.GetInstances(ctx, nil)
  fmt.Println(instances)

  vpcs, _ := c.GetVpcs(ctx, nil)
  fmt.Println(vpcs)

  return
}
Contribute

We use a custom generation tool located on cmd/main.go which basically uses a list of function definitions (cmd/functions.go) to generate the wrappers for those, if you want to add a call to the AWS API you have to add it to that list and if the implementation fits the template it'll be automatically generated/implemented.

If it does not fit the template you'll have to implement it manually, an example is the s3downloader.go.

To generate the code just run make generate.

Enjoy

That's it! Nothing more, nothing less.

Notes

YOUR data

By default the library only returns data that belongs to you, therefore snapshots, AMI, etc are only the one that you owned and not all available objects.

This could be fixed later on depending on the needs.

Tags everywhere?

Because the library currently simply make the call as a forwarder, it does not provide more complex calls, to return more complex data. Due to that, there are also elements to keep in mind, some calls relative to load balancer, or RDS return only the objects without tags, other calls need to be done to get those tags per resource.

License

Please see LICENSE.

Documentation

Overview

Package raws currently provides simplicity - one package vs multitude in AWS - as well as multi-region management - all calls are done for each selected region(s). Region's parameter also supports globbing, thus allowing to fetch data from all eu with: 'eu-*' or all eu-west with 'eu-west-*'

Currently only a couple of the most used information is gathered, but adding extra calls should not be complicated, as they all have the same logic.

For the sake of avoiding repetitive documentation, each function that this package contains with the context.Context type as a first parameter, won't be documented, at least if there is not special usage of it inside of the function, because the context.Context is provided for implementing the most adopted concurrency pattern, used by the Go community (see https://blog.golang.org/context).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorFrom added in v0.0.4

func ErrorFrom(service string, err error) error

ErrorFrom inspects err to find if there is an error in the service and returns it or them (in case of multiple), otherwise it returns nil. err must be of the type Error or Errors in order to be able to find if there are errors in the region; if err is from other type, the function always returns nil. The returned error is a value of the type Error when only one error is found in the region, or a value of the type Errors when multiple errors are found.

func ErrorIn added in v0.0.4

func ErrorIn(region string, err error) error

ErrorIn inspects err to find if there is an error in the region and returns it or them (in case of multiple), otherwise it returns nil. err must be of the type Error or Errors in order to be able to find if there are errors in the region; if err is from other type, the function always returns nil. The returned error is a value of the type Error when only one error is found in the region, or a value of the type Errors when multiple errors are found.

Types

type AWSReader

type AWSReader interface {
	// GetAccountID returns the current ID for the account used
	GetAccountID() string

	// GetRegions returns the currently used regions for the Connector
	GetRegions() []string

	// GetInstances returns all EC2 instances based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetInstances(ctx context.Context, input *ec2.DescribeInstancesInput) (map[string]ec2.DescribeInstancesOutput, error)

	// GetVpcs returns all EC2 VPCs based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetVpcs(ctx context.Context, input *ec2.DescribeVpcsInput) (map[string]ec2.DescribeVpcsOutput, error)

	// GetImages returns all EC2 AMI based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetImages(ctx context.Context, input *ec2.DescribeImagesInput) (map[string]ec2.DescribeImagesOutput, error)

	// GetOwnImages returns all EC2 AMI belonging to the Account ID based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetOwnImages(ctx context.Context, input *ec2.DescribeImagesInput) (map[string]ec2.DescribeImagesOutput, error)

	// GetSecurityGroups returns all EC2 security groups based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetSecurityGroups(ctx context.Context, input *ec2.DescribeSecurityGroupsInput) (map[string]ec2.DescribeSecurityGroupsOutput, error)

	// GetSubnets returns all EC2 subnets based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetSubnets(ctx context.Context, input *ec2.DescribeSubnetsInput) (map[string]ec2.DescribeSubnetsOutput, error)

	// GetVolumes returns all EC2 volumes based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetVolumes(ctx context.Context, input *ec2.DescribeVolumesInput) (map[string]ec2.DescribeVolumesOutput, error)

	// GetSnapshots returns all snapshots based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetSnapshots(ctx context.Context, input *ec2.DescribeSnapshotsInput) (map[string]ec2.DescribeSnapshotsOutput, error)

	// GetOwnSnapshots returns all snapshots belonging to the Account ID based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetOwnSnapshots(ctx context.Context, input *ec2.DescribeSnapshotsInput) (map[string]ec2.DescribeSnapshotsOutput, error)

	// GetLaunchTemplates returns all LaunchTemplate belonging to the Account ID based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetLaunchTemplates(ctx context.Context, input *ec2.DescribeLaunchTemplatesInput) (map[string]ec2.DescribeLaunchTemplatesOutput, error)

	// GetAutoScalingGroups returns all AutoScalingGroup belonging to the Account ID based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetAutoScalingGroups(ctx context.Context, input *autoscaling.DescribeAutoScalingGroupsInput) (map[string]autoscaling.DescribeAutoScalingGroupsOutput, error)

	// GetLaunchConfigurations returns all LaunchConfiguration belonging to the Account ID based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetLaunchConfigurations(ctx context.Context, input *autoscaling.DescribeLaunchConfigurationsInput) (map[string]autoscaling.DescribeLaunchConfigurationsOutput, error)

	// GetElastiCacheClusters returns all Elasticache clusters based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetElastiCacheClusters(ctx context.Context, input *elasticache.DescribeCacheClustersInput) (map[string]elasticache.DescribeCacheClustersOutput, error)

	// GetElastiCacheTags returns a list of tags of Elasticache resources based on its ARN.
	// Returned values are commented in the interface doc comment block.
	GetElastiCacheTags(ctx context.Context, input *elasticache.ListTagsForResourceInput) (map[string]elasticache.TagListMessage, error)

	// GetLoadBalancers returns a list of ELB (v1) based on the input from the different regions.
	// Returned values are commented in the interface doc comment block.
	GetLoadBalancers(ctx context.Context, input *elb.DescribeLoadBalancersInput) (map[string]elb.DescribeLoadBalancersOutput, error)

	// GetLoadBalancersTags returns a list of Tags based on the input from the different regions.
	// Returned values are commented in the interface doc comment block.
	GetLoadBalancersTags(ctx context.Context, input *elb.DescribeTagsInput) (map[string]elb.DescribeTagsOutput, error)

	// GetLoadBalancersV2 returns a list of ELB (v2) - also known as ALB - based on the input from the different regions.
	// Returned values are commented in the interface doc comment block.
	GetLoadBalancersV2(ctx context.Context, input *elbv2.DescribeLoadBalancersInput) (map[string]elbv2.DescribeLoadBalancersOutput, error)

	// GetLoadBalancersV2Tags returns a list of Tags based on the input from the different regions.
	// Returned values are commented in the interface doc comment block.
	GetLoadBalancersV2Tags(ctx context.Context, input *elbv2.DescribeTagsInput) (map[string]elbv2.DescribeTagsOutput, error)

	// GetDBInstances returns all DB instances based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetDBInstances(ctx context.Context, input *rds.DescribeDBInstancesInput) (map[string]rds.DescribeDBInstancesOutput, error)

	// GetDBInstancesTags returns a list of tags from an ARN, extra filters for tags can also be provided.
	// Returned values are commented in the interface doc comment block.
	GetDBInstancesTags(ctx context.Context, input *rds.ListTagsForResourceInput) (map[string]rds.ListTagsForResourceOutput, error)

	// ListBuckets returns all S3 buckets based on the input given and specifically
	// filtering by Location as ListBuckets does not do it by itself
	// Returned values are commented in the interface doc comment block.
	ListBuckets(ctx context.Context, input *s3.ListBucketsInput) (map[string]s3.ListBucketsOutput, error)

	// GetBucketTags returns tags associated with S3 buckets based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetBucketTags(ctx context.Context, input *s3.GetBucketTaggingInput) (map[string]s3.GetBucketTaggingOutput, error)

	// ListObjects returns a list of all S3 objects in a bucket based on the input given.
	// Returned values are commented in the interface doc comment block.
	ListObjects(ctx context.Context, input *s3.ListObjectsInput) (map[string]s3.ListObjectsOutput, error)

	// GetObjectsTags returns tags associated with S3 objects based on the input given.
	// Returned values are commented in the interface doc comment block.
	GetObjectsTags(ctx context.Context, input *s3.GetObjectTaggingInput) (map[string]s3.GetObjectTaggingOutput, error)

	// GetRecordedResourceCounts returns counts of the AWS resources which have
	// been recorded by AWS Config.
	// See https://docs.aws.amazon.com/config/latest/APIReference/API_GetDiscoveredResourceCounts.html
	// for more information about what to enable in your AWS account, the list of
	// supported resources, etc.
	GetRecordedResourceCounts(ctx context.Context, input *configservice.GetDiscoveredResourceCountsInput) (map[string]configservice.GetDiscoveredResourceCountsOutput, error)

	// DownloadObject downloads an object in a bucket based on the input given
	DownloadObject(ctx context.Context, w io.WriterAt, input *s3.GetObjectInput, options ...func(*s3manager.Downloader)) (int64, error)

	// GetCloudFrontDistributions returns all the CloudFront Distributions on the given input
	// Returned values are commented in the interface doc comment block.
	GetCloudFrontDistributions(ctx context.Context, input *cloudfront.ListDistributionsInput) (map[string]cloudfront.ListDistributionsOutput, error)

	// GetCloudFrontPublicKeys returns all the CloudFront Public Keys on the given input
	// Returned values are commented in the interface doc comment block.
	GetCloudFrontPublicKeys(ctx context.Context, input *cloudfront.ListPublicKeysInput) (map[string]cloudfront.ListPublicKeysOutput, error)

	// GetCloudFrontOriginAccessIdentities returns all the CloudFront Origin Access Identities on the given input
	// Returned values are commented in the interface doc comment block.
	GetCloudFrontOriginAccessIdentities(ctx context.Context, input *cloudfront.ListCloudFrontOriginAccessIdentitiesInput) (map[string]cloudfront.ListCloudFrontOriginAccessIdentitiesOutput, error)

	// GetAccessKeys returns all the IAM AccessKeys on the given input
	// Returned values are commented in the interface doc comment block.
	GetAccessKeys(ctx context.Context, input *iam.ListAccessKeysInput) (map[string]iam.ListAccessKeysOutput, error)

	// GetAccountAliases returns all the IAM AccountAliases on the given input
	// Returned values are commented in the interface doc comment block.
	GetAccountAliases(ctx context.Context, input *iam.ListAccountAliasesInput) (map[string]iam.ListAccountAliasesOutput, error)

	// GetAccountPasswordPolicy returns the IAM AccountPasswordPolicy on the given input
	// Returned values are commented in the interface doc comment block.
	GetAccountPasswordPolicy(ctx context.Context, input *iam.GetAccountPasswordPolicyInput) (map[string]iam.GetAccountPasswordPolicyOutput, error)

	// GetGroups returns the IAM Groups on the given input
	// Returned values are commented in the interface doc comment block.
	GetGroups(ctx context.Context, input *iam.ListGroupsInput) (map[string]iam.ListGroupsOutput, error)

	// GetGroupPolicies returns the IAM GroupPolicies on the given input
	// Returned values are commented in the interface doc comment block.
	GetGroupPolicies(ctx context.Context, input *iam.ListGroupPoliciesInput) (map[string]iam.ListGroupPoliciesOutput, error)

	// GetAttachedGroupPolicies returns the IAM AttachedGroupPolicies on the given input
	// Returned values are commented in the interface doc comment block.
	GetAttachedGroupPolicies(ctx context.Context, input *iam.ListAttachedGroupPoliciesInput) (map[string]iam.ListAttachedGroupPoliciesOutput, error)

	// GetIstanceProfiles returns the IAM InstanceProfiles on the given input
	// Returned values are commented in the interface doc comment block.
	GetInstanceProfiles(ctx context.Context, input *iam.ListInstanceProfilesInput) (map[string]iam.ListInstanceProfilesOutput, error)

	// GetOpenIDConnectProviders returns the IAM OpenIDConnectProviders on the given input
	// Returned values are commented in the interface doc comment block.
	GetOpenIDConnectProviders(ctx context.Context, input *iam.ListOpenIDConnectProvidersInput) (map[string]iam.ListOpenIDConnectProvidersOutput, error)

	// GetPolicies returns the IAM Policies on the given input
	// Returned values are commented in the interface doc comment block.
	GetPolicies(ctx context.Context, input *iam.ListPoliciesInput) (map[string]iam.ListPoliciesOutput, error)

	// GetRoles returns the IAM Roles on the given input
	// Returned values are commented in the interface doc comment block.
	GetRoles(ctx context.Context, input *iam.ListRolesInput) (map[string]iam.ListRolesOutput, error)

	// GetRolePolicies returns the IAM RolePolicies on the given input
	// Returned values are commented in the interface doc comment block.
	GetRolePolicies(ctx context.Context, input *iam.ListRolePoliciesInput) (map[string]iam.ListRolePoliciesOutput, error)

	// GetAttachedRolePolicies returns the IAM AttachedRolePolicies on the given input
	// Returned values are commented in the interface doc comment block.
	GetAttachedRolePolicies(ctx context.Context, input *iam.ListAttachedRolePoliciesInput) (map[string]iam.ListAttachedRolePoliciesOutput, error)

	// GetSAMLProviders returns the IAM SAMLProviders on the given input
	// Returned values are commented in the interface doc comment block.
	GetSAMLProviders(ctx context.Context, input *iam.ListSAMLProvidersInput) (map[string]iam.ListSAMLProvidersOutput, error)

	// GetServerCertificates returns the IAM ServerCertificates on the given input
	// Returned values are commented in the interface doc comment block.
	GetServerCertificates(ctx context.Context, input *iam.ListServerCertificatesInput) (map[string]iam.ListServerCertificatesOutput, error)

	// GetUsers returns the IAM Users on the given input
	// Returned values are commented in the interface doc comment block.
	GetUsers(ctx context.Context, input *iam.ListUsersInput) (map[string]iam.ListUsersOutput, error)

	// GetUserPolicies returns the IAM UserPolicies on the given input
	// Returned values are commented in the interface doc comment block.
	GetUserPolicies(ctx context.Context, input *iam.ListUserPoliciesInput) (map[string]iam.ListUserPoliciesOutput, error)

	// GetAttachedUserPolicies returns the IAM AttachedUserPolicies on the given input
	// Returned values are commented in the interface doc comment block.
	GetAttachedUserPolicies(ctx context.Context, input *iam.ListAttachedUserPoliciesInput) (map[string]iam.ListAttachedUserPoliciesOutput, error)

	// GetSSHPublicKey returns the IAM SSHPublicKey on the given input
	// Returned values are commented in the interface doc comment block.
	GetSSHPublicKey(ctx context.Context, input *iam.GetSSHPublicKeyInput) (map[string]iam.GetSSHPublicKeyOutput, error)

	// GetActiveReceiptRuleSet returns the SES ActiveReceiptRuleSet on the given input
	// Returned values are commented in the interface doc comment block.
	GetActiveReceiptRuleSet(ctx context.Context, input *ses.DescribeActiveReceiptRuleSetInput) (map[string]ses.DescribeActiveReceiptRuleSetOutput, error)

	// GetIdentities returns the SES Identities on the given input
	// Returned values are commented in the interface doc comment block.
	GetIdentities(ctx context.Context, input *ses.ListIdentitiesInput) (map[string]ses.ListIdentitiesOutput, error)

	// GetReceiptFilters returns the SES ReceiptFilters on the given input
	// Returned values are commented in the interface doc comment block.
	GetReceiptFilters(ctx context.Context, input *ses.ListReceiptFiltersInput) (map[string]ses.ListReceiptFiltersOutput, error)

	// GetConfigurationSets returns the SES ConfigurationSets on the given input
	// Returned values are commented in the interface doc comment block.
	GetConfigurationSets(ctx context.Context, input *ses.ListConfigurationSetsInput) (map[string]ses.ListConfigurationSetsOutput, error)

	// GetIdentityNotificationAttributes returns the SES IdentityNotificationAttributes on the given input
	// Returned values are commented in the interface doc comment block.
	GetIdentityNotificationAttributes(ctx context.Context, input *ses.GetIdentityNotificationAttributesInput) (map[string]ses.GetIdentityNotificationAttributesOutput, error)

	// GetTemplates returns the SES Templates on the given input
	// Returned values are commented in the interface doc comment block.
	GetTemplates(ctx context.Context, input *ses.ListTemplatesInput) (map[string]ses.ListTemplatesOutput, error)

	// GetReusableDelegationSets returns the Route53 ReusableDelegationSets on the given input
	// Returned values are commented in the interface doc comment block.
	GetReusableDelegationSets(ctx context.Context, input *route53.ListReusableDelegationSetsInput) (map[string]route53.ListReusableDelegationSetsOutput, error)

	// GetHealthChecks returns the Route53 HealthChecks on the given input
	// Returned values are commented in the interface doc comment block.
	GetHealthChecks(ctx context.Context, input *route53.ListHealthChecksInput) (map[string]route53.ListHealthChecksOutput, error)

	// GetQueryLoggingConfigs returns the Route53 QueryLoggingConfigs on the given input
	// Returned values are commented in the interface doc comment block.
	GetQueryLoggingConfigs(ctx context.Context, input *route53.ListQueryLoggingConfigsInput) (map[string]route53.ListQueryLoggingConfigsOutput, error)

	// GetResourceRecordSets returns the Route53 ResourceRecordSets on the given input
	// Returned values are commented in the interface doc comment block.
	GetResourceRecordSets(ctx context.Context, input *route53.ListResourceRecordSetsInput) (map[string]route53.ListResourceRecordSetsOutput, error)

	// GetHostedZones returns the Route53 HostedZones on the given input
	// Returned values are commented in the interface doc comment block.
	GetHostedZones(ctx context.Context, input *route53.ListHostedZonesInput) (map[string]route53.ListHostedZonesOutput, error)

	// GetVPCAssociationAuthorizations returns the Route53 VPCAssociationAuthorizations on the given input
	// Returned values are commented in the interface doc comment block.
	GetVPCAssociationAuthorizations(ctx context.Context, input *route53.ListVPCAssociationAuthorizationsInput) (map[string]route53.ListVPCAssociationAuthorizationsOutput, error)

	// GetResolverEndpoints returns the Route53Resolver ResolverEndpoints on the given input
	// Returned values are commented in the interface doc comment block.
	GetResolverEndpoints(ctx context.Context, input *route53resolver.ListResolverEndpointsInput) (map[string]route53resolver.ListResolverEndpointsOutput, error)

	// GetResolverRules returns the Route53Resolver ResolverRules on the given input
	// Returned values are commented in the interface doc comment block.
	GetResolverRules(ctx context.Context, input *route53resolver.ListResolverRulesInput) (map[string]route53resolver.ListResolverRulesOutput, error)

	// GetResolverRuleAssociations returns the Route53Resolver ResolverRuleAssociations on the given input
	// Returned values are commented in the interface doc comment block.
	GetResolverRuleAssociations(ctx context.Context, input *route53resolver.ListResolverRuleAssociationsInput) (map[string]route53resolver.ListResolverRuleAssociationsOutput, error)
}

AWSReader is the interface defining all methods that need to be implemented

The next behavior commented in the below paragraph, applies to every method which clearly match what's explained, for the sake of not repeating the same, over and over. The most of the methods defined by this interface, return their results in a map. Those maps, have as keys, the AWS region which have been requested and the values are the items returned by AWS for such region. Because the methods may make calls to different regions, in case that there is an error on a region, the returned map won't have any entry for such region and such errors will be reported by the returned error, nonetheless the items, got from the successful requests to other regions, will be returned, with the meaning that the methods will return partial results, in case of errors. For avoiding by the callers the problem of if the returned map may be nil, the function will always return a map instance, which will be of length 0 in case that there is not any successful request.

func NewAWSReader

func NewAWSReader(
	ctx context.Context, accessKey string, secretKey string, regions []string, config *aws.Config,
) (AWSReader, error)

NewAWSReader returns an object which also contains the accountID and extend the different regions to use.

The accountID is helpful to return only the AMI or snapshots that belong to the account.

While the regions slice also supports regex so, "eu-*" can be passed, and will be extended to: eu-west-1, eu-west-2 & eu-central-1.

When calls are done through the Connector instance, then all regions will be called for those services. Thus making requests to AWS much easier than through the different connectors/regions of its go SDK.

The connections are not all established while instancing, but the various sessions are, this way connections are only made for services that are called, otherwise only the sessions remain.

An error is returned if any of the needed AWS request for creating the reader returns an AWS error, in such case it will have any of the common error codes (see below) or EmptyStaticCreds code or a go standard error in case that no regions are matched with the ones available, at the time, in AWS. See:

type Error added in v0.0.4

type Error struct {
	// contains filtered or unexported fields
}

Error is a type which satisfied the standard error interface, but provides context over an error that the AWS SDK can originate.

func NewError added in v0.0.4

func NewError(region string, service string, e error) Error

NewError creates an Error object for the specific AWS region, service and containing the original error returned by the AWS SDK.

func (Error) Error added in v0.0.4

func (e Error) Error() string

Error satisfies the error interface and returns a string containing the region, service and the message of the AWS SDK error.

func (Error) Region added in v0.0.4

func (e Error) Region() string

Region returns the region of the error.

func (Error) Service added in v0.0.4

func (e Error) Service() string

Service Returns the service name of the error. NOTE, currently the service is not that necessary, but it could become useful to have as the project evolves and start making more complex calls to various endpoints.

type Errors added in v0.0.4

type Errors []Error

Errors type satisfies the standard error interface, thus allowing us to return an error when doing multiple call via the Go AWS SDK, even though multiple errors are met.

func (Errors) Error added in v0.0.4

func (e Errors) Error() string

Error returns a string which summarize how many errors happened and for each error, the region, the service and the error message reported by AWS original error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL