config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const AgentName = "matrixid"

AgentName the name used for User-Agent header. All http clients making requests between matrix serves include this header.

View Source
const ApplicationName = "sydent-go"

ApplicationName the name of the application.

View Source
const MaxRetries = 16

MaxRetries is the maximum number of retries for http requests made by matrixid clients before backing off.

View Source
const ThreepidSessionValidationLifetime = 24 * 60 * 60 * 1000

ThreepidSessionValidationLifetime duration in ms of the retaining period for sessions.

View Source
const ThreepidSessionValidationTimeout = 24 * 60 * 60 * 1000

ThreepidSessionValidationTimeout duration in MS of the time a user will have to wait before the session he/she created is validates.

Variables

View Source
var (
	InviteTpl                = "/email/invite_template.eml"
	InviteVector             = "/email/invite_template_vector.eml"
	VerificationTpl          = "/email/verification_template.eml"
	VerificationVector       = "/email/verification_template_vector.eml"
	VerifyResponsePage       = "/email/verify_response_page_template"
	VerifyResponsePageVector = "/email/verify_response_page_template_vector_im"
)

embedded templates

Functions

func Empty

func Empty(c *Matrix) bool

Empty returns true if c is empty.

func EnsureConnected

func EnsureConnected(driver, conn string) (db *sql.DB, err error)

EnsureConnected for automated deployments there are some cases when the database might be booting up so connections here will fall, this does exponential retries to connect to the database.

func FormatDate

func FormatDate(ts time.Time, local, useGMT bool) string

FormatDate similar to python email.utils.formatdate

func IsValidEmail

func IsValidEmail(email string) bool

func MergeTemplates

func MergeTemplates(a, b []Template) map[string]Template

func ProcessFile

func ProcessFile(src []byte) []byte

ProcessFile expands environment variables in src. This means it will replace all $VAR or ${VAR} declarations with values found in environment variables.

Types

type Client

type Client interface {
	Validator
	Send(from string, to []string, msg []byte) error
	Host() string
}

type Container

type Container struct {
	Name     string                 `hcl:",key"`
	State    string                 `hcl:"state"`
	Settings map[string]interface{} `hcl:"settings"`
}

Container abstract struct for storing namespaced settings.

type Crypto

type Crypto struct {
	Algorithm  string `hcl:"algorithm"`
	Version    string `hcl:"version"`
	SingingKey string `hcl:"signing_key"`
	VerifyKey  string `hcl:"verify_key"`
}

Crypto cryptographic keys used for signing and verifying messages.

func (Crypto) Key

func (c Crypto) Key() *signedjson.Key

func (Crypto) Valid

func (c Crypto) Valid() *Validation

Valid returns nil if c is a valid configuration for identity service crypto.

type DB

type DB struct {
	Driver string `hcl:"driver"`
	Conn   string `hcl:"conn"`
}

func (DB) Valid

func (db DB) Valid() *Validation

type Email

type Email struct {
	Providers    []Provider   `hcl:"provider"`
	Invite       Invite       `hcl:"invite"`
	Verification Verification `hcl:"verification"`
}

Email defines all possible configuration for email client.

func (Email) Provider

func (e Email) Provider(templates *template.Template) (EmailProvider, error)

func (Email) Valid

func (e Email) Valid(templates *template.Template) *Validation

type EmailProvider

type EmailProvider interface {
	Validator
	Mail
}

type Field

type Field struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient defines API for sending http requests.

type Invite

type Invite struct {
	From     string `hcl:"from"`
	Template string `hcl:"template"`
}

func (Invite) Valid

func (i Invite) Valid() *Validation

type Key

type Key struct {
	ID    string `hcl:"key"`
	Value string `hcl:"value"`
}

type Kmail

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

Kmail provide methods for sending emails.

func New

func New(client Client, tpl *template.Template) (*Kmail, error)

func (*Kmail) SendMail

func (k *Kmail) SendMail(ctx context.Context, tmpl, from string, to []string, data map[string]string) error

SendMail uses tmpl template to send and email, data is a context object which is passed to the cached template and rendered to generate the email message.

func (*Kmail) Valid

func (k *Kmail) Valid() *Validation

type Mail

type Mail interface {
	SendMail(ctx context.Context, tmpl, from string, to []string, data map[string]string) error
}

