goarnie

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MIT Imports: 5 Imported by: 0

README

goarnie

Build Status Go Report Card MIT

A Golang package for parsing and creating Amazon Resource Names (ARNs).

Supported ARN types

The following ARN types are currently supported:

IAM User

IAM User ARNs are represented by the IAMUserARN struct.

You can create instances of IAMUserARN by calling:

IAMUserARN functions
  • Header() (string, error) gets the header. This should always be "arn".
  • SetHeader(string) error sets the header.
  • Partition() (string, error) gets the partition. This will be "aws" or "aws-cn".
  • SetPartition(string) error sets the partition.
  • Service() (string, error) gets the partition. This will be "iam", "rds", "s3", etc.
  • SetService(string) error sets the partition.
  • Region() (string, error) gets the region. This will be "us-east-1", "eu-west-2", "ap-southeast-1", etc.
  • SetRegion(string) error sets the region.
  • Account() (string, error) gets the account ID.
  • SetAccount(string) error sets the account ID.
  • ResourceType() (string, error) gets the resource type. This should always be "user".
  • SetResourceType(string) error sets the resource type.
  • Name() (string, error) gets the user's name.
  • SetName(string) error sets the user's name.
  • IsValid() (bool, string, error) checks if the instance is valid.
  • ToARN() (string, error) gets the instance as a string ARN. The struct is also a Stringer.
MakeIAMUserARN(partition string, account string, name string) (IAMUserARN, error)
package main

import (
    "fmt"
    "github.com/cariad/goarnie"
)

func main() {
    arn, _ := goarnie.MakeIAMUserARN("aws", "555000000000", "rebecca")

    name, _ := arn.Name()
    fmt.Println(name)
    // rebecca

    fmt.Println(arn)
    // arn:aws:iam::555000000000:user/rebecca
}
MakeIAMUserARNFromString(value string) IAMUserARN
package main

import (
    "fmt"
    "github.com/cariad/goarnie"
)

func main() {
    arn := goarnie.MakeIAMUserARNFromString("arn:aws:iam::555000000000:user/rebecca")

    name, _ := arn.Name()
    fmt.Println(name)
    // rebecca

    fmt.Println(arn)
    // arn:aws:iam::555000000000:user/rebecca
}

RDS Database Instance

RDS Database Instance ARNs are represented by the RDSDatabaseInstanceARN struct.

You can create instances of RDSDatabaseInstanceARN by calling:

RDSDatabaseInstanceARN functions
  • Header() (string, error) gets the header. This should always be "arn".
  • SetHeader(string) error sets the header.
  • Partition() (string, error) gets the partition. This will be "aws" or "aws-cn".
  • SetPartition(string) error sets the partition.
  • Service() (string, error) gets the partition. This will be "iam", "rds", "s3", etc.
  • SetService(string) error sets the partition.
  • Region() (string, error) gets the region. This will be "us-east-1", "eu-west-2", "ap-southeast-1", etc.
  • SetRegion(string) error sets the region.
  • Account() (string, error) gets the account ID.
  • SetAccount(string) error sets the account ID.
  • ResourceType() (string, error) gets the resource type. This should always be "user".
  • SetResourceType(string) error sets the resource type.
  • DatabaseIdentifier() (string, error) gets the database identifier.
  • SetDatabaseIdentifier(string) error sets the database identifier.
  • IsValid() (bool, string, error) checks if the instance is valid.
  • ToARN() (string, error) gets the instance as a string ARN. The struct is also a Stringer.
MakeRDSDatabaseInstanceARN(partition string, region string, account string, database string) (DatabaseInstanceARN, error)
package main

import (
    "fmt"
    "github.com/cariad/goarnie"
)

func main() {
    arn, _ := goarnie.MakeRDSDatabaseInstanceARN("aws", "eu-west-2", "555000000000", "my-database")

    databaseIdentifier, _ := arn.DatabaseIdentifier()
    fmt.Println(databaseIdentifier)
    // my-database

    fmt.Println(arn)
    // arn:aws:rds:eu-west-2:555000000000:db:my-database
}
MakeRDSDatabaseInstanceARNFromString(value string) DatabaseInstanceARN
package main

import (
    "fmt"
    "github.com/cariad/goarnie"
)

func main() {
    arn := goarnie.MakeRDSDatabaseInstanceARNFromString("arn:aws:rds:eu-west-2:555000000000:db:my-database")

    databaseIdentifier, _ := arn.DatabaseIdentifier()
    fmt.Println(databaseIdentifier)
    // my-database

    fmt.Println(arn)
    // arn:aws:rds:eu-west-2:555000000000:db:my-database
}

Licence, credit & sponsorship

This project is published under the MIT Licence.

You don't owe me anything in return, but as an indie freelance coder there are two things I'd appreciate:

  • Credit. If your app or documentation has a credits page, please consider mentioning the projects you use.
  • Cash. If you want and are able to support future development, please consider becoming a patron or buying me a coffee. Thank you!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ARN added in v1.1.0

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

ARN describes an Amazon Resource Name.

func MakeARN added in v1.1.0

func MakeARN(partition string, service string, region string, account string) (ARN, error)

MakeARN makes a new ARN.

