utils

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNonExistingFolder

func CreateNonExistingFolder(path string, mode fs.FileMode) error

func FileExists

func FileExists(filename string) bool

func FormatFilePath

func FormatFilePath(path string) string

func GenerateCSRAndPrivateKey

func GenerateCSRAndPrivateKey(privateKey, keyType, domain string, SAN []string) (string, []byte, error)

GenerateCSRAndPrivateKey generates a Certificate Signing Request (CSR) and a private key.

func GenerateFingerprint

func GenerateFingerprint(content []byte) string

func GenerateRequestID added in v0.6.4

func GenerateRequestID() string

GenerateRequestID generates a unique request ID using crypto/rand

func GetKeyType

func GetKeyType(keyTypeStr string) (certcrypto.KeyType, error)

GetKeyType the type from which private keys should be generated.

func GetRequestID added in v0.6.4

func GetRequestID(ctx context.Context) string

GetRequestID retrieves the request ID from the context

func LoggerWithRequestID added in v0.6.4

func LoggerWithRequestID(ctx context.Context, logger log.Logger) log.Logger

LoggerWithRequestID returns a logger with the request ID from context

func RandomStringCrypto

func RandomStringCrypto(length int) (string, error)

func RandomWeekdayBeforeExpiration

func RandomWeekdayBeforeExpiration(expiration time.Time, minDays, maxDays int) time.Time

Function to generate a random weekday within a given range before an expiration date

func RequestLogHook

func RequestLogHook(logger *logrus.Logger) retryablehttp.RequestLogHook

RequestLogHook logs outgoing HTTP requests

func ResponseLogHook

func ResponseLogHook(logger *logrus.Logger, logJSONBody bool) retryablehttp.ResponseLogHook

ResponseLogHook logs the response status code and body

func ResponseLogHookDebug

func ResponseLogHookDebug(logger *logrus.Logger) retryablehttp.ResponseLogHook

ResponseLogHookDebug logs all responses with full details

func SHA1Hash

func SHA1Hash(content string) string

Get sha1 from string

func SanitizedDomain

func SanitizedDomain(logger log.Logger, domain string) string

SanitizedDomain Make sure no funny chars are in the cert names (like wildcards ;)).

func SetTLSConfig

func SetTLSConfig(cert string, key string, ca string, insecure bool) (*tls.Config, error)

func SetupLoggers added in v0.7.1

func SetupLoggers(logLevel, logFormat string) (log.Logger, *logrus.Logger)

SetupLoggers creates and configures all loggers (logrus, go-kit, and lego slog). Returns the go-kit logger and logrus logger.

func StructToMapInterface

func StructToMapInterface(data interface{}) map[string]interface{}

func ValidateLabels

func ValidateLabels(labels string) (errors []error)

func ValidateRenewalDays

func ValidateRenewalDays(value string) (int, int, error)

func WithRequestID added in v0.6.4

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID adds a request ID to the context

Types

type CustomTextFormatter

type CustomTextFormatter struct {
	TimestampFormat  string
	CallerPrettyfier func(*runtime.Frame) (string, string)
}

CustomTextFormatter is a custom logrus formatter

func (*CustomTextFormatter) Format

func (f *CustomTextFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements the logrus.Formatter interface

type CustomWriter

type CustomWriter struct {
	Writer io.Writer
}

Custom Writer to block INFO messages containg [DEBUG] in message

func (*CustomWriter) Write

func (cw *CustomWriter) Write(p []byte) (n int, err error)

type DebugLevelHook

type DebugLevelHook struct {
	Logger *logrus.Logger
}

Hook to redirect logs with message starting with [DEBUG] from INFO to DEBUG level

func (*DebugLevelHook) Fire

func (hook *DebugLevelHook) Fire(entry *logrus.Entry) error

func (*DebugLevelHook) Levels

func (hook *DebugLevelHook) Levels() []logrus.Level

type UTCFormatter

type UTCFormatter struct {
	logrus.Formatter
}

func (UTCFormatter) Format

func (u UTCFormatter) Format(e *logrus.Entry) ([]byte, error)

Jump to

Keyboard shortcuts

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