util

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplicationNameLabel = "application.apps.nine.ch/name"
	ManagedByAnnotation  = "app.kubernetes.io/managed-by"
	NctlName             = "nctl"
	PrivateKeySecretKey  = "privatekey"
	UsernameSecretKey    = "username"
	PasswordSecretKey    = "password"

	// DNSSetupURL redirects to the proper deplo.io docs entry about
	// how to setup custom hosts
	DNSSetupURL = "https://docs.nine.ch/a/myshbw3EY1"
	NoneText    = "<none>"
)
View Source
const (
	// BasicAuth key constants which represent the keys used in basic auth
	// secrets
	BasicAuthUsernameKey = "basicAuthUsername"
	BasicAuthPasswordKey = "basicAuthPassword"
)
View Source
const (
	PermKeyRole  = "role"
	PermKeyUsers = "users"
)

Variables

This section is empty.

Functions

func ApplicationLatestAvailableRelease added in v1.8.0

func ApplicationLatestAvailableRelease(ctx context.Context, client *api.Client, app types.NamespacedName) (*apps.Release, error)

func ApplicationLatestRelease added in v1.8.1

func ApplicationLatestRelease(ctx context.Context, client *api.Client, app types.NamespacedName) (*apps.Release, error)

ApplicationLatestRelease returns the latest release of an app, prioritizing available releases and if no available release is found just the latest progressing or failed release.

func ApplicationStaticEgresses added in v1.9.0

func ApplicationStaticEgresses(ctx context.Context, client *api.Client, app types.NamespacedName) ([]networking.StaticEgress, error)

ApplicationStaticEgresses returns all static egress resources targeting the specified app.

func ApplyProbePatch added in v1.12.2

func ApplyProbePatch(cfg *apps.Config, pp ProbePatch)

ApplyProbePatch mutates cfg.

func EnvVarByName added in v1.2.3

func EnvVarByName(envVars apps.EnvVars, name string) *apps.EnvVar

func EnvVarToString

func EnvVarToString(envs apps.EnvVars) string

func EnvVarsFromMap

func EnvVarsFromMap(env map[string]string, options ...EnvVarModifier) apps.EnvVars

func GitAuthSecretName

func GitAuthSecretName(app *apps.Application) string

GitAuthSecretName returns the name of the secret which contains the git credentials for the given applications git source

func OrderReleaseList added in v1.7.0

func OrderReleaseList(releaseList *apps.ReleaseList, reverse bool)

OrderReleaseList orders the given list of releases first by name and then by creation timestamp latest to oldest. Reverse reverses the order by creation timestamp to oldest to latest.

func PatchCORS added in v1.12.2

func PatchCORS(base *storage.CORSConfig, addChunks []string, removeChunks []string) (*storage.CORSConfig, error)

PatchCORS applies additive (--cors) and subtractive (--delete-cors) updates to an existing CORS configuration. Semantics for add:

  • origins/response-headers: union (trimmed, deduped, sorted)
  • max-age: set only if explicitly provided

Removals:

  • origins/response-headers: set-difference
  • specifying max-age here is rejected
  • if origins are targeted and removal leaves zero origins, the CORS configuration is cleared (function returns nil, changed=true)

func PatchCustomHostnames added in v1.12.2

func PatchCustomHostnames(base []string, clear bool, add []string, remove []string) ([]string, error)

PatchCustomHostnames applies add/clear/delete operations to a slice of BucketCustomHostname entries. It follows the common "patch" pattern:

  • If clear is true, the result is an empty list regardless of input.
  • Entries in add are parsed and replace any existing ones with the same host.
  • Entries in remove identify hostnames to be removed.

func PatchLifecyclePolicies added in v1.12.2

func PatchLifecyclePolicies(
	base []*storage.BucketLifecyclePolicy,
	clear bool,
	addChunks []string,
	deleteChunks []string,
) ([]*storage.BucketLifecyclePolicy, error)

PatchLifecyclePolicies applies a sequence of operations to a set of bucket lifecycle policies. Operations are applied in the following order:

  • Clear: optionally start from an empty set, discarding all existing policies.
  • Add: merge new or updated policies into the working set. Policies are keyed by prefix; providing the same prefix again replaces the previous entry.
  • Delete: remove policies by prefix from the working set.

The result is a deterministic, prefix-sorted slice.

func PatchPermissions added in v1.12.2

func PatchPermissions(base []*storage.BucketPermission, add, remove []string) ([]*storage.BucketPermission, error)

PatchPermissions applies additive and subtractive permission specs on top of an existing slice of BucketPermission objects. The input slices `add` and `remove` are raw flag values (e.g. "reader=user1,user2"), which are parsed and merged deterministically. Behavior:

  • `add`: users are added to the given role (duplicates deduped).
  • `remove`: users are removed from the given role.
  • `remove` with no users removes the whole role.
  • Empty/whitespace users are rejected.

The result is normalized so that roles and user names are sorted and duplicate-free.

Returns an error if role names are invalid, if empty users appear in `add`, or if parsing of the specs fails.

func PtrOrEmpty added in v1.12.2

func PtrOrEmpty(p *[]string) []string

PtrOrEmpty unwraps a *[]string flag value, returning nil if unset.

