sips

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: MIT Imports: 10 Imported by: 0

README

SIPS

GitHub tag (latest SemVer) Go Report Card

Disclaimer: SIPS is still in early development and is not guaranteed to do much of anything. Although it should function for basic usage, expect bugs, and definitely don't use it for anything that has money associated with it.

SIPS is a Simple IPFS Pinning Service. It does the bare minimum necessary to present a functional pinning service.

Setup

After installation, SIPS will have no users or tokens in its database. To create some, use the sipsctl utility that is provided:

$ sipsctl users add whateverUsernameYouWant
$ sipsctl tokens add --user whateverUsernameYouWant

You can then use that token with a pinning service client to add, remove, and list pins.

Documentation

Overview

Package sips provides structures for implementing an IPFS pinning service.

The primary purpose of this package is to allow a user to create an IPFS pinning service with minimal effort. The package is based around the PinHandler interface. An implementation of this interface can be passed to the Handler function in order to create an HTTP handler that serves a valid pinning service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(h PinHandler) http.Handler

Handler returns a new HTTP handler that uses h to handle pinning service requests. It will handle requests to the "/pins" path and related subpaths, so the user does not need to strip the prefix in order to use it.

func Token

func Token(ctx context.Context) (string, bool)

Token returns the auth token associated with the context.

Types

type Pin

type Pin struct {
	CID     string      `json:"cid"`
	Name    string      `json:"name"`
	Origins []string    `json:"origins"`
	Meta    interface{} `json:"meta,omitempty"`
}

Pin describes a single pinned item.

type PinHandler

type PinHandler interface {
	// Pins returns a list of pinning request statuses based on the
	// given query.
	Pins(ctx context.Context, query PinQuery) ([]PinStatus, error)

	// AddPin adds a new pin to the service's backend.
	AddPin(ctx context.Context, pin Pin) (PinStatus, error)

	// GetPin gets the status of a specific pinning request.
	GetPin(ctx context.Context, requestID string) (PinStatus, error)

	// UpdatePin replaces a pinning request's pin with new info.
	UpdatePin(ctx context.Context, requestID string, pin Pin) (PinStatus, error)

	// DeletePin removes a pinning request.
	DeletePin(ctx context.Context, requestID string) error
}

PinHandler is an interface satisfied by types that can be used to handle pinning service requests.

Every method is called after the authentication token is pulled from HTTP headers, so it can be assumed that a token is included in the provided context. It should not, however, be assumed that the token is valid.

Errors returned by a PinHandler's methods are returned to the client verbatim, so implementations should be careful not to include data that shouldn't be shown to clients in them. If an error implements StatusError, the HTTP status code returned will be whatever the error's Status method returns.

type PinQuery

type PinQuery struct {
	// CID is a list CIDs that are being searched for.
	CID []string

	// Name is the name of the desired pinning request.
	Name string

	// Match is the strategy to use for finding the name.
	Match TextMatchingStrategy

	// Status is a list of statuses used to filter the returned
	// requests.
	Status []RequestStatus

	// Before and After indicate creation time filters.
	Before, After time.Time

	// Limit is the maximum number of results that should be returned.
	// If the handler returns more than this, the list will be truncated
	// to match the value of this field.
	Limit int

	// Meta is used to filter against the Meta field of the returned
	// requests. Note that this is simply the result of unmarshalling
	// json using the encoding/json package, so it will likely be a
	// map[string]interface{}, but it might not be, either. It is up to
	// the handler to deal with this as it sees fit.
	Meta interface{}
}

PinQuery provides query info for finding pinning requests. Any fields which are zero values, or have length zero in the case of slices, should be considered as though they are not present.

type PinStatus

type PinStatus struct {
	RequestID string        `json:"requestid"`
	Status    RequestStatus `json:"status"`
	Created   time.Time     `json:"created"`
	Delegates []string      `json:"delegates"`
	Info      interface{}   `json:"info,omitempty"`

	Pin Pin `json:"pin"`
}

PinStatus indicates the status of a pinning request and provides associated info.

type RequestStatus

type RequestStatus string

RequestStatus is the status of a given pinning request.

const (
	Queued  RequestStatus = "queued"
	Pinning RequestStatus = "pinning"
	Pinned  RequestStatus = "pinned"
	Failed  RequestStatus = "failed"
)

type StatusError added in v0.1.2

type StatusError interface {
	Status() int
}

StatusError is implemented by errors returned by PinHandler implementations that want to send custom status codes to the client.

Several status codes have special handling. These include

  • 400 Bad Request
  • 401 Unauthorized
  • 404 Not Found
  • 409 Conflict

These status codes will produce special error messages for the client. All other status codes will produce the same error message as a 500 Internal Server Error code does.

type TextMatchingStrategy

type TextMatchingStrategy string

TextMatchingStrategy indicates a strategy to use for matching one string against another.

const (
	Exact    TextMatchingStrategy = "exact"
	IExact   TextMatchingStrategy = "iexact"
	Partial  TextMatchingStrategy = "partial"
	IPartial TextMatchingStrategy = "ipartial"
)

func (TextMatchingStrategy) Match

func (tms TextMatchingStrategy) Match(haystack, needle string) bool

Match performs a match using the specified strategy. It will panic if the strategy provided is invalid.

Directories

Path Synopsis
cmd
sips
sips is the primary implementation of a simple pinning service daemon.
sips is the primary implementation of a simple pinning service daemon.
sipsctl
sipsctl is a simple utility for administrating the database used by SIPS.
sipsctl is a simple utility for administrating the database used by SIPS.
internal
cli
log

Jump to

Keyboard shortcuts

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