Documentation
¶
Index ¶
- Variables
- func ServeMetrics()
- func SetupLogger(ctx context.Context, version, buildTime, commit string) (context.Context, *slog.Logger)
- type BlindedTokenBulkRedeemRequest
- type BlindedTokenIssueRequestV2
- type BlindedTokenRedemptionInfo
- type CacheInterface
- type CachingConfig
- type DBConfig
- type Equivalence
- type Queryable
- type Redemption
- type RedemptionV2
- type Server
- func (c *Server) BlindedTokenIssuerHandlerV2(w http.ResponseWriter, r *http.Request) *handlers.AppError
- func (c *Server) CheckRedeemedTokenEquivalence(issuer *model.Issuer, preimage *crypto.TokenPreimage, payload string, ...) (*RedemptionV2, Equivalence, error)
- func (c *Server) FetchAllIssuers() ([]model.Issuer, error)
- func (c *Server) GetLatestIssuer(issuerType string, issuerCohort int16) (*model.Issuer, *handlers.AppError)
- func (c *Server) GetLatestIssuerKafka(issuerType string, issuerCohort int16) (*model.Issuer, error)
- func (c *Server) InitDB()
- func (c *Server) InitDBConfig() error
- func (c *Server) InitDynamo()
- func (c *Server) ListenAndServe(ctx context.Context, logger *slog.Logger) error
- func (c *Server) LoadDBConfig(config DBConfig)
- func (c *Server) PersistRedemption(redemption RedemptionV2) error
- func (c *Server) RedeemToken(issuerForRedemption *model.Issuer, preimage *crypto.TokenPreimage, ...) error
- func (c *Server) RotateIssuersV3() error
- func (c *Server) SetupCronTasks()
Constants ¶
This section is empty.
Variables ¶
var ( // 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") )
var DefaultServer = &Server{
ListenPort: 2416,
}
DefaultServer on port
Functions ¶
func ServeMetrics ¶
func ServeMetrics()
ServeMetrics exposes the metrics collection endpoint on :9090
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) (any, bool)
Delete(k string)
SetDefault(k string, x any)
}
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 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 *slog.Logger `json:",omitempty"`
// contains filtered or unexported fields
}
Server - base server type
func LoadConfigFile ¶
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 ¶
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 ¶
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 ¶
InitDBConfig reads os environment and update conf
func (*Server) InitDynamo ¶
func (c *Server) InitDynamo()
InitDynamo initialzes the dynamo database connection
func (*Server) ListenAndServe ¶
ListenAndServe listen to ports and mount handlers
func (*Server) LoadDBConfig ¶
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 ¶
RotateIssuersV3 is the function that rotates time aware issuers
func (*Server) SetupCronTasks ¶
func (c *Server) SetupCronTasks()
SetupCronTasks run two functions every hour