MCPcopy Create free account
hub / github.com/bytebase/bytebase / ResolveTLSMaterial

Function ResolveTLSMaterial

backend/plugin/db/util/ssl.go:27–62  ·  view source on GitHub ↗
(ds *storepb.DataSource)

Source from the content-addressed store, hash-verified

25}
26
27func 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
64func readTLSPathFile(label, path string) (string, error) {
65 if !filepath.IsAbs(path) {

Calls 6

HasTLSPathFunction · 0.85
readTLSPathFileFunction · 0.85
GetUseSslMethod · 0.45
GetSslCaPathMethod · 0.45
GetSslCertPathMethod · 0.45
GetSslKeyPathMethod · 0.45