server

package
v0.0.0-...-423bd50 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: BSD-3-Clause Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version - the version?
	Version = "dev"

	// ErrNoSecretKey - configuration error, no secret key
	ErrNoSecretKey = errors.New("server config does not contain a key")
	// ErrRequestTooLarge - processing error, request is too big
	ErrRequestTooLarge = errors.New("request too large to process")
	// ErrUnrecognizedRequest - processing error, request unrecognized
	ErrUnrecognizedRequest = errors.New("received unrecognized request type")
)
View Source
var DefaultServer = &Server{
	ListenPort: 2416,
}

DefaultServer on port

Functions

func SetupLogger

func SetupLogger(ctx context.Context) (context.Context, *logrus.Logger)

SetupLogger creates a logger to use

Types

type BlindedTokenBulkRedeemRequest

type BlindedTokenBulkRedeemRequest struct {
	Payload string                       `json:"payload"`
	Tokens  []BlindedTokenRedemptionInfo `json:"tokens"`
}

BlindedTokenBulkRedeemRequest - this is the redemption in bulk form

type BlindedTokenIssueRequestV2

type BlindedTokenIssueRequestV2 struct {
	BlindedTokens []*crypto.BlindedToken `json:"blinded_tokens"`
	IssuerCohort  int16                  `json:"cohort"`
}

BlindedTokenIssueRequestV2 - version 2 blinded token issue request

type BlindedTokenRedemptionInfo

type BlindedTokenRedemptionInfo struct {
	TokenPreimage *crypto.TokenPreimage         `json:"t"`
	Signature     *crypto.VerificationSignature `json:"signature"`
	Issuer        string                        `json:"issuer"`
}

BlindedTokenRedemptionInfo - this is the redemption information

type CacheInterface

type CacheInterface interface {
	Get(k string) (interface{}, bool)
	Delete(k string)
	SetDefault(k string, x interface{})
}

CacheInterface cache functions

type CachingConfig

type CachingConfig struct {
	Enabled       bool `json:"enabled"`
	ExpirationSec int  `json:"expirationSec"`
}

CachingConfig is how long data is cached

type DBConfig

type DBConfig struct {
	ConnectionURI           string        `json:"connectionURI"`
	CachingConfig           CachingConfig `json:"caching"`
	MaxConnection           int           `json:"maxConnection"`
	DefaultDaysBeforeExpiry int           `json:"DefaultDaysBeforeExpiry"`
	DefaultIssuerValidDays  int           `json:"DefaultIssuerValidDays"`
	DynamodbEndpoint        string        `json:"DynamodbEndpoint"`
}

DBConfig defines app configurations

type Equivalence

type Equivalence int64

Equivalence represents the type of equality discovered when checking DynamoDB data

const (
	// UnknownEquivalence means equivalence could not be determined
	UnknownEquivalence Equivalence = iota
	// NoEquivalence means means there was no matching record of any kind in Dynamo
	NoEquivalence
	// IDEquivalence means a record with the same ID as the subject was found, but one
	// or more of its other fields did not match the subject
	IDEquivalence
	// BindingEquivalence means a record that matched all of the fields of the
	// subject was found
	BindingEquivalence
)

type Queryable

type Queryable interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

Queryable is an interface requiring the method Query

type Redemption

type Redemption struct {
	IssuerType string    `json:"issuerType" db:"issuer_type"`
	ID         string    `json:"id" db:"id"`
	Timestamp  time.Time `json:"timestamp" db:"ts"`
	Payload    string    `json:"payload" db:"payload"`
}

Redemption is a token Redeemed

type RedemptionV2

type RedemptionV2 struct {
	IssuerID  string    `json:"issuerId"`
	ID        string    `json:"id"`
	PreImage  string    `json:"preImage"`
	Timestamp time.Time `json:"timestamp"`
	Payload   string    `json:"payload"`
	TTL       int64     `json:"TTL"`
	Offset    int64     `json:"offset"`
}

RedemptionV2 is a token Redeemed

type Server

type Server struct {
	ListenPort   int            `json:"listen_port,omitempty"`
	MaxTokens    int            `json:"max_tokens,omitempty"`
	DBConfigPath string         `json:"db_config_path"`
	Logger       *logrus.Logger `json:",omitempty"`
	// contains filtered or unexported fields
}

Server - base server type

func LoadConfigFile

func LoadConfigFile(filePath string) (Server, error)

LoadConfigFile loads a file into conf and returns

func (*Server) BlindedTokenIssuerHandlerV2

func (c *Server) BlindedTokenIssuerHandlerV2(w http.ResponseWriter, r *http.Request) *handlers.AppError

BlindedTokenIssuerHandlerV2 - handler for token issuer v2

func (*Server) CheckRedeemedTokenEquivalence

func (c *Server) CheckRedeemedTokenEquivalence(issuer *model.Issuer, preimage *crypto.TokenPreimage, payload string, offset int64) (*RedemptionV2, Equivalence, error)

CheckRedeemedTokenEquivalence returns whether just the ID of a given RedemptionV2 token matches an existing persisted record, the whole value matches, or neither match and this is a new token to be redeemed.

func (*Server) FetchAllIssuers

func (c *Server) FetchAllIssuers() ([]model.Issuer, error)

FetchAllIssuers fetches issuers from a cache or a database based on their type, saving them in the cache if it has to query the database.

func (*Server) GetLatestIssuer

func (c *Server) GetLatestIssuer(issuerType string, issuerCohort int16) (*model.Issuer, *handlers.AppError)

GetLatestIssuer - get the latest issuer by type/cohort

func (*Server) GetLatestIssuerKafka

func (c *Server) GetLatestIssuerKafka(issuerType string, issuerCohort int16) (*model.Issuer, error)

GetLatestIssuerKafka - get the issuer and any processing error

func (*Server) InitDB

func (c *Server) InitDB()

InitDB initialzes the database connection based on a server's configuration

func (*Server) InitDBConfig

func (c *Server) InitDBConfig() error

InitDBConfig reads os environment and update conf

func (*Server) InitDynamo

func (c *Server) InitDynamo()

InitDynamo initialzes the dynamo database connection

func (*Server) ListenAndServe

func (c *Server) ListenAndServe(ctx context.Context, logger *logrus.Logger) error

ListenAndServe listen to ports and mount handlers

func (*Server) LoadDBConfig

func (c *Server) LoadDBConfig(config DBConfig)

LoadDBConfig loads config into server variable

func (*Server) PersistRedemption

func (c *Server) PersistRedemption(redemption RedemptionV2) error

PersistRedemption saves the redemption in the database

func (*Server) RedeemToken

func (c *Server) RedeemToken(issuerForRedemption *model.Issuer, preimage *crypto.TokenPreimage, payload string, offset int64) error

RedeemToken redeems a token given an issuer and and preimage

func (*Server) RotateIssuersV3

func (c *Server) RotateIssuersV3() error

RotateIssuersV3 is the function that rotates time aware issuers

func (*Server) SetupCronTasks

func (c *Server) SetupCronTasks()

SetupCronTasks run two functions every hour

Jump to

Keyboard shortcuts

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