utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TagLinkSecurityGroup is a tag that is used to identify the security group
	// that is used to allow access to VPC endpoints.
	TagLinkSecurityGroup = "bluelink:link:security-group"
	// TagLinkVPCName is a tag that is used to identify the flex VPC
	// that is used to allow access to VPC endpoints.
	TagLinkVPCName = "bluelink:link:flex-vpc:name"
	// TagBlueprintInstanceName is a tag that is used to identify the blueprint instance
	// that is used to allow access to VPC endpoints.
	TagBlueprintInstanceName = "bluelink:blueprint-instance:name"
	// TagBlueprintLinkIDPrefix is a tag prefix that is used to identify the blueprint link
	// that is used for networking resources created as a part of a link implementation.
	// Each link will have its own key entry in the tag with the link ID as the suffix.
	TagBlueprintLinkIDPrefix = "bluelink:blueprint-link:id:"
	// TagLinkVPCEndpoint is a tag that is used to identify the VPC endpoint
	// that is used to allow access to VPC endpoints.
	TagLinkVPCEndpoint = "bluelink:link:vpc-endpoint"
	// TagBluelinkService is a tag that is used to identify the service
	// that a resource such as a security group is intended to provide access to.
	TagBluelinkService = "bluelink:service"
)
View Source
const DefaultBluelinkTagPrefix = "bluelink:"

DefaultBluelinkTagPrefix is the default prefix for Bluelink provenance tags.

View Source
const (
	// MaxZipFileSize is the maximum size of a zip file in bytes
	// generated by the ZipInMemory function.
	MaxZipFileSize = 4 * 1024 * 1024 // 4MB
)

Variables

View Source
var (
	// IAMRoleNameGenerator generates names for IAM roles (64 char limit).
	IAMRoleNameGenerator = DefaultUniqueNameGenerator(64)

	// IAMUserNameGenerator generates names for IAM users (64 char limit).
	IAMUserNameGenerator = DefaultUniqueNameGenerator(64)

	// IAMGroupNameGenerator generates names for IAM groups (128 char limit).
	IAMGroupNameGenerator = DefaultUniqueNameGenerator(128)

	// IAMInstanceProfileNameGenerator generates names for IAM instance profiles (128 char limit).
	IAMInstanceProfileNameGenerator = DefaultUniqueNameGenerator(128)

	// LambdaFunctionNameGenerator generates names for Lambda functions (64 char limit).
	LambdaFunctionNameGenerator = DefaultUniqueNameGenerator(64)

	// S3BucketNameGenerator generates names for S3 buckets (63 char limit).
	S3BucketNameGenerator = DefaultUniqueNameGenerator(63)

	// EC2InstanceNameGenerator generates names for EC2 instances (255 char limit).
	EC2InstanceNameGenerator = DefaultUniqueNameGenerator(255)

	// DynamoDBTableNameGenerator generates names for DynamoDB tables (255 char limit).
	DynamoDBTableNameGenerator = DefaultUniqueNameGenerator(255)

	// IAMPolicyNameGenerator generates names for IAM policies (128 char limit).
	IAMPolicyNameGenerator = DefaultUniqueNameGenerator(128)

	// IAMOIDCProviderUrlGenerator generates names for IAM OIDC providers (255 char limit).
	IAMOIDCProviderUrlGenerator = DefaultUniqueNameGenerator(255)

	// IAMSAMLProviderNameGenerator generates names for IAM SAML providers (128 char limit).
	IAMSAMLProviderNameGenerator = DefaultUniqueNameGenerator(128)

	// IAMServerCertificateNameGenerator generates names for IAM server certificates (128 char limit).
	IAMServerCertificateNameGenerator = DefaultUniqueNameGenerator(128)
)

Common name generators for different AWS services.

