Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CertData ¶
func GetCertificateData ¶
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 }
Click to show internal directories.
Click to hide internal directories.