util

package
v0.0.0-...-3187082 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PhaseOnHttpRequest  = "on_http_request"
	PhaseOnHttpResponse = "on_http_response"

	LegacyPhaseInbound  = "inbound"
	LegacyPhaseOutbound = "outbound"
)
View Source
const (
	// FinalizerName is the finalizer used by the ngrok operator
	FinalizerName = "k8s.ngrok.com/finalizer"
)

Variables

This section is empty.

Functions

func AddFinalizer

func AddFinalizer(o client.Object) bool

AddFinalizer adds the ngrok finalizer to the object if not already present. Returns true if the finalizer was added.

func HasFinalizer

func HasFinalizer(o client.Object) bool

HasFinalizer returns true if the object has the ngrok finalizer present.

func IsInternalDomain

func IsInternalDomain(host string) bool

IsInternalDomain returns true if the given hostname ends with ".internal" TLD. Internal domains cannot be reserved via the ngrok API (returns HTTP 400). This function handles case-insensitivity and trailing dots.

func LoadCerts

func LoadCerts() (*x509.CertPool, error)

LoadCerts loads all certs from customCertsPath once, merges them with system certs

func MergeMaps

func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V

MergeMaps merges multiple maps into a single map giving precedence to the last map in the list

func ObjToGVK

func ObjToGVK(obj client.Object) string

ObjToGroupVersionKind converts a client.Object to its GVK

func ObjToHumanGvkName

func ObjToHumanGvkName(obj client.Object) string

ObjToHumanGvkName converts a client.Object to a human-readable full name including GroupVersionKind

func ObjToHumanName

func ObjToHumanName(obj client.Object) string

ObjToHumanName converts a client.Object to a human-readable name

func ObjToKind

func ObjToKind(obj client.Object) string

ObjToKind converts a client.Object to its kind

func ObjToName

func ObjToName(obj client.Object) string

ObjectsToName converts a client.Object to its name

func ParseAndSanitizeEndpointURL

func ParseAndSanitizeEndpointURL(input string, isIngressURL bool) (*url.URL, error)

ParseAndSanitizeEndpointURL parses/sanitizes an input string for an endpoint url and provides a *url.URL following the restrictions for endpoints. when isIngressURL is true, the input string does not require a port (excluding tcp addresses)

func ParseHelmDictionary

func ParseHelmDictionary(dict string) (map[string]string, error)

ParseHelmDictionary parses a string in the format of a Helm dictionary and returns a map - Keys and Values must be strings - Format must be key=val,key=val

func RegisterAndSyncFinalizer

func RegisterAndSyncFinalizer(ctx context.Context, c client.Writer, o client.Object) error

RegisterAndSyncFinalizer adds the ngrok finalizer to the object if not already present. If it adds the finalizer, it patches the object in the Kubernetes API. Uses Patch instead of Update to avoid resourceVersion conflicts by only sending the diff.

func RemoveAndSyncFinalizer

func RemoveAndSyncFinalizer(ctx context.Context, c client.Writer, o client.Object) error

RemoveAndSyncFinalizer removes the ngrok finalizer from the object if present. If it removes the finalizer, it patches the object in the Kubernetes API. Uses Patch instead of Update to avoid resourceVersion conflicts by only sending the diff.

func RemoveFinalizer

func RemoveFinalizer(o client.Object) bool

RemoveFinalizer removes the ngrok finalizer from the object if present. Returns true if the finalizer was removed.

func ToClientObjects

func ToClientObjects[T any, PT interface {
	*T
	client.Object
}](s []T) []client.Object

ToClientObjects converts a slice of objects whose pointer implements client.Object to a slice of client.Objects

Types

type ActionType

type ActionType string

type Actions

type Actions struct {
	EndpointActions []RawAction
}

type EndpointAction

type EndpointAction struct {
	Type   string    `json:"type"`
	Config RawConfig `json:"config"`
}

type EndpointRule

type EndpointRule struct {
	Name    string      `json:"name"`
	Actions []RawAction `json:"actions"`
}

type RawAction

type RawAction = json.RawMessage

RawAction exists to make generic raw json/map manipulation more legible. It adds no additional functionality on top of RawMessage.

type RawConfig

type RawConfig = json.RawMessage

RawConfig exists to make generic raw json/map manipulation more legible. It adds no additional functionality on top of RawMessage.

type RawRule

type RawRule = json.RawMessage

RawRule exists to make generic raw json/map manipulation more legible. It adds no additional functionality on top of RawMessage.

type TrafficPolicy

type TrafficPolicy interface {
	// Merge takes another instance of TrafficPolicy and merges them.
	Merge(TrafficPolicy)
	// MergeRawRule merges the rule into the list of existing rules in the specified phase.
	MergeEndpointRule(rule EndpointRule, phase string) error
	// Deconstruct must be implemented such that two differing underlying implementations can be represented as the same
	// format during merges.
	Deconstruct() map[string][]RawRule
	// ToCRDJson returns a raw json version of the underlying traffic policy document to be saved to an Edge CRD.
	ToCRDJson() (json.RawMessage, error)
	// ToAPIJson() returns a raw json version of the underlying traffic policy document to be sent to the backend API.
	ToAPIJson() (json.RawMessage, error)
	// IsLegacyPolicy determines if the specified policy contains legacy phases.
	IsLegacyPolicy() bool
	// Enabled returns the value if it was present in a traffic policy document, nil if not.
	Enabled() *bool
	// ConvertLegacyPhases explicitly maps old phases to new phases. This doesn't guarantee in a resulting "valid" phase set,
	// so users will need to check the implementation used for this interface.
	ConvertLegacyDirectionsToPhases()
}

func NewTrafficPolicy

func NewTrafficPolicy() TrafficPolicy

func NewTrafficPolicyFromJson

func NewTrafficPolicyFromJson(msg json.RawMessage) (TrafficPolicy, error)

Jump to

Keyboard shortcuts

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