cert

package
v0.0.0-...-984f6f0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertData

type CertData struct {
	ProfileName string
	CA          string
	Cert        string
	Key         string
}

func GetCertificateData

func GetCertificateData(secret *corev1.Secret, profile string) (*CertData, error)
func GetCertificateData(dir, profile string) (*CertData, error) {
	certData := &CertData{
		ProfileName: profile,
	}
	fmt.Printf("getCertificateData: %s\n", dir)
	files, err := os.ReadDir(dir)
	if err != nil {
		fmt.Printf("getCertificateData error: %s\n", err.Error())
		return nil, err
	}
	for _, f := range files {
		fmt.Printf("filename: %s\n", f.Name())
		if !f.IsDir() {
			b, err := os.ReadFile(filepath.Join(dir, f.Name()))
			if err != nil {
				return nil, err
			}
			var found bool
			if f.Name() == "ca.crt" {
				certData.CA, found = getStringInBetween(string(b), caStartMarker, caEndMarker, true)
				if !found {
					return nil, fmt.Errorf("cannot get the ca string")
				}
			}
			if f.Name() == "tls.crt" {
				certData.Cert, found = getStringInBetween(string(b), certStartMarker, certEndMarker, true)
				if !found {
					return nil, fmt.Errorf("cannot get the cert string")
				}
			}
			if f.Name() == "tls.key" {
				certData.Key, found = getStringInBetween(string(b), keyStartMarker, keyEndMarker, false)
				if !found {
					return nil, fmt.Errorf("cannot get the key string")
				}
				certData.Key = strings.ReplaceAll(certData.Key, "\n", "")
			}
		}
	}
	return certData, nil
}

Jump to

Keyboard shortcuts

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