@@ -18,6 +18,8 @@ func Client(log slog.Logger, extraCertsPath string) (*http.Client, error) {
18
18
return & http.Client {}, nil
19
19
}
20
20
21
+ log = log .With (slog .F ("root_path" , extraCertsPath ))
22
+ log .Debug (context .Background (), "adding certs to default pool" )
21
23
pool , err := certPool (log , extraCertsPath )
22
24
if err != nil {
23
25
return nil , xerrors .Errorf ("cert pool: %w" , err )
@@ -47,26 +49,25 @@ func certPool(log slog.Logger, certsPath string) (*x509.CertPool, error) {
47
49
return nil , xerrors .Errorf ("stat %v: %w" , certsPath , err )
48
50
}
49
51
50
- if fi .IsDir () {
51
- entries , err := os . ReadDir ( certsPath )
52
+ if ! fi .IsDir () {
53
+ err = addCert ( log , pool , certsPath )
52
54
if err != nil {
53
- return nil , xerrors .Errorf ("read dir %v : %w" , certsPath , err )
55
+ return nil , xerrors .Errorf ("add cert : %w" , err )
54
56
}
55
-
56
- for _ , entry := range entries {
57
- path := filepath .Join (certsPath , entry .Name ())
58
- err = addCert (log , pool , path )
59
- if err != nil {
60
- return nil , xerrors .Errorf ("add cert: %w" , err )
61
- }
62
- }
63
-
64
57
return pool , nil
65
58
}
66
59
67
- err = addCert ( log , pool , certsPath )
60
+ entries , err := os . ReadDir ( certsPath )
68
61
if err != nil {
69
- return nil , xerrors .Errorf ("add cert: %w" , err )
62
+ return nil , xerrors .Errorf ("read dir %v: %w" , certsPath , err )
63
+ }
64
+
65
+ for _ , entry := range entries {
66
+ path := filepath .Join (certsPath , entry .Name ())
67
+ err = addCert (log , pool , path )
68
+ if err != nil {
69
+ return nil , xerrors .Errorf ("add cert: %w" , err )
70
+ }
70
71
}
71
72
72
73
return pool , nil
@@ -82,5 +83,6 @@ func addCert(log slog.Logger, pool *x509.CertPool, path string) error {
82
83
log .Error (context .Background (), "failed to append cert" ,
83
84
slog .F ("filepath" , path ))
84
85
}
86
+ log .Debug (context .Background (), "added cert" , slog .F ("path" , path ))
85
87
return nil
86
88
}
0 commit comments