@@ -17,14 +17,50 @@ const (
17
17
defaultRegistryName = "default"
18
18
)
19
19
20
- // RegistryRoutes defines the routes for the registry API.
21
- type RegistryRoutes struct {
22
- provider registry.Provider
20
+ // RegistryType represents the type of registry
21
+ type RegistryType string
22
+
23
+ const (
24
+ // RegistryTypeFile represents a local file registry
25
+ RegistryTypeFile RegistryType = "file"
26
+ // RegistryTypeURL represents a remote URL registry
27
+ RegistryTypeURL RegistryType = "url"
28
+ // RegistryTypeDefault represents a built-in registry
29
+ RegistryTypeDefault RegistryType = "default"
30
+ )
31
+
32
+ // getRegistryInfo returns the registry type and the source
33
+ func getRegistryInfo () (RegistryType , string ) {
34
+ url , localPath , _ , registryType := config .GetRegistryConfig ()
35
+
36
+ switch registryType {
37
+ case "url" :
38
+ return RegistryTypeURL , url
39
+ case "file" :
40
+ return RegistryTypeFile , localPath
41
+ default :
42
+ // Default built-in registry
43
+ return RegistryTypeDefault , ""
44
+ }
23
45
}
24
46
47
+ // getCurrentProvider returns the current registry provider
48
+ func getCurrentProvider (w http.ResponseWriter ) (registry.Provider , bool ) {
49
+ provider , err := registry .GetDefaultProvider ()
50
+ if err != nil {
51
+ http .Error (w , "Failed to get registry provider" , http .StatusInternalServerError )
52
+ logger .Errorf ("Failed to get registry provider: %v" , err )
53
+ return nil , false
54
+ }
55
+ return provider , true
56
+ }
57
+
58
+ // RegistryRoutes defines the routes for the registry API.
59
+ type RegistryRoutes struct {}
60
+
25
61
// RegistryRouter creates a new router for the registry API.
26
- func RegistryRouter (provider registry. Provider ) http.Handler {
27
- routes := RegistryRoutes {provider : provider }
62
+ func RegistryRouter () http.Handler {
63
+ routes := RegistryRoutes {}
28
64
29
65
r := chi .NewRouter ()
30
66
r .Get ("/" , routes .listRegistries )
@@ -49,19 +85,28 @@ func RegistryRouter(provider registry.Provider) http.Handler {
49
85
// @Produce json
50
86
// @Success 200 {object} registryListResponse
51
87
// @Router /api/v1beta/registry [get]
52
- func (routes * RegistryRoutes ) listRegistries (w http.ResponseWriter , _ * http.Request ) {
53
- reg , err := routes .provider .GetRegistry ()
88
+ func (* RegistryRoutes ) listRegistries (w http.ResponseWriter , _ * http.Request ) {
89
+ provider , ok := getCurrentProvider (w )
90
+ if ! ok {
91
+ return
92
+ }
93
+
94
+ reg , err := provider .GetRegistry ()
54
95
if err != nil {
55
96
http .Error (w , "Failed to get registry" , http .StatusInternalServerError )
56
97
return
57
98
}
58
99
100
+ registryType , source := getRegistryInfo ()
101
+
59
102
registries := []registryInfo {
60
103
{
61
104
Name : defaultRegistryName ,
62
105
Version : reg .Version ,
63
106
LastUpdated : reg .LastUpdated ,
64
107
ServerCount : len (reg .Servers ),
108
+ Type : registryType ,
109
+ Source : source ,
65
110
},
66
111
}
67
112
@@ -98,7 +143,7 @@ func (*RegistryRoutes) addRegistry(w http.ResponseWriter, _ *http.Request) {
98
143
// @Success 200 {object} getRegistryResponse
99
144
// @Failure 404 {string} string "Not Found"
100
145
// @Router /api/v1beta/registry/{name} [get]
101
- func (routes * RegistryRoutes ) getRegistry (w http.ResponseWriter , r * http.Request ) {
146
+ func (* RegistryRoutes ) getRegistry (w http.ResponseWriter , r * http.Request ) {
102
147
name := chi .URLParam (r , "name" )
103
148
104
149
// Only "default" registry is supported currently
@@ -107,17 +152,26 @@ func (routes *RegistryRoutes) getRegistry(w http.ResponseWriter, r *http.Request
107
152
return
108
153
}
109
154
110
- reg , err := routes .provider .GetRegistry ()
155
+ provider , ok := getCurrentProvider (w )
156
+ if ! ok {
157
+ return
158
+ }
159
+
160
+ reg , err := provider .GetRegistry ()
111
161
if err != nil {
112
162
http .Error (w , "Failed to get registry" , http .StatusInternalServerError )
113
163
return
114
164
}
115
165
166
+ registryType , source := getRegistryInfo ()
167
+
116
168
response := getRegistryResponse {
117
169
Name : defaultRegistryName ,
118
170
Version : reg .Version ,
119
171
LastUpdated : reg .LastUpdated ,
120
172
ServerCount : len (reg .Servers ),
173
+ Type : registryType ,
174
+ Source : source ,
121
175
Registry : reg ,
122
176
}
123
177
@@ -249,7 +303,7 @@ func (*RegistryRoutes) removeRegistry(w http.ResponseWriter, r *http.Request) {
249
303
// @Success 200 {object} listServersResponse
250
304
// @Failure 404 {string} string "Not Found"
251
305
// @Router /api/v1beta/registry/{name}/servers [get]
252
- func (routes * RegistryRoutes ) listServers (w http.ResponseWriter , r * http.Request ) {
306
+ func (* RegistryRoutes ) listServers (w http.ResponseWriter , r * http.Request ) {
253
307
registryName := chi .URLParam (r , "name" )
254
308
255
309
// Only "default" registry is supported currently
@@ -258,7 +312,12 @@ func (routes *RegistryRoutes) listServers(w http.ResponseWriter, r *http.Request
258
312
return
259
313
}
260
314
261
- servers , err := routes .provider .ListServers ()
315
+ provider , ok := getCurrentProvider (w )
316
+ if ! ok {
317
+ return
318
+ }
319
+
320
+ servers , err := provider .ListServers ()
262
321
if err != nil {
263
322
logger .Errorf ("Failed to list servers: %v" , err )
264
323
http .Error (w , "Failed to list servers" , http .StatusInternalServerError )
@@ -285,7 +344,7 @@ func (routes *RegistryRoutes) listServers(w http.ResponseWriter, r *http.Request
285
344
// @Success 200 {object} getServerResponse
286
345
// @Failure 404 {string} string "Not Found"
287
346
// @Router /api/v1beta/registry/{name}/servers/{serverName} [get]
288
- func (routes * RegistryRoutes ) getServer (w http.ResponseWriter , r * http.Request ) {
347
+ func (* RegistryRoutes ) getServer (w http.ResponseWriter , r * http.Request ) {
289
348
registryName := chi .URLParam (r , "name" )
290
349
serverName := chi .URLParam (r , "serverName" )
291
350
@@ -295,7 +354,12 @@ func (routes *RegistryRoutes) getServer(w http.ResponseWriter, r *http.Request)
295
354
return
296
355
}
297
356
298
- server , err := routes .provider .GetServer (serverName )
357
+ provider , ok := getCurrentProvider (w )
358
+ if ! ok {
359
+ return
360
+ }
361
+
362
+ server , err := provider .GetServer (serverName )
299
363
if err != nil {
300
364
logger .Errorf ("Failed to get server '%s': %v" , serverName , err )
301
365
http .Error (w , "ImageMetadata not found" , http .StatusNotFound )
@@ -325,6 +389,10 @@ type registryInfo struct {
325
389
LastUpdated string `json:"last_updated"`
326
390
// Number of servers in the registry
327
391
ServerCount int `json:"server_count"`
392
+ // Type of registry (file, url, or default)
393
+ Type RegistryType `json:"type"`
394
+ // Source of the registry (URL, file path, or empty string for built-in)
395
+ Source string `json:"source"`
328
396
}
329
397
330
398
// registryListResponse represents the response for listing registries
@@ -347,6 +415,10 @@ type getRegistryResponse struct {
347
415
LastUpdated string `json:"last_updated"`
348
416
// Number of servers in the registry
349
417
ServerCount int `json:"server_count"`
418
+ // Type of registry (file, url, or default)
419
+ Type RegistryType `json:"type"`
420
+ // Source of the registry (URL, file path, or empty string for built-in)
421
+ Source string `json:"source"`
350
422
// Full registry data
351
423
Registry * registry.Registry `json:"registry"`
352
424
}
0 commit comments