logic

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package logic provides logic layers of Graylog API mock server. Basically enduser does not use the package directly, but the struct Logic is embed to mockserver.Server .

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogWE

func LogWE(sc int, entry *log.Entry, msg string)

LogWE outputs outputs log at Warn or Error level.

func ValidateObjectID

func ValidateObjectID(id string) error

ValidateObjectID validates ObjectID.

Types

type Logic

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

Logic represents a mock of the Graylog API. This is embedded to mockserver.Server.

func NewLogic

func NewLogic(store store.Store) (*Logic, error)

NewLogic returns new Server. The argument `store` is the store which the server uses. If `store` is nil, the default plain store is used and data is not persisted.

func (*Logic) AddDashboard added in v0.4.0

func (lgc *Logic) AddDashboard(dashboard *graylog.Dashboard) (int, error)

AddDashboard adds an dashboard to the mock server.

func (*Logic) AddIndexSet

func (lgc *Logic) AddIndexSet(is *graylog.IndexSet) (int, error)

AddIndexSet adds an index set to the Mock Server.

func (*Logic) AddInput

func (lgc *Logic) AddInput(input *graylog.Input) (int, error)

AddInput adds an input to the mock server.

func (*Logic) AddRole

func (lgc *Logic) AddRole(role *graylog.Role) (int, error)

AddRole adds a new role.

func (*Logic) AddStream

func (lgc *Logic) AddStream(stream *graylog.Stream) (int, error)

AddStream adds a stream to the Server.

func (*Logic) AddStreamRule

func (lgc *Logic) AddStreamRule(rule *graylog.StreamRule) (int, error)

AddStreamRule adds a stream rule to the Server.

func (*Logic) AddUser

func (lgc *Logic) AddUser(user *graylog.User) (int, error)

AddUser adds a user to the Server.

func (*Logic) AddUserToRole

func (lgc *Logic) AddUserToRole(userName, roleName string) (int, error)

AddUserToRole adds a user to a role.

func (*Logic) Auth

func (lgc *Logic) Auth() bool

Auth returns whether the authentication and authentication are enabled.

func (*Logic) Authenticate

func (lgc *Logic) Authenticate(name, password string) (*graylog.User, int, error)

Authenticate authenticates a user.

func (*Logic) Authorize

func (lgc *Logic) Authorize(user *graylog.User, scope string, args ...string) (int, error)

Authorize authorizes a user. If the user doesn't have the permission, an error is returned.

// whether the user has the permission to read all roles
if sc, err := lgc.Authorize(user, "roles:read", ""); err != nil {
	fmt.Println(sc, err) // 403, "authorization failure"
}

// whether the user has the permission to read the role "foo"
sc, err := lgc.Authorize(admin, "roles:read", "foo")
fmt.Println(sc, err) // 200, nil

func (*Logic) DeleteDashboard added in v0.4.0

func (lgc *Logic) DeleteDashboard(id string) (int, error)

DeleteDashboard deletes a dashboard from the mock server.

func (*Logic) DeleteIndexSet

func (lgc *Logic) DeleteIndexSet(id string) (int, error)

DeleteIndexSet removes a index set from the Mock Server.

func (*Logic) DeleteInput

func (lgc *Logic) DeleteInput(id string) (int, error)

DeleteInput deletes a input from the mock server.

func (*Logic) DeleteRole

func (lgc *Logic) DeleteRole(name string) (int, error)

DeleteRole deletes a role.

func (*Logic) DeleteStream

func (lgc *Logic) DeleteStream(id string) (int, error)

DeleteStream deletes a stream from the Server.

func (*Logic) DeleteStreamRule

func (lgc *Logic) DeleteStreamRule(streamID, streamRuleID string) (int, error)

DeleteStreamRule deletes a stream rule from the Server.

func (*Logic) DeleteUser

func (lgc *Logic) DeleteUser(name string) (int, error)

DeleteUser removes a user from the Server.

func (*Logic) GetAlert added in v0.3.0

func (lgc *Logic) GetAlert(id string) (*graylog.Alert, int, error)

GetAlert returns an alert. If an alert is not found, returns an error.

