explorerclient

package module
v0.0.0-...-ef487f3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT Imports: 12 Imported by: 0

README

Explorer client

This repo contains a simple and limited implementation of a ThreeFold explorer client.
https://explorer.grid.tf

This client only implements endpoints needed for the purposes of Bancadati and is therefor very limited in functionality.

Usage

This is an example that lists all the nodes of a certain farm in pages of 10 nodes.

package main

import (
	"fmt"
	"log"

	"github.com/bancadati/explorerclient"
)

func main() {
	cl, err := explorerclient.NewClient("https://explorer.grid.tf/explorer")
	if err != nil {
		log.Fatal(err)
	}

	f := &explorerclient.NodeFilter{}
	f.WithFarm(173636)

	pageSize := 10
	page := 1

	for {
		nodePager := explorerclient.NewPager(page, pageSize)
		nodes, err := cl.ListNodes(f, nodePager)
		if err != nil {
			log.Fatal(err)
		}
		for _, node := range nodes {
			fmt.Println(node.NodeID, node.Location)
		}

		if len(nodes) == pageSize {
			page++
			continue
		}

		break
	}
}

Documentation

Overview

Package explorerclient provides a simple HTTP client for the Threefold explorer API This package simplifies and reduces the dependencies from the Threefold implementation (https://github.com/threefoldtech/tfexplorer/tree/master/client) This also means not all functionality is used and only the API endpoints needed for Bancadati are implemented.

Index

Constants

View Source
const (
	// DefaultBaseURL represents the default API URL for the Threefold Explorer
	DefaultBaseURL = "https://explorer.grid.tf/explorer/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a TF explorer client

func NewClient

func NewClient(baseURL string) (*Client, error)

NewClient returns a new TF explorer client

func (*Client) GetFarm

func (cl *Client) GetFarm(id int64) (*Farm, error)

GetFarm returns the details of a single farm

func (*Client) GetNode

func (cl *Client) GetNode(id string) (*Node, error)

GetNode returns the details of a single node

func (*Client) ListFarms

func (cl *Client) ListFarms(page *Pager) ([]Farm, error)

ListFarms lists all farms on the explorer

func (*Client) ListNodes

func (cl *Client) ListNodes(f *NodeFilter, page *Pager) ([]Node, error)

ListNodes lists all nodes from on the explorer

type Date

type Date struct{ time.Time }

Date is a jumpscale date wrapper

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON formatting to JSON will return the unix time stamp

func (Date) String

func (d Date) String() ([]byte, error)

String implements stringer interface

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(bytes []byte) error

UnmarshalJSON converts jumpscale data in json to Golang time.Time

type Farm

type Farm struct {
	ID              int64               `json:"id"`
	ThreebotID      int64               `json:"threebot_id"`
	IyoOrganization string              `json:"iyo_organization"`
	Name            string              `json:"name"`
	WalletAddresses []WalletAddress     `json:"wallet_addresses"`
	Location        Location            `json:"location"`
	Email           string              `json:"email"`
	ResourcePrices  []NodeResourcePrice ` json:"resource_prices"`
	PrefixZero      IPRange             `json:"prefix_zero"`
}

Farm represents a farm

type HTTPError

type HTTPError struct {
	// contains filtered or unexported fields
}

HTTPError is the error type returned by the client it contains the error and the HTTP response

func (HTTPError) Error

func (h HTTPError) Error() string

func (HTTPError) Response

func (h HTTPError) Response() http.Response

Response return the HTTP response that trigger this error

type IPRange

type IPRange struct{ net.IPNet }

IPRange type

func ParseIPRange

func ParseIPRange(txt string) (r IPRange, err error)

ParseIPRange parse iprange

func (IPRange) MarshalJSON

func (i IPRange) MarshalJSON() ([]byte, error)

MarshalJSON dumps IPRange as a string

func (IPRange) String

func (i IPRange) String() string

func (*IPRange) UnmarshalText

func (i *IPRange) UnmarshalText(text []byte) error

UnmarshalText loads IPRange from string

type Iface

type Iface struct {
	Name       string     `json:"name"`
	Addrs      []IPRange  `json:"addrs"`
	Gateway    []net.IP   `json:"gateway"`
	MacAddress MacAddress `json:"macaddress"`
}

Iface represents an interface

type IfaceTypeEnum

type IfaceTypeEnum uint8

IfaceTypeEnum represents interface types

const (
	// IfaceTypeMacvlan represents macvlan
	IfaceTypeMacvlan IfaceTypeEnum = iota
	// IfaceTypeVlan represents vlan
	IfaceTypeVlan
)

func (IfaceTypeEnum) String

func (e IfaceTypeEnum) String() string

type Location

type Location struct {
	City      string  `json:"city"`
	Country   string  `json:"country"`
	Continent string  `json:"continent"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

Location represents a physical location

type MacAddress

type MacAddress struct{ net.HardwareAddr }

MacAddress type

func (MacAddress) MarshalText

func (mac MacAddress) MarshalText() ([]byte, error)

MarshalText marshals MacAddress type to a string

func (*MacAddress) UnmarshalText

func (mac *MacAddress) UnmarshalText(addr []byte) error

UnmarshalText loads a macaddress from a string

type Node

type Node struct {
	ID                int64          `json:"id"`
	Hostname          string         `json:"hostname"`
	NodeID            string         `json:"node_id"`
	NodeIDV1          string         `json:"node_id_v1"`
	FarmID            int64          `json:"farm_id"`
	OsVersion         string         `json:"os_version"`
	Created           Date           `json:"created"`
	Updated           Date           `json:"updated"`
	Uptime            int64          `json:"uptime"`
	Address           string         `json:"address"`
	Location          Location       `json:"location"`
	TotalResources    ResourceAmount `json:"total_resources"`
	UsedResources     ResourceAmount `json:"used_resources"`
	ReservedResources ResourceAmount `json:"reserved_resources"`
	Workloads         WorkloadAmount `json:"workloads"`
	Proofs            []Proof        `json:"proofs"`
	Ifaces            []Iface        `json:"ifaces"`
	PublicConfig      *PublicIface   `json:"public_config"`
	FreeToUse         bool           `json:"free_to_use"`
	Approved          bool           `json:"approved"`
	PublicKeyHex      string         `json:"public_key_hex"`
	WgPorts           []int64        `json:"wg_ports"`
}

Node represents a node

type NodeFilter

type NodeFilter struct {
	// contains filtered or unexported fields
}

NodeFilter used to build a query for node list

func (*NodeFilter) Apply

func (n *NodeFilter) Apply(query url.Values)

Apply fills query

func (*NodeFilter) WithCRU

func (n *NodeFilter) WithCRU(cru int64) *NodeFilter

WithCRU filter with CRU

func (*NodeFilter) WithCity

func (n *NodeFilter) WithCity(city string) *NodeFilter

WithCity filter with city

func (*NodeFilter) WithCountry

func (n *NodeFilter) WithCountry(country string) *NodeFilter

WithCountry filter with country

func (*NodeFilter) WithFarm

func (n *NodeFilter) WithFarm(id int64) *NodeFilter

WithFarm filter with farm

func (*NodeFilter) WithHRU

func (n *NodeFilter) WithHRU(hru int64) *NodeFilter

WithHRU filter with HRU

func (*NodeFilter) WithMRU

func (n *NodeFilter) WithMRU(sru int64) *NodeFilter

WithMRU filter with mru

func (*NodeFilter) WithProofs

func (n *NodeFilter) WithProofs(proofs bool) *NodeFilter

WithProofs filter with proofs

type NodeResourcePrice

type NodeResourcePrice struct {
	Currency PriceCurrencyEnum `json:"currency"`
	Cru      float64           `json:"cru"`
	Mru      float64           `json:"mru"`
	Hru      float64           `json:"hru"`
	Sru      float64           `json:"sru"`
	Nru      float64           `json:"nru"`
}

NodeResourcePrice represents a node resource price

type Pager

type Pager struct {
	// contains filtered or unexported fields
}

Pager for listing

func NewPager

func NewPager(page, size int) *Pager

NewPager returns a pager

func Page

func Page(page, size int) *Pager

Page returns a pager

type PriceCurrencyEnum

type PriceCurrencyEnum uint8

PriceCurrencyEnum represents currencies

const (
	// PriceCurrencyEUR represents EUR
	PriceCurrencyEUR PriceCurrencyEnum = iota
	// PriceCurrencyUSD Represents USD
	PriceCurrencyUSD
	// PriceCurrencyTFT represents TFT
	PriceCurrencyTFT
	// PriceCurrencyAED represents AED
	PriceCurrencyAED
	// PriceCurrencyGBP represents GBP
	PriceCurrencyGBP
)

func (PriceCurrencyEnum) String

func (e PriceCurrencyEnum) String() string

type Proof

type Proof struct {
	Created      Date                   `json:"created"`
	HardwareHash string                 `json:"hardware_hash"`
	DiskHash     string                 `json:"disk_hash"`
	Hardware     map[string]interface{} `json:"hardware"`
	Disks        map[string]interface{} `json:"disks"`
	Hypervisor   []string               `json:"hypervisor"`
}

Proof represents proof?

type PublicIface

type PublicIface struct {
	Master  string        `json:"master"`
	Type    IfaceTypeEnum `json:"type"`
	Ipv4    IPRange       `json:"ipv4"`
	Ipv6    IPRange       `json:"ipv6"`
	Gw4     net.IP        `json:"gw4"`
	Gw6     net.IP        `json:"gw6"`
	Version int64         `json:"version"`
}

PublicIface represents a public interface

type ResourceAmount

type ResourceAmount struct {
	CRU uint64  `json:"cru"`
	MRU float64 `json:"mru"`
	HRU float64 `json:"hru"`
	SRU float64 `json:"sru"`
}

ResourceAmount contains an amount for each resource

type WalletAddress

type WalletAddress struct {
	Asset   string ` json:"asset"`
	Address string `json:"address"`
}

WalletAddress represents a wallet address

type WorkloadAmount

type WorkloadAmount struct {
	Network        uint16 `bson:"network" json:"network"`
	Volume         uint16 `bson:"volume" json:"volume"`
	ZDBNamespace   uint16 `bson:"zdb_namespace" json:"zdb_namespace"`
	Container      uint16 `bson:"container" json:"container"`
	K8sVM          uint16 `bson:"k8s_vm" json:"k8s_vm"`
	Proxy          uint16 `bson:"proxy" json:"proxy"`
	ReverseProxy   uint16 `bson:"reverse_proxy" json:"reverse_proxy"`
	Subdomain      uint16 `bson:"subdomain" json:"subdomain"`
	DelegateDomain uint16 `bson:"delegate_domain" json:"delegate_domain"`
}

WorkloadAmount represents an amount of workload

Jump to

Keyboard shortcuts

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