rest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: GPL-3.0 Imports: 20 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptPayloadFromContext

func DecryptPayloadFromContext(c *gin.Context, requestBody interface{}) error

retrieves token from gin context

Types

type AuthCrypt

type AuthCrypt interface {
	// indicates if crypt instance has been
	// initialized with authenticated keys
	// that are synchronized between the
	// client and server
	IsAuthenticated() bool
	WaitForAuth() bool

	// a key to be passed along with encrypted
	// auth tokens and used to verify the
	// authenticity of requests
	AuthTokenKey() string

	// crypt instance used to encrypt and
	// decrypt tokens and payloads. the
	// cipher can change when auth keys
	// are recycled so the mutex should
	// be used to guard access to it
	Crypt() (*crypto.Crypt, *sync.Mutex)
}

specification for an authenticatable and encryptedable rest api interface used to secure requests

type AuthToken

type AuthToken interface {
	// updates with an encrypted token
	SetEncryptedToken(encryptedToken string) error
	// returns the encrypted auth token
	GetEncryptedToken() (string, error)

	// signs the data for the given keys in the transport
	// data request headers and "body" for a request and
	// response headers and "body" for a response. data
	// would point to either an http.Request or http.Response
	// instance.
	SignTransportData(keys []string, data interface{}) error
	ValidateTransportData(data interface{}) error

	// signs and encrypts the given payload
	EncryptPayload(payload io.Reader) (io.Reader, error)
	// decrypts the payload and validates the decrypted
	// payload checksum
	DecryptPayload(body io.Reader) (io.ReadCloser, error)
	DecryptAndDecodePayload(body io.Reader, obj interface{}) error

	// saves the token in the gin context
	SetInContext(c *gin.Context)
}

func NewRequestAuthToken

func NewRequestAuthToken(authCrypt AuthCrypt) (AuthToken, error)

creates an authenticated token to send with a request

func NewResponseAuthToken

func NewResponseAuthToken(authCrypt AuthCrypt) AuthToken

creates and authenticated response token from a request token

type NV

type NV map[string]string

type RenderEncryptedPayload

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

Gin renderer for encrypted payloads

func NewEncryptedRender

func NewEncryptedRender(c *gin.Context, p interface{}) RenderEncryptedPayload

func (RenderEncryptedPayload) Render

func (RenderEncryptedPayload) WriteContentType

func (r RenderEncryptedPayload) WriteContentType(w http.ResponseWriter)

type Request

type Request struct {
	Path      string
	Headers   NV
	QueryArgs NV
	RawQuery  string
	Body      interface{}
	// contains filtered or unexported fields
}

func (*Request) DoDelete

func (r *Request) DoDelete(response *Response) error

func (*Request) DoGet

func (r *Request) DoGet(response *Response) error

func (*Request) DoPost

func (r *Request) DoPost(response *Response) error

func (*Request) DoPut

func (r *Request) DoPut(response *Response) error

type Response

type Response struct {
	StatusCode int
	Headers    NV

	Body  interface{}
	Error interface{}

	RawErrorMessage string
}

type RestApiClient

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

func NewRestApiClient

func NewRestApiClient(ctx context.Context, url string) *RestApiClient

func (*RestApiClient) NewRequest

func (c *RestApiClient) NewRequest(request *Request) *Request

func (*RestApiClient) WithAuthCrypt

func (c *RestApiClient) WithAuthCrypt(authCrypt AuthCrypt) *RestApiClient

func (*RestApiClient) WithHttpClient

func (c *RestApiClient) WithHttpClient(httpClient *http.Client) *RestApiClient

Jump to

Keyboard shortcuts

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