awsarn

command module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

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

The Go Gopher

There is no documentation for this package.

Directories

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

Jump to

Keyboard shortcuts

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