Documentation ¶
Index ¶
- Constants
- Variables
- func DashboardParams(r *http.Request, auth *AuthToken) map[string]interface{}
- func ExtendTemplate(base *t.Template, path string) (*t.Template, error)
- func FormatRequest(r *http.Request) string
- func HttpHandler(h Handler) http.Handler
- func IPFromRequest(r *http.Request) string
- func JsonifyErrorResponse(e ErrorResponse) []byte
- func LoadTemplates(tt *Templates, p string) error
- func PlatformDisplayName(platform string) string
- func RateLimit(handler http.Handler, quotas map[Route]RateQuota, deniedHandler http.Handler) http.Handler
- func RegisterStorable(t Storable, loc string)
- type Account
- func (a *Account) AddAuthToken(token *AuthToken)
- func (a *Account) AuthTokensByType(typ string) []*AuthToken
- func (acc *Account) Deserialize(data []byte) error
- func (a *Account) Devices() []*AuthToken
- func (a *Account) ExpireUnusedAuthTokens()
- func (acc *Account) Key() []byte
- func (a *Account) RemoveAuthToken(t *AuthToken) bool
- func (a *Account) RemoveExpiredAuthTokens()
- func (acc *Account) Serialize() ([]byte, error)
- func (a *Account) ToMap() map[string]interface{}
- func (a *Account) UpdateAuthToken(t *AuthToken)
- type AccountInfo
- type AccountNotFound
- type ActivateAuthToken
- func (h *ActivateAuthToken) Activate(authRequest *AuthRequest) error
- func (h *ActivateAuthToken) GetAuthRequest(r *http.Request) (*AuthRequest, error)
- func (h *ActivateAuthToken) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error
- func (h *ActivateAuthToken) SetAuthCookie(w http.ResponseWriter, at *AuthToken)
- func (h *ActivateAuthToken) Success(w http.ResponseWriter, r *http.Request, authRequest *AuthRequest) error
- type AuthRequest
- type AuthToken
- type Authenticate
- type BadRequest
- type CSRF
- type CheckEndpointVersion
- type CheckMethod
- type CliApp
- func (cliApp *CliApp) CreateAccount(context *cli.Context) error
- func (cliApp *CliApp) DeleteAccount(context *cli.Context) error
- func (cliApp *CliApp) DisplayAccount(context *cli.Context) error
- func (cliApp *CliApp) GenSecret(context *cli.Context) error
- func (cliApp *CliApp) InitServer() error
- func (cliApp *CliApp) InitWithConfig(config *CliConfig) error
- func (cliApp *CliApp) ListAccounts(context *cli.Context) error
- func (cliApp *CliApp) RunServer(context *cli.Context) error
- type CliConfig
- type Dashboard
- type DataStore
- type DeleteAccount
- type DeleteStore
- type Device
- type EmailConfig
- type EmailRateLimiter
- type EmailSender
- type Endpoint
- type ErrorResponse
- type ExpiredAuthToken
- type HandleError
- type HandlePanic
- type Handler
- type HandlerFunc
- type InvalidAuthToken
- type InvalidCsrfToken
- type Job
- type LevelDBConfig
- type LevelDBIterator
- type LevelDBStorage
- func (s *LevelDBStorage) CanStore(t Storable) bool
- func (s *LevelDBStorage) Close() error
- func (s *LevelDBStorage) Delete(t Storable) error
- func (s *LevelDBStorage) Get(t Storable) error
- func (s *LevelDBStorage) Iterator(t Storable) (StorageIterator, error)
- func (s *LevelDBStorage) Open() error
- func (s *LevelDBStorage) Put(t Storable) error
- func (s *LevelDBStorage) Ready() bool
- type LockAccount
- type Log
- type LogConfig
- type LoginPage
- type Logout
- type MemoryStorage
- func (s *MemoryStorage) CanStore(t Storable) bool
- func (s *MemoryStorage) Close() error
- func (s *MemoryStorage) Delete(t Storable) error
- func (s *MemoryStorage) Get(t Storable) error
- func (s *MemoryStorage) Iterator(t Storable) (StorageIterator, error)
- func (s *MemoryStorage) Open() error
- func (s *MemoryStorage) Put(t Storable) error
- func (s *MemoryStorage) Ready() bool
- type MethodNotAllowed
- type MiddleWare
- type RateLimitExceeded
- type RateQuota
- type ReadStore
- type RecordSender
- type RequestAuthToken
- type Revoke
- type RootHandler
- type Route
- type SendWriter
- type Sender
- type Server
- func (server *Server) Authenticate(r *http.Request) (*AuthToken, error)
- func (server *Server) BaseUrl(r *http.Request) string
- func (server *Server) CleanUp() error
- func (server *Server) DeleteAccount(email string) error
- func (server *Server) GetAccountMutex(email string) *sync.Mutex
- func (server *Server) HandleError(e error, w http.ResponseWriter, r *http.Request)
- func (server *Server) Init() error
- func (server *Server) InitEndpoints()
- func (server *Server) InitHandler()
- func (server *Server) LockAccount(email string)
- func (server *Server) LogError(err error, r *http.Request)
- func (server *Server) SendDeprecatedVersionEmail(r *http.Request) error
- func (server *Server) Start() error
- func (server *Server) UnlockAccount(email string)
- func (server *Server) WrapEndpoint(endpoint *Endpoint) Handler
- type ServerConfig
- type ServerError
- type SliceIterator
- type StaticHandler
- type Storable
- type Storage
- type StorageIterator
- type Templates
- type UnauthorizedError
- type UnsupportedApiVersion
- type UnsupportedEndpoint
- type VaryBy
- type VoidHandler
- type Whitelist
- type WriteStore
Constants ¶
const (
ApiVersion = 1
)
const Version = "1.3.0"
Variables ¶
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
var CSRFTemplateField = csrf.TemplateField
var CSRFTemplateTag = csrf.TemplateTag
var CSRFToken = csrf.Token
var DefaultAssetsPath = filepath.Join(gopath, "src/github.com/maklesoft/padlock-cloud/assets")
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\"",
}
var PerMin = throttled.PerMin
var PerSec = throttled.PerSec
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 FormatRequest ¶
func HttpHandler ¶
func IPFromRequest ¶
func JsonifyErrorResponse ¶
func JsonifyErrorResponse(e ErrorResponse) []byte
func LoadTemplates ¶
Loads templates from given directory
func PlatformDisplayName ¶
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 ¶
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 ¶
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 (*Account) Deserialize ¶
Implementation of the `Storable.Deserialize` method
func (*Account) ExpireUnusedAuthTokens ¶
func (a *Account) ExpireUnusedAuthTokens()
Expires auth tokens that haven't been used in a while
func (*Account) RemoveAuthToken ¶
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) UpdateAuthToken ¶
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 ¶
func (h *ActivateAuthToken) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error
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 ¶
Creates an auth token from a given request by parsing the `Authorization` header and `auth` cookie
func AuthTokenFromString ¶
Creates an auth token from it's string representation of the form "AuthToken base64(t.Email):t.Token"
func NewAuthToken ¶
Creates a new auth token for a given `email`
func (*AuthToken) Description ¶
func (*AuthToken) String ¶
Returns a string representation of the auth token in the form "AuthToken base64(t.Email):t.Token"
func (*AuthToken) Validate ¶
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 ¶
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 CheckEndpointVersion ¶
func (*CheckEndpointVersion) Wrap ¶
func (m *CheckEndpointVersion) Wrap(h Handler) Handler
type CheckMethod ¶
func (*CheckMethod) Wrap ¶
func (m *CheckMethod) Wrap(h Handler) Handler
type CliApp ¶
func (*CliApp) CreateAccount ¶
func (*CliApp) DeleteAccount ¶
func (*CliApp) DisplayAccount ¶
func (*CliApp) InitServer ¶
func (*CliApp) InitWithConfig ¶
func (*CliApp) ListAccounts ¶
type CliConfig ¶
type CliConfig struct { Log LogConfig `yaml:"log"` Server ServerConfig `yaml:"server"` LevelDB LevelDBConfig `yaml:"leveldb"` Email EmailConfig `yaml:"email"` }
func (*CliConfig) LoadFromFile ¶
type DataStore ¶
DataStore represents the data associated to a given account
func (*DataStore) Deserialize ¶
Implementation of the `Storable.Deserialize` 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 (*Device) Description ¶
func (*Device) UpdateFromRequest ¶
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)
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`.
type ErrorResponse ¶
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 HandlerFunc ¶
func (HandlerFunc) Handle ¶
func (f HandlerFunc) Handle(w http.ResponseWriter, r *http.Request, a *AuthToken) error
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 LevelDBConfig ¶
type LevelDBConfig struct { // Path to directory on disc where database files should be stored Path string `yaml:"path"` }
type LevelDBIterator ¶
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 ¶
func (*Log) InitWithConfig ¶
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 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 RecordSender ¶
Mock implementation of the `Sender` interface. Simply records arguments passed to the `Send` method
func (*RecordSender) Reset ¶
func (s *RecordSender) Reset()
type RequestAuthToken ¶
type RequestAuthToken struct {
*Server
}
func (*RequestAuthToken) Handle ¶
func (h *RequestAuthToken) Handle(w http.ResponseWriter, r *http.Request, auth *AuthToken) error
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 RootHandler ¶
type RootHandler struct {
*Server
}
func (*RootHandler) Handle ¶
func (h *RootHandler) Handle(w http.ResponseWriter, r *http.Request, a *AuthToken) error
type SendWriter ¶
type Sender ¶
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 ¶
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) DeleteAccount ¶ added in v1.3.0
func (*Server) GetAccountMutex ¶ added in v1.3.0
func (*Server) HandleError ¶
Global error handler. Writes a appropriate response to the provided `http.ResponseWriter` object and logs / notifies of internal server errors
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) SendDeprecatedVersionEmail ¶
func (*Server) UnlockAccount ¶ added in v1.3.0
func (*Server) WrapEndpoint ¶
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) 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 ¶
func (h *StaticHandler) Handle(w http.ResponseWriter, r *http.Request, a *AuthToken) error
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 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 VoidHandler ¶
type VoidHandler struct { }
func (*VoidHandler) Handle ¶
func (h *VoidHandler) Handle(w http.ResponseWriter, r *http.Request, a *AuthToken) error
type Whitelist ¶
func NewWhitelist ¶
func (*Whitelist) IsWhitelisted ¶
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