func (*Logic) GetAlertConditions added in v0.2.0

func (lgc *Logic) GetAlertConditions() ([]graylog.AlertCondition, int, int, error)

GetAlertConditions returns a list of alert conditions.

func (*Logic) GetAlerts added in v0.3.0

func (lgc *Logic) GetAlerts(since, limit int) ([]graylog.Alert, int, int, error)

GetAlerts returns a list of alerts.

func (*Logic) GetDashboard added in v0.4.0

func (lgc *Logic) GetDashboard(id string) (*graylog.Dashboard, int, error)

GetDashboard returns an dashboard. If an dashboard is not found, returns an error.

func (*Logic) GetDashboards added in v0.4.0

func (lgc *Logic) GetDashboards() ([]graylog.Dashboard, int, int, error)

GetDashboards returns a list of dashboards.

func (*Logic) GetEnabledStreams

func (lgc *Logic) GetEnabledStreams() ([]graylog.Stream, int, int, error)

GetEnabledStreams returns all enabled streams.

func (*Logic) GetIndexSet

func (lgc *Logic) GetIndexSet(id string) (*graylog.IndexSet, int, error)

GetIndexSet returns an index set. If an index set is not found, returns an error.

func (*Logic) GetIndexSetStats

func (lgc *Logic) GetIndexSetStats(id string) (*graylog.IndexSetStats, int, error)

GetIndexSetStats returns an index set stats.

func (*Logic) GetIndexSetStatsMap

func (lgc *Logic) GetIndexSetStatsMap() (map[string]graylog.IndexSetStats, int, error)

GetIndexSetStatsMap returns a each Index Set's statistics.

func (*Logic) GetIndexSets

func (lgc *Logic) GetIndexSets(skip, limit int) ([]graylog.IndexSet, int, int, error)

GetIndexSets returns a list of all index sets.

func (*Logic) GetInput

func (lgc *Logic) GetInput(id string) (*graylog.Input, int, error)

GetInput returns an input. If an input is not found, returns an error.

func (*Logic) GetInputs

func (lgc *Logic) GetInputs() ([]graylog.Input, int, int, error)

GetInputs returns a list of inputs.

func (*Logic) GetRole

func (lgc *Logic) GetRole(name string) (*graylog.Role, int, error)

GetRole returns a Role. If a role is not found, an error is returns.

func (*Logic) GetRoles

func (lgc *Logic) GetRoles() ([]graylog.Role, int, int, error)

GetRoles returns a list of roles.

func (*Logic) GetStream

func (lgc *Logic) GetStream(id string) (*graylog.Stream, int, error)

GetStream returns a stream.

func (*Logic) GetStreamRule

func (lgc *Logic) GetStreamRule(streamID, streamRuleID string) (*graylog.StreamRule, int, error)

GetStreamRule returns a stream rule.

func (*Logic) GetStreamRules

func (lgc *Logic) GetStreamRules(streamID string) ([]graylog.StreamRule, int, int, error)

GetStreamRules returns a list of all stream rules of a given stream.

func (*Logic) GetStreams

func (lgc *Logic) GetStreams() ([]graylog.Stream, int, int, error)

GetStreams returns a list of all streams.

func (*Logic) GetTotalIndexSetStats

func (lgc *Logic) GetTotalIndexSetStats() (*graylog.IndexSetStats, int, error)

GetTotalIndexSetStats returns all index set's statistics.

func (*Logic) GetUser

func (lgc *Logic) GetUser(username string) (*graylog.User, int, error)

GetUser returns a user.

func (*Logic) GetUsers

func (lgc *Logic) GetUsers() ([]graylog.User, int, error)

GetUsers returns a list of users.

func (*Logic) HasDashboard added in v0.4.0

func (lgc *Logic) HasDashboard(id string) (bool, error)

HasDashboard returns whether the dashboard exists.

func (*Logic) HasIndexSet

func (lgc *Logic) HasIndexSet(id string) (bool, error)

HasIndexSet returns whether the user exists.

func (*Logic) HasInput

func (lgc *Logic) HasInput(id string) (bool, error)

HasInput returns whether the input exists.

func (*Logic) HasRole

func (lgc *Logic) HasRole(name string) (bool, error)

