| 25 | } |
| 26 | |
| 27 | func ResolveTLSMaterial(ds *storepb.DataSource) (*storepb.DataSource, error) { |
| 28 | if ds == nil { |
| 29 | return nil, nil |
| 30 | } |
| 31 | resolved := proto.Clone(ds).(*storepb.DataSource) |
| 32 | if !resolved.GetUseSsl() || !HasTLSPath(resolved) { |
| 33 | return resolved, nil |
| 34 | } |
| 35 | |
| 36 | if resolved.GetSslCaPath() != "" { |
| 37 | content, err := readTLSPathFile("CA certificate", resolved.GetSslCaPath()) |
| 38 | if err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | resolved.SslCa = content |
| 42 | resolved.SslCaPath = "" |
| 43 | } |
| 44 | if resolved.GetSslCertPath() != "" { |
| 45 | content, err := readTLSPathFile("client certificate", resolved.GetSslCertPath()) |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | resolved.SslCert = content |
| 50 | resolved.SslCertPath = "" |
| 51 | } |
| 52 | if resolved.GetSslKeyPath() != "" { |
| 53 | content, err := readTLSPathFile("client key", resolved.GetSslKeyPath()) |
| 54 | if err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | resolved.SslKey = content |
| 58 | resolved.SslKeyPath = "" |
| 59 | } |
| 60 | |
| 61 | return resolved, nil |
| 62 | } |
| 63 | |
| 64 | func readTLSPathFile(label, path string) (string, error) { |
| 65 | if !filepath.IsAbs(path) { |