api

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package api provides primitives to interact with the openapi HTTP API.

Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func NewCreateSessionRequest

func NewCreateSessionRequest(server string, body CreateSessionJSONRequestBody) (*http.Request, error)

NewCreateSessionRequest calls the generic CreateSession builder with application/json body

func NewCreateSessionRequestWithBody

func NewCreateSessionRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewCreateSessionRequestWithBody generates requests for CreateSession with any type of body

func NewGenerateTotpRequest

func NewGenerateTotpRequest(server string, id string, body GenerateTotpJSONRequestBody) (*http.Request, error)

NewGenerateTotpRequest calls the generic GenerateTotp builder with application/json body

func NewGenerateTotpRequestWithBody

func NewGenerateTotpRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error)

NewGenerateTotpRequestWithBody generates requests for GenerateTotp with any type of body

func NewGetSessionRequest

func NewGetSessionRequest(server string, id string) (*http.Request, error)

NewGetSessionRequest generates requests for GetSession

func NewPostTocRequest

func NewPostTocRequest(server string, id string, body PostTocJSONRequestBody) (*http.Request, error)

NewPostTocRequest calls the generic PostToc builder with application/json body

func NewPostTocRequestWithBody

func NewPostTocRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error)

NewPostTocRequestWithBody generates requests for PostToc with any type of body

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

func RegisterHandlers

func RegisterHandlers(router EchoRouter, si ServerInterface)

RegisterHandlers adds each server route to the EchoRouter.

func RegisterHandlersWithBaseURL

func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string)

Registers handlers, and prepends BaseURL to the paths, so that the paths can be served under a prefix.

Types

type AddToc

type AddToc struct {
	// EncryptedToc The constituent's Toc encrypted with the session's public key
	EncryptedToc string `json:"encrypted_toc"`
}

AddToc defines model for AddToc.

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) CreateSessionWithBody

func (c *Client) CreateSessionWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) GenerateTotp

func (c *Client) GenerateTotp(ctx context.Context, id string, body GenerateTotpJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) GenerateTotpWithBody

func (c *Client) GenerateTotpWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) GetSession

func (c *Client) GetSession(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) PostToc

func (c *Client) PostToc(ctx context.Context, id string, body PostTocJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) PostTocWithBody

func (c *Client) PostTocWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// CreateSessionWithBody request with any body
	CreateSessionWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	CreateSession(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// GetSession request
	GetSession(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error)

	// PostTocWithBody request with any body
	PostTocWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	PostToc(ctx context.Context, id string, body PostTocJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// GenerateTotpWithBody request with any body
	GenerateTotpWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	GenerateTotp(ctx context.Context, id string, body GenerateTotpJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) CreateSessionWithBodyWithResponse

func (c *ClientWithResponses) CreateSessionWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error)

CreateSessionWithBodyWithResponse request with arbitrary body returning *CreateSessionResponse

func (*ClientWithResponses) CreateSessionWithResponse

func (c *ClientWithResponses) CreateSessionWithResponse(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error)

func (*ClientWithResponses) GenerateTotpWithBodyWithResponse

func (c *ClientWithResponses) GenerateTotpWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*GenerateTotpResponse, error)

GenerateTotpWithBodyWithResponse request with arbitrary body returning *GenerateTotpResponse

func (*ClientWithResponses) GenerateTotpWithResponse

func (c *ClientWithResponses) GenerateTotpWithResponse(ctx context.Context, id string, body GenerateTotpJSONRequestBody, reqEditors ...RequestEditorFn) (*GenerateTotpResponse, error)

func (*ClientWithResponses) GetSessionWithResponse

func (c *ClientWithResponses) GetSessionWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetSessionResponse, error)

GetSessionWithResponse request returning *GetSessionResponse

func (*ClientWithResponses) PostTocWithBodyWithResponse

func (c *ClientWithResponses) PostTocWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTocResponse, error)

PostTocWithBodyWithResponse request with arbitrary body returning *PostTocResponse

func (*ClientWithResponses) PostTocWithResponse

func (c *ClientWithResponses) PostTocWithResponse(ctx context.Context, id string, body PostTocJSONRequestBody, reqEditors ...RequestEditorFn) (*PostTocResponse, error)

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// CreateSessionWithBodyWithResponse request with any body
	CreateSessionWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error)

	CreateSessionWithResponse(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error)

	// GetSessionWithResponse request
	GetSessionWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetSessionResponse, error)

	// PostTocWithBodyWithResponse request with any body
	PostTocWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTocResponse, error)

	PostTocWithResponse(ctx context.Context, id string, body PostTocJSONRequestBody, reqEditors ...RequestEditorFn) (*PostTocResponse, error)

	// GenerateTotpWithBodyWithResponse request with any body
	GenerateTotpWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*GenerateTotpResponse, error)

	GenerateTotpWithResponse(ctx context.Context, id string, body GenerateTotpJSONRequestBody, reqEditors ...RequestEditorFn) (*GenerateTotpResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type CreateSessionJSONRequestBody

type CreateSessionJSONRequestBody = NewSession

CreateSessionJSONRequestBody defines body for CreateSession for application/json ContentType.

type CreateSessionResponse

type CreateSessionResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *SessionCredentials
	JSONDefault  *DefaultError
}

