util

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CertificateBlockType = "CERTIFICATE"

	// ECPrivateKeyBlockType is a possible value for pem.Block.Type.
	ECPrivateKeyBlockType = "EC PRIVATE KEY"

	// RSAPrivateKeyBlockType is a possible value for pem.Block.Type.
	RSAPrivateKeyBlockType = "RSA PRIVATE KEY"

	// PrivateKeyBlockType is a possible value for pem.Block.Type.
	PrivateKeyBlockType = "PRIVATE KEY"

	// PublicKeyBlockType is a possible value for pem.Block.Type.
	PublicKeyBlockType = "PUBLIC KEY"
)

Variables

This section is empty.

Functions

func CertHasExpired

func CertHasExpired(cert *x509.Certificate) bool

func CopyFile

func CopyFile(sourceFile, destinationFile string) error

func DeleteSliceElement

func DeleteSliceElement(slice []string, element string) []string

func DisableEscapeJson

func DisableEscapeJson(data interface{}) (string, error)

func EncodeCertPEM

func EncodeCertPEM(cert *x509.Certificate) []byte

EncodeCertPEM returns PEM-endcoded certificate data

func GenerateCA

func GenerateCA(organization string) (caBundle string, caCert *x509.Certificate, caPrivKey *rsa.PrivateKey, err error)

func GenerateCertAndKeyConfig

func GenerateCertAndKeyConfig(caCert *x509.Certificate, caKey *rsa.PrivateKey,
	config *cert.Config) (*x509.Certificate, *rsa.PrivateKey, error)

Tobe optimized

func GenerateClientCertAndKey

func GenerateClientCertAndKey(caCert *x509.Certificate, caKey *rsa.PrivateKey,
	clientCN string) (*x509.Certificate, *rsa.PrivateKey, error)

func GetHostAllIPs

func GetHostAllIPs() (map[string]string, error)

func GetHostPublicIP

func GetHostPublicIP() (string, error)

func GetIPByInterfaceName

func GetIPByInterfaceName(name string) (ip string, err error)

func GetLocalAddrByInterface

func GetLocalAddrByInterface(name string) (net.Addr, error)

func GetLocalIP

func GetLocalIP() (string, error)

func GetRandToken

func GetRandToken(n int) string

func GetServiceCertByRootca

func GetServiceCertByRootca(commonName, organization string, dns []string, rootCA *x509.Certificate, key *rsa.PrivateKey) ([]byte, []byte, error)

func GetStringInBetween

func GetStringInBetween(str string, start string, end string) (result string)

func IsFileExist

func IsFileExist(path string) bool

func NewPrivateKey

func NewPrivateKey() (*rsa.PrivateKey, error)

NewPrivateKey creates an RSA private key change fa

func NewSignedCert

func NewSignedCert(cfg *cert.Config, key crypto.Signer,
	caCert *x509.Certificate, caKey crypto.Signer) (*x509.Certificate, error)

NewSignedCert creates a signed certificate using the given CA certificate and key

func OutPutMessage

func OutPutMessage(msg string)

func OutSuccessMessage

func OutSuccessMessage(msg string)

func ParseCertsPEM

func ParseCertsPEM(pemCerts []byte) ([]*x509.Certificate, error)

ParseCertsPEM returns the x509.Certificates contained in the given PEM-encoded byte array Returns an error if a certificate could not be parsed, or if the data does not contain any certificates

func ParsePrivateKeyPEMRSA

func ParsePrivateKeyPEMRSA(keyData []byte) (*rsa.PrivateKey, error)

func PodToYaml

func PodToYaml(pod *corev1.Pod) ([]byte, error)

func PrintFlags

func PrintFlags(flags *pflag.FlagSet)

PrintFlags logs the flags in the flagset

func ReadFile

func ReadFile(path string) ([]byte, error)

func RemoveDuplicateElement

func RemoveDuplicateElement(slice []string) []string

func RemoveFile

func RemoveFile(filePath string) error

func RunLinuxCommand

func RunLinuxCommand(command string) (string, string, error)

func RunLinuxShellFile

func RunLinuxShellFile(filename string) (string, string, error)

func SetFileContent

func SetFileContent(file, pattern, content string) string

SetFileContent generates cmd for set file content.

func SetupSignalHandler

func SetupSignalHandler() <-chan struct{}

SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned which is closed on one of these signals. If a second signal is caught, the program is terminated with exit code 1.

func SplitHostPortIgnoreMissingPort

func SplitHostPortIgnoreMissingPort(v string) (addr string, port string, err error)

func SplitHostPortWithDefaultPort

func SplitHostPortWithDefaultPort(v string, defaultPort string) (addr string, port string, err error)

func ToJson

func ToJson(v interface{}) string

func ToJsonForm

func ToJsonForm(v interface{}) string

func UpdateLogLevel

func UpdateLogLevel(w http.ResponseWriter, r *http.Request)

func WriteFile

func WriteFile(file, ctx string) error

func WriteWithAppend

func WriteWithAppend(name, content string) error

func WriteWithBufio

func WriteWithBufio(name, content string) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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