padlockcloud

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiVersion = 1
)
View Source
const Version = "1.3.0"

Variables

View Source
var (
	// A particular implementation of the Storable implementation is not supported
	ErrUnregisteredStorable = errors.New("padlock: unregistered storable type")
	// An object was not found
	ErrNotFound = errors.New("padlock: not found")
	// A query was attempted on a closed storage
	ErrStorageClosed = errors.New("padlock: storage closed")
)

Error singletons

View Source
var CSRFTemplateField = csrf.TemplateField
View Source
var CSRFTemplateTag = csrf.TemplateTag
View Source
var CSRFToken = csrf.Token
View Source
var DefaultAssetsPath = filepath.Join(gopath, "src/github.com/maklesoft/padlock-cloud/assets")
View Source
var IOS_DEVICES = map[string]string{
	"iPhone1,1": "iPhone",
	"iPhone1,2": "iPhone 3G",
	"iPhone2,1": "iPhone 3GS",
	"iPhone3,1": "iPhone 4",
	"iPhone3,2": "iPhone 4",
	"iPhone3,3": "iPhone 4",
	"iPhone4,1": "iPhone 4S",
	"iPhone5,1": "iPhone 5",
	"iPhone5,2": "iPhone 5",
	"iPhone5,3": "iPhone 5C",
	"iPhone5,4": "iPhone 5C",
	"iPhone6,1": "iPhone 5S",
	"iPhone6,2": "iPhone 5S",
	"iPhone7,1": "iPhone 6 Plus",
	"iPhone7,2": "iPhone 6",
	"iPhone8,1": "iPhone 6S",
	"iPhone8,2": "iPhone 6S Plus",
	"iPhone8,3": "iPhone SE",
	"iPhone8,4": "iPhone SE",
	"iPhone9,1": "iPhone 7",
	"iPhone9,2": "iPhone 7 Plus",
	"iPhone9,3": "iPhone 7",
	"iPhone9,4": "iPhone 7 Plus",

	"iPod1,1": "iPod touch (1st Gen)",
	"iPod2,1": "iPod touch (2nd Gen)",
	"iPod3,1": "iPod touch (3rd Gen)",
	"iPod4,1": "iPod touch (4th Gen)",
	"iPod5,1": "iPod touch (5th Gen)",
	"iPod7,1": "iPod touch (6th Gen)",

	"iPad1,1":  "iPad (1st Gen)",
	"iPad1,2":  "iPad (1st Gen)",
	"iPad2,1":  "iPad (2nd Gen)",
	"iPad2,2":  "iPad (2nd Gen)",
	"iPad2,3":  "iPad (2nd Gen)",
	"iPad2,4":  "iPad (2nd Gen)",
	"iPad2,5":  "iPad mini (1st Gen)",
	"iPad2,6":  "iPad mini (1st Gen)",
	"iPad2,7":  "iPad mini (1st Gen)",
	"iPad3,1":  "iPad (3rd Gen)",
	"iPad3,2":  "iPad (3rd Gen)",
	"iPad3,3":  "iPad (3rd Gen)",
	"iPad3,4":  "iPad (4th Gen)",
	"iPad3,5":  "iPad (4th Gen)",
	"iPad3,6":  "iPad (4th Gen)",
	"iPad4,1":  "iPad Air (1st Gen)",
	"iPad4,2":  "iPad Air (1st Gen)",
	"iPad4,3":  "iPad Air",
	"iPad4,4":  "iPad mini (2nd Gen)",
	"iPad4,5":  "iPad mini (2nd Gen)",
	"iPad4,6":  "iPad mini (2nd Gen)",
	"iPad4,7":  "iPad mini (3rd Gen)",
	"iPad4,8":  "iPad mini (3rd Gen)",
	"iPad4,9":  "iPad mini (3rd Gen)",
	"iPad5,1":  "iPad mini (4th Gen)",
	"iPad5,2":  "iPad mini (4th Gen)",
	"iPad5,3":  "iPad Air (2nd Gen)",
	"iPad5,4":  "iPad Air (2nd Gen)",
	"iPad6,3":  "iPad Pro 9.7\"",
	"iPad6,4":  "iPad Pro 9.7\"",
	"iPad6,7":  "iPad Pro 12.9\" (1st Gen)",
	"iPad6,8":  "iPad Pro 12.9\" (1st Gen))",
	"iPad6,11": "iPad (5th Gen)",
	"iPad6,12": "iPad (5th Gen)",
	"iPad7,1":  "iPad Pro 12.9\" (2nd Gen)",
	"iPad7,2":  "iPad Pro 12.9\" (2nd Gen)",
	"iPad7,3":  "iPad Pro 10.5\"",
	"iPad7,4":  "iPad Pro 10.5\"",
}
View Source
var PerMin = throttled.PerMin
View Source
var PerSec = throttled.PerSec
View Source
var StorableTypes = map[reflect.Type]string{}

