api

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNetworkRequired = errors.New("request requires a valid network (mainnet or testnet)")
)

Functions

func NotAllowed

func NotAllowed(c *gin.Context)

NotAllowed returns a JSON 405 response for the API.

func NotFound

func NotFound(c *gin.Context)

NotFound returns a JSON 404 response for the API.

Types

type APIv1

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

APIv1 implements the BFFClient interface.

func (*APIv1) Do

func (s *APIv1) Do(req *http.Request, data interface{}, checkStatus bool) (rep *http.Response, err error)

Do executes an http request against the server, performs error checking, and deserializes the response data into the specified struct if requested.

func (*APIv1) Lookup

func (s *APIv1) Lookup(ctx context.Context, in *LookupParams) (out *LookupReply, err error)

func (*APIv1) NewRequest

func (s *APIv1) NewRequest(ctx context.Context, method, path string, data interface{}, params *url.Values) (req *http.Request, err error)

NewRequest creates an http.Request with the specified context and method, resolving the path to the root endpoint of the API (e.g. /v2) and serializes the data to JSON. This method also sets the default headers of all GDS Admin API v2 client requests.

func (*APIv1) Register

func (s *APIv1) Register(ctx context.Context, in *RegisterRequest) (out *RegisterReply, err error)

func (*APIv1) Status

func (s *APIv1) Status(ctx context.Context, in *StatusParams) (out *StatusReply, err error)

func (*APIv1) VerifyContact

func (s *APIv1) VerifyContact(ctx context.Context, in *VerifyContactParams) (out *VerifyContactReply, err error)

type BFFClient

type BFFClient interface {
	Status(ctx context.Context, in *StatusParams) (out *StatusReply, err error)
	Lookup(ctx context.Context, in *LookupParams) (out *LookupReply, err error)
	Register(ctx context.Context, in *RegisterRequest) (out *RegisterReply, err error)
	VerifyContact(ctx context.Context, in *VerifyContactParams) (out *VerifyContactReply, err error)
}

func New

func New(endpoint string) (_ BFFClient, err error)

New creates a new api.v1 API client that implements the BFF interface.

type LookupParams

type LookupParams struct {
	ID         string `url:"uuid,omitempty" form:"uuid"`
	CommonName string `url:"common_name,omitempty" form:"common_name"`
}

LookupParams is converted into a GDS LookupRequest.

type LookupReply

type LookupReply struct {
	Results []map[string]interface{} `json:"results"`
}

LookupReply can return 1-2 results either one result found from one directory service or results found from both TestNet and MainNet. If no results are found, the Lookup endpoint returns a 404 error (not found). The result is the simplest case, just a JSON serialization of the protocol buffers returned from GDS to help long term maintainability. The protocol buffers contain a "registered_directory" field that will have either vaspdirectory.net or trisatest.net inside of it - which can be used to identify which network the record is associated with. The protocol buffers may also contain an "error" field - the BFF will handle this field by logging the error but will exclude it from any results returned.

type RegisterReply

type RegisterReply struct {
	Error               map[string]interface{} `json:"error,omitempty"`
	Id                  string                 `json:"id"`
	RegisteredDirectory string                 `json:"registered_directory"`
	CommonName          string                 `json:"common_name"`
	Status              string                 `json:"status"`
	Message             string                 `json:"message"`
	PKCS12Password      string                 `json:"pkcs12password"`
}

RegisterReply is converted from a protocol buffer RegisterReply.

type RegisterRequest

type RegisterRequest struct {
	// The network of the directory to register with, e.g. testnet or mainnet
	// NOTE: not required for front-end, used to determine endpoint in the client.
	Network string `json:"network,omitempty"`

	// RegisterRequest ProtocolBuffer fields
	Entity           map[string]interface{} `json:"entity"`
	Contacts         map[string]interface{} `json:"contacts"`
	TRISAEndpoint    string                 `json:"trisa_endpoint"`
	CommonName       string                 `json:"common_name"`
	Website          string                 `json:"website"`
	BusinessCategory string                 `json:"business_category"`
	VASPCategories   []string               `json:"vasp_categories"`
	EstablishedOn    string                 `json:"established_on"`
	TRIXO            map[string]interface{} `json:"trixo"`
}

RegisterRequest is converted into a protocol buffer RegisterRequest to send to the specified GDS in v1.4. In v1.5 this will be expanded to include fields for both TestNet and MainNet registration (e.g. multiple fields for endpoint and domain). All generic fields (e.g. map[string]interface{}) should match their protobuf spec.

type Reply

type Reply struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty" yaml:"error,omitempty"`
}

Reply contains standard fields that are used for generic API responses and errors

func ErrorResponse

func ErrorResponse(err interface{}) Reply

ErrorResponse constructs an new response from the error or returns a success: false.

type StatusParams

type StatusParams struct {
	NoGDS bool `url:"nogds,omitempty" form:"nogds" default:"false"`
}

StatusParams is parsed from the query parameters of the GET request

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
	TestNet string `json:"testnet,omitempty"`
	MainNet string `json:"mainnet,omitempty"`
}

StatusReply is returned on status requests. Note that no request is needed.

type VerifyContactParams

type VerifyContactParams struct {
	ID        string `url:"vaspID,omitempty" form:"vaspID"`
	Token     string `url:"token,omitempty" form:"token"`
	Directory string `url:"registered_directory,omitempty" form:"registered_directory"`
}

VerifyContactParams is converted into a GDS VerifyContactRequest.

type VerifyContactReply

type VerifyContactReply struct {
	Error   map[string]interface{} `json:"error,omitempty"`
	Status  string                 `json:"status"`
	Message string                 `json:"message"`
}

VerifyContactReply

Jump to

Keyboard shortcuts

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