View Source
var Services = map[string][]string{
	"account":         {},
	"lambda":          {},
	"iam":             {},
	"dynamodb":        {},
	"sqs":             {},
	"ssm":             {},
	"kms":             {},
	"elasticache":     {},
	"secretsmanager":  {},
	"events":          {"eventbridge"},
	"cloudcontrolapi": {"cloudcontrol"},
}

Services is a map of AWS services and their aliases.

Functions

func AWSConfigCacheKey

func AWSConfigCacheKey(
	sessionID string,
	meta map[string]*core.MappingNode,
) string

AWSConfigCacheKey creates a cache key for the given session ID and metadata specific to a specific request for an action on a resource, data source, or link.

func AWSConfigFromProviderContext

func AWSConfigFromProviderContext(
	ctx context.Context,
	providerContext provider.Context,
	meta map[string]*core.MappingNode,
	env map[string]string,
	loader AWSConfigLoader,
) (*aws.Config, error)

AWSConfigFromProviderContext creates an AWS config from the given provider context and environment variables.

func AWSServiceList

func AWSServiceList() string

AWSServiceList returns a string of all the AWS services and their aliases.

func AssumeRoleOptions

func AssumeRoleOptions(
	providerContext provider.Context,
) []func(*config.LoadOptions) error

AssumeRoleOptions returns the assume role options derived from the given provider context.

func AssumeRoleWithWebIdentityOptions

func AssumeRoleWithWebIdentityOptions(
	providerContext provider.Context,
) []func(*config.LoadOptions) error

AssumeRoleWithWebIdentityOptions returns the assume role with web identity options derived from the given provider context.

func BuildBluelinkTagFiltersForLookup

func BuildBluelinkTagFiltersForLookup(
	input *provider.ResourceGetExternalStateInput,
) []rgtatypes.TagFilter

BuildBluelinkTagFiltersForLookup creates Resource Groups Tagging API tag filters for looking up a resource by its Bluelink provenance tags. This is used for fallback lookups when the external ID (ARN) is not available.

func CalculateIPv4SubnetCIDRBlocks

func CalculateIPv4SubnetCIDRBlocks(vpcCIDRBlock string, numSubnets int) ([]string, error)

CalculateIPv4SubnetCIDRBlocks calculates the IPv4 CIDR blocks for a given number of subnets to be deployed to the VPC with the given CIDR block.

func CalculateIPv6SubnetCIDRBlocks

func CalculateIPv6SubnetCIDRBlocks(
	vpcCIDRBlock string,
	numSubnets int,
	subnetPrefix int,
) ([]string, error)

CalculateIPv6SubnetCIDRBlocks calculates the IPv6 CIDR blocks for a given number of subnets to be deployed to the VPC with the given CIDR block.

func CertOptions

func CertOptions(
	providerContext provider.Context,
	env map[string]string,
) ([]func(*config.LoadOptions) error, error)

CertOptions returns the cert options derived from the given provider context and environment variables.

func CreateTagBluelinkService

func CreateTagBluelinkService(serviceName string) ec2types.Tag

CreateTagBluelinkService creates a tag that is used to identify the service that is used to allow access to VPC endpoints.

func CreateTagBlueprintInstanceName

func CreateTagBlueprintInstanceName(instanceName string) ec2types.Tag

CreateTagBlueprintInstanceName creates a tag that is used to identify the blueprint instance associated with a networking resource created as a part of a link implementation.

func CreateTagBlueprintLinkID

func CreateTagBlueprintLinkID(linkID string) ec2types.Tag

CreateTagBlueprintLinkID creates a tag that is used to identify the blueprint link that is used to allow access to VPC endpoints.

func CreateTagFilterBluelinkService added in v0.5.0

func CreateTagFilterBluelinkService(serviceName string) ec2types.Filter

CreateTagFilterBluelinkService returns a filter matching the AWS service a link's networking resources were created for.

A tag is matched with a "tag:" prefix on the filter name. Passing the bare tag key makes EC2 reject the whole call with InvalidParameterValue, which is what happened at both call sites before this existed.