func MakeARNFromString added in v1.1.0

func MakeARNFromString(arn string) ARN

MakeARNFromString makes a new ARN from a string.

func (ARN) Account added in v1.1.0

func (arn ARN) Account() (string, error)

Account gets the account ID.

func (ARN) Header added in v1.1.0

func (arn ARN) Header() (string, error)

Header gets the header.

func (ARN) IsValid added in v1.1.0

func (arn ARN) IsValid() (bool, string, error)

IsValid checks if the field values are valid.

func (ARN) Partition added in v1.1.0

func (arn ARN) Partition() (string, error)

Partition gets the partition.

func (ARN) Region added in v1.1.0

func (arn ARN) Region() (string, error)

Region gets the region.

func (ARN) Service added in v1.1.0

func (arn ARN) Service() (string, error)

Service gets the service.

func (*ARN) SetAccount added in v1.1.0

func (arn *ARN) SetAccount(account string) error

SetAccount sets the partition.

func (*ARN) SetHeader added in v1.1.0

func (arn *ARN) SetHeader(header string) error

SetHeader sets the header.

func (*ARN) SetPartition added in v1.1.0

func (arn *ARN) SetPartition(partition string) error

SetPartition sets the partition.

func (*ARN) SetRegion added in v1.1.0

func (arn *ARN) SetRegion(region string) error

SetRegion sets the region.

func (*ARN) SetService added in v1.1.0

func (arn *ARN) SetService(service string) error

SetService sets the service.

func (ARN) ToARN added in v1.1.0

func (arn ARN) ToARN() (string, error)

ToARN converts the ARN to a string ARN.

type DatabaseInstanceARN added in v1.1.0

type DatabaseInstanceARN struct {
	ARN
	// contains filtered or unexported fields
}

DatabaseInstanceARN describes the ARN of an RDS database instance.

func MakeRDSDatabaseInstanceARN added in v1.1.0

func MakeRDSDatabaseInstanceARN(partition string, region string, account string, database string) (DatabaseInstanceARN, error)

MakeRDSDatabaseInstanceARN makes a new DatabaseInstanceARN.

func MakeRDSDatabaseInstanceARNFromString added in v1.1.0

func MakeRDSDatabaseInstanceARNFromString(value string) DatabaseInstanceARN

MakeRDSDatabaseInstanceARNFromString makes a new DatabaseInstanceARN from a string.

func (DatabaseInstanceARN) DatabaseIdentifier added in v1.1.0

func (arn DatabaseInstanceARN) DatabaseIdentifier() (string, error)

DatabaseIdentifier gets the database identifier.

func (DatabaseInstanceARN) IsValid added in v1.1.0

func (arn DatabaseInstanceARN) IsValid() (bool, string, error)

IsValid checks if the field values are valid.

func (DatabaseInstanceARN) ResourceType added in v1.1.0

func (arn DatabaseInstanceARN) ResourceType() (string, error)

ResourceType gets the resource type.

func (*DatabaseInstanceARN) SetDatabaseIdentifier added in v1.1.0

func (arn *DatabaseInstanceARN) SetDatabaseIdentifier(database string) error

SetDatabaseIdentifier sets the database identifier.

func (*DatabaseInstanceARN) SetResourceType added in v1.1.0

func (arn *DatabaseInstanceARN) SetResourceType(resourceType string) error

SetResourceType sets the resource type.

func (DatabaseInstanceARN) String added in v1.1.0

func (arn DatabaseInstanceARN) String() string

func (DatabaseInstanceARN) ToARN added in v1.1.0

func (arn DatabaseInstanceARN) ToARN() (string, error)

ToARN converts the ARN to a string ARN.

type IAMUserARN added in v1.1.0

type IAMUserARN struct {
	ARN
	// contains filtered or unexported fields
}

IAMUserARN describes the ARN of an IAM User.

func MakeIAMUserARN added in v1.1.0

func MakeIAMUserARN(partition string, account string, name string) (IAMUserARN, error)

MakeIAMUserARN makes a new IAMUserARN.

func MakeIAMUserARNFromString added in v1.1.0

func MakeIAMUserARNFromString(value string) IAMUserARN

MakeIAMUserARNFromString makes a new v from a string.

func (IAMUserARN) IsValid added in v1.1.0

func (arn IAMUserARN) IsValid() (bool, string, error)

IsValid checks if the field values are valid.

func (IAMUserARN) Name added in v1.1.0

func (arn IAMUserARN) Name() (string, error)

Name gets the name.

func (IAMUserARN) ResourceType added in v1.1.0

func (arn IAMUserARN) ResourceType() (string, error)

ResourceType gets the resource type.

func (*IAMUserARN) SetName added in v1.1.0

func (arn *IAMUserARN) SetName(name string) error

SetName sets the name.

func (*IAMUserARN) SetResourceType added in v1.1.0

func (arn *IAMUserARN) SetResourceType(resourceType string) error

SetResourceType sets the resource type.

func (IAMUserARN) String added in v1.1.0

func (arn IAMUserARN) String() string

func (IAMUserARN) ToARN added in v1.1.0

func (arn IAMUserARN) ToARN() (string, error)

ToARN converts the ARN to a string ARN.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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