openapi

package
v0.0.0-...-89def8d Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 1 Imported by: 0

README

Go API Server for openapi

About this spec

The IPFS Pinning Service API is intended to be an implementation-agnostic API:

  • For use and implementation by pinning service providers
  • For use in client mode by IPFS nodes and GUI-based applications

Note: while ready for implementation, this spec is still a work in progress! 🏗️ Your input and feedback are welcome and valuable as we develop this API spec. Please join the design discussion at github.com/ipfs/pinning-services-api-spec.

Schemas

This section describes the most important object types and conventions.

A full list of fields and schemas can be found in the schemas section of the YAML file.

Identifiers

cid

Content Identifier (CID) points at the root of a DAG that is pinned recursively.

requestid

Unique identifier of a pin request.

When a pin is created, the service responds with unique requestid that can be later used for pin removal. When the same cid is pinned again, a different requestid is returned to differentiate between those pin requests.

Service implementation should use UUID, hash(accessToken,Pin,PinStatus.created), or any other opaque identifier that provides equally strong protection against race conditions.

Objects

Pin object

pin object

The Pin object is a representation of a pin request.

It includes the cid of data to be pinned, as well as optional metadata in name, origins, and meta.

Pin status response

pin status response object

The PinStatus object is a representation of the current state of a pinning operation. It includes the original pin object, along with the current status and globally unique requestid of the entire pinning request, which can be used for future status checks and management. Addresses in the delegates array are peers delegated by the pinning service for facilitating direct file transfers (more details in the provider hints section). Any additional vendor-specific information is returned in optional info.

The pin lifecycle

pinning service objects and lifecycle

Creating a new pin object

The user sends a Pin object to POST /pins and receives a PinStatus response:

  • requestid in PinStatus is the identifier of the pin operation, which can can be used for checking status, and removing the pin in the future
  • status in PinStatus indicates the current state of a pin

Checking status of in-progress pinning

status (in PinStatus) may indicate a pending state (queued or pinning). This means the data behind Pin.cid was not found on the pinning service and is being fetched from the IPFS network at large, which may take time.

In this case, the user can periodically check pinning progress via GET /pins/{requestid} until pinning is successful, or the user decides to remove the pending pin.

Replacing an existing pin object

The user can replace an existing pin object via POST /pins/{requestid}. This is a shortcut for removing a pin object identified by requestid and creating a new one in a single API call that protects against undesired garbage collection of blocks common to both pins. Useful when updating a pin representing a huge dataset where most of blocks did not change. The new pin object requestid is returned in the PinStatus response. The old pin object is deleted automatically.

Removing a pin object

A pin object can be removed via DELETE /pins/{requestid}.

Provider hints

A pinning service will use the DHT and other discovery methods to locate pinned content; however, it is a good practice to provide additional provider hints to speed up the discovery phase and start the transfer immediately, especially if a client has the data in their own datastore or already knows of other providers.

The most common scenario is a client putting its own IPFS node's multiaddrs in Pin.origins, and then attempt to connect to every multiaddr returned by a pinning service in PinStatus.delegates to initiate transfer. At the same time, a pinning service will try to connect to multiaddrs provided by the client in Pin.origins.

This ensures data transfer starts immediately (without waiting for provider discovery over DHT), and mutual direct dial between a client and a service works around peer routing issues in restrictive network topologies, such as NATs, firewalls, etc.

NOTE: Connections to multiaddrs in origins and delegates arrays should be attempted in best-effort fashion, and dial failure should not fail the pinning operation. When unable to act on explicit provider hints, DHT and other discovery methods should be used as a fallback by a pinning service.

NOTE: All multiaddrs MUST end with /p2p/{peerID} and SHOULD be fully resolved and confirmed to be dialable from the public internet. Avoid sending addresses from local networks.

Custom metadata

Pinning services are encouraged to add support for additional features by leveraging the optional Pin.meta and PinStatus.info fields. While these attributes can be application- or vendor-specific, we encourage the community at large to leverage these attributes as a sandbox to come up with conventions that could become part of future revisions of this API.

Pin metadata

String keys and values passed in Pin.meta are persisted with the pin object.