HasRole returns whether the role with given name exists.

func (*Logic) HasStream

func (lgc *Logic) HasStream(id string) (bool, error)

HasStream returns whether the stream exists.

func (*Logic) HasStreamRule

func (lgc *Logic) HasStreamRule(streamID, streamRuleID string) (bool, error)

HasStreamRule returns whether the stream sule exists.

func (*Logic) HasUser

func (lgc *Logic) HasUser(username string) (bool, error)

HasUser returns whether the user exists.

func (*Logic) InitData

func (lgc *Logic) InitData() error

InitData sets an initial data.

func (*Logic) Load

func (lgc *Logic) Load() error

Load reads Mock Server's data from a file.

func (*Logic) Logger

func (lgc *Logic) Logger() *log.Logger

Logger returns a logger. This logger is logrus.Logger . https://github.com/sirupsen/logrus You can change the Logic's logger configuration freely.

lgc := logic.NewLogic(nil)
logger := lgc.Logger()
logger.SetFormatter(&log.JSONFormatter{})
logger.SetLevel(log.WarnLevel)

func (*Logic) PauseStream

func (lgc *Logic) PauseStream(id string) (int, error)

PauseStream pauses a stream.

func (*Logic) RemoveUserFromRole

func (lgc *Logic) RemoveUserFromRole(
	userName, roleName string,
) (int, error)

RemoveUserFromRole removes a user from a role.

func (*Logic) ResumeStream

func (lgc *Logic) ResumeStream(id string) (int, error)

ResumeStream resumes a stream.

func (*Logic) RoleMembers

func (lgc *Logic) RoleMembers(name string) ([]graylog.User, int, error)

RoleMembers returns members of a given role.

func (*Logic) Save

func (lgc *Logic) Save() error

Save writes Mock Server's data in a file for persistence.

func (*Logic) SetAuth

func (lgc *Logic) SetAuth(authEnabled bool)

SetAuth sets whether the authentication and authentication are enabled. Disable the authentication.

lgc.SetAuth(false)

Enable the authentication.

lgc.SetAuth(true)

func (*Logic) SetDefaultIndexSet

func (lgc *Logic) SetDefaultIndexSet(id string) (*graylog.IndexSet, int, error)

SetDefaultIndexSet sets a default index set

func (*Logic) SetStore

func (lgc *Logic) SetStore(store store.Store)

SetStore sets a store to the mock server.

func (*Logic) UpdateDashboard added in v0.4.0

func (lgc *Logic) UpdateDashboard(dashboard *graylog.Dashboard) (int, error)

UpdateDashboard updates an dashboard at the Server. Required: none Allowed: Title, Description

func (*Logic) UpdateIndexSet

func (lgc *Logic) UpdateIndexSet(prms *graylog.IndexSetUpdateParams) (*graylog.IndexSet, int, error)

UpdateIndexSet updates an index set at the Mock Server.

func (*Logic) UpdateInput

func (lgc *Logic) UpdateInput(prms *graylog.InputUpdateParams) (*graylog.Input, int, error)

UpdateInput updates an input at the Server. Required: Title, Type, Attrs Allowed: Global, Node

func (*Logic) UpdateRole

func (lgc *Logic) UpdateRole(name string, prms *graylog.RoleUpdateParams) (*graylog.Role, int, error)

UpdateRole updates a role.

func (*Logic) UpdateStream

func (lgc *Logic) UpdateStream(prms *graylog.StreamUpdateParams) (*graylog.Stream, int, error)

UpdateStream updates a stream at the Server.

func (*Logic) UpdateStreamRule

func (lgc *Logic) UpdateStreamRule(prms *graylog.StreamRuleUpdateParams) (int, error)

UpdateStreamRule updates a stream rule of the Server.

func (*Logic) UpdateUser

func (lgc *Logic) UpdateUser(prms *graylog.UserUpdateParams) (int, error)

UpdateUser updates a user of the Server. "email", "permissions", "full_name", "password"

func (*Logic) UserList

func (lgc *Logic) UserList() ([]graylog.User, error)

UserList returns a list of all users.

Jump to

Keyboard shortcuts

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