Map of supported `Storable` implementations along with identifier strings that can be used for internal store or file names

Functions

func DashboardParams

func DashboardParams(r *http.Request, auth *AuthToken) map[string]interface{}

func ExtendTemplate

func ExtendTemplate(base *t.Template, path string) (*t.Template, error)

func FormatRequest

func FormatRequest(r *http.Request) string

func HttpHandler

func HttpHandler(h Handler) http.Handler

func IPFromRequest

func IPFromRequest(r *http.Request) string

func JsonifyErrorResponse

func JsonifyErrorResponse(e ErrorResponse) []byte

func LoadTemplates

func LoadTemplates(tt *Templates, p string) error

Loads templates from given directory

func PlatformDisplayName

func PlatformDisplayName(platform string) string

func RateLimit

func RateLimit(handler http.Handler, quotas map[Route]RateQuota, deniedHandler http.Handler) http.Handler

Limits the rate of a given handler to a certain number of requests per minute

func RegisterStorable

func RegisterStorable(t Storable, loc string)

Types

type Account

type Account struct {
	// The email servers as a unique identifier and as a means for
	// requesting/activating api keys
	Email string
	// Time the account was created
	Created time.Time
	// A set of api keys that can be used to access the data associated with this
	// account
	AuthTokens []*AuthToken
}

A struct representing a user with a set of api keys

func (*Account) AddAuthToken

func (a *Account) AddAuthToken(token *AuthToken)

Adds an api key to this account. If an api key for the given device is already registered, that one will be replaced

func (*Account) AuthTokensByType

func (a *Account) AuthTokensByType(typ string) []*AuthToken

func (*Account) Deserialize

func (acc *Account) Deserialize(data []byte) error

Implementation of the `Storable.Deserialize` method

func (*Account) Devices

func (a *Account) Devices() []*AuthToken

func (*Account) ExpireUnusedAuthTokens

func (a *Account) ExpireUnusedAuthTokens()

Expires auth tokens that haven't been used in a while

func (*Account) Key

func (acc *Account) Key() []byte

Implements the `Key` method of the `Storable` interface

func (*Account) RemoveAuthToken

func (a *Account) RemoveAuthToken(t *AuthToken) bool

Removes the corresponding auth token from the accounts `AuthTokens` slice

func (*Account) RemoveExpiredAuthTokens

func (a *Account) RemoveExpiredAuthTokens()

Filters out auth tokens that have been expired for 7 days or more

func (*Account) Serialize

func (acc *Account) Serialize() ([]byte, error)

Implementation of the `Storable.Serialize` method

func (*Account) ToMap

func (a *Account) ToMap() map[string]interface{}

func (*Account) UpdateAuthToken

func (a *Account) UpdateAuthToken(t *AuthToken)

Updates the correspoding auth token in the accounts `AuthTokens` slice with the value of `t`

type AccountInfo

type AccountInfo struct {
	*Server
}

func (*AccountInfo) Handle

func (h *AccountInfo) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

type AccountNotFound

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

func (*AccountNotFound) Code

func (e *AccountNotFound) Code() string

func (*AccountNotFound) Error

func (e *AccountNotFound) Error() string

func (*AccountNotFound) Message

func (e *AccountNotFound) Message() string

func (*AccountNotFound) Status

func (e *AccountNotFound) Status() int

type ActivateAuthToken

type ActivateAuthToken struct {
	*Server
}

