1
1
2
- ## Project Documentation
2
+ # Node Registrar Service
3
3
4
- ### Overview
5
- This project provides an API for registring zos nodes using the Go Gin framework and PostgreSQL database.
4
+ ## Overview
5
+
6
+ This project provides an API for registring zos nodes using the Go Gin framework and PostgreSQL database.
6
7
The API supports operations like registring, listing, and updating farms and nodes, as well as reporting uptime and consumption data for nodes.
7
8
8
- ### Endpoint Descriptions
9
+ ## Features
10
+
11
+ - ** Farm Management**
12
+ - Create/update farms with owner authorization
13
+ - List farms with filtering/pagination
14
+ - Automatic twin ID association via authentication
15
+
16
+ - ** Node Registration**
17
+ - Create/update nodes with owner authorization
18
+ - Uptime reporting
19
+ - Node metadata management (location, interfaces, specs)
20
+
21
+ - ** Account System**
22
+ - ED25519/SR25519 authentication
23
+ - Relay management for RMB communication
24
+
25
+ - ** Security**
26
+ - Challenge-response authentication middleware
27
+ - Ownership verification for mutations
28
+ - Timestamp replay protection
29
+
30
+ ## Endpoint Descriptions
31
+
32
+ ### Farms Endpoints
9
33
10
- #### Farms Endpoints
11
34
1 . ** GET /farms/** - List all farms, or use FarmFilter to list specific set of farms.
12
35
2 . ** GET /farms/: farm_id ** - Get a specific farm by ID.
13
36
3 . ** POST /farms/** - Create a new farm.
14
37
4 . ** PATCH /farms/** - Update an existing farm.
15
38
16
- #### Nodes Endpoints
39
+ ### Nodes Endpoints
40
+
17
41
1 . ** GET /nodes/** - List all nodes, or use NodeFilter to list specific set of nodes.
18
42
2 . ** GET /nodes/: node_id ** - Get a specific node by ID.
19
43
3 . ** POST /nodes/** - Register a new node.
@@ -23,52 +47,97 @@ The API supports operations like registring, listing, and updating farms and nod
23
47
## Setup Instructions
24
48
25
49
1 . ** Start PostgreSQL:**
50
+
26
51
``` bash
27
52
make postgres
28
53
```
54
+
29
55
2 . ** Run the Server:**
56
+
30
57
``` bash
31
58
make run
32
59
```
60
+
33
61
3 . ** Stop PostgreSQL:**
62
+
34
63
``` bash
35
64
make stop-postgres
36
65
```
37
66
38
- ### Swagger Documentation
67
+ ## Swagger Documentation
68
+
39
69
Once the server is running, Swagger documentation can be accessed at:
40
- ```
70
+
71
+ ``` bash
41
72
http://< domain> :< port> /swagger/index.html
42
73
```
74
+
43
75
Replace ` <domain> ` and ` <port> ` with the appropriate values.
44
76
45
- ### How to Use the Server
77
+ ## How to Use the Server
78
+
46
79
1 . Use a tool like Postman or cURL to interact with the API.
47
80
2 . Refer to the Swagger documentation for detailed information about request parameters and response structures.
48
81
49
- ### How to run the server with docker
50
- 1 . use the docker file to build the docker image
51
- ```
52
- docker build -t registrar:latest .
53
- ```
82
+ ## How to run the server with docker
83
+
84
+ 1 . use the docker file to build the docker image
85
+
86
+ ``` bash
87
+ docker build -t registrar:latest .
88
+ ```
89
+
54
90
2 . run the image
91
+
92
+ ``` bash
93
+ docker run -d \
94
+ -p 8080:8080 \
95
+ --name registrar \
96
+ registrar:latest \
97
+ ./server
98
+ --postgres-host=< your-postgres-host> \
99
+ --postgres-port=5432 \
100
+ --postgres-db=< your-db-name> \
101
+ --postgres-user=< your-db-user> \
102
+ --postgres-password=< your-db-password> \
103
+ --ssl-mode=disable \
104
+ --sql-log-level=2 \
105
+ --max-open-conn=10 \
106
+ --max-idle-conn=5 \
107
+ --server-port=8080 \
108
+ --< domain=your-domain> \
109
+ --network=main\
110
+ --admin_twin_id=1
111
+ --debug
112
+ ```
113
+
114
+ ## Authentication
115
+
116
+ Requests requiring authorization must include:
117
+
118
+ ``` http
119
+ X-Auth: Base64(Challenge):Base64(Signature)
55
120
```
56
- docker run -d \
57
- -p 8080:8080 \
58
- --name registrar \
59
- registrar:latest \
60
- ./server
61
- --postgres-host=<your-postgres-host> \
62
- --postgres-port=5432 \
63
- --postgres-db=<your-db-name> \
64
- --postgres-user=<your-db-user> \
65
- --postgres-password=<your-db-password> \
66
- --ssl-mode=disable \
67
- --sql-log-level=2 \
68
- --max-open-conn=10 \
69
- --max-idle-conn=5 \
70
- --server-port=8080 \
71
- --<domain=your-domain> \
72
- --network=main\
73
- --debug
121
+
122
+ ** Challenge Format:**
123
+ ` <unix_timestamp>:<twin_id> `
124
+
125
+ ** Signature:**
126
+ ED25519/SR25519 signature of challenge bytes
127
+
128
+ ## Database Schema
129
+
130
+ Key Tables:
131
+
132
+ - ` accounts ` - Authentication credentials and relay configs
133
+ - ` farms ` - Farm metadata with owner relationship
134
+ - ` nodes ` - Node hardware/resources specification
135
+ - ` uptime_reports ` - Historical node availability data
136
+
137
+ ## Development
138
+
139
+ ### Generating Swagger Docs
140
+
141
+ ``` bash
142
+ swag init -g pkg/server/handlers.go --output docs --parseDependency --parseDepth 2
74
143
```
0 commit comments