awsarn

package module
v0.0.0-...-87075fc Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2018 License: Apache-2.0 Imports: 10 Imported by: 3

README

AWS ARN

GoDoc Go Report Card

The AWS ARN library provides Go representation for AWS ARNs and useful functions to parse and validate ARN strings.

Reference: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html

To get the package, execute:

go get github.com/jcmturner/awsarn

To import this package, add the following line to your code:

import "github.com/jcmturner/awsarn"

Usage

For full API documentation refer to the GoDoc link above.

Parse

Creating an ARN instance from an ARN string:

import "github.com/jcmturner/awsarn"

arnStr := "arn:aws:iam::012345678912:user/testuser"
arn, err := awsarn.Parse(arnStr, http.DefaultClient)

fmt.Printf(
`Partition: %s
Service %s
Region %s
AccountID %s
ResourceType %s
Resource %s
`,
        arn.Partition,
        arn.Service,
        arn.Region,
        arn.AccountID,
        arn.ResourceType,
        arn.Resource,
        )
String

Get the AWS ARN in string format:

arnStr := arn.String()
fmt.Println(arnStr)
Validate
arnStr := "arn:aws:iam::012345678912:user/testuser"
if awsarn.Valid(arnStr, http.DefaultClient) {
        fmt.Println("ARN valid")
} else {
        fmt.Println("ARN invalid")
}

Online Reference Data

Validation can use the AWS ip-ranges.json document as reference data for the valid values of AWS regions. AWS bring new regions online and therefore this is the best, most up to date source of valid regions.

To disable the use of this online resource pass a nil pointer where *http.Client is required as an argument.

If you need to define the use of an HTTP proxy to reach the internet configure the transport on an http.Client passed as an argument.

proxyURL, err := url.Parse("http://proxyName:proxyPort")
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}}

arnStr := "arn:aws:iam::012345678912:user/testuser"
if awsarn.Valid(arnStr, client) {
        fmt.Println("ARN valid")
} else {
        fmt.Println("ARN invalid")
}

Documentation

Overview

Package arn provides utilities for manipulating Amazon Resource Names: http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AWSRegions

func AWSRegions(client *http.Client) ([]string, error)

AWSRegions returns a slice of valid AWS region names. If the nil is passed for the client then a static list of well known regions is returned rather than making an HTTP request.

func Valid

func Valid(arn string, client *http.Client) bool

Valid checks the format and content of the ARN string are valid. The http.Client is required to check the region in the ARN is valid against an authoritative AWS data source. To disable the HTTP check for the region pass nil as the client and the region will be checked against a static set of well known AWS regions only.

func ValidRegion

func ValidRegion(region string, client *http.Client) bool

ValidRegion checks the region is a valid AWS region. The http.Client is required to check the region against an authoritative AWS data source. To disable the HTTP check for the region pass nil as the client and the region will be checked against a static set of well known AWS regions only.

Types

type ARN

type ARN struct {
	Partition    string
	Service      string
	Region       string
	AccountID    string
	ResourceType string

	Resource string
	// contains filtered or unexported fields
}

ARN is a struct representing structure of an ARN.

func Parse

func Parse(arn string, client *http.Client) (ARN, error)

Parse validates an ARN string and returns an ARN type. An http.Client can be provided to validate the region against the latest regions queries from an AWS endpoint. To disable this HTTP request pass nil as the client and the region will be validated against a static set of well known AWS regions.

func (*ARN) String

func (a *ARN) String() string

String returns the AWS standard string representation of an ARN type.

type AWSIPRanges

type AWSIPRanges struct {
	SyncToken     string `json:"syncToken"`
	CreateDateStr string `json:"createDate"`
	CreateDate    time.Time
	Prefixes      []struct {
		IPPrefix string `json:"ip_prefix"`
		IP       net.IP
		Network  *net.IPNet
		Region   string `json:"region"`
		Service  string `json:"service"`
	} `json:"prefixes"`
	Ipv6Prefixes []struct {
		Ipv6Prefix string `json:"ipv6_prefix"`
		IP         net.IP
		Network    *net.IPNet
		Region     string `json:"region"`
		Service    string `json:"service"`
	} `json:"ipv6_prefixes"`
}

AWSIPRanges represents the AWS ip-ranges.json document.

func AWSIPRangesDoc

func AWSIPRangesDoc(client *http.Client) (awsip AWSIPRanges, err error)

AWSIPRangesDoc reads the ip-ranges.json document from https://ip-ranges.amazonaws.com/ip-ranges.json and returns an AWSIPRanges type.

Jump to

Keyboard shortcuts

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