client

package module
Version: v0.0.0-...-93b26d4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 21 Imported by: 4

README

HTTP Client for keys.pub

This documentation is in progress.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

Types

type Client

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

Client ...

func New

func New(urs string) (*Client, error)

New creates a Client for the a Web API.

func (*Client) AdminCheck

func (c *Client) AdminCheck(ctx context.Context, check string, admin *keys.EdX25519Key) error

AdminCheck performs user & sigchain associated with key by an admin. The server periodically checks users and sigchains, but this tells the server to do it right away. If check is a kid, will check that key. If check is "all" (not recommended), it will check all keys.

func (*Client) Check

func (c *Client) Check(ctx context.Context, key *keys.EdX25519Key) error

Check user & sigchain associated with edx25519 key. The server periodically checks users and sigchains, but this tells the server to do it right away.

func (*Client) Disco

func (c *Client) Disco(ctx context.Context, sender keys.ID, recipient *keys.EdX25519Key, typ DiscoType) (string, error)

Disco gets a discovery address.

func (*Client) DiscoDelete

func (c *Client) DiscoDelete(ctx context.Context, sender *keys.EdX25519Key, recipient keys.ID) error

DiscoDelete removes discovery addresses.

func (*Client) DiscoSave

func (c *Client) DiscoSave(ctx context.Context, sender *keys.EdX25519Key, recipient keys.ID, typ DiscoType, data string, expire time.Duration) error

DiscoSave puts a discovery offer or answer.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *nethttp.Client

HTTPClient we are using.

func (*Client) InviteCode

func (c *Client) InviteCode(ctx context.Context, sender *keys.EdX25519Key, code string) (*api.InviteCodeResponse, error)

InviteCode looks for an invite with code.

func (*Client) InviteCodeCreate

func (c *Client) InviteCodeCreate(ctx context.Context, sender *keys.EdX25519Key, recipient keys.ID) (*api.InviteCodeCreateResponse, error)

InviteCodeCreate creates an invite code.

func (*Client) Request

func (c *Client) Request(ctx context.Context, req *Request) (*Response, error)

Request makes a request.

func (*Client) SetClock

func (c *Client) SetClock(clock tsutil.Clock)

SetClock sets the clock Now fn.

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(httpClient *nethttp.Client)

SetHTTPClient sets the http.Client to use.

func (*Client) ShareOpen

func (c *Client) ShareOpen(ctx context.Context, key *keys.EdX25519Key) ([]byte, error)

ShareOpen opens a secret.

func (*Client) ShareSeal

func (c *Client) ShareSeal(ctx context.Context, key *keys.EdX25519Key, data []byte, expire time.Duration) error

ShareSeal saves a secret on remote with expire.

func (*Client) Sigchain

func (c *Client) Sigchain(ctx context.Context, kid keys.ID) (*api.SigchainResponse, error)

Sigchain for KID. If sigchain not found, a nil response is returned.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/keys-pub/keys"
	"github.com/keys-pub/keys-ext/http/client"
	"github.com/keys-pub/keys/http"
	"github.com/keys-pub/keys/user"
	"github.com/keys-pub/keys/user/services"
)

func main() {
	cl, err := client.New("https://keys.pub")
	if err != nil {
		log.Fatal(err)
	}

	// Get the keys.Sigchain.
	kid := keys.ID("kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3")
	resp, err := cl.Sigchain(context.TODO(), kid)
	if err != nil {
		log.Fatal(err)
	}
	sc, err := resp.Sigchain()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", sc.Spew())

	// Find the user.User in the keys.Sigchain.
	usr, err := user.FindInSigchain(sc)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", usr)

	// Verify the user.
	result := services.Verify(context.TODO(), services.HTTPS, http.NewClient(), usr)
	if result.Status != user.StatusOK {
		log.Fatalf("User check failed: %+v", result)
	}

	// Check result status.
	fmt.Printf("%s\n", result.Status)

}
Output:

/sigchain/kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3/1 {".sig":"Rf39uRlHXTqmOjcqUs5BTssshRdqpaFfmoYYJuA5rNVGgGd/bRG8p8ZebB8K+w9kozMpnuAoa4lko+oPHcabCQ==","data":"eyJrIjoia2V4MXlkZWNhdWxzZzVxdHkyYXh5eTc3MGNqZHZxbjNlZjJxYTg1eHc4N3AwOXlkbHZzNWx1cnE1M3gwcDMiLCJuIjoia2V5cy5wdWIiLCJzcSI6MSwic3IiOiJodHRwcyIsInUiOiJodHRwczovL2tleXMucHViL2tleXNwdWIudHh0In0=","kid":"kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3","seq":1,"ts":1588276919715,"type":"user"}
keys.pub@https!kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3-1#https://keys.pub/keyspub.txt
ok

func (*Client) SigchainSave

func (c *Client) SigchainSave(ctx context.Context, st *keys.Statement) error

SigchainSave ...

func (*Client) URL

func (c *Client) URL() *url.URL

URL ...

func (*Client) User

func (c *Client) User(ctx context.Context, kid keys.ID) (*api.UserResponse, error)

User ...

func (*Client) UserSearch

func (c *Client) UserSearch(ctx context.Context, query string, limit int) (*api.UserSearchResponse, error)

UserSearch ...

type ContextLogger

type ContextLogger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

ContextLogger interface used in this package with request context.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type DiscoType

type DiscoType string

DiscoType is the type of discovery address.

const (
	// Offer initiates.
	Offer DiscoType = "offer"
	// Answer listens.
	Answer DiscoType = "answer"
)

type Error

type Error struct {
	StatusCode int      `json:"code"`
	Message    string   `json:"message"`
	URL        *url.URL `json:"url,omitempty"`
}

Error ...

func (Error) Error

func (e Error) Error() string

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

Logger interface used in this package.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

type Request

type Request struct {
	Method string
	Path   string
	Params url.Values
	// Body        io.Reader
	// ContentHash string
	Body     []byte
	Key      *keys.EdX25519Key
	Headers  []http.Header
	Progress func(n int64)
}

Request ...

type Response

type Response struct {
	Data      []byte
	CreatedAt time.Time
	UpdatedAt time.Time
}

Response ...

Jump to

Keyboard shortcuts

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