@@ -20,6 +20,14 @@ const (
20
20
OnlineCutoffTime = 40 * time .Minute
21
21
)
22
22
23
+ type Farm struct {
24
+ FarmID uint64 `json:"farm_id"`
25
+ FarmName string `json:"farm_name"`
26
+ TwinID uint64 `json:"twin_id"`
27
+ Dedicated bool `json:"dedicated"`
28
+ StellarAddress string `json:"stellar_address"`
29
+ }
30
+
23
31
// @title Node Registrar API
24
32
// @version 1.0
25
33
// @description API for managing TFGrid node registration
@@ -35,7 +43,7 @@ const (
35
43
// @Param twin_id query int false "Filter by twin ID"
36
44
// @Param page query int false "Page number" default(1)
37
45
// @Param size query int false "Results per page" default(10)
38
- // @Success 200 {object} []db. Farm "List of farms"
46
+ // @Success 200 {object} []Farm "List of farms"
39
47
// @Failure 400 {object} map[string]any "Bad request"
40
48
// @Router /farms [get]
41
49
func (s Server ) listFarmsHandler (c * gin.Context ) {
@@ -54,7 +62,19 @@ func (s Server) listFarmsHandler(c *gin.Context) {
54
62
return
55
63
}
56
64
57
- c .JSON (http .StatusOK , farms )
65
+ // dorp extra db field
66
+ var res []Farm
67
+ for _ , farm := range farms {
68
+ res = append (res , Farm {
69
+ FarmID : farm .FarmID ,
70
+ FarmName : farm .FarmName ,
71
+ TwinID : farm .TwinID ,
72
+ Dedicated : farm .Dedicated ,
73
+ StellarAddress : farm .StellarAddress ,
74
+ })
75
+ }
76
+
77
+ c .JSON (http .StatusOK , res )
58
78
}
59
79
60
80
// @Summary Get farm details
@@ -63,7 +83,7 @@ func (s Server) listFarmsHandler(c *gin.Context) {
63
83
// @Accept json
64
84
// @Produce json
65
85
// @Param farm_id path int true "Farm ID"
66
- // @Success 200 {object} db. Farm "Farm details"
86
+ // @Success 200 {object} Farm "Farm details"
67
87
// @Failure 400 {object} map[string]any "Invalid farm ID"
68
88
// @Failure 404 {object} map[string]any "Farm not found"
69
89
// @Router /farms/{farm_id} [get]
@@ -88,7 +108,16 @@ func (s Server) getFarmHandler(c *gin.Context) {
88
108
return
89
109
}
90
110
91
- c .JSON (http .StatusOK , farm )
111
+ // dorp extra db field
112
+ res := Farm {
113
+ FarmID : farm .FarmID ,
114
+ FarmName : farm .FarmName ,
115
+ TwinID : farm .TwinID ,
116
+ Dedicated : farm .Dedicated ,
117
+ StellarAddress : farm .StellarAddress ,
118
+ }
119
+
120
+ c .JSON (http .StatusOK , res )
92
121
}
93
122
94
123
// @Summary Create new farm
@@ -203,6 +232,21 @@ func (s Server) updateFarmHandler(c *gin.Context) {
203
232
})
204
233
}
205
234
235
+ type Node struct {
236
+ NodeID uint64 `json:"node_id"`
237
+ FarmID uint64 `json:"farm_id"`
238
+ TwinID uint64 `json:"twin_id"`
239
+ Location db.Location `json:"location"`
240
+ Resources db.Resources `json:"resources"`
241
+ Interfaces []db.Interface `json:"interfaces"`
242
+ SecureBoot bool `json:"secure_boot"`
243
+ Virtualized bool `json:"virtualized"`
244
+ SerialNumber string `json:"serial_number"`
245
+ LastSeen time.Time `json:"last_seen"`
246
+ Online bool `json:"online"`
247
+ Approved bool
248
+ }
249
+
206
250
// @Summary List nodes
207
251
// @Description Get a list of nodes with optional filters
208
252
// @Tags nodes
@@ -217,7 +261,7 @@ func (s Server) updateFarmHandler(c *gin.Context) {
217
261
// @Param last_seen query int false "Filter nodes last seen within this many minutes"
218
262
// @Param page query int false "Page number" default(1)
219
263
// @Param size query int false "Results per page" default(10)
220
- // @Success 200 {object} []db. Node "List of nodes with online status"
264
+ // @Success 200 {object} []Node "List of nodes with online status"
221
265
// @Failure 400 {object} map[string]any "Bad request"
222
266
// @Router /nodes [get]
223
267
func (s Server ) listNodesHandler (c * gin.Context ) {
@@ -236,13 +280,27 @@ func (s Server) listNodesHandler(c *gin.Context) {
236
280
return
237
281
}
238
282
239
- // Set online status for each node
240
283
cutoffTime := time .Now ().Add (- OnlineCutoffTime )
241
- for i := range nodes {
242
- nodes [i ].Online = ! nodes [i ].LastSeen .IsZero () && nodes [i ].LastSeen .After (cutoffTime )
284
+ var res []Node
285
+ for i , node := range nodes {
286
+ res = append (res , Node {
287
+ NodeID : node .NodeID ,
288
+ FarmID : node .FarmID ,
289
+ TwinID : node .TwinID ,
290
+ Location : node .Location ,
291
+ Resources : node .Resources ,
292
+ Interfaces : node .Interfaces ,
293
+ SecureBoot : node .SecureBoot ,
294
+ SerialNumber : node .SerialNumber ,
295
+ Virtualized : node .Virtualized ,
296
+ LastSeen : node .LastSeen ,
297
+ Approved : node .Approved ,
298
+ // Set online status for each node
299
+ Online : ! nodes [i ].LastSeen .IsZero () && nodes [i ].LastSeen .After (cutoffTime ),
300
+ })
243
301
}
244
302
245
- c .JSON (http .StatusOK , nodes )
303
+ c .JSON (http .StatusOK , res )
246
304
}
247
305
248
306
// @Summary Get node details
@@ -251,7 +309,7 @@ func (s Server) listNodesHandler(c *gin.Context) {
251
309
// @Accept json
252
310
// @Produce json
253
311
// @Param node_id path int true "Node ID"
254
- // @Success 200 {object} db. Node "Node details with online status and last_seen information"
312
+ // @Success 200 {object} Node "Node details with online status and last_seen information"
255
313
// @Failure 400 {object} map[string]any "Invalid node ID"
256
314
// @Failure 404 {object} map[string]any "Node not found"
257
315
// @Router /nodes/{node_id} [get]
@@ -275,11 +333,24 @@ func (s Server) getNodeHandler(c *gin.Context) {
275
333
return
276
334
}
277
335
278
- // Determine if the node is online (has sent an uptime report in the last 30 minutes)
279
336
cutoffTime := time .Now ().Add (- OnlineCutoffTime )
280
- node .Online = ! node .LastSeen .IsZero () && node .LastSeen .After (cutoffTime )
281
-
282
- c .JSON (http .StatusOK , node )
337
+ res := Node {
338
+ NodeID : node .NodeID ,
339
+ FarmID : node .FarmID ,
340
+ TwinID : node .TwinID ,
341
+ Location : node .Location ,
342
+ Resources : node .Resources ,
343
+ Interfaces : node .Interfaces ,
344
+ SecureBoot : node .SecureBoot ,
345
+ SerialNumber : node .SerialNumber ,
346
+ Virtualized : node .Virtualized ,
347
+ LastSeen : node .LastSeen ,
348
+ Approved : node .Approved ,
349
+ // Determine if the node is online (has sent an uptime report in the last 30 minutes)
350
+ Online : ! node .LastSeen .IsZero () && node .LastSeen .After (cutoffTime ),
351
+ }
352
+
353
+ c .JSON (http .StatusOK , res )
283
354
}
284
355
285
356
type NodeRegistrationRequest struct {
@@ -517,13 +588,20 @@ type AccountCreationRequest struct {
517
588
RMBEncKey string `json:"rmb_enc_key,omitempty"`
518
589
}
519
590
591
+ type Account struct {
592
+ TwinID uint64 `json:"twin_id"`
593
+ Relays []string `json:"relays"` // Optional list of relay domains
594
+ RMBEncKey string `json:"rmb_enc_key"` // Optional base64 encoded public key for rmb communication
595
+ PublicKey string `json:"public_key"`
596
+ }
597
+
520
598
// @Summary Create new account
521
599
// @Description Create a new twin account with cryptographic verification
522
600
// @Tags accounts
523
601
// @Accept json
524
602
// @Produce json
525
603
// @Param request body AccountCreationRequest true "Account creation data"
526
- // @Success 201 {object} db. Account "Created account details"
604
+ // @Success 201 {object} Account "Created account details"
527
605
// @Failure 400 {object} map[string]any "Invalid request"
528
606
// @Failure 409 {object} map[string]any "Account already exists"
529
607
// @Router /accounts [post]
@@ -593,7 +671,13 @@ func (s *Server) createAccountHandler(c *gin.Context) {
593
671
return
594
672
}
595
673
596
- c .JSON (http .StatusCreated , account )
674
+ res := Account {
675
+ TwinID : account .TwinID ,
676
+ PublicKey : account .PublicKey ,
677
+ RMBEncKey : account .RMBEncKey ,
678
+ Relays : account .Relays ,
679
+ }
680
+ c .JSON (http .StatusCreated , res )
597
681
}
598
682
599
683
type UpdateAccountRequest struct {
@@ -654,7 +738,7 @@ func (s *Server) updateAccountHandler(c *gin.Context) {
654
738
// @Produce json
655
739
// @Param twin_id query uint64 false "Twin ID of the account"
656
740
// @Param public_key query string false "Base64 decoded Public key of the account"
657
- // @Success 200 {object} db. Account "Account details"
741
+ // @Success 200 {object} Account "Account details"
658
742
// @Failure 400 {object} map[string]any "Invalid request"
659
743
// @Failure 404 {object} map[string]any "Account not found"
660
744
// @Router /accounts [get]
@@ -694,7 +778,13 @@ func (s *Server) getAccountHandler(c *gin.Context) {
694
778
return
695
779
}
696
780
697
- c .JSON (http .StatusOK , account )
781
+ res := Account {
782
+ TwinID : account .TwinID ,
783
+ PublicKey : account .PublicKey ,
784
+ RMBEncKey : account .RMBEncKey ,
785
+ Relays : account .Relays ,
786
+ }
787
+ c .JSON (http .StatusCreated , res )
698
788
return
699
789
}
700
790
@@ -708,7 +798,14 @@ func (s *Server) getAccountHandler(c *gin.Context) {
708
798
c .JSON (http .StatusInternalServerError , gin.H {"error" : "failed to get account" })
709
799
return
710
800
}
711
- c .JSON (http .StatusOK , account )
801
+
802
+ res := Account {
803
+ TwinID : account .TwinID ,
804
+ PublicKey : account .PublicKey ,
805
+ RMBEncKey : account .RMBEncKey ,
806
+ Relays : account .Relays ,
807
+ }
808
+ c .JSON (http .StatusCreated , res )
712
809
return
713
810
}
714
811
}
0 commit comments