secret

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package secret contains useful functionality for select secret

Index

Constants

This section is empty.

Variables

View Source
var DefaultMutator = &NoOpMutator{}

DefaultMutator is a no-operation implementation of the Mutator interface. It is used as a default option when there is no Mutator associated with the context.

Functions

func GetSecretByRefOrLabel

func GetSecretByRefOrLabel(ctx context.Context, clt client.Client, ref *corev1.ObjectReference) (obj *corev1.Secret, err error)

GetSecretByRefOrLabel retrieves an secret If the ref.namespace is empty, it will use the namespace from the ctx. If the resource does not exist, it will try to match according to the label.

func HasAnnotationsKey

func HasAnnotationsKey(annotations, expectedAnnotaions map[string]string, matchValue bool) bool

HasAnnotationsKey whether to include the expected annotation key, returns true when the expected annotation is empty.

func SelectToolSecret

func SelectToolSecret(logger *zap.SugaredLogger, clientI interface{}, resourceURL string, option SelectSecretOption) (secret *corev1.Secret, err error)

SelectToolSecret will select secret according to tool address and resource scope on secret

clientI could be sigs.k8s.io/controller-runtime/pkg/client.Client or k8s.io/client-go/kubernetes.Interface or "k8s.io/client-go/informers".SharedInformerFactory
resourceURL refers resource url lik git http url or harbor http url. eg. https://github.com/example or  build.harbor.com/example
namespaces refers to all namespaces where the secret may exist

if no secret was found, secret will be nil and err is nil if any errors occurred, err will not be nil The meaning of preferred is that if there is a secret with this name, it will be selected first, and preferredNs means the namespace where the secret is located

func SelectToolSecretByRefOrLabelOrURL

func SelectToolSecretByRefOrLabelOrURL(ctx context.Context, currentNamespace string, url string, secretRef *corev1.ObjectReference) (*corev1.Secret, error)

SelectToolSecretByRefOrLabelOrURL will select secret by secretRef first, if not found, will select by label, if not found, will select by url

func SelectToolSecretFrom added in v0.9.0

func SelectToolSecretFrom(logger *zap.SugaredLogger, secretList []corev1.Secret, isGlobal bool, resourceURL *neturl.URL, option SelectSecretOption) []corev1.Secret

SelectToolSecretFrom selects the secret that matches the resource url from the secret list

func WithMutator added in v0.9.0

func WithMutator(ctx context.Context, mutator Mutator) context.Context

WithMutator attaches a Mutator to a context and returns the new context.

Types

type MutateFunc added in v0.9.0

type MutateFunc func(context.Context, *corev1.Secret) error

MutateFunc is a function type that implements the Mutator interface.

func (MutateFunc) Mutate added in v0.9.0

func (m MutateFunc) Mutate(ctx context.Context, secret *corev1.Secret) error

type Mutator added in v0.9.0

type Mutator interface {
	Mutate(context.Context, *corev1.Secret) error
}

Mutator interface defines a method for modifying Secret objects.

func MutatorFromCtx added in v0.9.0

func MutatorFromCtx(ctx context.Context) Mutator

MutatorFromCtx retrieves a Mutator from the given context. If no Mutator is found, it returns the noOpMutator.

type MutatorList added in v0.9.0

type MutatorList []Mutator

MutatorList is a slice of Mutators.

func (MutatorList) Mutate added in v0.9.0

func (m MutatorList) Mutate(ctx context.Context, secret *corev1.Secret) error

Mutate iterates over the list of mutators and applies them to the provided Secret object.

type NoOpMutator added in v0.9.0

type NoOpMutator struct {
}

NoOpMutator struct implements the Mutator interface but performs no actions.

func (*NoOpMutator) Mutate added in v0.9.0

func (a *NoOpMutator) Mutate(_ context.Context, secret *corev1.Secret) error

Mutate is the NoOpMutator's implementation that simply returns the passed-in Secret object without any modifications.

type ResourcePathFormat

type ResourcePathFormat struct {
	// contains filtered or unexported fields
}

ResourcePathFormat manage the resource path format

func NewResourcePathFormat

func NewResourcePathFormat(pathJson, subPathJson string) *ResourcePathFormat

NewResourcePathFormat construct a ResourcePathFormat from json string

func (*ResourcePathFormat) FormatPathAllScene

func (p *ResourcePathFormat) FormatPathAllScene(scope string) (list []string)

FormatPathAllScene get the formatted strings of all scenes

func (*ResourcePathFormat) FormatPathByScene

func (p *ResourcePathFormat) FormatPathByScene(scene metav1alpha1.ResourcePathScene, scope string) string

FormatPathByScene get the formatted string of special scene

type SecretTypeList

type SecretTypeList []corev1.SecretType

func (SecretTypeList) Contains

func (s SecretTypeList) Contains(e corev1.SecretType) bool

type SelectSecretOption

type SelectSecretOption struct {

	// Scene indicates resource url format in different scenario
	Scene string

	// PerferredSecret will return the secret if it is be selected
	PerferredSecret types.NamespacedName

	// ExcludedSecretTypes exclude some secret types when do selecting
	ExcludedSecretTypes SecretTypeList

	// SecretTypes means only secret which type exist in this list will be selected
	// if it is empty means there is no limit for secret type when selecting
	SecretTypes SecretTypeList

	// Namespace indicates current namespace that current resource belongs.
	// the secret will be searched in this namespace
	// as a default action, secret in the same namespace could be used by other resources in same namespace
	Namespace string
	// GlobalCredentialsNamespace is the namespace that we save global credentials.
	// it is not public to all namespace only until it is bind to one project(namespace)
	// the secret will be searched in this namespace
	GlobalCredentialsNamespace string

	// LabelSelector is label selector when select secret, default will be everything
	LabelSelector labels.Selector

	// IncludeAnnotaion if specified, it needs to be filtered base IncludeAnnotaion. Currently only key value filtering is used.
	IncludeAnnotaion map[string]string
}

SelectSecretOption encapsulate the configuration related to selecting secrets

func NewSecretSelectOption

func NewSecretSelectOption(preferredSecret types.NamespacedName, namespace string, globalCredentialsNamespace string) (option SelectSecretOption)

NewSecretSelectOption just construct SecretSelectOption

type SortedSecretList

type SortedSecretList []corev1.Secret

func (SortedSecretList) Len

func (s SortedSecretList) Len() int

func (SortedSecretList) Less

func (s SortedSecretList) Less(i, j int) bool

func (SortedSecretList) Swap

func (s SortedSecretList) Swap(i, j int)

Jump to

Keyboard shortcuts

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