client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: BSD-3-Clause Imports: 23 Imported by: 5

Documentation

Overview

This package contains the implementation of the InterlockLedger Node REST API client.

Its code is based on the code generated by the Swagger code generator created from the openapi.json from the InterlockLedger node. It has been manually patched to get a better code organization and implement some features that could not be auto generated.

From this version onward, all code for this package will be manually updated to ensure full backward compatibility.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// This error is used to report optimistic lock errors in some APIs. Those
	// errors are usually associated with the return 409 when the parameter
	// `lastChangedRecordSerial` is sent with the incorrect value.
	ErrOptimisticLockError = errors.New("optimistic lock failed")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

func GetHeaderInt64 added in v0.2.0

func GetHeaderInt64(headers http.Header, name string, defVal int64) (int64, error)

Helper function used to extract int64 values from a header.

It returns the value of the header if it is valid. The default value if it is not present or the default value and an error if the header is invalid.

Types

type APIClient

type APIClient struct {
	ChainApi *ChainApiService

	DocumentsApi *DocumentsApiService

	JsonDocumentApi *JsonDocumentApiService

	NodeApi *NodeApiService

	RecordApi *RecordApiService

	OpaqueApi *OpaqueService
	// contains filtered or unexported fields
}

APIClient manages communication with the InterlockLedger Node REST API API vv7.2.0 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

Example
// Creates a new configuration.
configuration := NewConfiguration()
// Set the name of the server here
configuration.BasePath = "https://your_node_server:port/"
// Sets the required client certificate. Without it, you will not be able to
// access the node as client certificate is the only authentication method
// accepted by the client.
err := configuration.SetClientCertificate("cert.pem", "key.pem")
if err != nil {
	fmt.Fprintf(os.Stderr, "Unable to load the client certificate: %v\n", err)
	os.Exit(1)
}
// Create the new client
client := NewAPIClient(configuration)

// Query the version of the server.
version, _, err := client.NodeApi.ApiVersion(context.TODO())
if err != nil {
	fmt.Fprintf(os.Stderr, "Unable to query the server's version: %v\n", err)
	os.Exit(1)
}
fmt.Printf("The server's version is %s\n", version)
Output:

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

func (*APIClient) ToGenericSwaggerError

func (c *APIClient) ToGenericSwaggerError(err error) *GenericSwaggerError

This helper function tries to convert a given error into a GenericSwaggerError. Returns nil if the type does not match.

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the swagger operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

This is an API response.

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

Creates a new API response.

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

Creates a new API response with an error.

type ChainApiChainInterlockingsListOpts

type ChainApiChainInterlockingsListOpts struct {
	HowManyFromLast optional.Int32
	Page            optional.Int32
	PageSize        optional.Int32
}

Optional parameters of GET /chain/{chain}/interlockings.

type ChainApiService

type ChainApiService service

Chain API service.

func (*ChainApiService) ChainActiveAppsAdd

func (a *ChainApiService) ChainActiveAppsAdd(ctx context.Context, chain string, localVarPostBody []int64) ([]int64, *http.Response, error)

Calls POST /chain/{chain}/activeApps.

func (*ChainApiService) ChainActiveAppsList

func (a *ChainApiService) ChainActiveAppsList(ctx context.Context, chain string) ([]int64, *http.Response, error)

Calls GET /chain/{chain}/activeApps.

func (*ChainApiService) ChainCreate

Calls POST /chain.

func (*ChainApiService) ChainDetails

func (a *ChainApiService) ChainDetails(ctx context.Context, chain string) (models.ChainSummaryModel, *http.Response, error)

Calls GET /chain/{chain}.

func (*ChainApiService) ChainInterlockingAdd

func (*ChainApiService) ChainInterlockingsList

Calls GET /chain/{chain}/interlockings.

func (*ChainApiService) ChainPermittedKeysAdd

func (a *ChainApiService) ChainPermittedKeysAdd(ctx context.Context, chain string, keys []models.KeyPermitModel) ([]models.KeyDetailsModel, *http.Response, error)

func (*ChainApiService) ChainPermittedKeysList

func (a *ChainApiService) ChainPermittedKeysList(ctx context.Context, chain string) ([]models.KeyDetailsModel, *http.Response, error)

Calls GET /chain/{chain}/key.

func (*ChainApiService) ChainsList

Calls GET /chain.

type Configuration

