etcd

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

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

Go to latest
Published: Feb 11, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

This folder gives you all required functions to use connect to the etcd database and obtain all the information you need within the spider.

In order to test the etcd library, run the following:

docker network create --subnet=172.18.0.0/16 --gateway 172.18.0.1 spidernet
docker run -d \
  -p 2379:2379 \
  --network spidernet \
  --ip 172.18.18.20 \
  --name spiderweber_testing_etcd_library \
  quay.io/coreos/etcd \
  /usr/local/bin/etcd \
  --listen-client-urls http://0.0.0.0:2379 \
  --advertise-client-urls http://0.0.0.0:2379
export ETCD_HOST="172.18.18.20:2379"
go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client holds the etcd connection

func (*Client) ConsumeToken

func (c *Client) ConsumeToken(secret string) (Token, error)

ConsumeToken receives a secret and returns the token or an error. After returning the result, the token gets deleted (if found, obviously).

func (*Client) DeleteKnot

func (c *Client) DeleteKnot(ip, port string) error

DeleteKnot removes a knot and also keys from wings:

func (*Client) DeletePubkey

func (c *Client) DeletePubkey(pubkey string) error

DeletePubkey receives a string and deletes public key by prefix it also deletes the public key from the wings

func (*Client) DeleteWing

func (c *Client) DeleteWing(name string) error

func (*Client) GenerateToken

func (c *Client) GenerateToken(owner string, wings []string) (string, error)

GenerateToken will receive the owner&wings and return the secret for the new token

func (*Client) GetAllKnots

func (c *Client) GetAllKnots(knots *[]Knot) error

GetAllKnots always returns all knots, or error

func (*Client) GetAllPubkeys

func (c *Client) GetAllPubkeys(pubkeys *[]Pubkey) error

GetAllPubkeys receives a pointer to a slice and fills it up with all public keys

func (*Client) GetAllTokens

func (c *Client) GetAllTokens(tokens *[]Token) error

GetAllTokens receives a pointer to a slice and fills it up with all tokens

func (*Client) GetAllWings

func (c *Client) GetAllWings(wings *[]Wing) error

func (*Client) GetKnot

func (c *Client) GetKnot(ip, port string) (Knot, error)

GetKnot returns all keys belonging to a knot in the database keys will always start with "knot:"

func (*Client) GetPubkey

func (c *Client) GetPubkey(pubkey string) (Pubkey, error)

GetPubkey receives a string and returns the pubkey or an error

func (*Client) GetWing

func (c *Client) GetWing(name string) (Wing, error)

func (*Client) InitDB

func (c *Client) InitDB()

InitDB starts the connection to etcd

func (*Client) PutKnot

func (c *Client) PutKnot(knot Knot) error

PutKnot validates the IP and after that adds the knot in the DB If a knot already exists for the IP:Port combination, it returns error

func (*Client) PutPubkey

func (c *Client) PutPubkey(pubkey Pubkey) error

PutPubkey allows you to add a public key to the database The function also adds the wing to prefix "wings:" The public key must be unique so an error is returned if it is found in the DB

type KVPair

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

KVPair can be used to send data at etcd

type Knot

type Knot struct {
	IP            string
	Port          string
	Name          string
	Wings         []string
	BootTimestamp time.Time
}

Knot holds informaton

func (Knot) GetIPPort

func (k Knot) GetIPPort() string

GetIPPort is used when you need IP.Port This function is here so that you see that we use . instead of :

type Pubkey

type Pubkey struct {
	Pubkey string
	Owner  string
	Wings  []string
}

Pubkey struct hold information about a public key wings are just a slice of strings

type Token

type Token struct {
	Secret string
	Owner  string
	Wings  []string
}

Token structure holds all information regarding the token. These tokens are designed to be used only one time.

type Wing

type Wing struct {
	Name    string
	Pubkeys []string
	Knots   []string
}

Jump to

Keyboard shortcuts

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