@@ -2,8 +2,10 @@ package registry
2
2
3
3
import (
4
4
"crypto/tls"
5
+ "errors"
5
6
"fmt"
6
7
"io/ioutil"
8
+ "log"
7
9
"net/http"
8
10
"os"
9
11
"time"
@@ -21,9 +23,10 @@ type SchemaRegistry struct {
21
23
schemaPathTemplate string
22
24
cache cache.Cache
23
25
strict bool
26
+ debug bool
24
27
}
25
28
26
- func newHTTPRegistry (schemaPathTemplate string , cacheFolder string , strict bool , skipTLS bool ) (* SchemaRegistry , error ) {
29
+ func newHTTPRegistry (schemaPathTemplate string , cacheFolder string , strict bool , skipTLS bool , debug bool ) (* SchemaRegistry , error ) {
27
30
reghttp := & http.Transport {
28
31
MaxIdleConns : 100 ,
29
32
IdleConnTimeout : 3 * time .Second ,
@@ -53,6 +56,7 @@ func newHTTPRegistry(schemaPathTemplate string, cacheFolder string, strict bool,
53
56
schemaPathTemplate : schemaPathTemplate ,
54
57
cache : filecache ,
55
58
strict : strict ,
59
+ debug : debug ,
56
60
}, nil
57
61
}
58
62
@@ -71,21 +75,41 @@ func (r SchemaRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8sVers
71
75
72
76
resp , err := r .c .Get (url )
73
77
if err != nil {
74
- return nil , fmt .Errorf ("failed downloading schema at %s: %s" , url , err )
78
+ msg := fmt .Sprintf ("failed downloading schema at %s: %s" , url , err )
79
+ if r .debug {
80
+ log .Println (msg )
81
+ }
82
+ return nil , errors .New (msg )
75
83
}
76
84
defer resp .Body .Close ()
77
85
78
86
if resp .StatusCode == http .StatusNotFound {
79
- return nil , newNotFoundError (fmt .Errorf ("no schema found" ))
87
+ msg := fmt .Sprintf ("could not find schema at %s" , url )
88
+ if r .debug {
89
+ log .Print (msg )
90
+ }
91
+ return nil , newNotFoundError (errors .New (msg ))
80
92
}
81
93
82
94
if resp .StatusCode != http .StatusOK {
83
- return nil , fmt .Errorf ("error while downloading schema at %s - received HTTP status %d" , url , resp .StatusCode )
95
+ msg := fmt .Sprintf ("error while downloading schema at %s - received HTTP status %d" , url , resp .StatusCode )
96
+ if r .debug {
97
+ log .Print (msg )
98
+ }
99
+ return nil , fmt .Errorf (msg )
84
100
}
85
101
86
102
body , err := ioutil .ReadAll (resp .Body )
87
103
if err != nil {
88
- return nil , fmt .Errorf ("failed downloading schema at %s: %s" , url , err )
104
+ msg := fmt .Sprintf ("failed parsing schema from %s: %s" , url , err )
105
+ if r .debug {
106
+ log .Print (msg )
107
+ }
108
+ return nil , errors .New (msg )
109
+ }
110
+
111
+ if r .debug {
112
+ log .Printf ("using schema found at %s" , url )
89
113
}
90
114
91
115
if r .cache != nil {
0 commit comments