type Configuration struct {
	// Base path of the server API.
	BasePath string `json:"basePath,omitempty"`
	// The name of the host.
	Host string `json:"host,omitempty"`
	// The scheme to be used.
	Scheme string `json:"scheme,omitempty"`
	// Set of headers to be sent on all requests.
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	// The client's user agent.
	UserAgent string `json:"userAgent,omitempty"`
	// If true, the server connections will not be validated.
	NoServerVerification bool `json:"noServerVerification"`
	// Path to the client certificate file (PEM).
	CertFile string `json:"certFile,omitempty"`
	// Path to the client key file (PEM).
	KeyFile string `json:"keyFile,omitempty"`
	// Path to the client PFX certificate/key file.
	PFXFile string `json:"pfxFile,omitempty"`
	// Password of the client PFX certificate/key file.
	PFXPassword string `json:"pfxPassword,omitempty"`
	// The client associated with this configuration.
	HTTPClient *http.Client `json:"-"`
	// The set of client certificates to be used. It will be initialized according
	// to the current configuration if necessary.
	ClientCertificates []tls.Certificate `json:"-"`
	// The certificate pool to be used. It will be automatically initialized
	// when required.
	CertPool *x509.CertPool `json:"-"`
}

Configuration of the client.

func NewConfiguration

func NewConfiguration() *Configuration

Creates a new client configuration.

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

Adds custom headers to all connections from this client.

func (*Configuration) Init added in v0.2.0

func (c *Configuration) Init() error

Initializes the inner HTTPClient using the current parameters.

It will load the client certificate from either PFXFile (preffered) or CertFile/KeyFile parameters and enable or disable the server verification based on the value of NoServerVerification.

If called more than once, the previos HTTPClient will be replaced by the new one.

On success, if the fields CertPool and ClientCertificates are not initialized, they will be initialized according to the current configuration.

If fails if there is no valid client certificate to load.

func (*Configuration) SetClientCert added in v0.2.0

func (c *Configuration) SetClientCert(cert tls.Certificate, noServerVerification bool) error

Loads the client certificate required to access the API and sets the `http.Client`.

func (*Configuration) SetClientCertificate

func (c *Configuration) SetClientCertificate(certificateFile string, keyFile string) error

Loads the client certificate required to access the API and sets the `http.Client`.

func (*Configuration) SetClientCertificateEx added in v0.2.0

func (c *Configuration) SetClientCertificateEx(
	certificateFile string, keyFile string, noServerVerification bool) error

Loads the client certificate required to access the API and sets the `http.Client`.

func (*Configuration) SetClientCertificatePKCS12 added in v0.2.0

func (c *Configuration) SetClientCertificatePKCS12(file string, password string) error

Loads the client certificate required to access the API and sets the `http.Client`.

func (*Configuration) SetClientCertificatePKCS12Ex added in v0.2.0

func (c *Configuration) SetClientCertificatePKCS12Ex(
	file string, password string, noServerVerification bool) error

Loads the client certificate required to access the API and sets the `http.Client`.

type DocumentsApiDocumentsAddDocumentParams

type DocumentsApiDocumentsAddDocumentParams struct {
	Name        string
	Comment     string
	Path        string
	ContentType string
	Contents    io.Reader
}

Parameters of POST /documents/transaction/{transactionId}.

type DocumentsApiService

type DocumentsApiService service

Document API service.

func (*DocumentsApiService) DocumentsAddDocument

Calls POST /documents/transaction/{transactionId}.

func (*DocumentsApiService) DocumentsBeginTransaction

Calls POST /documents/transaction

func (*DocumentsApiService) DocumentsCommitTransaction

func (a *DocumentsApiService) DocumentsCommitTransaction(ctx context.Context, transactionId string) (string, *http.Response, error)

Calls POST /documents/transaction/{transactionId}/commit.

func (*DocumentsApiService) DocumentsGetAllDocuments

func (a *DocumentsApiService) DocumentsGetAllDocuments(ctx context.Context, locator string) (*http.Response, error)

Calls GET /documents/{locator}/zip.

On success, the Body inside the returned http.Response.Body will have a stream to the contents of the file. The caller must close http.Response.Body when it is no longer required.

func (*DocumentsApiService) DocumentsGetConfig

Calls GET /documents/configuration.

func (*DocumentsApiService) DocumentsGetMetadata

func (a *DocumentsApiService) DocumentsGetMetadata(ctx context.Context, locator string) (models.DocumentsMetadataModel, *http.Response, error)

Calls GET /documents/{locator}/metadata.

func (*DocumentsApiService) DocumentsGetSingleDocument