func (*ActivateAuthToken) Activate

func (h *ActivateAuthToken) Activate(authRequest *AuthRequest) error

func (*ActivateAuthToken) GetAuthRequest

func (h *ActivateAuthToken) GetAuthRequest(r *http.Request) (*AuthRequest, error)

func (*ActivateAuthToken) Handle

Hander function for activating a given api key

func (*ActivateAuthToken) SetAuthCookie

func (h *ActivateAuthToken) SetAuthCookie(w http.ResponseWriter, at *AuthToken)

func (*ActivateAuthToken) Success

func (h *ActivateAuthToken) Success(w http.ResponseWriter, r *http.Request, authRequest *AuthRequest) error

type AuthRequest

type AuthRequest struct {
	Code      string
	Token     string
	AuthToken *AuthToken
	Created   time.Time
	Redirect  string
}

AuthRequest represents an api key - activation token pair used to activate a given api key `AuthRequest.Token` is used to activate the AuthToken through a separate channel (e.g. email)

func NewAuthRequest

func NewAuthRequest(email string, tType string, actType string, device *Device) (*AuthRequest, error)

Creates a new `AuthRequest` with a given `email`

func (*AuthRequest) Deserialize

func (ar *AuthRequest) Deserialize(data []byte) error

Implementation of the `Storable.Deserialize` method

func (*AuthRequest) Key

func (ar *AuthRequest) Key() []byte

Implementation of the `Storable.Key` interface method

func (*AuthRequest) Serialize

func (ar *AuthRequest) Serialize() ([]byte, error)

Implementation of the `Storable.Serialize` method

type AuthToken

type AuthToken struct {
	Email          string
	Token          string
	Type           string
	Id             string
	Created        time.Time
	LastUsed       time.Time
	Expires        time.Time
	ClientVersion  string
	ClientPlatform string
	Device         *Device
	// contains filtered or unexported fields
}

A wrapper for an api key containing some meta info like the user and device name

func AuthTokenFromRequest

func AuthTokenFromRequest(r *http.Request) (*AuthToken, error)

Creates an auth token from a given request by parsing the `Authorization` header and `auth` cookie

func AuthTokenFromString

func AuthTokenFromString(str string) (*AuthToken, error)

Creates an auth token from it's string representation of the form "AuthToken base64(t.Email):t.Token"

func NewAuthToken

func NewAuthToken(email string, t string, device *Device) (*AuthToken, error)

Creates a new auth token for a given `email`

func (*AuthToken) Account

func (t *AuthToken) Account() *Account

Returns the account associated with this auth token

func (*AuthToken) Description

func (t *AuthToken) Description() string

func (*AuthToken) Expired

func (t *AuthToken) Expired() bool

Returns true if `t` is expires, false otherwise

func (*AuthToken) String

func (t *AuthToken) String() string

Returns a string representation of the auth token in the form "AuthToken base64(t.Email):t.Token"

func (*AuthToken) ToMap

func (t *AuthToken) ToMap() map[string]interface{}

func (*AuthToken) Validate

func (t *AuthToken) Validate(a *Account) bool

Validates the auth token against account `a`, i.e. looks for the corresponding token in the accounts `AuthTokens` slice. If found, the token is considered valid and it's value is updated with the value of the corresponding auth token in `a.AuthTokens` and the `account` field is set to `a`

type Authenticate

type Authenticate struct {
	*Server
	Type string
}

func (*Authenticate) Wrap

func (m *Authenticate) Wrap(h Handler) Handler

type BadRequest

type BadRequest struct {
	Msg string
}

func (*BadRequest) Code

func (e *BadRequest) Code() string

func (*BadRequest) Error

func (e *BadRequest) Error() string

func (*BadRequest) Message

func (e *BadRequest) Message() string

func (*BadRequest) Status

func (e *BadRequest) Status() int

type CSRF

type CSRF struct {
	*Server
}

func (*CSRF) Wrap

func (m *CSRF) Wrap(h Handler) Handler

type CheckEndpointVersion

type CheckEndpointVersion struct {
	*Server
	Version int
}

func (*CheckEndpointVersion) Wrap

type CheckMethod

type CheckMethod struct {
	Allowed map[string]Handler
}

