utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package utils contains helpers shared by the ec2 controllers.

Index

Constants

View Source
const (
	CodeGroupNotFound      = "InvalidGroup.NotFound"
	CodeDependency         = "DependencyViolation"
	CodePermissionNotFound = "InvalidPermission.NotFound"
)

AWS error codes the ec2 controllers handle.

Variables

This section is empty.

Functions

func DiffTags

func DiffTags(desired map[string]string, current []*svcapitypes.Tag) (add []svcsdktypes.Tag, remove []svcsdktypes.Tag)

DiffTags returns the tags to create (new or changed values) and to delete so that current equals desired. Tags reserved by AWS are left alone.

func ErrorCode

func ErrorCode(err error) string

ErrorCode returns the AWS error code of err, or "".

func FindRule

func FindRule(ctx context.Context, c RuleClient, r Rule, egress bool) (*svcsdktypes.SecurityGroupRule, error)

FindRule returns the rule of r's group that Matches r, or nil if there is none. r must be valid.

func FromSDK

func FromSDK(tags []svcsdktypes.Tag) []*svcapitypes.Tag

FromSDK converts SDK tags to API tags.

func IsGroupNotFound

func IsGroupNotFound(err error) bool

IsGroupNotFound reports whether err means that the security group does not exist.

func NormalizeProtocol

func NormalizeProtocol(p string) string

NormalizeProtocol returns the form AWS reports a protocol in: lower case, with the numbers of tcp, udp, icmp and icmpv6 replaced by their names.

func SpecTags added in v0.2.0

func SpecTags(spec []*svcapitypes.Tag) map[string]string

SpecTags returns the spec tags as a map: the tags the resource should have, besides those AWS sets.

func TagSpecifications

func TagSpecifications(rt svcsdktypes.ResourceType, tags map[string]string) []svcsdktypes.TagSpecification

TagSpecifications returns the tag specification of a create call.

func UpdateTags

func UpdateTags(ctx context.Context, c TagClient, id string, desired map[string]string, current []*svcapitypes.Tag) error

UpdateTags makes the tags of the resource with the given ID equal desired. CreateTags overwrites the values of existing keys.

Types

type Rule

type Rule struct {
	GroupID                   *string
	IPProtocol                *string
	FromPort                  *int64
	ToPort                    *int64
	CIDRIPv4                  *string
	CIDRIPv6                  *string
	PrefixListID              *string
	ReferencedSecurityGroupID *string
	Description               *string
}

Rule is a single security group rule, as specified by the SecurityGroupIngressRule and SecurityGroupEgressRule kinds.

func (Rule) Diff

func (r Rule) Diff(observed svcsdktypes.SecurityGroupRule, egress bool) ([]string, error)

Diff returns the JSON names of the spec fields whose desired value differs from the observed rule. It returns an error if the observed rule can't be changed into the desired one: it belongs to another group, has the other direction (egress is true for SecurityGroupEgressRule), or has another source type (e.g. a prefix list instead of an IPv4 CIDR).

func (Rule) IPPermission

func (r Rule) IPPermission() svcsdktypes.IpPermission

IPPermission returns the rule in the form Authorize* calls take.

func (Rule) Matches

func (r Rule) Matches(observed svcsdktypes.SecurityGroupRule, egress bool) bool

Matches reports whether observed is the rule r. Within a group, AWS allows only one rule with the same direction, protocol, ports and source; the description and tags can differ.

func (Rule) RuleUpdate

RuleUpdate returns the ModifySecurityGroupRules entry that makes the rule with the given ID equal r. AWS can't change the group or the source type in place; Diff reports those as errors.

func (Rule) Validate

func (r Rule) Validate() error

Validate checks what the API server can't: AWS would otherwise accept some invalid combinations by creating a different rule than specified.

type RuleClient

type RuleClient interface {
	DescribeSecurityGroupRules(context.Context, *svcsdk.DescribeSecurityGroupRulesInput, ...func(*svcsdk.Options)) (*svcsdk.DescribeSecurityGroupRulesOutput, error)
}

RuleClient is the part of the EC2 API used to look up rules.

type TagClient

type TagClient interface {
	CreateTags(context.Context, *svcsdk.CreateTagsInput, ...func(*svcsdk.Options)) (*svcsdk.CreateTagsOutput, error)
	DeleteTags(context.Context, *svcsdk.DeleteTagsInput, ...func(*svcsdk.Options)) (*svcsdk.DeleteTagsOutput, error)
}

TagClient is the part of the EC2 API used to manage tags.

Jump to

Keyboard shortcuts

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