func (a *DocumentsApiService) DocumentsGetSingleDocument(ctx context.Context, locator string, index int32) (*http.Response, error)

Calls GET /documents/{locator}/{index}.

On success, the Body inside the returned http.Response.Body will have a stream to the contents of the file. The caller must close http.Response.Body when it is no longer required.

func (*DocumentsApiService) DocumentsGetTransactionStatus

func (a *DocumentsApiService) DocumentsGetTransactionStatus(ctx context.Context, transactionId string) (models.DocumentsTransactionModel, *http.Response, error)

Calls GET /documents/transaction/{transactionId}.

type GenericSwaggerError

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

GenericSwaggerError Provides access to the body, error and model on returned errors.

func (GenericSwaggerError) Body

func (e GenericSwaggerError) Body() []byte

Body returns the raw bytes of the response

func (GenericSwaggerError) Error

func (e GenericSwaggerError) Error() string

Error returns non-empty string if there was an error.

func (GenericSwaggerError) Model

func (e GenericSwaggerError) Model() interface{}

Model returns the unpacked model of the error

type JsonDocumentApiService

type JsonDocumentApiService service

func (*JsonDocumentApiService) JsonDocumentsAdd

func (a *JsonDocumentApiService) JsonDocumentsAdd(ctx context.Context, chain string, jsonDoc models.Object) (models.JsonDocumentModel, *http.Response, error)

Calls POST /jsonDocuments@{chain}.

func (*JsonDocumentApiService) JsonDocumentsAddWithChainKeys

func (a *JsonDocumentApiService) JsonDocumentsAddWithChainKeys(ctx context.Context, chain string, xPubKeyChains []string, jsonDoc models.Object) (models.JsonDocumentModel, *http.Response, error)

Calls POST /jsonDocuments@{chain}/withChainKeys

func (*JsonDocumentApiService) JsonDocumentsAddWithIndirectKeys

func (a *JsonDocumentApiService) JsonDocumentsAddWithIndirectKeys(ctx context.Context, chain string, xPubKeyReferences []string,
	jsonDoc models.Object) (models.JsonDocumentModel, *http.Response, error)

Calls POST /jsonDocuments@{chain}/withIndirectKeys.

func (*JsonDocumentApiService) JsonDocumentsAddWithKey

func (a *JsonDocumentApiService) JsonDocumentsAddWithKey(ctx context.Context, chain string, xPubKey string, xPubKeyId string, jsonDoc models.Object) (models.JsonDocumentModel, *http.Response, error)

Calls POST /jsonDocuments@{chain}/withKey.

func (*JsonDocumentApiService) JsonDocumentsAllowReaders

func (a *JsonDocumentApiService) JsonDocumentsAllowReaders(ctx context.Context, chain string,
	allowedReaders *models.AllowedReadersModel) (string, *http.Response, error)

Calls POST /jsonDocuments@{chain}/allow.

func (*JsonDocumentApiService) JsonDocumentsGet

func (a *JsonDocumentApiService) JsonDocumentsGet(ctx context.Context, chain string, serial int64) (models.JsonDocumentModel, *http.Response, error)

Calls GET /jsonDocuments@{chain}/{serial}.

type NodeApiInterlockingsListOpts

type NodeApiInterlockingsListOpts struct {
	LastKnownBlock optional.Int64
	LastToFirst    optional.Bool
	Page           optional.Int32
	PageSize       optional.Int32
}

Optional parameters of GET /interlockings/{targetChain}.

type NodeApiService

type NodeApiService service

Node API service.

func (*NodeApiService) ApiVersion

func (a *NodeApiService) ApiVersion(ctx context.Context) (string, *http.Response, error)

Calls GET /apiVersion.

func (*NodeApiService) AppsList

Calls GET /apps.

func (*NodeApiService) InterlockingsList

func (a *NodeApiService) InterlockingsList(ctx context.Context, targetChain string, optionalParams *NodeApiInterlockingsListOpts) (models.InterlockingRecordModelPageOf, *http.Response, error)

Calls GET /interlockings/{targetChain}.

func (*NodeApiService) MirrorAdd

func (a *NodeApiService) MirrorAdd(ctx context.Context, chains []string) ([]models.ChainIdModel, *http.Response, error)

Calls POST /mirrors.

func (*NodeApiService) MirrorsList

func (a *NodeApiService) MirrorsList(ctx context.Context) ([]models.ChainIdModel, *http.Response, error)

Calls GET /mirrors.

func (*NodeApiService) NodeDetails

Calls GET /.

