utils

package
v0.0.0-...-ff5590b Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 30 Imported by: 585

Documentation

Overview

Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at

http://aws.amazon.com/apache2.0/

or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at

http://aws.amazon.com/apache2.0/

or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	EphemeralPortMin = 32768
	EphemeralPortMax = 60999
)

From https://www.kernel.org/doc/html/latest//networking/ip-sysctl.html#ip-variables

View Source
const (

	// DefaultPortRangeStart indicates the first port in ephemeral port range
	DefaultPortRangeStart = 49153
	// DefaultPortRangeEnd indicates the last port in ephemeral port range
	DefaultPortRangeEnd = 65535
)

Variables

View Source
var (
	OpenFile = os.Open
)

Functions

func BoolPtr

func BoolPtr(b bool) *bool

func CompleteJsonUnmarshal

func CompleteJsonUnmarshal(b []byte, iface interface{}) error

CompleteJsonUnmarshal determines if a given struct has members corresponding to every key of a json object (passed as the json string). By default, Go ignores fields in an object which have no corresponding struct member and this can be used to determine if this ignoring has occurred Errors will result in "false" as a return value

func DefaultIfBlank

func DefaultIfBlank(str string, default_value string) string

func ExtractVersion

func ExtractVersion(input string) string

ExtractVersion extracts a matching version from the version number string

func FileExists

func FileExists(filePath string) (bool, error)

Checks if a file exists on the provided file path.

func GenerateEphemeralPortNumbers

func GenerateEphemeralPortNumbers(n int, reserved []uint16) ([]uint16, error)

GenerateEphemeralPortNumbers generates a list of n unique port numbers in the 32768-60999 range. The resulting port number list is guaranteed to not include any port number present in "reserved" parameter.

func GetAttachmentId

func GetAttachmentId(attachmentArn string) (string, error)

GetAttachmentId retrieves the ID from an attachment's ARN. asssumes arn structure: arn:[partition]:ec2:[region]:[account-id]:[attachment-type]/[resource-id]

func GetCPUFlags

func GetCPUFlags(cpuInfo *CPUInfo) map[string]bool

GetCPUFlags merges all processors' flags and return as a map. Returning map makes it easy to check whether a flag exists or not.

func GetCanonicalPath

func GetCanonicalPath(path string) string

func GetDynamicHostPortRange

func GetDynamicHostPortRange() (start int, end int, err error)

GetDynamicHostPortRange returns the ephemeral port range defined by the "/proc/sys/net/ipv4/ip_local_port_range" kernel parameter. Ref: https://github.com/moby/moby/blob/master/libnetwork/portallocator/portallocator_linux.go

func GetHostPort

func GetHostPort(protocol string, dynamicHostPortRange string) (string, error)

GetHostPort gets 1 host port from the ephemeral host port range defined on the host. dynamicHostPortRange can be set by customers using ECS Agent environment variable ECS_DYNAMIC_HOST_PORT_RANGE; otherwise, ECS Agent will use the default value returned from GetDynamicHostPortRange() in the utils package.

func GetHostPortRange

func GetHostPortRange(numberOfPorts int, protocol string, dynamicHostPortRange string) (string, error)

GetHostPortRange gets N contiguous host ports from the ephemeral host port range defined on the host. dynamicHostPortRange can be set by customers using ECS Agent environment variable ECS_DYNAMIC_HOST_PORT_RANGE; otherwise, ECS Agent will use the default value returned from GetDynamicHostPortRange() in the utils package.

func GetRequestFailureStatusCode

func GetRequestFailureStatusCode(err error) int

GetRequestFailureStatusCode returns the status code from a RequestFailure error, or 0 if the error is not of that type

func GetTaskID

func GetTaskID(taskARN string) (string, error)

GetTaskID retrieves the task ID from task ARN.

func Int64Ptr

func Int64Ptr(i int64) *int64

func IntPtr

func IntPtr(i int) *int

func IsAWSErrorCodeEqual

func IsAWSErrorCodeEqual(err error, code string) bool

IsAWSErrorCodeEqual returns true if the err implements Error interface of awserr and it has the same error code as the passed in error code.

func JsonKeys

func JsonKeys(b []byte) ([]string, error)