Mail is an interface for sending transactional email for the matrixid home server.

type Matrix

type Matrix struct {
	Mode      string     `hcl:"mode"`
	Server    Server     `hcl:"server"`
	DB        DB         `hcl:"db"`
	Email     Email      `hcl:"email"`
	Templates []Template `hcl:"templates"`
	Peers     []Peer     `hcl:"peer"`
	// contains filtered or unexported fields
}

Matrix is the central configuration for the whole server. This stores settings for all services api and evertything needed to run the server.

func LoadFile

func LoadFile(src []byte) (*Matrix, error)

LoadFile decodes Matrix object from src. src is either json/hcl configuration in raw bytes.

func LoadFromEnv

func LoadFromEnv() *Matrix

func Sample

func Sample() *Matrix

Sample sample home server configuration.

func (*Matrix) GetTemplate

func (m *Matrix) GetTemplate() *template.Template

func (*Matrix) LoadTemplates

func (m *Matrix) LoadTemplates() error

func (*Matrix) Valid

func (m *Matrix) Valid() *Validation

Valid performs validation of m. Call Validation.IsValid() to see if validation passed.

func (*Matrix) Validate

func (m *Matrix) Validate(lg logger.Logger) (ok bool)

Validate validate m and logs the error message in case m is not valid to lg.

func (*Matrix) WriteToFile

func (m *Matrix) WriteToFile(filename string) error

WriteToFile marshals m and writes the hcl configuration to the the file filename.

type NoopMail

type NoopMail struct{}

NoopMail implements Mail intreface but does not actually send the email.

func (NoopMail) SendMail

func (n NoopMail) SendMail(ctx context.Context, tmpl, from string, to []string, data map[string]string) error

SendMail does nothing and always returns nil.

func (NoopMail) Valid

func (n NoopMail) Valid() *Validation

type Peer

type Peer struct {
	Name               string `hcl:",key"`
	BaseReplicationURL string `hcl:"base_replication_url"`
}

Peer defines settings for remote replication.

type Provider

type Provider Container

Provider email provider settings.

type SMTPClient

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

func NewSMAPCLient

func NewSMAPCLient(cfg SMTPEmail) *SMTPClient

func (*SMTPClient) Host

func (s *SMTPClient) Host() string

func (*SMTPClient) Send

func (s *SMTPClient) Send(from string, to []string, msg []byte) error

func (*SMTPClient) Valid

func (s *SMTPClient) Valid() *Validation

type SMTPEmail

type SMTPEmail struct {
	Enabled  bool
	Username string
	Password string
	Host     string
	Port     int64
}

SMTPEmail smtp plain auth configurations.

func (SMTPEmail) Valid

func (s SMTPEmail) Valid() *Validation

type Server

type Server struct {
	Name           string `hcl:"name"`
	Port           string `hcl:"port"`
	ClientHTTPBase string `hcl:"client_http_base"`
	Crypto         Crypto `hcl:"crypto"`
}

Server defines setting for the main server. Unlike the reference implementation, all services are provided under the same server, service specific configuration is used to enable/disable services. So, this is the one and only server that runs on boot up.

Only TLS server is supported. Failure to provide tls certificates will result in validation error.

TODO: Add let's encrypt support with auto-tls.

func (Server) Address

func (s Server) Address() string

Address returns the server address to bind to.

func (Server) Valid

func (s Server) Valid() *Validation

Valid validates s settings.

type Template

type Template struct {
	Name string `hcl:",key"`
	Path string `hcl:"path"`
}

func EmbedTemplates

func EmbedTemplates() []Template

type Validation

type Validation struct {
	Namespace string        `json:"namespace"`
	Fields    []Field       `json:"fields,omitempty"`
	Children  []*Validation `json:",omitempty"`
}

func (Validation) IsValid

func (v Validation) IsValid() bool

func (*Validation) Set

func (v *Validation) Set(name, value string)

func (Validation) String

func (v Validation) String() string

type Validator

type Validator interface {
	Valid() *Validation
}

type Verification

type Verification struct {
	From         string `hcl:"from"`
	Template     string `hcl:template"`
	ResponsePage string `hcl:"response_page_template"`
}

Verification stores details used when sending token validation emails.

func (Verification) Valid

func (i Verification) Valid() *Validation

Jump to

Keyboard shortcuts

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