func (*NodeApiService) PeersList

func (a *NodeApiService) PeersList(ctx context.Context) ([]models.PeerModel, *http.Response, error)

Calls GET /peers.

type OpaqueService added in v0.2.0

type OpaqueService service

Node API service.

func (*OpaqueService) Create added in v0.2.0

func (a *OpaqueService) Create(ctx context.Context,
	chain string, appId int64, payloadType int64, payload io.Reader, lastChangedRecordSerial int64) (models.OpaqueRecordModel, *http.Response, error)

Calls POST /opaque/{chain}.

func (*OpaqueService) Get added in v0.2.0

func (a *OpaqueService) Get(ctx context.Context,
	chain string, serial int64) ([]byte, int64, int64, *http.Response, error)

Calls GET /opaque/{chain}@{serial}. It returns the current payload, the appId (reserved for future uses), the payloadTypeId and the actual response.

func (*OpaqueService) QueryJson added in v0.2.0

func (a *OpaqueService) QueryJson(ctx context.Context,
	chain string, appId int64, payloadTypeIds []int64, howMany int64, lastToFirst bool, page int, pageSize int) (models.PageOfOpaqueRecordsModel, *http.Response, error)

Calls GET /opaque/{chain}@{serial}. It returns the current payload, the lastChangedRecordSerial (reserved for future uses) and the actual response.

type RecordApiPagingOpts

type RecordApiPagingOpts struct {
	Page        optional.Int32
	PageSize    optional.Int32
	LastToFirst optional.Bool
}

Base RecordApi record options.

type RecordApiRecordAddAsJsonOpts

type RecordApiRecordAddAsJsonOpts struct {
	ApplicationId optional.Int64
	PayloadTagId  optional.Int64
	Type_         optional.String
}

Options for POST /records@{chain}/asJson.

type RecordApiRecordsListAsJsonOpts

type RecordApiRecordsListAsJsonOpts struct {
	RecordApiPagingOpts
	FirstSerial optional.Int64
	LastSerial  optional.Int64
}

Options for GET /records@{chain}/asJson.

type RecordApiRecordsListOpts

type RecordApiRecordsListOpts struct {
	RecordApiPagingOpts
	FirstSerial optional.Int64
	LastSerial  optional.Int64
}

Options for GET /records@{chain}.

type RecordApiRecordsQueryAsJsonOpts

type RecordApiRecordsQueryAsJsonOpts struct {
	RecordApiPagingOpts
	QueryAsInterlockQL optional.String
	HowMany            optional.Int64
}

Options for Calls GET /records@{chain}/asJson/query.

type RecordApiRecordsQueryOpts

type RecordApiRecordsQueryOpts struct {
	RecordApiPagingOpts
	QueryAsInterlockQL optional.String
	HowMany            optional.Int64
}

Options for GET /records@{chain}/query.

type RecordApiService

type RecordApiService service

Record API service.

func (*RecordApiService) RecordAdd

func (a *RecordApiService) RecordAdd(ctx context.Context, chain string, localVarPostBody *models.NewRecordModel) (models.RecordModel, *http.Response, error)

Calls POST /records@{chain}.

func (*RecordApiService) RecordAddAsJson

func (a *RecordApiService) RecordAddAsJson(ctx context.Context, chain string, options *RecordApiRecordAddAsJsonOpts, jsonPayload interface{}) (models.RecordModel, *http.Response, error)

Calls POST /records@{chain}/asJson.

func (*RecordApiService) RecordGet

func (a *RecordApiService) RecordGet(ctx context.Context, chain string, serial int64) (models.RecordModel, *http.Response, error)

Calls GET /records@{chain}/{serial}.

func (*RecordApiService) RecordGetAsJson

func (a *RecordApiService) RecordGetAsJson(ctx context.Context, chain string, serial int64) (models.RecordModelAsJson, *http.Response, error)

Calls GET /records@{chain}/asJson/{serial}.

func (*RecordApiService) RecordsList

Calls GET /records@{chain}.

func (*RecordApiService) RecordsListAsJson

Calls GET /records@{chain}/asJson.

func (*RecordApiService) RecordsQuery

Calls GET /records@{chain}/query.

func (*RecordApiService) RecordsQueryAsJson

Calls GET /records@{chain}/asJson/query.

Directories

Path Synopsis
This package contains the implementation of the InterlockLedger Node REST API JSON models.
This package contains the implementation of the InterlockLedger Node REST API JSON models.

Jump to

Keyboard shortcuts

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