(label, path string)
| 62 | } |
| 63 | |
| 64 | func readTLSPathFile(label, path string) (string, error) { |
| 65 | if !filepath.IsAbs(path) { |
| 66 | return "", errors.Errorf("%s path must be absolute", label) |
| 67 | } |
| 68 | info, err := os.Stat(path) |
| 69 | if err != nil { |
| 70 | return "", errors.Errorf("failed to read %s file", label) |
| 71 | } |
| 72 | if !info.Mode().IsRegular() { |
| 73 | return "", errors.Errorf("%s path must point to a regular file", label) |
| 74 | } |
| 75 | if info.Size() == 0 { |
| 76 | return "", errors.Errorf("%s file is empty", label) |
| 77 | } |
| 78 | if info.Size() > maxTLSMaterialFileSize { |
| 79 | return "", errors.Errorf("%s file is too large", label) |
| 80 | } |
| 81 | |
| 82 | file, err := os.Open(path) |
| 83 | if err != nil { |
| 84 | return "", errors.Errorf("failed to read %s file", label) |
| 85 | } |
| 86 | defer file.Close() |
| 87 | |
| 88 | content, err := io.ReadAll(io.LimitReader(file, maxTLSMaterialFileSize+1)) |
| 89 | if err != nil { |
| 90 | return "", errors.Errorf("failed to read %s file", label) |
| 91 | } |
| 92 | if len(content) == 0 { |
| 93 | return "", errors.Errorf("%s file is empty", label) |
| 94 | } |
| 95 | if int64(len(content)) > maxTLSMaterialFileSize { |
| 96 | return "", errors.Errorf("%s file is too large", label) |
| 97 | } |
| 98 | return string(content), nil |
| 99 | } |
| 100 | |
| 101 | // GetTLSConfig gets the TLS config for connection. |
| 102 | // The datasource must already have path-backed TLS material resolved via ResolveTLSMaterial. |
no test coverage detected