crypter

package
v0.0.0-...-c32710b Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package crypter implements an encryption services. the main purpose is to encrypt files / binary payloads. initial implementation focuses on PDF files

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvlaidPayloadType tells the caller that encryption is not possible fo the supplied payload-type
	ErrInvlaidPayloadType = errors.New("invalid payload type supplied")
)

Functions

func EndpointLoggingMiddleware

func EndpointLoggingMiddleware(logger logging.Logger, endpointName string) endpoint.Middleware

EndpointLoggingMiddleware returns an endpoint middleware that logs the duration of each invocation, and the resulting error, if any.

func MakeEncryptEndpoint

func MakeEncryptEndpoint(s EncryptionService) endpoint.Endpoint

MakeEncryptEndpoint constructs an Encrypt endpoint wrapping the service.

func NewGRPCServer

func NewGRPCServer(endpoints Endpoints, logger logging.Logger) proto.CrypterServer

NewGRPCServer makes endpoints available as a gRPC CrypterServer.

Types

type AppConfig

type AppConfig struct {
	TokenSecurity TokenSecurity
	Logging       LogConfig
	Environment   Environment
	ServiceName   string
	HostID        string
}

AppConfig holds the application configuration

type Claim

type Claim struct {
	Name  string
	URL   string
	Roles []string
}

Claim defines the required claims

type EncryptionService

type EncryptionService interface {
	// Encrypt uses the supplied token to validate the user and encrypts the provided payload
	// The encryption is performend using the supplied passwords.
	Encrypt(ctx context.Context, req Request) ([]byte, error)
}

EncryptionService describes a service that encrypts payloads

func NewGRPCClient

func NewGRPCClient(conn *grpc.ClientConn) EncryptionService

NewGRPCClient returns a EncryptionService backed by a gRPC server at the other end of the conn. The caller is responsible for constructing the conn, and eventually closing the underlying transport. We bake-in certain middlewares, implementing the client library pattern.

func NewService

func NewService(logger logging.Logger, tokenSetting TokenSecurity) EncryptionService

NewService returns a Service with all of the expected middlewares wired in.

type Endpoints

type Endpoints struct {
	CrypterEndpoint endpoint.Endpoint
}

Endpoints collects all of the endpoints that compose a service. It's meant to be used as a helper struct, to collect all of the endpoints into a single parameter. An endpoint is needed per service method.

func NewEndpoints

func NewEndpoints(svc EncryptionService, logger logging.Logger) Endpoints

NewEndpoints returns Endpoints which wrap the provided server, and wires in all of the expected endpoint middlewares via the various parameters.

func (Endpoints) Encrypt

func (e Endpoints) Encrypt(ctx context.Context, req Request) ([]byte, error)

Encrypt implements the service interface, so Endpoints may be used as a service. This is primarily useful in the context of a client library.

type Environment

type Environment string

Environment specifies operation modes

const (
	// Development is used in development
	Development Environment = "Development"
	// Production is used for deployments
	Production Environment = "Production"
)

type LogConfig

type LogConfig struct {
	FilePath string
	LogLevel string
	// GrayLogServer defines the address of a log-aggregator using Graylog
	GrayLogServer string
}

LogConfig is used to define settings for the logging process

type PayloadType

type PayloadType string

PayloadType enumerates the available payload types

const (
	// PDF is a payload of application/pdf
	PDF PayloadType = "PDF"
)

type Request

type Request struct {
	AuthToken string
	Payload   []byte
	Type      PayloadType
	InitPass  string
	NewPass   string
}

Request combines the parameters passed on to the encryption service

type Response

type Response struct {
	Payload []byte `json:"payload"`
	Err     error  `json:"-"` // should be intercepted by Failed/errorEncoder
}

Response collects the response values for the Encrypt method.

func (Response) Failed

func (r Response) Failed() error

Failed implements endpoint.Failer.

type ServiceMiddleware

type ServiceMiddleware func(EncryptionService) EncryptionService

ServiceMiddleware describes a service (as opposed to endpoint) middleware. it is used to intercept the method execution and perform actions before/after the serivce method execution

func ServiceLoggingMiddleware

func ServiceLoggingMiddleware(logger logging.Logger) ServiceMiddleware

ServiceLoggingMiddleware takes a logger as a dependency and returns a ServiceLoggingMiddleware.

type TokenSecurity

type TokenSecurity struct {
	JwtIssuer     string
	JwtSecret     string
	Claim         Claim
	CacheDuration string
}

TokenSecurity settings for the application

Jump to

Keyboard shortcuts

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