func CreateTagFilterFlexVPCNameForLink(flexVPCName string) ec2types.Filter

CreateTagFilterFlexVPCNameForLink creates a filter that is used to identify the flex VPC that is used to allow access to VPC endpoints. This is to be used for components created as a part of a link implementation and is different from the tag used for the core flex VPC resources.

func CreateTagFlexVPCNameForLink(flexVPCName string) ec2types.Tag

CreateTagFlexVPCNameForLink creates a filter that is used to identify the flex VPC that is used to allow access to VPC endpoints. This is to be used for components created as a part of a link implementation and is different from the tag used for the core flex VPC resources.

func CreateTagLinkSecurityGroup

func CreateTagLinkSecurityGroup() ec2types.Tag

CreateTagLinkSecurityGroup creates a tag that is used to identify the security group that is used to allow access to VPC endpoints.

func CreateTagLinkVPCEndpoint

func CreateTagLinkVPCEndpoint() ec2types.Tag

CreateTagLinkVPCEndpoint creates a tag that is used to identify the VPC endpoint that is used to allow access to VPC endpoints.

func CredentialOptions

func CredentialOptions(
	providerContext provider.Context,
) []func(*config.LoadOptions) error

CredentialOptions returns the credential options derived from the given provider context.

func EC2MetadataServiceOptions

func EC2MetadataServiceOptions(
	providerContext provider.Context,
	env map[string]string,
) []func(*config.LoadOptions) error

EC2MetadataServiceOptions returns the ec2 metadata service options derived from the given provider context and environment variables.

func ExtractARNFromCurrentState

func ExtractARNFromCurrentState(
	currentStateSpecData *core.MappingNode,
	context string,
) (string, error)

ExtractARNFromCurrentState extracts the ARN from the current state spec data, this only works when the "arn" field is present as a a top-level field in provided spec data.

func ExtractARNFromResourceInfo

func ExtractARNFromResourceInfo(resourceInfo *provider.ResourceInfo) (string, bool)

ExtractARNFromResourceInfo extracts the ARN from the resource info, this only works when the "arn" field is present as a a top-level field in provided spec data.

func FilterTags

func FilterTags[T any](tags []T, getKey func(T) string, prefix string) []T

FilterTags is a generic function that filters out Bluelink provenance tags from a slice. It takes a slice of tags, a function to extract the key from each tag, and the prefix to filter. Returns a new slice containing only non-Bluelink tags.

func FilterTagsMap

func FilterTagsMap(tags map[string]string, prefix string) map[string]string

FilterTagsMap filters out Bluelink provenance tags from a map. Returns a new map containing only non-Bluelink tags.

func GetBluelinkTagPrefix

func GetBluelinkTagPrefix(taggingConfig *provider.TaggingConfig) string

GetBluelinkTagPrefix returns the tag prefix from tagging config, or the default if not set.

func GetEndpointFromProviderConfig

func GetEndpointFromProviderConfig(
	providerContext provider.Context,
	service string,
	aliases []string,
) (*core.ScalarValue, bool)

GetEndpointFromProviderConfig returns the endpoint for a given service or one of its aliases.

func GetOtherLinkTagsFromSecurityGroup

func GetOtherLinkTagsFromSecurityGroup(
	securityGroup *ec2types.SecurityGroup,
	excludeLinkID string,
) []ec2types.Tag

GetOtherLinkTagsFromSecurityGroup gets all link tags from a security group except for the specified link ID.

func GetOtherLinkTagsFromVPCEndpoint

func GetOtherLinkTagsFromVPCEndpoint(
	endpoint *ec2types.VpcEndpoint,
	excludeLinkID string,
) []ec2types.Tag

GetOtherLinkTagsFromVPCEndpoint gets all link tags from a VPC endpoint except for the specified link ID.

func HTTPClientOptions

func HTTPClientOptions(
	providerContext provider.Context,
) []func(*config.LoadOptions) error

