shared

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2015 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Software versin
	Version = "0.1.0"
	// DefClientGID is the default client group ID
	DefClientGID = 1
	// DefAdminGID is the default admin group ID
	DefAdminGID = 2
	// SuperGID is the super group ID
	SuperGID = 3
)
View Source
const (

	// Session ID header
	HdrSession = "Session-ID"
	// MAC header
	HdrMAC = "X-AUTH-MAC"
	// Session key header
	HdrKey = "X-AUTH-KEY"
)

Header names

Variables

View Source
var DefaultAdminPass = []byte("password")

Functions

func Read

func Read(d FileData, path string) error

func Write

func Write(d FileData, path string) error

Types

type ACL

type ACL interface {
	Lookup(gorm.DB, uint, uint) bool
}

ACL returns true if the UID/GID pair should be allowed access to the subject.

type Auth

type Auth struct {
	Name     string `json:",omitempty"`
	Password []byte `json:",omitempty"`
}

type ClientSession

type ClientSession interface {
	GetName() string
	GetUID() uint
	GetGID() uint
	IsAdmin() bool
	IsSuper() bool
	NextKey() crypto.Binary
	CheckACL(gorm.DB, ...ACL) bool
}

type Config

type Config struct {
	Runtime Runtime // These are only used at runtime, and never saved to disk
	Startup Startup // These are stored in the config file
	DB      gorm.DB // DB interface (only used in server mode)
	Session Session // Admin/Client transport data
	// contains filtered or unexported fields
}

Root config object

func (*Config) Decode

func (c *Config) Decode(data []byte) error

Decode reads TOML data into the startup part of a config tree.

func (*Config) Encode

func (c *Config) Encode() ([]byte, error)

Encode encodes the Startup part of a config tree in TOML format.

func (*Config) Fatal

func (c *Config) Fatal(values ...interface{})

Fatal is a wrapper around log.Fatal()

func (*Config) Log

func (c *Config) Log(level log.LogLevel, values ...interface{})

Log is a wrapper around log.Log()

func (*Config) NewClient

func (c *Config) NewClient()

NewClient allocations all objects used by the client.

func (*Config) NewServer

func (c *Config) NewServer()

NewServer allocates all objects used by the server

func (*Config) StartLogging

func (c *Config) StartLogging() error

StartLogging is a wrapper around log.Start()

func (*Config) StopLogging

func (c *Config) StopLogging() error

StopLogging is a wrapper around log.Stop()

type DBSettings

type DBSettings struct {
	Host     string
	Port     string
	User     string
	Pass     string `toml:"Password"`
	Database string
	Driver   string
	File     string
}

type FileData

type FileData interface {
	Encode() ([]byte, error)
	Decode([]byte) error
}

type Key

type Key struct {
	Name      string `json:",omitempty"`
	Client    string `json:",omitempty"`
	Admin     string `json:",omitempty"`
	Path      string `json:",omitempty"`
	Key       []byte `json:",omitempty"`
	Secret    []byte `json:",omitempty"`
	UserKey   []byte `json:",omitempty"`
	GroupPub  []byte `json:",omitempty"`
	GroupPriv []byte `json:",omitempty"`
}

type Message

type Message struct {
	Key      Key    `json:",omitempty"`
	User     User   `json:",omitempty"`
	X509     X509   `json:"x509,omitempty"`
	Auth     Auth   `json:",omitempty"`
	Response string `json:",omitempty"`
}

func ReadResp

func ReadResp(r io.Reader) (resp []Message, err error)

ReadResp parses a message array from an io.Reader.

func RespMessage

func RespMessage(r string) (m Message)

RespMessage creates a message with a given response string.

type Pool

type Pool interface {
	Validate(Request) bool
}

Pool is an interface for a session pool. It requires a Validate method, which verifies a Request.

type Request

type Request struct {
	Req     Message
	Session ClientSession
	// contains filtered or unexported fields
}

func (*Request) Parse

func (r *Request) Parse(body []byte, resp http.ResponseWriter) bool

New reads the request body and headers from the client request, and sets the response writer.

func (*Request) Reply

func (r *Request) Reply(code int, messages ...Message)

Reply sends a response to a request. We never return anything, as there's no useful handling the server can do if our response fails.

func (*Request) SetSessionID

func (r *Request) SetSessionID(id int64)

type Runtime

type Runtime struct {
	Log        io.Writer
	Key        *crypto.TLSKey
	Cert       *crypto.TLSCert
	CAKey      *crypto.TLSKey
	CACert     *crypto.TLSCert
	CA         *crypto.CertPool
	Keypair    *crypto.Key
	ServerCert crypto.Binary
	Password   crypto.Binary
}

Runtime attributes. These should never be written to disk

type Server

type Server struct {
	Pool *Pool
	Mux  *http.ServeMux
	// contains filtered or unexported fields
}

func (*Server) New

func (s *Server) New(cfg *Config) (err error)

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop()

func (*Server) Wait

func (s *Server) Wait()

type Session

type Session struct {
	Password   []byte
	ServerCert []byte
	GroupKey   crypto.Binary
	// contains filtered or unexported fields
}

func (*Session) Get

func (s *Session) Get(url string) (resp []Message, err error)

func (*Session) Login

func (s *Session) Login(cfg *Config) (err error)

func (*Session) Logout

func (s *Session) Logout(cfg *Config) (err error)

func (*Session) New

func (s *Session) New(cfg *Config) error

func (*Session) Post

func (s *Session) Post(url string, msg Message) (resp []Message, err error)

type Startup

type Startup struct {
	Dir      string // Directory where certs etc are stored
	NodeName string // Should be set to hostname for servers.
	Address  string
	LogFile  string
	LogLevel log.LogLevel
	Crypto   StartupCrypto `toml:"files"`
	DB       DBSettings    `toml:"database"`
}

Startup attributes. These can be written to the config file safely

type StartupCrypto

type StartupCrypto struct {
	Cert       string
	Key        string
	CACert     string
	CAKey      string
	KeyPair    string
	ServerCert string
	Password   string // Client only.
}

type User

type User struct {
	Name     string `json:",omitempty"`
	Admin    bool   `json:",omitempty"`
	Group    string `json:",omitempty"`
	Password []byte `json:",omitempty"`
	Key      []byte `json:",omitempty"`
}

type X509

type X509 struct {
	Name string `json:",omitempty"`
	Cert []byte `json:",omitempty"`
}

Jump to

Keyboard shortcuts

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