func (*CheckMethod) Wrap

func (m *CheckMethod) Wrap(h Handler) Handler

type CliApp

type CliApp struct {
	*cli.App
	Storage    Storage
	Server     *Server
	Config     *CliConfig
	ConfigPath string
}

func NewCliApp

func NewCliApp() *CliApp

func (*CliApp) CreateAccount

func (cliApp *CliApp) CreateAccount(context *cli.Context) error

func (*CliApp) DeleteAccount

func (cliApp *CliApp) DeleteAccount(context *cli.Context) error

func (*CliApp) DisplayAccount

func (cliApp *CliApp) DisplayAccount(context *cli.Context) error

func (*CliApp) GenSecret

func (cliApp *CliApp) GenSecret(context *cli.Context) error

func (*CliApp) InitServer

func (cliApp *CliApp) InitServer() error

func (*CliApp) InitWithConfig

func (cliApp *CliApp) InitWithConfig(config *CliConfig) error

func (*CliApp) ListAccounts

func (cliApp *CliApp) ListAccounts(context *cli.Context) error

func (*CliApp) RunServer

func (cliApp *CliApp) RunServer(context *cli.Context) error

type CliConfig

type CliConfig struct {
	Log     LogConfig     `yaml:"log"`
	Server  ServerConfig  `yaml:"server"`
	LevelDB LevelDBConfig `yaml:"leveldb"`
	Email   EmailConfig   `yaml:"email"`
}

func (*CliConfig) LoadFromFile

func (c *CliConfig) LoadFromFile(path string) error

type Dashboard

type Dashboard struct {
	*Server
}

func (*Dashboard) Handle

func (h *Dashboard) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

type DataStore

type DataStore struct {
	Account *Account
	Content []byte
}

DataStore represents the data associated to a given account

func (*DataStore) Deserialize

func (d *DataStore) Deserialize(data []byte) error

Implementation of the `Storable.Deserialize` interface method

func (*DataStore) Key

func (d *DataStore) Key() []byte

Implementation of the `Storable.Key` interface method

func (*DataStore) Serialize

func (d *DataStore) Serialize() ([]byte, error)

Implementation of the `Storable.Serialize` interface method

type DeleteAccount added in v1.3.0

type DeleteAccount struct {
	*Server
}

func (*DeleteAccount) Handle added in v1.3.0

func (h *DeleteAccount) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

type DeleteStore

type DeleteStore struct {
	*Server
}

func (*DeleteStore) Handle

func (h *DeleteStore) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

type Device

type Device struct {
	// Permanent fields - these are not going to change
	Platform     string `json:"platform"`
	UUID         string `json:"uuid"`
	Manufacturer string `json:"manufacturer"`
	Model        string `json:"model"`
	// Dynamic fields - these may be updated
	OSVersion  string `json:"osVersion"`
	HostName   string `json:"hostName"`
	AppVersion string `json:"appVersion"`
}

func DeviceFromRequest

func DeviceFromRequest(r *http.Request) *Device

func (*Device) Description

func (d *Device) Description() string

func (*Device) UpdateFromRequest

func (d *Device) UpdateFromRequest(r *http.Request)

type EmailConfig

type EmailConfig struct {
	// User name used for authentication with the mail server
	User string `yaml:"user"`
	// Mail server address
	Server string `yaml:"server"`
	// Port on which to contact the mail server
	Port string `yaml:"port"`
	// Password used for authentication with the mail server
	Password string `yaml:"password"`
	// Sender mail address for outgoing mails. If empty, `User` is used instead.
	From string `yaml:"from"`
}

type EmailRateLimiter

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

func NewEmailRateLimiter

func NewEmailRateLimiter(ipQuota RateQuota, emailQuota RateQuota) (*EmailRateLimiter, error)

func (*EmailRateLimiter) RateLimit

func (erl *EmailRateLimiter) RateLimit(ip string, email string) bool

type EmailSender

type EmailSender struct {
	Config *EmailConfig
	// Function used to actually send the mail. Same signature as `smtp.SendMail`.
	SendFunc func(addr string, a smtp.Auth, from string, to []string, msg []byte) error
}