HTTPClientOptions returns the http client options derived from the given provider context.

func HasIngressFromSecurityGroupID added in v0.5.0

func HasIngressFromSecurityGroupID(
	securityGroup *ec2types.SecurityGroup,
	sourceSecurityGroupID string,
) bool

HasIngressFromSecurityGroupID checks if the security group has an ingress rule admitting the given source security group.

Matched on GroupId rather than GroupName: a group in a non-default VPC is always referenced by ID, and EC2 does not populate GroupName on such a reference, so a name-based check can never match and would report every rule as absent.

func HasSecurityGroupTagForLink(
	securityGroup *ec2types.SecurityGroup,
	linkID string,
) bool

HasSecurityGroupTagForLink checks if the security group has a tag that associates it with the given link ID.

func HasVPCEndpointTagForLink(
	endpoint *ec2types.VpcEndpoint,
	linkID string,
) bool

HasVPCEndpointTagForLink checks if the VPC endpoint has a tag that associates it with the given link ID.

func IsBluelinkTag

func IsBluelinkTag(key, prefix string) bool

IsBluelinkTag checks if a tag key is a Bluelink provenance tag.

func MatchesEC2Tag

func MatchesEC2Tag(
	expectedTag ec2types.Tag,
	currentTag ec2types.Tag,
) bool

MatchesEC2Tag checks if the current tag matches the expected tag for EC2 resources.

func MergeBluelinkTagsWithUserTags

func MergeBluelinkTagsWithUserTags(
	input *provider.ResourceDeployInput,
	userTags map[string]string,
) map[string]string

MergeBluelinkTagsWithUserTags extracts Bluelink system tags from input, converts to AWS format, and merges with user-provided tags. User tags take precedence on key conflicts. Returns map[string]string suitable for AWS SDK calls.

func RegionOptions

func RegionOptions(
	providerContext provider.Context,
	meta map[string]*core.MappingNode,
) []func(*config.LoadOptions) error

RegionOptions returns the region options derived from the given provider context.

func RetryConfigOptions

func RetryConfigOptions(
	providerContext provider.Context,
	env map[string]string,
) []func(*config.LoadOptions) error

RetryConfigOptions returns the retry config options derived from the given provider context and environment variables.

func SharedEndpointOptions

func SharedEndpointOptions(
	providerContext provider.Context,
) []func(*config.LoadOptions) error

SharedEndpointOptions returns the shared endpoint options derived from the given provider context.

func ToTagsMap

func ToTagsMap(specTags *core.MappingNode) map[string]string

ToTagsMap converts a MappingNode to a map of tags. The MappingNode is expected to be an array of objects with "key" and "value" fields.

func VPCEndpointInSubnets

func VPCEndpointInSubnets(
	endpoint *ec2types.VpcEndpoint,
	subnets []string,
) bool

VPCEndpointInSubnets checks if the VPC endpoint is in the given subnets.

func ZipInMemory

func ZipInMemory(
	fileName string,
	content string,
) (string, error)

ZipInMemory creates a zip archive in memory that contains a single file with the given file name and content. This returns a base64 encoded string representation of the zip archive.

Types

type AWSConfigCreator

type AWSConfigCreator func(
	ctx context.Context,
	providerContext provider.Context,
	meta map[string]*core.MappingNode,
	env map[string]string,
	loader AWSConfigLoader,
) (*aws.Config, error)

AWSConfigCreator is a function that produces an AWS config from the given provider context and environment variables.

type AWSConfigLoader

type AWSConfigLoader interface {
	LoadDefaultConfig(
		ctx context.Context,
		optFns ...func(*config.LoadOptions) error,
	) (aws.Config, error)
}

AWSConfigLoader defines the interface for loading AWS configurations.

type AWSConfigStore

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

AWSConfigStore is a store for AWS config that is used to derive and cache AWS config on a per-session basis.

func NewAWSConfigStore

