Skip to content

Commit baabf66

Browse files
authored
Merge pull request #56 from threefoldtech/development-fix-registrar-readme
Development fix registrar readme
2 parents f6a846b + ba9d895 commit baabf66

File tree

19 files changed

+253
-368
lines changed

19 files changed

+253
-368
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Set up Go
2828
uses: actions/setup-go@v5
2929
with:
30-
go-version: 1.21
30+
go-version: 1.23
3131

3232
- name: Build
3333
run: make build

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Go
1616
uses: actions/setup-go@v5
1717
with:
18-
go-version: 1.21
18+
go-version: 1.23
1919

2020
- name: Run golangci-lint
2121
uses: golangci/golangci-lint-action@v6

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Go
2020
uses: actions/setup-go@v5
2121
with:
22-
go-version: 1.21
22+
go-version: 1.23
2323

2424
- name: Run GoReleaser
2525
uses: goreleaser/goreleaser-action@v6.2.1

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Set up Go
1212
uses: actions/setup-go@v5
1313
with:
14-
go-version: "1.21"
14+
go-version: "1.23"
1515

1616
- name: Check out code into the Go module directory
1717
uses: actions/checkout@v4

go.work

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
go 1.21.0
1+
go 1.23.0
22

33
use ./node-registrar
4+
use ./rmb-sdk-go

go.work.sum

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,40 @@ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpV
66
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
77
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
88
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
9+
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
10+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
11+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
912
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1013
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
1114
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
1215
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
13-
github.com/vedhavyas/go-subkey v1.0.3 h1:iKR33BB/akKmcR2PMlXPBeeODjWLM90EL98OrOGs8CA=
14-
github.com/vedhavyas/go-subkey v1.0.3/go.mod h1:CloUaFQSSTdWnINfBRFjVMkWXZANW+nd8+TI5jYcl6Y=
15-
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
16+
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
17+
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
18+
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
19+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
20+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
21+
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
22+
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
23+
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
24+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
25+
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
27+
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
28+
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
1629
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
1730
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
31+
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
1832
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
33+
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
1934
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
35+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
36+
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
37+
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
38+
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
39+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
40+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
41+
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
42+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
43+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
2044
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
2145
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

node-registrar/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21-alpine AS builder
1+
FROM golang:1.23-alpine AS builder
22

33
WORKDIR /app
44

node-registrar/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
run:
22
go run cmds/main.go --postgres-host localhost --postgres-port 5432 --postgres-db postgres --postgres-user postgres --postgres-password password --domain localhost --server-port 8080
33

4-
postgres:
4+
start-postgres:
55
docker run --name postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -p 5432:5432 -d postgres
66

77
stop-postgres:

node-registrar/README.md

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11

22
# Node Registrar Service
33

