api

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AccountsHost is the host on which the accounts service is listening.
	// NOTE: this variable is overwritten with what is set in the environment
	AccountsHost = "accounts"

	// AccountsPort is the port on which the accounts service is listening.
	// NOTE: this variable is overwritten with what is set in the environment
	AccountsPort = "3000"
)

Functions

func UserFromReq

func UserFromReq(req *http.Request, logger *logrus.Logger) (*database.User, error)

UserFromReq identifies the user making the request by reading the attached skynet cookie and querying Accounts service for the user's info.

func WriteError added in v0.1.1

func WriteError(w http.ResponseWriter, err error, code int)

WriteError wraps WriteError from the skyd node api

Types

type API

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

API is our central entry point to all subsystems relevant to serving requests.

func New

func New(skydClient *SkydClient, db *database.DB, logger *logrus.Logger) (*API, error)

New creates a new API instance.

func (*API) ListenAndServe

func (api *API) ListenAndServe(port int) error

ListenAndServe starts the API server on the given port.

func (*API) ServeHTTP

func (api *API) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements the http.Handler interface.

type BlockPOST

type BlockPOST struct {
	Skylink  skylink  `json:"skylink"`
	Reporter Reporter `json:"reporter"`
	Tags     []string `json:"tags"`

	// Hash represents the hash of the Skylink's merkle root. Either 'hash'
	// or 'skylink' must be set. If both are set the Skylink's hash value
	// must correspond with the hash.
	//
	// It is encouraged to use this field when possible as it allows
	// services that interact with the blocker to only deal with hashes
	// instead of skylinks.
	Hash crypto.Hash `json:"hash"`
}

BlockPOST describes a request to the /block endpoint.

type BlockResponse

type BlockResponse struct {
	Invalids []InvalidInput `json:"invalids"`
}

BlockResponse is the response object returned by the Skyd API's block endpoint

func (*BlockResponse) InvalidHashes

func (br *BlockResponse) InvalidHashes() ([]database.Hash, error)

InvalidHashes is a helper method that converts the list of invalid inputs to an array of hashes.

type BlockWithPoWGET

type BlockWithPoWGET struct {
	Target string `json:"target"`
}

BlockWithPoWGET is the response a user gets from the /blockpow endpoint.

type BlockWithPoWPOST

type BlockWithPoWPOST struct {
	BlockPOST
	PoW modules.BlockPoW `json:"pow"`
}

BlockWithPoWPOST describes a request to the /blockpow endpoint containing a pow.

type BlockedHash

type BlockedHash struct {
	Hash crypto.Hash `json:"hash"`
	Tags []string    `json:"tags"`
}

BlockedHash describes a blocked hash along with the set of tags it was reported with

type BlocklistGET

type BlocklistGET struct {
	Entries []BlockedHash `json:"entries"`
	HasMore bool          `json:"hasmore"`
}

BlocklistGET returns a list of blocked hashes

type DaemonReadyResponse

type DaemonReadyResponse struct {
	Ready     bool `json:"ready"`
	Consensus bool `json:"consensus"`
	Gateway   bool `json:"gateway"`
	Renter    bool `json:"renter"`
}

DaemonReadyResponse is the response object returned by the Skyd API's ready endpoint

type InvalidInput

type InvalidInput struct {
	Input string `json:"input"`
	Error string `json:"error"`
}

InvalidInput is a struct that wraps the invalid input along with an error string indicating why it was deemed invalid

type Reporter

type Reporter struct {
	Name         string `json:"name"`
	Email        string `json:"email"`
	OtherContact string `json:"othercontact"`
}

Reporter is a person who reported that a given skylink should be blocked.

type SkydClient

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

SkydClient is a helper struct that gets initialised using a portal url. It exposes API methods and abstracts the response handling.

func NewCustomSkydClient

func NewCustomSkydClient(portalURL string, headers http.Header) *SkydClient

NewCustomSkydClient returns a new SkydClient instance for given portal url and lets you pass a set of headers that will be set on every request.

func NewSkydClient

func NewSkydClient(portalURL, apiPassword string) *SkydClient

NewSkydClient returns a client that has the default user-agent set.

func (*SkydClient) BlockHashes

func (c *SkydClient) BlockHashes(hashes []database.Hash) ([]database.Hash, []database.Hash, error)

BlockHashes will perform an API call to skyd to block the given hashes. It returns which hashes were blocked, which hashes were invalid and potentially an error.

func (*SkydClient) BlocklistGET

func (c *SkydClient) BlocklistGET(offset int) (*BlocklistGET, error)

BlocklistGET calls the `/portal/blocklist` endpoint with given parameters

func (*SkydClient) DaemonReady

func (c *SkydClient) DaemonReady() bool

DaemonReady connects to the local skyd and checks its status. Returns true only if skyd is fully ready.

func (c *SkydClient) ResolveSkylink(skylink skymodules.Skylink) (skymodules.Skylink, error)

ResolveSkylink will resolve the given skylink.

Jump to

Keyboard shortcuts

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