JsonKeys takes an arbitrary byte array representing a json stringified object and returns all the keys of that object.

func MapToTags

func MapToTags(tagsMap map[string]string) []*ecs.Tag

MapToTags converts a map to a slice of tags.

func MkdirAllAndChown

func MkdirAllAndChown(path string, perm fs.FileMode, uid, gid int) error

func NewJitteredTicker

func NewJitteredTicker(ctx context.Context, start, end time.Duration) <-chan time.Time

NewJitteredTicker works like a time.Ticker except with randomly distributed ticks between start and end duration.

func ParseBool

func ParseBool(str string, default_ bool) bool

func ParseRepositoryTag

func ParseRepositoryTag(repoTag string) (repository string, tag string)

ParseRepositoryTag mimics the go-dockerclient's ParseReposirotyData. The only difference is that it doesn't ignore the sha when present.

func RandHex

func RandHex() string

func Remove

func Remove(slice []string, s int) []string

Removes element at a particular index in the slice

func ResetTracker

func ResetTracker()

ResetTracker resets the last assigned host port to 0.

func SearchStrInDir

func SearchStrInDir(dir, filePrefix, content string) error

SearchStrInDir searches the files in directory for specific content

func SlicesDeepEqual

func SlicesDeepEqual(slice1, slice2 interface{}) bool

SlicesDeepEqual checks if slice1 and slice2 are equal, disregarding order.

func StrSliceContains

func StrSliceContains(strs []string, s string) bool

func StrSliceEqual

func StrSliceEqual(s1, s2 []string) bool

func Strptr

func Strptr(s string) *string

Types

type CPUInfo

type CPUInfo struct {
	Processors []Processor `json:"processors"`
}

func ReadCPUInfo

func ReadCPUInfo(path string) (*CPUInfo, error)

type ChanSemaphore

type ChanSemaphore struct {
	Count int // Public for introspection; should not be written to
	// contains filtered or unexported fields
}

Implements semaphore

func (*ChanSemaphore) Post

func (s *ChanSemaphore) Post()

func (*ChanSemaphore) Wait

func (s *ChanSemaphore) Wait()

type LicenseProvider

type LicenseProvider interface {
	GetText() (string, error)
}

func NewLicenseProvider

func NewLicenseProvider() LicenseProvider

type Processor

type Processor struct {
	Flags []string `json:"flags"`
}

type Semaphore

type Semaphore interface {
	Post()
	Wait()
}

func NewSemaphore

func NewSemaphore(count int) Semaphore

type UUIDProvider

type UUIDProvider interface {
	New() string
}

UUIDProvider wraps 'uuid' methods for testing

func NewDynamicUUIDProvider

func NewDynamicUUIDProvider() UUIDProvider

NewDynamicUUIDProvider returns a new dynamicUUIDProvider

func NewStaticUUIDProvider

func NewStaticUUIDProvider(staticID string) UUIDProvider

NewStaticUUIDProvider returns a new staticUUIDProvider

type Version

type Version string

func (Version) Matches

func (lhs Version) Matches(selector string) (bool, error)

Matches returns whether or not a version matches a given selector. The selector can be any of the following:

* x.y.z -- Matches a version exactly the same as the selector version * >=x.y.z -- Matches a version greater than or equal to the selector version * >x.y.z -- Matches a version greater than the selector version * <=x.y.z -- Matches a version less than or equal to the selector version * <x.y.z -- Matches a version less than the selector version * x.y.z,a.b.c -- Matches if the version matches either of the two selector versions

Directories

Path Synopsis
mocks
Package mock_bufiowrapper is a generated GoMock package.
Package mock_bufiowrapper is a generated GoMock package.
mocks
Package mock_ioutilwrapper is a generated GoMock package.
Package mock_ioutilwrapper is a generated GoMock package.
mocks
Package mock_loader is a generated GoMock package.
Package mock_loader is a generated GoMock package.
mocks
Package mock_mobypkgwrapper is a generated GoMock package.
Package mock_mobypkgwrapper is a generated GoMock package.
Package mock_utils is a generated GoMock package.
Package mock_utils is a generated GoMock package.
mocks
Package mock_nswrapper is a generated GoMock package.
Package mock_nswrapper is a generated GoMock package.

Jump to

Keyboard shortcuts

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