Potential uses:

  • Pin.meta[app_id]: Attaching a unique identifier to pins created by an app enables filtering pins per app via ?meta={\"app_id\":<UUID>}
  • Pin.meta[vendor_policy]: Vendor-specific policy (for example: which region to use, how many copies to keep)

Note that it is OK for a client to omit or ignore these optional attributes; doing so should not impact the basic pinning functionality.

Pin status info

Additional PinStatus.info can be returned by pinning service.

Potential uses:

  • PinStatus.info[status_details]: more info about the current status (queue position, percentage of transferred data, summary of where data is stored, etc); when PinStatus.status=failed, it could provide a reason why a pin operation failed (e.g. lack of funds, DAG too big, etc.)
  • PinStatus.info[dag_size]: the size of pinned data, along with DAG overhead
  • PinStatus.info[raw_size]: the size of data without DAG overhead (eg. unixfs)
  • PinStatus.info[pinned_until]: if vendor supports time-bound pins, this could indicate when the pin will expire

Pagination and filtering

Pin objects can be listed by executing GET /pins with optional parameters:

  • When no filters are provided, the endpoint will return a small batch of the 10 most recently created items, from the latest to the oldest.
  • The number of returned items can be adjusted with the limit parameter (implicit default is 10).
  • If the value in PinResults.count is bigger than the length of PinResults.results, the client can infer there are more results that can be queried.
  • To read more items, pass the before filter with the timestamp from PinStatus.created found in the oldest item in the current batch of results. Repeat to read all results.
  • Returned results can be fine-tuned by applying optional after, cid, name, status, or meta filters.

Note: pagination by the created timestamp requires each value to be globally unique. Any future considerations to add support for bulk creation must account for this.

Overview

This server was generated by the [openapi-generator] (https://openapi-generator.tech) project. By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.

To see how to make this your own, look here:

README

  • API version: 1.0.0
  • Build date: 2021-03-17T15:36:11.936787-07:00[America/Los_Angeles]
Running the server

To run the server, follow these simple steps:

go run main.go

To run the server in a docker container

docker build --network=host -t openapi .

Once the image is built, just run

docker run --rm -it openapi 
Known Issue

Endpoints sharing a common path may result in issues. For example, /v2/pet/findByTags and /v2/pet/:petId will result in an issue with the Gin framework. For more information about this known limitation, please refer to gin-gonic/gin#388 for more information.

A workaround is to manually update the path and handler. Please refer to gin-gonic/gin/issues/205#issuecomment-296155497 for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Failure

type Failure struct {
	Error FailureError `json:"error"`
}

Failure - Response for a failed request

type FailureError

type FailureError struct {

	// Mandatory string identifying the type of error
	Reason string `json:"reason"`

	// Optional, longer description of the error; may include UUID of transaction for support, links to documentation etc
	Details string `json:"details,omitempty"`
}

type Pin

type Pin struct {

	// Content Identifier (CID) to be pinned recursively
	Cid string `json:"cid"`

	// Optional name for pinned data; can be used for lookups later
	Name string `json:"name,omitempty"`

	// Optional list of multiaddrs known to provide the data
	Origins []string `json:"origins,omitempty"`

	// Optional metadata for pin object
	Meta map[string]string `json:"meta,omitempty"`
}

Pin - Pin object

type PinResults

type PinResults struct {

	// The total number of pin objects that exist for passed query filters
	Count int32 `json:"count"`

	// An array of PinStatus results
	Results []PinStatus `json:"results"`
}

PinResults - Response used for listing pin objects matching request

type PinStatus

type PinStatus struct {

	// Globally unique identifier of the pin request; can be used to check the status of ongoing pinning, or pin removal
	Requestid string `json:"requestid"`

	Status Status `json:"status"`

	// Immutable timestamp indicating when a pin request entered a pinning service; can be used for filtering results and pagination
	Created time.Time `json:"created"`

	Pin Pin `json:"pin"`

	// List of multiaddrs designated by pinning service for transferring any new data from external peers
	Delegates []string `json:"delegates"`

	// Optional info for PinStatus response
	Info map[string]string `json:"info,omitempty"`
}

PinStatus - Pin object with status

type Query

type Query struct {
	// Cid can be used to filter by one or more Pin Cids.
	Cid []string `form:"cid" json:"cid,omitempty"`
	// Name can be used to filer by Pin name (by default case-sensitive, exact match).
	Name string `form:"name" json:"name,omitempty"`
	// Match can be used to customize the text matching strategy applied when Name is present.
	Match string `form:"match" json:"match,omitempty"`
	// Status can be used to filter by Pin status.
	Status string `form:"status" json:"status,omitempty"`
	// Before can by used to filter by before creation (queued) time.
	Before time.Time `form:"before" json:"before,omitempty"`
	// After can by used to filter by after creation (queued) time.
	After time.Time `form:"after" json:"after,omitempty"`
	// Limit specifies the max number of Pins to return.
	Limit int32 `form:"limit" json:"limit,omitempty"`
}

Query represents Pin query parameters. This is derived from the openapi spec using https://github.com/deepmap/oapi-codegen, not https://github.com/OpenAPITools/openapi-generator, which doens't output anything for the listPins query body.

type QueryMeta

type QueryMeta map[string]string

QueryMeta can be used to filter results by Pin metadata. This was pulled out of the openapi generated Query above because gin is not able to auto parse the map string value sent by the generic pinning client, i.e., "meta=map[foo:one bar:two]".

type Status

type Status string

Status : Status a pin object can have at a pinning service

const (
	QUEUED  Status = "queued"
	PINNING Status = "pinning"
	PINNED  Status = "pinned"
	FAILED  Status = "failed"
)

List of Status

type TextMatchingStrategy

type TextMatchingStrategy string

TextMatchingStrategy : Alternative text matching strategy

const (
	EXACT    TextMatchingStrategy = "exact"
	IEXACT   TextMatchingStrategy = "iexact"
	PARTIAL  TextMatchingStrategy = "partial"
	IPARTIAL TextMatchingStrategy = "ipartial"
)

List of TextMatchingStrategy

Jump to

Keyboard shortcuts

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