EmailSender implements the `Sender` interface for emails

func NewEmailSender

func NewEmailSender(c *EmailConfig) *EmailSender

NewEmailSender returns an EmailSender which sends mail using `smtp.SendMail`. Its configuration points to the given `EmailConfig`.

func (*EmailSender) Send

func (sender *EmailSender) Send(rec string, subject string, body string) error

Attempts to send an email to a given recipient.

type Endpoint

type Endpoint struct {
	Handlers map[string]Handler
	Version  int
	AuthType string
}

func (*Endpoint) Handle

func (endpoint *Endpoint) Handle(w http.ResponseWriter, r *http.Request, a *AuthToken) error

type ErrorResponse

type ErrorResponse interface {
	error
	Code() string
	Status() int
	Message() string
}

type ExpiredAuthToken

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

func (*ExpiredAuthToken) Code

func (e *ExpiredAuthToken) Code() string

func (*ExpiredAuthToken) Error

func (e *ExpiredAuthToken) Error() string

func (*ExpiredAuthToken) Message

func (e *ExpiredAuthToken) Message() string

func (*ExpiredAuthToken) Status

func (e *ExpiredAuthToken) Status() int

type HandleError

type HandleError struct {
	*Server
}

func (*HandleError) Wrap

func (m *HandleError) Wrap(h Handler) Handler

type HandlePanic

type HandlePanic struct {
}

func (*HandlePanic) Wrap

func (m *HandlePanic) Wrap(h Handler) Handler

type Handler

type Handler interface {
	Handle(http.ResponseWriter, *http.Request, *AuthToken) error
}

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request, *AuthToken) error

func (HandlerFunc) Handle

type InvalidAuthToken

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

func (*InvalidAuthToken) Code

func (e *InvalidAuthToken) Code() string

func (*InvalidAuthToken) Error

func (e *InvalidAuthToken) Error() string

func (*InvalidAuthToken) Message

func (e *InvalidAuthToken) Message() string

func (*InvalidAuthToken) Status

func (e *InvalidAuthToken) Status() int

type InvalidCsrfToken

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

func (*InvalidCsrfToken) Code

func (e *InvalidCsrfToken) Code() string

func (*InvalidCsrfToken) Error

func (e *InvalidCsrfToken) Error() string

func (*InvalidCsrfToken) Message

func (e *InvalidCsrfToken) Message() string

func (*InvalidCsrfToken) Status

func (e *InvalidCsrfToken) Status() int

type Job

type Job struct {
	Action func()
	// contains filtered or unexported fields
}

func (*Job) Start

func (j *Job) Start(interval time.Duration)

func (*Job) Stop

func (j *Job) Stop()

type LevelDBConfig

type LevelDBConfig struct {
	// Path to directory on disc where database files should be stored
	Path string `yaml:"path"`
}

type LevelDBIterator

type LevelDBIterator struct {
	iterator.Iterator
}

func (*LevelDBIterator) Get

func (iter *LevelDBIterator) Get(t Storable) error

type LevelDBStorage

type LevelDBStorage struct {
	Config *LevelDBConfig
	// contains filtered or unexported fields
}

LevelDB implementation of the `Storage` interface

func (*LevelDBStorage) CanStore

func (s *LevelDBStorage) CanStore(t Storable) bool

func (*LevelDBStorage) Close

func (s *LevelDBStorage) Close() error

Implementation of the `Storage.Close` interface method

func (*LevelDBStorage) Delete

func (s *LevelDBStorage) Delete(t Storable) error

Implementation of the `Storage.Delete` interface method

func (*LevelDBStorage) Get

func (s *LevelDBStorage) Get(t Storable) error

Implementation of the `Storage.Get` interface method

func (*LevelDBStorage) Iterator

func (s *LevelDBStorage) Iterator(t Storable) (StorageIterator, error)

func (*LevelDBStorage) Open

func (s *LevelDBStorage) Open() error

Implementation of the `Storage.Open` interface method

func (*LevelDBStorage) Put

func (s *LevelDBStorage) Put(t Storable) error

Implementation of the `Storage.Put` interface method

func (*LevelDBStorage) Ready

func (s *LevelDBStorage) Ready() bool