4+
[![Go Report Card](https://goreportcard.com/badge/github.com/threefoldtech/tfgrid-sdk-go/node-registrar)](https://goreportcard.com/report/github.com/threefoldtech/tfgrid-sdk-go/node-registrar)
5+
[![GoDoc](https://godoc.org/github.com/threefoldtech/tfgrid-sdk-go/node-registrar?status.svg)](https://godoc.org/github.com/threefoldtech/tfgrid-sdk-go/node-registrar)
6+
47
## Overview
58

6-
This project provides an API for registring zos nodes using the Go Gin framework and PostgreSQL database.
7-
The API supports operations like registring, listing, and updating farms and nodes, as well as reporting uptime and consumption data for nodes.
9+
This project provides an API for registring and managing zos nodes on ThreeFold GridV4. Built with the Go Gin framework and PostgreSQL database,
10+
It offers operations like registring, listing, and updating farms and nodes, as well as reporting uptime and consumption data for nodes.
811

912
## Features
1013

@@ -31,25 +34,29 @@ The API supports operations like registring, listing, and updating farms and nod
3134

3235
### Farms Endpoints
3336

34-
1. **GET /farms/** - List all farms, or use FarmFilter to list specific set of farms.
35-
2. **GET /farms/:farm_id** - Get a specific farm by ID.
36-
3. **POST /farms/** - Create a new farm.
37-
4. **PATCH /farms/** - Update an existing farm.
37+
| Method | Endpoint | Description |
38+
|--------|----------|-------------|
39+
| GET | `/farms/` | List all farms with optional filtering |
40+
| GET | `/farms/:farm_id` | Get a specific farm by ID |
41+
| POST | `/farms/` | Create a new farm |
42+
| PATCH | `/farms/` | Update an existing farm |
3843

3944
### Nodes Endpoints
4045

41-
1. **GET /nodes/** - List all nodes, or use NodeFilter to list specific set of nodes.
42-
2. **GET /nodes/:node_id** - Get a specific node by ID.
43-
3. **POST /nodes/** - Register a new node.
44-
4. **POST /nodes/:node_id/uptime** - Report uptime for a specific node.
45-
5. **POST /nodes/:node_id/consumption** - Report consumption for a specific node.
46+
| Method | Endpoint | Description |
47+
|--------|----------|-------------|
48+
| GET | `/nodes/` | List all nodes with optional filtering |
49+
| GET | `/nodes/:node_id` | Get a specific node by ID |
50+
| POST | `/nodes/` | Register a new node |
51+
| POST | `/nodes/:node_id/uptime` | Report uptime for a specific node |
52+
| POST | `/nodes/:node_id/consumption` | Report consumption for a specific node |
4653

4754
## Setup Instructions
4855

4956
1. **Start PostgreSQL:**
5057

5158
```bash
52-
make postgres
59+
make start-postgres
5360
```
5461

5562
2. **Run the Server:**
@@ -81,11 +88,11 @@ Replace `<domain>` and `<port>` with the appropriate values.
8188

8289
## How to run the server with docker
8390

84-
1. use the docker file to build the docker image
91+
1. To use the docker file to build the docker image, run this command in the root directory of the sdk
8592

86-
```bash
87-
docker build -t registrar:latest .
88-
```
93+
```bash
94+
docker build -t registrar:latest -f node-registrar/Dockerfile .
95+
```
8996

9097
2. run the image
9198

@@ -125,14 +132,14 @@ X-Auth: Base64(Challenge):Base64(Signature)
125132
**Signature:**
126133
ED25519/SR25519 signature of challenge bytes
127134

128-
## Database Schema
129-
130-
Key Tables:
135+
The service uses a PostgreSQL database with the following key tables:
131136

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
137+
| Table | Description |
138+
|-------|-------------|
139+
| `accounts` | Authentication credentials and relay configurations |
140+
| `farms` | Farm metadata with owner relationship |
141+
| `nodes` | Node hardware specifications and resources |
142+
| `uptime_reports` | Historical node availability data |
136143

137144
## Development
138145

@@ -141,3 +148,41 @@ Key Tables:
141148
```bash
142149
swag init -g pkg/server/handlers.go --output docs --parseDependency --parseDepth 2
143150
```
151+
152+
## Client Library
153+
154+
A Go client library is available to interact with the Node Registrar Service. See the [client documentation](./client/README.md) for details on installation and usage.
155+
156+
Example usage:
157+
158+
```go
159+
import "github.com/threefoldtech/tfgrid-sdk-go/node-registrar/client"
160+
161+
// Initialize client
162+
cli, err := client.NewRegistrarClient("https://registrar.dev.grid.tf", mnemonic)
163+
164+
// Register a node
165+
node := Node{
166+
TwinID: twinID,
167+
FarmID: farmID,
168+
Interfaces: interfaces,
169+
Location: location,
170+
Resources: resources,
171+
SerialNumber: serialNumber,
172+
SecureBoot: secureBoot,
173+
Virtualized: virtualized,
174+
}
175+
nodeID, err := cli.RegisterNode(node)
176+
```
177+
178+
### Generating Swagger Documentation
179+
180+
```bash
181+
swag init -g pkg/server/handlers.go --output docs --parseDependency --parseDepth 2
182+
```
183+
184+
### Running Tests
185+
186+
```bash
187+
make test
188+
```

node-registrar/client/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/pkg/errors"
13-
"github.com/vedhavyas/go-subkey/v2"
13+
subkey "github.com/vedhavyas/go-subkey/v2"
1414
)
1515

1616
var ErrorAccountNotFound = fmt.Errorf("failed to get requested account from node registrar")

node-registrar/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"net/http"
55

66
"github.com/pkg/errors"
7-
"github.com/vedhavyas/go-subkey/v2"
7+
subkey "github.com/vedhavyas/go-subkey/v2"
88
)
99

1010
type RegistrarClient struct {

0 commit comments

Comments
 (0)