func ParseCreateSessionResponse

func ParseCreateSessionResponse(rsp *http.Response) (*CreateSessionResponse, error)

ParseCreateSessionResponse parses an HTTP response from a CreateSessionWithResponse call

func (CreateSessionResponse) Status

func (r CreateSessionResponse) Status() string

Status returns HTTPResponse.Status

func (CreateSessionResponse) StatusCode

func (r CreateSessionResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type DefaultError

type DefaultError = Error

DefaultError defines model for DefaultError.

type EchoRouter

type EchoRouter interface {
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

This is a simple interface which specifies echo.Route addition functions which are present on both echo.Echo and echo.Group, since we want to allow using either of them for path registration

type Error

type Error struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
}

Error defines model for Error.

type ErrorCode

type ErrorCode string

ErrorCode defines model for Error.Code.

const (
	InvalidTOTPSecret ErrorCode = "InvalidTOTPSecret"
)

Defines values for ErrorCode.

type GenerateTotpJSONRequestBody

type GenerateTotpJSONRequestBody = SessionKeyEncryptionKey

GenerateTotpJSONRequestBody defines body for GenerateTotp for application/json ContentType.

type GenerateTotpResponse

type GenerateTotpResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *TOTPCode
	JSONDefault  *DefaultError
}

func ParseGenerateTotpResponse

func ParseGenerateTotpResponse(rsp *http.Response) (*GenerateTotpResponse, error)

ParseGenerateTotpResponse parses an HTTP response from a GenerateTotpWithResponse call

func (GenerateTotpResponse) Status

func (r GenerateTotpResponse) Status() string

Status returns HTTPResponse.Status

func (GenerateTotpResponse) StatusCode

func (r GenerateTotpResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type GetSessionResponse

type GetSessionResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *Session
	JSONDefault  *DefaultError
}

func ParseGetSessionResponse

func ParseGetSessionResponse(rsp *http.Response) (*GetSessionResponse, error)

ParseGetSessionResponse parses an HTTP response from a GetSessionWithResponse call

func (GetSessionResponse) Status

func (r GetSessionResponse) Status() string

Status returns HTTPResponse.Status

func (GetSessionResponse) StatusCode

func (r GetSessionResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type NewSession

type NewSession struct {
	// TocZero A Toc is a "piece" in which a TOTP secret gets split.
	TocZero Toc `json:"toc_zero"`

	// Ttl Seconds until the TOTP generation endpoint expires, starting from the first TOTP generated.
	Ttl *int `json:"ttl,omitempty"`
}

NewSession defines model for NewSession.

type PostTocJSONRequestBody

type PostTocJSONRequestBody = AddToc

PostTocJSONRequestBody defines body for PostToc for application/json ContentType.

type PostTocResponse

type PostTocResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSONDefault  *DefaultError
}

func ParsePostTocResponse

func ParsePostTocResponse(rsp *http.Response) (*PostTocResponse, error)

ParsePostTocResponse parses an HTTP response from a PostTocWithResponse call

func (PostTocResponse) Status

func (r PostTocResponse) Status() string

Status returns HTTPResponse.Status

func (PostTocResponse) StatusCode