type LockAccount added in v1.3.0

type LockAccount struct {
	*Server
}

Middleware for locking state for a given account, if authenticated

func (*LockAccount) Wrap added in v1.3.0

func (m *LockAccount) Wrap(h Handler) Handler

type Log

type Log struct {
	Info   *log.Logger
	Error  *log.Logger
	Sender Sender
	Config *LogConfig
}

func NewLog

func NewLog(config *LogConfig, sender Sender) *Log

func (*Log) Init

func (l *Log) Init() error

func (*Log) InitWithConfig

func (l *Log) InitWithConfig(config *LogConfig)

type LogConfig

type LogConfig struct {
	// File to write logs to
	LogFile string `yaml:"log_file"`
	// File to write errors to. Defaults to the value of `LogFile`
	ErrFile string `yaml:"err_file"`
	// An address to send error notifications to
	NotifyErrors string `yaml:"notify_errors"`
}

type LoginPage

type LoginPage struct {
	*Server
}

func (*LoginPage) Handle

func (h *LoginPage) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

type Logout

type Logout struct {
	*Server
}

func (*Logout) Handle

func (h *Logout) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

type MemoryStorage

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

In-memory implemenation of the `Storage` interface Mainly used for testing

func (*MemoryStorage) CanStore

func (s *MemoryStorage) CanStore(t Storable) bool

func (*MemoryStorage) Close

func (s *MemoryStorage) Close() error

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(t Storable) error

func (*MemoryStorage) Get

func (s *MemoryStorage) Get(t Storable) error

func (*MemoryStorage) Iterator

func (s *MemoryStorage) Iterator(t Storable) (StorageIterator, error)

func (*MemoryStorage) Open

func (s *MemoryStorage) Open() error

func (*MemoryStorage) Put

func (s *MemoryStorage) Put(t Storable) error

func (*MemoryStorage) Ready

func (s *MemoryStorage) Ready() bool

type MethodNotAllowed

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

func (*MethodNotAllowed) Code

func (e *MethodNotAllowed) Code() string

func (*MethodNotAllowed) Error

func (e *MethodNotAllowed) Error() string

func (*MethodNotAllowed) Message

func (e *MethodNotAllowed) Message() string

func (*MethodNotAllowed) Status

func (e *MethodNotAllowed) Status() int

type MiddleWare

type MiddleWare interface {
	Wrap(Handler) Handler
}

type RateLimitExceeded

type RateLimitExceeded struct {
}

func (*RateLimitExceeded) Code

func (e *RateLimitExceeded) Code() string

func (*RateLimitExceeded) Error

func (e *RateLimitExceeded) Error() string

func (*RateLimitExceeded) Message

func (e *RateLimitExceeded) Message() string

func (*RateLimitExceeded) Status

func (e *RateLimitExceeded) Status() int

type RateQuota

type RateQuota throttled.RateQuota

type ReadStore

type ReadStore struct {
	*Server
}

func (*ReadStore) Handle

func (h *ReadStore) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

Handler function for retrieving the data associated with a given account

type RecordSender

type RecordSender struct {
	Recipient string
	Subject   string
	Message   string
}

Mock implementation of the `Sender` interface. Simply records arguments passed to the `Send` method

func (*RecordSender) Reset

func (s *RecordSender) Reset()

func (*RecordSender) Send

func (s *RecordSender) Send(rec string, subj string, message string) error

type RequestAuthToken

type RequestAuthToken struct {
	*Server
}

func (*RequestAuthToken) Handle

Handler function for requesting an api key. Generates a key-token pair and stores them. The token can later be used to activate the api key. An email is sent to the corresponding email address with an activation url. Expects `email` and `device_name` parameters through either multipart/form-data or application/x-www-urlencoded parameters

type Revoke

type Revoke struct {
	*Server
}

func (*Revoke) Handle

func (h *Revoke) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

type RootHandler

type RootHandler struct {
	*Server
}

func (*RootHandler) Handle

func (h *RootHandler) Handle(w http.ResponseWriter, r *http.Request, a *AuthToken) error

type Route

type Route struct {
	Url    string
	Method string
}

type SendWriter

