registry

package module
v0.0.0-...-7c55829 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

README

registry

contains server and cli for node management across edge/fog of igrid network

run registry server

First make sure you have go and postgresql installed then go to the terminal and execute this command

go run cmd/server/main.go
using registry cli

This command-line utility can be used if the registry server is online i.e the above step has executed successfully

build the utility

For windows

cd cmd/registry
go build -o registry.exe

For Unix/Linux

cd cmd/registry
go build -o registry
install the utility

Processes may differ from different OS (explanations incoming)

list 100 devices in the igrid networks
registry list -l 100
get details of the device by specifying the mac address
registry get -m <mac-address>
or
registry get --mac-address <mac-address>
check if the device is valid
registry auth -u <mac-address> -t <token>
#example command
registry auth -u "44-08-D6-03-72-C3" -t "58ac8f69-b6ab-4f87-8206-fa9f13c6d"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMacAddress   = errors.New("invalid mac address")
	ErrGeneratingNodeToken = errors.New("error generating new node token")
)
View Source
var ErrGeneratingID = errors.New("generating id failed")

ErrGeneratingID indicates error in generating UUID

Functions

func Connect

func Connect() (*sql.DB, error)

Connect creates a connection to the PostgreSQL instance and applies any

Types

type Node

type Node struct {
	Addr      string     `json:"addr"`
	Name      string     `json:"name"`
	Type      Type       `json:"type"`
	Status    NodeStatus `json:"status"`
	Latitude  string     `json:"lat"`
	Longitude string     `json:"long"`
	Token     string     `json:"token"`
	CreatedAt int64      `json:"created_at"`
}

Node represent the edge node deployed in the igrid network

func NewNode

func NewNode(addr, name, lat, long string, nodeType Type) (Node, error)

func (Node) String

func (n Node) String() string

type NodeStatus

type NodeStatus int
const (
	Revoked NodeStatus = iota + 1
	AllowedOffline
	AllowedOnline
)

func (NodeStatus) String

func (ns NodeStatus) String() string

type Pinger

type Pinger interface {
	Ping()
}

type Repository

type Repository interface {

	//Save persists the Node information to database
	Save(ctx context.Context, node Node) error

	//Get return Node information if a correct MAC Addr is
	//provided or return error if anything goes wrong
	Get(ctx context.Context, addr string) (Node, error)

	//Delete the node from the data store=
	Delete(ctx context.Context, addr string) error

	//Update change details of the node
	Update(ctx context.Context, node Node, addr string) error

	//List
	List(ctx context.Context) ([]Node, error)

	//Auth check if the node is authenticated
	Auth(ctx context.Context, addr string, token string) (bool, error)

	//Revoke
	Revoke(ctx context.Context, addr string, token string) (bool, error)
}

func NewPostgreSQL

func NewPostgreSQL(db *sql.DB) Repository

func NewSQLite

func NewSQLite(db *sql.DB) Repository

NewSQLite init sqlite db db, err := sql.Open("sqlite3", "database/regctl.db")

type Service

type Service interface {

	//Auth check if the node is authenticated
	Auth(ctx context.Context, addr string, token string) (bool, error)

	//Add persists the details of a new Node
	Add(ctx context.Context, node Node) (Node, error)

	//Delete the existing Node making it invalid
	Delete(ctx context.Context, addr string) error

	//Get the details of already persisted node
	Get(ctx context.Context, addr string) (Node, error)

	//Update the details of a Node
	Update(ctx context.Context, addr string, node Node) (Node, error)

	//List all the valid Nodes
	List(ctx context.Context) ([]Node, error)

	//Revoke access
	Revoke(ctx context.Context, addr, token string) (bool, error)

	//CheckStatus
	CheckStatus(ctx context.Context, node Node) (NodeStatus, error)
}

Service describes the service.

func NewService

func NewService(repo Repository, logger log.Logger) Service

type Type

type Type int
const (
	Sensor Type = iota + 1
	Actuator
	Controller
)

func (Type) String

func (t Type) String() string

type UUIDProvider

type UUIDProvider interface {
	// ID generates the unique identifier.
	ID() (string, error)
}

UUIDProvider specifies an API for generating unique identifiers.

func UuidProvider

func UuidProvider() UUIDProvider

UuidProvider instantiates a UUID provider.

Directories

Path Synopsis
api
http
THIS FILE IS AUTO GENERATED BY GK-CLI DO NOT EDIT!!
THIS FILE IS AUTO GENERATED BY GK-CLI DO NOT EDIT!!
cmd
regctl
* Copyright © 2020 PIUS ALFRED <ME.PIUS1102@GMAIL.COM> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* Copyright © 2020 PIUS ALFRED <ME.PIUS1102@GMAIL.COM> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL