Documentation ¶
Index ¶
- Constants
- Variables
- func CheckUserPassword(u *User, pass string) bool
- func HashConfig(c *AppConfig) []byte
- func HashUserPassword(u *User, raw string) string
- func InsufficientPermissions(need, have UserPermissions) error
- func PermissionsToName(p UserPermissions) string
- type AppConfig
- type ConfigVersionNotFound
- type Configer
- type DBConf
- func (d *DBConf) DeleteUser(name string) error
- func (d *DBConf) GetConfig(versionHash string) (*AppConfig, error)
- func (d *DBConf) GetCurrent() (*AppConfig, error)
- func (d *DBConf) GetUser(name string) (*User, error)
- func (d *DBConf) GetUserByUserName(name string) (*User, error)
- func (d *DBConf) ListSnapshots() []*Snapshot
- func (d *DBConf) ListUsers() ([]*User, error)
- func (d *DBConf) PutConfig(a *AppConfig, u *User) (string, error)
- func (d *DBConf) PutUser(u *User) error
- type MockProvider
- func (m *MockProvider) DeleteUser(name string) error
- func (m *MockProvider) GetConfig(version string) (*AppConfig, error)
- func (m *MockProvider) GetCurrent() (*AppConfig, error)
- func (m *MockProvider) GetUser(name string) (*User, error)
- func (m *MockProvider) GetUserByUserName(name string) (*User, error)
- func (m *MockProvider) ListSnapshots() []*Snapshot
- func (m *MockProvider) ListUsers() ([]*User, error)
- func (m *MockProvider) PutConfig(c *AppConfig, u *User) (string, error)
- func (m *MockProvider) PutUser(u *User) error
- type Provider
- type Schema
- type Snapshot
- type Upgrader
- type User
- type UserNotFound
- type UserPermissions
- type Version
Constants ¶
const ( // CurrentBucketName is the name of the bucket that holds the current // verison of the config CurrentBucketName = "current" // CurrentVersionHash is the "hash" name of the current config CurrentVersionHash = "current" )
const ( READ = iota WRITE ADMIN // bless users to higher permissions levels )
Variables ¶
var ( AboutBucket = []byte("about") Schemas = []Schema{ { Version: Version{ 0, 10, 4, }, Buckets: []string{ "app", "user", }, Upgrader: func(old *bolt.DB) error { return nil }, }, { Version: Version{ 0, 12, 0, }, Buckets: []string{ "app", "user", }, Upgrader: func(old *bolt.DB) error { convertToKV := func(i interface{}) *event.TagSet { if i == nil { return event.NewTagset(0) } m := i.(map[string]interface{}) kv := event.NewTagset(len(m)) for k, v := range m { kv.Set(k, v.(string)) } return kv } upgradeRawSnapshot := func(buff []byte) ([]byte, error) { oldSnap := make(map[string]interface{}) err := json.Unmarshal(buff, &oldSnap) if err != nil { return nil, err } app, ok := oldSnap["app"].(map[string]interface{}) if !ok { return nil, fmt.Errorf("Unable to upgrade snapshot. No 'app' section found.") } raw_pols, ok := app["policies"] if ok { pols, ok := raw_pols.(map[string]interface{}) if ok { for k, v := range pols { x := v.(map[string]interface{}) logrus.Debugf("Removing old match/not_match from %s", k) x["match"] = convertToKV(x["match"]) x["not_match"] = convertToKV(x["not_match"]) x["group_by"] = convertToKV(x["group_by"]) } } else { log.Println(reflect.TypeOf(raw_pols).String()) } } app["global_policy"] = map[string]interface{}{} oldSnap["app"] = app return json.Marshal(&oldSnap) } err := old.Update(func(tx *bolt.Tx) error { b := tx.Bucket([]byte("app")) if b == nil { logrus.Warning("No config snapshots found") return nil } newSnapshots := make([]struct { key []byte val []byte }, 0, b.Stats().KeyN) b.ForEach(func(k, v []byte) error { logrus.Debugf("Starting snapshot upgrade on: %s", string(k)) upgraded, err := upgradeRawSnapshot(v) if err != nil { logrus.Errorf("Unable to upgrade snapshot: %s %s", string(k), err.Error()) } newSnapshots = append(newSnapshots, struct { key []byte val []byte }{ key: k, val: upgraded, }) return nil }) for _, snap := range newSnapshots { err := b.Put(snap.key, snap.val) if err != nil { logrus.Errorf("Unable to write upgraded snapshot to database %s %s", string(snap.key), err.Error()) } logrus.Debugf("Finished snapshot upgrade on: %s", string(snap.key)) } return nil }) return err }, }, { Version: Version{ 0, 13, 0, }, Buckets: []string{ "app", "user", }, Upgrader: func(old *bolt.DB) error { upgradeRawSnapshot := func(buff []byte) ([]byte, error) { oldSnap := make(map[string]interface{}) err := json.Unmarshal(buff, &oldSnap) if err != nil { return nil, err } app, ok := oldSnap["app"].(map[string]interface{}) if !ok { return nil, fmt.Errorf("Unable to upgrade snapshot. No 'app' section found.") } app["escalations"] = map[string]interface{}{} oldSnap["app"] = app return json.Marshal(&oldSnap) } err := old.Update(func(tx *bolt.Tx) error { b := tx.Bucket([]byte("app")) if b == nil { logrus.Warning("No config snapshots found") return nil } newSnapshots := make([]struct { key []byte val []byte }, 0, b.Stats().KeyN) b.ForEach(func(k, v []byte) error { logrus.Debugf("Starting snapshot upgrade on: %s", string(k)) upgraded, err := upgradeRawSnapshot(v) if err != nil { logrus.Errorf("Unable to upgrade snapshot: %s %s", string(k), err.Error()) } newSnapshots = append(newSnapshots, struct { key []byte val []byte }{ key: k, val: upgraded, }) return nil }) for _, snap := range newSnapshots { err := b.Put(snap.key, snap.val) if err != nil { logrus.Errorf("Unable to write upgraded snapshot to database %s %s", string(snap.key), err.Error()) } logrus.Debugf("Finished snapshot upgrade on: %s", string(snap.key)) } return nil }) return err }, }, } )
var ( Current = Version{ Major: 0, Minor: 15, Patch: 1, } First = Version{ 0, 10, 4, } )
var ( // BucketNames holds the names of the buckets used to store versioned configs BucketNames = []string{ "app", "user", } )
Functions ¶
func CheckUserPassword ¶ added in v0.15.0
CheckUserPassword compares a raw password against the the stored hash'ed password
func HashConfig ¶ added in v0.15.0
func HashUserPassword ¶ added in v0.15.0
return the password hash for a given user, given the raw password
func InsufficientPermissions ¶ added in v0.15.0
func InsufficientPermissions(need, have UserPermissions) error
func PermissionsToName ¶ added in v0.15.0
func PermissionsToName(p UserPermissions) string
Types ¶
type AppConfig ¶
type AppConfig struct { EscalationsDir string `json:"escalations_dir"` KeepAliveAge time.Duration `json:"-"` RawKeepAliveAge string `json:"keep_alive_age"` DbPath string `json:"db_path"` Escalations map[string]*escalation.EscalationPolicy `json:"escalations"` Encoding string `json:"encoding"` Policies map[string]*escalation.Policy `json:"policies"` EventProviders *provider.EventProviderCollection `json:"event_providers"` LogLevel string `json:"log_level"` APIPort int `json:"API_port"` Hash []byte `json:"-"` // contains filtered or unexported fields }
AppConfig provides configuration options for setting up the application
func NewDefaultConfig ¶
func NewDefaultConfig() *AppConfig
NewDefaultConfig create and return a new instance of the default configuration
func (*AppConfig) FileName ¶ added in v0.15.0
FileName returns the name of the file that was used to create this AppConfig
func (*AppConfig) Provider ¶ added in v0.15.0
Provider returns the Provider that created this AppConfig
func (*AppConfig) SetProvider ¶ added in v0.15.0
SetProvider changes the AppConfigs provider to the givin one
type ConfigVersionNotFound ¶ added in v0.15.0
type ConfigVersionNotFound string
func (ConfigVersionNotFound) Error ¶ added in v0.15.0
func (c ConfigVersionNotFound) Error() string
type Configer ¶
type Configer interface { ConfigStruct() interface{} Init(interface{}) error }
A Configer provides an interface to dynamicaly load configuration
type DBConf ¶ added in v0.15.0
type DBConf struct {
// contains filtered or unexported fields
}
DBConf provides methods for reading and writing configs from a database
func (*DBConf) DeleteUser ¶ added in v0.15.0
DeleteUser by the User.Id
func (*DBConf) GetConfig ¶ added in v0.15.0
GetConfig get the config file which has the hash of given version
func (*DBConf) GetCurrent ¶ added in v0.15.0
GetCurrent loads the current version of the config
func (*DBConf) GetUserByUserName ¶ added in v0.15.0
GetUserByUserName
func (*DBConf) ListSnapshots ¶ added in v0.15.0
type MockProvider ¶ added in v0.15.0
type MockProvider struct {
// contains filtered or unexported fields
}
func (*MockProvider) DeleteUser ¶ added in v0.15.0
func (m *MockProvider) DeleteUser(name string) error
func (*MockProvider) GetConfig ¶ added in v0.15.0
func (m *MockProvider) GetConfig(version string) (*AppConfig, error)
func (*MockProvider) GetCurrent ¶ added in v0.15.0
func (m *MockProvider) GetCurrent() (*AppConfig, error)
func (*MockProvider) GetUser ¶ added in v0.15.0
func (m *MockProvider) GetUser(name string) (*User, error)
func (*MockProvider) GetUserByUserName ¶ added in v0.15.0
func (m *MockProvider) GetUserByUserName(name string) (*User, error)
func (*MockProvider) ListSnapshots ¶ added in v0.15.0
func (m *MockProvider) ListSnapshots() []*Snapshot
func (*MockProvider) ListUsers ¶ added in v0.15.0
func (m *MockProvider) ListUsers() ([]*User, error)
func (*MockProvider) PutConfig ¶ added in v0.15.0
func (m *MockProvider) PutConfig(c *AppConfig, u *User) (string, error)
func (*MockProvider) PutUser ¶ added in v0.15.0
func (m *MockProvider) PutUser(u *User) error
type Provider ¶ added in v0.15.0
type Provider interface { GetConfig(version string) (*AppConfig, error) GetCurrent() (*AppConfig, error) PutConfig(*AppConfig, *User) (string, error) ListSnapshots() []*Snapshot GetUser(userName string) (*User, error) GetUserByUserName(string) (*User, error) DeleteUser(userName string) error PutUser(u *User) error ListUsers() ([]*User, error) }
A Provider can read and write configs, along with querying for versions
func GetProvider ¶ added in v0.15.0
GetProvider returns a config provider at that given path. If nothing exists at that path, one will be created. If a bad kind id provided, a nil value will be returned
func NewMockProvider ¶ added in v0.15.0
func NewMockProvider() Provider
type Schema ¶ added in v0.15.0
Schema represents a bucket schema for a bolt.Db
func GetSchemaFromDb ¶ added in v0.15.0
func LatestSchema ¶ added in v0.15.0
func LatestSchema() Schema
LatestSchema returns the newest schema
type Snapshot ¶ added in v0.15.0
type Snapshot struct { Hash string `json:"hash"` Timestamp time.Time `json:"time_stamp"` App *AppConfig `json:"app"` CreatorId uint16 `json:"creator_id"` // the User.Id of who created this snapshot CreatorName string `json:"creator_name"` CreatorUserName string `json:"creator_user_name"` }
Snapshot represents a bangarang config at a given point in time
type User ¶ added in v0.15.0
type User struct { Name string `json:"name"` UserName string `json:"user_name"` PasswordHash string `json:"password_hash"` Permissions UserPermissions `json:"permissions"` // contains filtered or unexported fields }
User holds information about who a user is, and what they are allowed to do
func NewUser ¶ added in v0.15.0
func NewUser(name, userName, rawPassword string, permissions UserPermissions) *User
type UserNotFound ¶ added in v0.15.0
type UserNotFound string
func (UserNotFound) Error ¶ added in v0.15.0
func (u UserNotFound) Error() string
type UserPermissions ¶ added in v0.15.0
type UserPermissions int
UserPermissions describes what a user is allowed to do
func NameToPermissions ¶ added in v0.15.0
func NameToPermissions(name string) UserPermissions