type SendWriter struct {
	Sender
	Recipient string
	Subject   string
}

func (*SendWriter) Write

func (sw *SendWriter) Write(p []byte) (int, error)

type Sender

type Sender interface {
	Send(recipient string, subject string, message string) error
}

Sender is a interface that exposes the `Send` method for sending messages with a subject to a given recipient.

type Server

type Server struct {
	*graceful.Server
	*Log
	Storage   Storage
	Sender    Sender
	Templates *Templates
	Config    *ServerConfig
	Secure    bool
	Endpoints map[string]*Endpoint
	// contains filtered or unexported fields
}

The Server type holds all the contextual data and logic used for running a Padlock Cloud instances Users should use the `NewServer` function to instantiate an `Server` instance

func NewServer

func NewServer(log *Log, storage Storage, sender Sender, config *ServerConfig) *Server

Instantiates and initializes a new Server and returns a reference to it

func (*Server) Authenticate

func (server *Server) Authenticate(r *http.Request) (*AuthToken, error)

Retreives Account object from a http.Request object by evaluating the Authorization header and cross-checking it with api keys of existing accounts. Returns an `InvalidAuthToken` error if no valid Authorization header is provided or if the provided email:api_key pair does not match any of the accounts in the database.

func (*Server) BaseUrl

func (server *Server) BaseUrl(r *http.Request) string

func (*Server) CleanUp

func (server *Server) CleanUp() error

func (*Server) DeleteAccount added in v1.3.0

func (server *Server) DeleteAccount(email string) error

func (*Server) GetAccountMutex added in v1.3.0

func (server *Server) GetAccountMutex(email string) *sync.Mutex

func (*Server) HandleError

func (server *Server) HandleError(e error, w http.ResponseWriter, r *http.Request)

Global error handler. Writes a appropriate response to the provided `http.ResponseWriter` object and logs / notifies of internal server errors

func (*Server) Init

func (server *Server) Init() error

func (*Server) InitEndpoints

func (server *Server) InitEndpoints()

Registeres http handlers for various routes

func (*Server) InitHandler

func (server *Server) InitHandler()

func (*Server) LockAccount added in v1.3.0

func (server *Server) LockAccount(email string)

func (*Server) LogError

func (server *Server) LogError(err error, r *http.Request)

func (*Server) SendDeprecatedVersionEmail

func (server *Server) SendDeprecatedVersionEmail(r *http.Request) error

func (*Server) Start

func (server *Server) Start() error

func (*Server) UnlockAccount added in v1.3.0

func (server *Server) UnlockAccount(email string)

func (*Server) WrapEndpoint

func (server *Server) WrapEndpoint(endpoint *Endpoint) Handler

Registers handlers mapped by method for a given path

type ServerConfig

type ServerConfig struct {
	// Path to assets directory; used for loading templates and such
	AssetsPath string `yaml:"assets_path"`
	// Port to listen on
	Port int `yaml:"port"`
	// Path to TLS certificate
	TLSCert string `yaml:"tls_cert"`
	// Path to TLS key file
	TLSKey string `yaml:"tls_key"`
	// Explicit base url to use in place of http.Request::Host when generating urls and such
	BaseUrl string `yaml:"base_url"`
	// Secret used for authenticating cookies
	Secret string `yaml:"secret"`
	// Enable Cross-Origin Resource Sharing
	Cors bool `yaml:"cors"`
	// Test mode
	Test bool `yaml:"test"`
	// Whitelisted path
	WhitelistPath string `yaml:"whitelist_path"`
}

Server configuration

type ServerError

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

func (*ServerError) Code

func (e *ServerError) Code() string

func (*ServerError) Error

func (e *ServerError) Error() string

func (*ServerError) Format added in v1.3.0

func (e *ServerError) Format(s fmt.State, verb rune)

func (*ServerError) Message

func (e *ServerError) Message() string

func (*ServerError) Status

func (e *ServerError) Status() int

type SliceIterator

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

func (*SliceIterator) Get

func (iter *SliceIterator) Get(t Storable) error

func (*SliceIterator) Next

func (iter *SliceIterator) Next() bool

func (*SliceIterator) Release

func (iter *SliceIterator) Release()

