utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Overview

Package utils provides generic utility routines used within FSM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertToPEM added in v1.1.0

func CertToPEM(caBytes []byte) ([]byte, error)

CertToPEM converts a certificate to PEM format

func ConvertPEMCertToX509 added in v1.1.0

func ConvertPEMCertToX509(pemCrt []byte) (*x509.Certificate, error)

ConvertPEMCertToX509 converts a PEM certificate to x509

func ConvertPEMPrivateKeyToX509 added in v1.1.0

func ConvertPEMPrivateKeyToX509(pemKey []byte) (*rsa.PrivateKey, error)

ConvertPEMPrivateKeyToX509 converts a PEM private key to x509

func CreateOrUpdate added in v1.1.0

CreateOrUpdate creates or updates the object

func CsrToPEM added in v1.1.0

func CsrToPEM(csrBytes []byte) ([]byte, error)

CsrToPEM converts a CSR to PEM format

func DecodeYamlToUnstructured added in v1.1.0

func DecodeYamlToUnstructured(data []byte) (*unstructured.Unstructured, error)

DecodeYamlToUnstructured decodes YAML to Unstructured

func ErrorListToError added in v1.1.0

func ErrorListToError(errorList field.ErrorList) error

ErrorListToError converts a list of errors to a single error

func EvaluateTemplate added in v1.1.0

func EvaluateTemplate(t *template.Template, data interface{}) string

EvaluateTemplate evaluates the given template with the given data and returns the result as a string.

func GatewayCodebasePath added in v1.1.0

func GatewayCodebasePath(namespace string) string

GatewayCodebasePath get the codebase URL for the gateway in specified namespace inherit hierarchy: /base/gateways -> /local/gateways -> /local/gw/[ns]

func GenerateRandom added in v1.1.0

func GenerateRandom(n int) string

GenerateRandom generates random string.

func GetBytes added in v1.1.0

func GetBytes(key interface{}) ([]byte, error)

GetBytes returns the bytes of the given object.

func GetDefaultGatewaysPath added in v1.1.0

func GetDefaultGatewaysPath() string

GetDefaultGatewaysPath returns the path to the gateways codebase. inherit hierarchy: /base/gateways -> /local/gateways -> /local/gw/[ns]

func GetDefaultIngressPath added in v1.1.0

func GetDefaultIngressPath() string

GetDefaultIngressPath returns the path to the ingress codebase.

func GetDefaultServicesPath added in v1.1.0

func GetDefaultServicesPath() string

GetDefaultServicesPath returns the path to the services codebase.

func GetEnv

func GetEnv(envVar string, defaultValue string) string

GetEnv is a convenience wrapper for os.Getenv() with additional default value return when empty or unset

func GetIPFromContext

func GetIPFromContext(ctx context.Context) net.Addr

GetIPFromContext obtains the IP address of the caller from the context.

func GetLastChunkOfSlashed

func GetLastChunkOfSlashed(s string) string

GetLastChunkOfSlashed splits a string by slash and returns the last chunk.

func GetSecretDataHash added in v1.1.0

func GetSecretDataHash(secret *corev1.Secret) uint32

GetSecretDataHash returns a hash of the given secret data.

func GrpcServe

func GrpcServe(ctx context.Context, grpcServer *grpc.Server, lis net.Listener, cancel context.CancelFunc, serverType string, errorCh chan interface{})

GrpcServe starts the gRPC server passed.

func Hash added in v1.0.1

func Hash(bytes []byte) uint64

Hash calculates an FNV-1 hash from a given byte array

func HashFNV added in v1.1.0

func HashFNV(s string) string

HashFNV returns a hash string of the given string.

func HashFromString

func HashFromString(s string) (uint64, error)

HashFromString calculates an FNV-1 hash from a given string, returns it as a uint64 and error, if any

func IP2Int added in v1.0.1

func IP2Int(ip net.IP) *big.Int

IP2Int converts ip addr to int.

func ImagePullPolicyByTag added in v1.1.0

func ImagePullPolicyByTag(image string) corev1.PullPolicy

ImagePullPolicyByTag returns the pull policy for the given image tag.

func IngressCodebasePath added in v1.1.0

func IngressCodebasePath() string

IngressCodebasePath returns the path to the ingress codebase.

func Int2IP16 added in v1.0.1

func Int2IP16(nn uint64) net.IP

Int2IP16 converts uint64 to ipv6.

func Int2IP4 added in v1.0.1

func Int2IP4(nn uint32) net.IP

Int2IP4 converts uint32 to ipv4.

func NamespacedIngressCodebasePath added in v1.1.0

func NamespacedIngressCodebasePath(namespace string) string

NamespacedIngressCodebasePath returns the path to the ingress codebase for the given namespace.

func NewGrpc

func NewGrpc(serverType string, port int, certPem, keyPem, rootCertPem []byte) (*grpc.Server, net.Listener, error)

NewGrpc creates a new gRPC server

func ParseEnabled added in v1.1.0

func ParseEnabled(enabled string) bool

ParseEnabled parses the given string to a boolean value.

func ParseImageName added in v1.1.0

func ParseImageName(image string) (string, string, string, error)

ParseImageName parses a docker image string into three parts: repo, tag and digest. If both tag and digest are empty, a default image tag will be returned.

func PrettyJSON

func PrettyJSON(js []byte, prefix string) ([]byte, error)

PrettyJSON Unmarshals and Marshall again with Indent so it is human readable

func RSAKeyToPEM added in v1.1.0

func RSAKeyToPEM(privateKey *rsa.PrivateKey) ([]byte, error)

RSAKeyToPEM converts a RSA private key to PEM format

func RegisterExitHandlers added in v1.1.0

func RegisterExitHandlers(shutdownFuncs ...func()) (stop chan struct{})

RegisterExitHandlers registers a shutdown function to be called when a signal is received.

func RegisterOSExitHandlers added in v1.1.0

func RegisterOSExitHandlers(shutdownFuncs ...func()) (stop chan struct{})

RegisterOSExitHandlers registers a shutdown function to be called when a signal is received.

func SecretNamespaceAndName added in v1.1.0

func SecretNamespaceAndName(secretName string, ing *networkingv1.Ingress) (string, string, error)

SecretNamespaceAndName returns the namespace and name of the secret.

func SimpleHash added in v1.1.0

func SimpleHash(obj interface{}) string

SimpleHash returns a hash string of the given object.

func StringsEqual added in v1.1.0

func StringsEqual(left, right []string) bool

StringsEqual compares two string slices and returns true if they are equal.

func SvcAccountToK8sSvcAccount

func SvcAccountToK8sSvcAccount(svcAccount *corev1.ServiceAccount) identity.K8sServiceAccount

SvcAccountToK8sSvcAccount converts a Kubernetes service to a MeshService.

func ValidateClient

ValidateClient ensures that the connected client is authorized to connect to the gRPC server.

Types

This section is empty.

Directories

Path Synopsis
Package cidr calculates CIDR network
Package cidr calculates CIDR network

Jump to

Keyboard shortcuts

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