Skip to content

Development fix registrar readme #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.23

- name: Build
run: make build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.23

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.23

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6.2.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.23"

- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
go 1.21.0
go 1.23.0

use ./node-registrar
use ./rmb-sdk-go
30 changes: 27 additions & 3 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,40 @@ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpV
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/vedhavyas/go-subkey v1.0.3 h1:iKR33BB/akKmcR2PMlXPBeeODjWLM90EL98OrOGs8CA=
github.com/vedhavyas/go-subkey v1.0.3/go.mod h1:CloUaFQSSTdWnINfBRFjVMkWXZANW+nd8+TI5jYcl6Y=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
2 changes: 1 addition & 1 deletion node-registrar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-alpine AS builder
FROM golang:1.23-alpine AS builder

WORKDIR /app

Expand Down
2 changes: 1 addition & 1 deletion node-registrar/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
run:
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

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

stop-postgres:
Expand Down
91 changes: 68 additions & 23 deletions node-registrar/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

# Node Registrar Service

[![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)
[![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)

## Overview

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

## Features

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

### Farms Endpoints

1. **GET /farms/** - List all farms, or use FarmFilter to list specific set of farms.
2. **GET /farms/:farm_id** - Get a specific farm by ID.
3. **POST /farms/** - Create a new farm.
4. **PATCH /farms/** - Update an existing farm.
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/farms/` | List all farms with optional filtering |
| GET | `/farms/:farm_id` | Get a specific farm by ID |
| POST | `/farms/` | Create a new farm |
| PATCH | `/farms/` | Update an existing farm |

### Nodes Endpoints

1. **GET /nodes/** - List all nodes, or use NodeFilter to list specific set of nodes.
2. **GET /nodes/:node_id** - Get a specific node by ID.
3. **POST /nodes/** - Register a new node.
4. **POST /nodes/:node_id/uptime** - Report uptime for a specific node.
5. **POST /nodes/:node_id/consumption** - Report consumption for a specific node.
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/nodes/` | List all nodes with optional filtering |
| GET | `/nodes/:node_id` | Get a specific node by ID |
| POST | `/nodes/` | Register a new node |
| POST | `/nodes/:node_id/uptime` | Report uptime for a specific node |
| POST | `/nodes/:node_id/consumption` | Report consumption for a specific node |

## Setup Instructions

1. **Start PostgreSQL:**

```bash
make postgres
make start-postgres
```

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

## How to run the server with docker

1. use the docker file to build the docker image
1. To use the docker file to build the docker image, run this command in the root directory of the sdk

```bash
docker build -t registrar:latest .
```
```bash
docker build -t registrar:latest -f node-registrar/Dockerfile .
```

2. run the image

Expand Down Expand Up @@ -125,14 +132,14 @@ X-Auth: Base64(Challenge):Base64(Signature)
**Signature:**
ED25519/SR25519 signature of challenge bytes

## Database Schema

Key Tables:
The service uses a PostgreSQL database with the following key tables:

- `accounts` - Authentication credentials and relay configs
- `farms` - Farm metadata with owner relationship
- `nodes` - Node hardware/resources specification
- `uptime_reports` - Historical node availability data
| Table | Description |
|-------|-------------|
| `accounts` | Authentication credentials and relay configurations |
| `farms` | Farm metadata with owner relationship |
| `nodes` | Node hardware specifications and resources |
| `uptime_reports` | Historical node availability data |

## Development

Expand All @@ -141,3 +148,41 @@ Key Tables:
```bash
swag init -g pkg/server/handlers.go --output docs --parseDependency --parseDepth 2
```

## Client Library

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.

Example usage:

```go
import "github.com/threefoldtech/tfgrid-sdk-go/node-registrar/client"

// Initialize client
cli, err := client.NewRegistrarClient("https://registrar.dev.grid.tf", mnemonic)

// Register a node
node := Node{
TwinID: twinID,
FarmID: farmID,
Interfaces: interfaces,
Location: location,
Resources: resources,
SerialNumber: serialNumber,
SecureBoot: secureBoot,
Virtualized: virtualized,
}
nodeID, err := cli.RegisterNode(node)
```

### Generating Swagger Documentation

```bash
swag init -g pkg/server/handlers.go --output docs --parseDependency --parseDepth 2
```

### Running Tests

```bash
make test
```
2 changes: 1 addition & 1 deletion node-registrar/client/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/vedhavyas/go-subkey/v2"
subkey "github.com/vedhavyas/go-subkey/v2"
)

var ErrorAccountNotFound = fmt.Errorf("failed to get requested account from node registrar")
Expand Down
2 changes: 1 addition & 1 deletion node-registrar/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/pkg/errors"
"github.com/vedhavyas/go-subkey/v2"
subkey "github.com/vedhavyas/go-subkey/v2"
)

type RegistrarClient struct {
Expand Down
Loading
Loading