Documentation
¶
Overview ¶
Package arn provides utilities for building AWS ARNs.
Index ¶
- Constants
- Variables
- func Build(service, region, accountID, resource string) string
- func BuildGlobal(service, region, accountID, resource string) string
- func BuildS3(resource string) string
- func Canonical(text string) string
- func FindMismatch(text, partition string, tolerateCommercial bool) (string, bool)
- func HasService(arnStr, svc string) bool
- func Localize(text, partition string) string
- func Partition(arnStr string) string
- func PartitionForRegion(region string) string
- func PartitionStrict() bool
- func S3(region, resource string) string
- func ValidateForRegion(region, arnStr string) error
- func WithPartition(region, arnStr string) string
Constants ¶
const EnvPartitionStrict = "GOPHERSTACK_PARTITION_STRICT"
EnvPartitionStrict set to "false" disables cross-partition ARN rejection.
Variables ¶
var ErrPartitionMismatch = errors.New("ARN partition does not match the request partition")
ErrPartitionMismatch is returned when an ARN's partition differs from the partition of the request's region.
Functions ¶
func Build ¶
Build constructs an AWS ARN from the given components. For IAM (service == "iam"), the region is omitted as IAM is a global service. The partition is derived from the region so GovCloud, China, and ISO regions produce wire-correct ARNs. Format: arn:{partition}:{service}:{region}:{accountID}:{resource}.
func BuildGlobal ¶ added in v1.2.0
BuildGlobal constructs an AWS ARN for a resource kind that is global (no region segment) even though the owning service is otherwise regional -- e.g. Direct Connect's DirectConnectGateway (confirmed via the real Terraform AWS provider source: `c.GlobalARN(ctx, "directconnect", "dx-gateway/"+id)`, gateway.go's gatewayARN). This differs from Build's existing service==\"iam\" special case, which is a whole-service exception: BuildGlobal is for services that are region-scoped for every OTHER resource kind but have one specific global resource kind, so the caller opts in per call site rather than the region omission being baked into the service name. The partition is still derived from region (regional resources of the same service may need it for GovCloud/China/ISO callers), even though region itself is omitted from the resulting ARN. Format: arn:{partition}:{service}::{accountID}:{resource}.
func BuildS3 ¶
BuildS3 constructs an ARN for an S3 resource. S3 ARNs have no region or account ID component. Format: arn:aws:s3:::{resource}.
func Canonical ¶
Canonical rewrites every non-commercial ARN partition in text to "aws" (plain and URL-encoded), the form global-service backends store and evaluate policies in.
func FindMismatch ¶
FindMismatch scans text for embedded ARNs and returns the first whose partition differs from partition. With tolerateCommercial, "aws" ARNs never count as mismatches: global services (IAM, S3, ...) still emit them regardless of the request region.
func HasService ¶
HasService reports whether arnStr is an ARN of the given service in any known partition.
func Localize ¶
Localize rewrites every "aws" partition ARN in text to partition (plain and URL-encoded).
func Partition ¶
Partition returns the partition segment of arnStr, or "" when arnStr is not a well-formed ARN of a known partition.
func PartitionForRegion ¶
PartitionForRegion returns the AWS partition (e.g. "aws", "aws-us-gov", "aws-cn", "aws-iso", "aws-iso-b") for the given region. Empty or unknown regions resolve to the standard "aws" partition.
Real AWS resources living in GovCloud or China use distinct ARN partitions and clients reject cross-partition ARNs. Use this helper when constructing ARNs from a region whose partition is not known a priori.
func PartitionStrict ¶
func PartitionStrict() bool
PartitionStrict reports whether cross-partition ARNs are rejected (the default).
func ValidateForRegion ¶
ValidateForRegion returns an ErrPartitionMismatch-wrapping error when arnStr names a known partition other than the one region belongs to. Non-ARN input and empty regions pass.
func WithPartition ¶
WithPartition rewrites the partition of arnStr to match region. Non-ARNs are returned unchanged.
Types ¶
This section is empty.