func ToBucketLifecyclePolicy added in v1.12.2

func ToBucketLifecyclePolicy(ls LifecycleSpec) *storage.BucketLifecyclePolicy

func ToStrings added in v1.12.2

func ToStrings[T ~string](in []T) []string

ToStrings converts a slice of types which are 'strings' under the hood into a []string

func UnverifiedAppHosts

func UnverifiedAppHosts(app *apps.Application) []string

func UpdateEnvVars added in v1.2.3

func UpdateEnvVars(oldEnvs []apps.EnvVar, newEnvs, sensitiveEnvs map[string]string, toDelete []string) apps.EnvVars

func ValidatePEM added in v1.3.0

func ValidatePEM(content string) (*string, error)

ValidatePEM validates if the passed content is in valid PEM format, errors out if the content is empty

func VerifiedAppHosts

func VerifiedAppHosts(app *apps.Application) []string

Types

type BasicAuth added in v1.1.1

type BasicAuth struct {
	Username string `json:"username" yaml:"username"`
	Password string `json:"password" yaml:"password"`
}

BasicAuth contains credentials for basic authentication

func NewBasicAuthFromSecret added in v1.1.1

func NewBasicAuthFromSecret(ctx context.Context, secret meta.Reference, client *api.Client) (*BasicAuth, error)

NewBasicAuthFromSecret returns a basic auth resource filled with data from a secret.

type CORSFieldMask added in v1.12.2

type CORSFieldMask struct {
	Origins         bool
	ResponseHeaders bool
	MaxAge          bool
}

CORSFieldMask indicates which keys were explicitly present across chunks.

type DNSDetail added in v1.2.2

type DNSDetail struct {
	Application string `json:"application"`
	Project     string `json:"project"`
	TXTRecord   string `json:"txtRecord"`
	CNAMETarget string `json:"cnameTarget"`
}

func GatherDNSDetails added in v1.2.2

func GatherDNSDetails(items []apps.Application) []DNSDetail

GatherDNSDetails retrieves the DNS details of all given applications

type EnvVarModifier added in v1.12.2

type EnvVarModifier func(envVar *apps.EnvVar)

func Sensitive added in v1.12.2

func Sensitive() EnvVarModifier

type GitAuth

type GitAuth struct {
	Username      *string
	Password      *string
	SSHPrivateKey *string
}

func GitAuthFromApp added in v1.4.0

func GitAuthFromApp(ctx context.Context, client *api.Client, app *apps.Application) (GitAuth, error)

func (GitAuth) Enabled

func (git GitAuth) Enabled() bool

Enabled returns true if any kind of credentials are set in the GitAuth

func (GitAuth) HasBasicAuth added in v1.3.0

func (git GitAuth) HasBasicAuth() bool

func (GitAuth) HasPrivateKey added in v1.3.0

func (git GitAuth) HasPrivateKey() bool

func (GitAuth) Secret

func (git GitAuth) Secret(app *apps.Application) *corev1.Secret

func (GitAuth) UpdateSecret

func (git GitAuth) UpdateSecret(secret *corev1.Secret)

UpdateSecret replaces the data of the secret with the data from GitAuth. Only replaces fields which are non-nil.

func (GitAuth) Valid added in v1.2.1

func (git GitAuth) Valid() error

Valid validates the credentials in the GitAuth

type LifecycleSpec added in v1.12.2

type LifecycleSpec struct {
	Prefix          string
	ExpireAfterDays *int32
	IsLive          bool
}

func LifecycleFromMap added in v1.12.2

func LifecycleFromMap(m map[string]string) (LifecycleSpec, error)

type OptInt32 added in v1.12.2

type OptInt32 struct {
	State SetState
	Val   int32
}

OptInt32 is an "Optional int32 field" wrapper. It works the same way as OptString, but for numeric fields. Again, this lets us distinguish Unset (no flag) vs Set (positive value) vs Clear (explicitly reset to nil/default).

type OptString added in v1.12.2

type OptString struct {
	State SetState
	Val   string
}

OptString is an "Optional string field" wrapper. It carries both a string value and a state (Unset / Set / Clear).

type Patcher added in v1.12.2

type Patcher interface {
	ToProbePatch() ProbePatch
}

Patcher is implemented by command-specific flag structs to produce a ProbePatch.

type PermissionSpec added in v1.12.2

type PermissionSpec struct {
	Role  string
	Users []string
}

PermissionSpec represents a parsed permission entry. Each spec binds a role to a (possibly empty) list of users.

type ProbePatch added in v1.12.2

type ProbePatch struct {
	Path          OptString
	PeriodSeconds OptInt32
}

ProbePatch is the normalized type used by both create and update paths.

type SetState added in v1.12.2

type SetState int

SetState describes how a field should be applied.

const (
	// leave as-is
	Unset SetState = iota
	// set to value
	Set
	// explicitly remove/unset
	Clear
)

type StringSet added in v1.12.2

type StringSet map[string]struct{}

func (StringSet) Add added in v1.12.2

func (s StringSet) Add(v string)

func (StringSet) Del added in v1.12.2

func (s StringSet) Del(v string)

func (StringSet) Has added in v1.12.2

func (s StringSet) Has(v string) bool

Jump to

Keyboard shortcuts

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