burner

package
v0.0.0-...-ffaa3c7 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMessageDoesntExist = errors.New("message doesn't exist")

ErrMessageDoesntExist is returned by GetMessagesByID when it cant find that specific message

Functions

func CacheControl

func CacheControl(sec int) alice.Constructor

CacheControl sets the Cache-Control header

func JSONContentType

func JSONContentType(h http.Handler) http.Handler

JSONContentType sets content type of request to json

func Refresh

func Refresh(sec int) alice.Constructor

Refresh sets how often the page should refresh

func RestoreRealIP

func RestoreRealIP(h http.Handler) http.Handler

RestoreRealIP uses the real ip of the request from the CF-Connecting-IP header

func SetVersionHeader

func SetVersionHeader(h http.Handler) http.Handler

SetVersionHeader adds a header with the current version

Types

type Config

type Config struct {
	Key                string
	URL                string
	StaticURL          string
	Email              EmailProvider
	Domains            []string
	Developing         bool
	UsingLambda        bool
	RestoreRealIP      bool
	Database           Database
	BlacklistedDomains []string
	EmitMetrics        bool
	MetricPort         string
}

Config contains key configuration parameters to be passed to New()

type Database

type Database interface {
	// Start is where you should do schema creation and launch gorountines for background operations
	Start() error
	SaveNewInbox(inbox Inbox) error
	GetInboxByID(id string) (Inbox, error)
	GetInboxByAddress(address string) (Inbox, error)
	EmailAddressExists(address string) (bool, error)
	SetInboxCreated(inbox Inbox) error
	SetInboxFailed(inbox Inbox) error
	SaveNewMessage(message Message) error
	GetMessagesByInboxID(id string) ([]Message, error)
	GetMessageByID(inboxID string, messageID string) (Message, error)
}

Database lists methods needed to implement a db

type EmailGenerator

type EmailGenerator interface {
	NewRandom() string
	NewFromUserAndHost(user string, host string) (string, error)
}

type EmailProvider

type EmailProvider interface {
	Start(websiteAddr string, db Database, r *mux.Router, isBlacklistedDomain func(string) bool) error
	Stop() error
	RegisterRoute(i Inbox) (string, error)
}

EmailProvider represents a mail provider that burner.kiwi can use to receive mail from

type Errors

type Errors struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

Errors is our error struct for if something goes wrong

type Inbox

type Inbox struct {
	Address              string `dynamodbav:"email_address" json:"address" db:"address"`
	ID                   string `dynamodbav:"id" json:"id" db:"id"`
	CreatedAt            int64  `dynamodbav:"created_at" json:"created_at" db:"created_at"`
	CreatedBy            string `dynamodbav:"created_by" json:"-" db:"created_by"`
	TTL                  int64  `dynamodbav:"ttl" json:"ttl" db:"ttl"`
	EmailProviderRouteID string `dynamodbav:"ep_routeid" json:"-" db:"ep_routeid"`
	FailedToCreate       bool   `dynamodbav:"failed_to_create" json:"-" db:"failed_to_create"`
}

Inbox contains data on a temporary inbox including its address and ttl

func NewInbox

func NewInbox() Inbox

NewInbox returns an inbox with failed to create and route id set.

type Message

type Message struct {
	InboxID         string `dynamodbav:"inbox_id" json:"-" db:"inbox_id"`
	ID              string `dynamodbav:"message_id" json:"id" db:"message_id"`
	ReceivedAt      int64  `dynamodbav:"received_at" json:"received_at" db:"received_at"`
	EmailProviderID string `dynamodbav:"ep_id" json:"-" db:"ep_id"`
	Sender          string `dynamodbav:"sender" json:"sender" db:"sender"`
	FromName        string `dynamodbav:"fromName" json:"from_name" db:"from_name"`
	FromAddress     string `dynamodbav:"fromEmail" json:"from_address" db:"from_address"`
	Subject         string `dynamodbav:"subject" json:"subject" db:"subject"`
	BodyHTML        string `dynamodbav:"body_html" json:"body_html" db:"body_html"`
	BodyPlain       string `dynamodbav:"body_plain" json:"body_plain" db:"body_plain"`
	TTL             int64  `dynamodbav:"ttl" json:"ttl" db:"ttl"`
}

Message contains details of an individual email message received by the burner

type Response

type Response struct {
	Success bool        `json:"success"`
	Errors  interface{} `json:"errors"`
	Result  interface{} `json:"result"`
}

Response is the root response for every api call

type Server

type Server struct {
	Router *mux.Router
	// contains filtered or unexported fields
}

Server bundles several data types together for dependency injection into http handlers

func New

func New(cfg Config, db Database, email EmailProvider) (*Server, error)

New returns a burner with the given settings

func (*Server) CheckPermissionJSON

func (s *Server) CheckPermissionJSON(h http.Handler) http.Handler

CheckPermissionJSON checks whether or not the user has permission to call a url

func (*Server) CheckSessionCookieExists

func (s *Server) CheckSessionCookieExists(h http.Handler) http.Handler

CheckSessionExists checks for the existence of the session cookie and displays and error if false

func (*Server) ConfirmDeleteInbox

func (s *Server) ConfirmDeleteInbox(w http.ResponseWriter, r *http.Request)

ConfirmDeleteInbox removes the user session cookie

func (*Server) DeleteInbox

func (s *Server) DeleteInbox(w http.ResponseWriter, r *http.Request)

DeleteInbox prompts for a confirmation to delete from the user

func (*Server) EditInbox

func (s *Server) EditInbox(w http.ResponseWriter, r *http.Request)

EditInbox prompts the user for a new name for the inbox route

func (*Server) GetAllMessagesJSON

func (s *Server) GetAllMessagesJSON(w http.ResponseWriter, r *http.Request)

GetAllMessagesJSON returns all messages in json

func (*Server) GetInboxDetailsJSON

func (s *Server) GetInboxDetailsJSON(w http.ResponseWriter, r *http.Request)

GetInboxDetailsJSON returns details on a singular inbox by the given inbox id

func (*Server) Index

func (s *Server) Index(w http.ResponseWriter, r *http.Request)

Index either creates a new inbox or returns the existing one

func (*Server) IndividualMessage

func (s *Server) IndividualMessage(w http.ResponseWriter, r *http.Request)

IndividualMessage returns a singular message to the user

func (*Server) NewInboxJSON

func (s *Server) NewInboxJSON(w http.ResponseWriter, r *http.Request)

NewInboxJSON generates a new email address and returns it to the caller

func (*Server) NewNamedInbox

func (s *Server) NewNamedInbox(w http.ResponseWriter, r *http.Request)

newNamedInbox generates a new Inbox with a specific route and host.

func (*Server) Ping

func (s *Server) Ping(w http.ResponseWriter, r *http.Request)

Ping returns PONG when called

func (*Server) SecurityHeaders

func (s *Server) SecurityHeaders() alice.Constructor

SecurityHeaders sets a whole bunch of headers to secure the site

Jump to

Keyboard shortcuts

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