func NewAWSConfigStore(
	env []string,
	createAWSConfig AWSConfigCreator,
	loader AWSConfigLoader,
	configStoreCacheKey CacheKeyCreator,
) *AWSConfigStore

NewAWSConfigStore creates a new store for deriving and caching AWS config.

func (*AWSConfigStore) FromProviderContext

func (s *AWSConfigStore) FromProviderContext(
	ctx context.Context,
	providerContext provider.Context,
	meta map[string]*core.MappingNode,
) (*aws.Config, error)

FromProviderContext creates configuration to be used to create AWS SDK clients.

type CacheKeyCreator

type CacheKeyCreator func(
	sessionID string,
	meta map[string]*core.MappingNode,
) string

CacheKeyCreator is a function that creates a cache key from the given session ID and metadata.

type DefaultAWSConfigLoader

type DefaultAWSConfigLoader struct{}

DefaultAWSConfigLoader implements AWSConfigLoader using the AWS SDK.

func (*DefaultAWSConfigLoader) LoadDefaultConfig

func (l *DefaultAWSConfigLoader) LoadDefaultConfig(
	ctx context.Context,
	optFns ...func(*config.LoadOptions) error,
) (aws.Config, error)

type Tag

type Tag struct {
	Key   string
	Value string
}

Tag is an intermediary representation of a tag that is used across AWS services (The SDK provides a different type for each service). This is used to provide a consistent interface for the tag changes that should be converted to the upstream service's tag type.

type TagsDiffResult

type TagsDiffResult[UpstreamTag any] struct {
	ToSet    []UpstreamTag
	ToRemove []string
}

TagsDiffResult is the result of the DiffTags function, it contains the tags that should be set and the tag keys that should be removed.

func DiffTags

func DiffTags[UpstreamTag any](
	changes *provider.Changes,
	tagsRootPath string,
	transformTag func(tag *Tag) UpstreamTag,
) *TagsDiffResult[UpstreamTag]

DiffTags provides a general purpose utility to derive the difference between two sets of tags stored in a resource spec for the purpose of making calls to the upstream service to apply tag changes. There is a limitation in the `Changes` data that the plugin receives in that when the tags are stored in a list, it does not provide sufficient information on the key of the tags to be removed as it just reports an updated or removed index in the list. For this reason, resource implementations need to use the actual current and upcoming resource spec data to derive the tag changes so that the correct tags are removed, added and replaced.

tagsRootPath is the path to the tags field in the resource spec, the expected format is to use "$" to represent the root of the spec (e.g. "$.tags").

func DiffTagsWithBluelink[UpstreamTag any](
	changes *provider.Changes,
	deployInput *provider.ResourceDeployInput,
	tagsRootPath string,
	transformTag func(tag *Tag) UpstreamTag,
) *TagsDiffResult[UpstreamTag]

DiffTagsWithBluelink provides tag diffing that includes Bluelink system tags. It works like DiffTags but merges Bluelink tags with the desired user tags before computing the diff.

tagsRootPath is the path to the tags field in the resource spec, the expected format is to use "$" to represent the root of the spec (e.g. "$.tags").

type UniqueNameGenerator

type UniqueNameGenerator func(input *provider.ResourceDeployInput) (string, error)

UniqueNameGenerator is a function type for generating unique names.

func DefaultUniqueNameGenerator

func DefaultUniqueNameGenerator(maxLength int) UniqueNameGenerator

DefaultUniqueNameGenerator creates a unique name using blueprint instance name, resource name, and a nanoid with a configurable character limit. Uses input.InstanceName which provides meaningful, human-readable names.

func SQSQueueNameGenerator

func SQSQueueNameGenerator(fifoQueue bool) UniqueNameGenerator

SQSQueueNameGenerator generates names for SQS queues (80 char limit) and accounts for FIFO queues, ensuring the name ends with '.fifo'.

Jump to

Keyboard shortcuts

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