type StaticHandler

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

func NewStaticHandler

func NewStaticHandler(dir string, path string) *StaticHandler

func (*StaticHandler) Handle

type Storable

type Storable interface {
	// This method is used for retrieving a key hat can be used to identify an object
	// The returned value should be unique and constant
	Key() []byte
	// Creates a string representation of an object. Data returned from this method should
	// be able to be fed into the `Deserialize` method to retrieve the original state
	Serialize() ([]byte, error)
	// Populates the fields from serialized data.
	Deserialize([]byte) error
}

Common interface for types that can be stored using the `Storage` interface.

type Storage

type Storage interface {
	// Prepares the database for use
	Open() error
	// Closes the database and performs cleanup actions
	Close() error
	// Returns readyness of the storage
	Ready() bool
	// Whether storage can store a certain storable
	CanStore(t Storable) bool
	// Populates a given `Storable` object with data retrieved from the store
	Get(Storable) error
	// Updates the store with the data from a given `Storable` object
	Put(Storable) error
	// Removes a given `Storable` object from the store
	Delete(Storable) error
	// Lists all keys for a given `Storable` type
	Iterator(Storable) (StorageIterator, error)
}

Common interface for storage implementations

type StorageIterator

type StorageIterator interface {
	Next() bool
	Get(Storable) error
	Release()
}

type Templates

type Templates struct {
	BasePage  *t.Template
	BaseEmail *t.Template
	// Email template for api key activation email
	ActivateAuthTokenEmail *t.Template
	// Email template for clients using an outdated api version
	DeprecatedVersionEmail *t.Template
	ErrorPage              *t.Template
	LoginPage              *t.Template
	Dashboard              *t.Template
}

Wrapper for holding references to template instances used for rendering emails, webpages etc.

type UnauthorizedError

type UnauthorizedError struct {
}

func (*UnauthorizedError) Code

func (e *UnauthorizedError) Code() string

func (*UnauthorizedError) Error

func (e *UnauthorizedError) Error() string

func (*UnauthorizedError) Message

func (e *UnauthorizedError) Message() string

func (*UnauthorizedError) Status

func (e *UnauthorizedError) Status() int

type UnsupportedApiVersion

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

func (*UnsupportedApiVersion) Code

func (e *UnsupportedApiVersion) Code() string

func (*UnsupportedApiVersion) Error

func (e *UnsupportedApiVersion) Error() string

func (*UnsupportedApiVersion) Message

func (e *UnsupportedApiVersion) Message() string

func (*UnsupportedApiVersion) Status

func (e *UnsupportedApiVersion) Status() int

type UnsupportedEndpoint

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

func (*UnsupportedEndpoint) Code

func (e *UnsupportedEndpoint) Code() string

func (*UnsupportedEndpoint) Error

func (e *UnsupportedEndpoint) Error() string

func (*UnsupportedEndpoint) Message

func (e *UnsupportedEndpoint) Message() string

func (*UnsupportedEndpoint) Status

func (e *UnsupportedEndpoint) Status() int

type VaryBy

type VaryBy struct{}

func (*VaryBy) Key

func (v *VaryBy) Key(r *http.Request) string

type VoidHandler

type VoidHandler struct {
}

func (*VoidHandler) Handle

func (h *VoidHandler) Handle(w http.ResponseWriter, r *http.Request, a *AuthToken) error

type Whitelist

type Whitelist struct {
	// Whitelisted emails
	Emails map[string]bool
}

func NewWhitelist

func NewWhitelist(path string) (*Whitelist, error)

func (*Whitelist) IsWhitelisted

func (w *Whitelist) IsWhitelisted(email string) bool

Returns whether email is whitelisted or not

type WriteStore

type WriteStore struct {
	*Server
}

func (*WriteStore) Handle

func (h *WriteStore) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error

Handler function for updating the data associated with a given account. This does NOT implement a diffing algorith of any kind since Padlock Cloud is completely ignorant of the data structures involved. Instead, clients should retrieve existing data through the `ReadStore` endpoint first, perform any necessary decryption/parsing, consolidate the data with any existing local data and then reupload the full, encrypted data set

Jump to

Keyboard shortcuts

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