func (r PostTocResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type ServerInterface

type ServerInterface interface {
	// Start a new session
	// (POST /sessions)
	CreateSession(ctx echo.Context) error
	// Retrieve a session details by its ID
	// (GET /sessions/{id})
	GetSession(ctx echo.Context, id string) error
	// Join a new Toc to an existing session
	// (POST /sessions/{id}/tocs)
	PostToc(ctx echo.Context, id string) error
	// Close the session and generate the TOTP
	// (POST /sessions/{id}/totp)
	GenerateTotp(ctx echo.Context, id string) error
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

ServerInterfaceWrapper converts echo contexts to parameters.

func (*ServerInterfaceWrapper) CreateSession

func (w *ServerInterfaceWrapper) CreateSession(ctx echo.Context) error

CreateSession converts echo context to params.

func (*ServerInterfaceWrapper) GenerateTotp

func (w *ServerInterfaceWrapper) GenerateTotp(ctx echo.Context) error

GenerateTotp converts echo context to params.

func (*ServerInterfaceWrapper) GetSession

func (w *ServerInterfaceWrapper) GetSession(ctx echo.Context) error

GetSession converts echo context to params.

func (*ServerInterfaceWrapper) PostToc

func (w *ServerInterfaceWrapper) PostToc(ctx echo.Context) error

PostToc converts echo context to params.

type Session

type Session struct {
	// Complete True when enough Tocs have been provided and TOTPs may be generated
	Complete bool `json:"complete"`

	// CreatedAt The time when the session started
	CreatedAt time.Time `json:"created_at"`

	// ExpiresAt When the sessions will expire and no longer accept Tocs
	ExpiresAt *time.Time `json:"expires_at,omitempty"`

	// Id The identifier of a session
	Id string `json:"id"`

	// TocGroupId An identifier for the group of Tocs used in this session
	TocGroupId string `json:"toc_group_id"`

	// TocsInGroup The total number of Tocs in the group
	TocsInGroup int `json:"tocs_in_group"`

	// TocsProvided The number of Tocs already provided by consituents to the oracle for this session
	TocsProvided int `json:"tocs_provided"`

	// TocsThreshold The minimum number of Tocs required
	TocsThreshold int `json:"tocs_threshold"`

	// Ttl Seconds until the TOTP generation endpoint expires, starting from the first token generated.
	Ttl *int `json:"ttl,omitempty"`
}

Session defines model for Session.

type SessionCredentials

type SessionCredentials struct {
	// Complete True when enough Tocs have been provided and TOTPs may be generated
	Complete bool `json:"complete"`

	// CreatedAt The time when the session started
	CreatedAt time.Time `json:"created_at"`

	// ExpiresAt When the sessions will expire and no longer accept Tocs
	ExpiresAt *time.Time `json:"expires_at,omitempty"`

	// Id The identifier of a session
	Id string `json:"id"`

	// Kek A key used to encrypt the Toc encryption key held by the oracle.
	// This key is kept by the applicant and shared when a TOTP is generated.
	Kek []byte `json:"kek"`

	// Tek A public key used by constituents to encrypt their Tocs before sharing them with the oracle.
	// The applicant receives it when creating a sessions,
	// and must share it with constituents when requesting their approval.
	Tek string `json:"tek"`

	// TocGroupId An identifier for the group of Tocs used in this session
	TocGroupId string `json:"toc_group_id"`

	// TocsInGroup The total number of Tocs in the group
	TocsInGroup int `json:"tocs_in_group"`

	// TocsProvided The number of Tocs already provided by consituents to the oracle for this session
	TocsProvided int `json:"tocs_provided"`

	// TocsThreshold The minimum number of Tocs required
	TocsThreshold int `json:"tocs_threshold"`

	// Ttl Seconds until the TOTP generation endpoint expires, starting from the first token generated.
	Ttl *int `json:"ttl,omitempty"`
}

SessionCredentials defines model for SessionCredentials.

type SessionKeyEncryptionKey

type SessionKeyEncryptionKey struct {
	// Kek A key used to encrypt the Toc encryption key held by the oracle.
	// This key is kept by the applicant and shared when a TOTP is generated.
	Kek []byte `json:"kek"`
}

SessionKeyEncryptionKey defines model for SessionKeyEncryptionKey.

type SessionTocEncryptionKey

type SessionTocEncryptionKey struct {
	// Tek A public key used by constituents to encrypt their Tocs before sharing them with the oracle.
	// The applicant receives it when creating a sessions,
	// and must share it with constituents when requesting their approval.
	Tek string `json:"tek"`
}

SessionTocEncryptionKey defines model for SessionTocEncryptionKey.

type TOTPCode

type TOTPCode struct {
	// SessionExpiresAt The time when this session will expire and cannot be called again
	SessionExpiresAt time.Time `json:"session_expires_at"`

	// Totp The current TOTP
	Totp string `json:"totp"`

	// TotpExpiresAt The time when the current TOTP will expire
	TotpExpiresAt time.Time `json:"totp_expires_at"`
}

TOTPCode defines model for TOTPCode.

type Toc

type Toc struct {
	// GroupId Each Toc is part of a group. Tocs from the same group can reconstruct a secret
	GroupId string `json:"group_id"`

	// GroupSize The number of Tocs in the group
	GroupSize int `json:"group_size"`

	// GroupThreshold The nubmer of Tocs needed to reconstruct the secret
	GroupThreshold int `json:"group_threshold"`

	// Note Free-text to describe the purpose of a Toc
	Note *string `json:"note,omitempty"`

	// Share The actual share that players should keep secret
	Share []byte `json:"share"`

	// TocId A Toc is unique, this ID ensures a Toc is not reused
	TocId []byte `json:"toc_id"`
}

Toc A Toc is a "piece" in which a TOTP secret gets split.

Jump to

Keyboard shortcuts

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