logic

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 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) AddCollectorConfiguration added in v0.7.0

func (lgc *Logic) AddCollectorConfiguration(cfg *graylog.CollectorConfiguration) (int, error)

AddCollectorConfiguration adds a collector configuration to the mock server.

func (*Logic) AddCollectorConfigurationInput added in v0.7.0

func (lgc *Logic) AddCollectorConfigurationInput(id string, input *graylog.CollectorConfigurationInput) (int, error)

AddCollectorConfigurationInput adds a collector configuration input to the mock server.

func (*Logic) AddCollectorConfigurationOutput added in v0.7.0

func (lgc *Logic) AddCollectorConfigurationOutput(id string, output *graylog.CollectorConfigurationOutput) (int, error)

AddCollectorConfigurationOutput adds a collector configuration output to the mock server.

func (*Logic) AddCollectorConfigurationSnippet added in v0.7.0

func (lgc *Logic) AddCollectorConfigurationSnippet(id string, snippet *graylog.CollectorConfigurationSnippet) (int, error)

AddCollectorConfigurationSnippet adds a collector configuration snippet to the mock server.

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) DeleteCollectorConfiguration added in v0.7.0

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

DeleteCollectorConfiguration deletes a collector configuration from the mock server.

func (*Logic) DeleteCollectorConfigurationInput added in v0.7.0

func (lgc *Logic) DeleteCollectorConfigurationInput(cfgID, inputID string) (int, error)

DeleteCollectorConfigurationInput deletes a collector configuration input from the mock server.

func (*Logic) DeleteCollectorConfigurationOutput added in v0.7.0

func (lgc *Logic) DeleteCollectorConfigurationOutput(cfgID, outputID string) (int, error)

DeleteCollectorConfigurationOutput deletes a collector configuration output from the mock server.

func (*Logic) DeleteCollectorConfigurationSnippet added in v0.7.0

func (lgc *Logic) DeleteCollectorConfigurationSnippet(cfgID, snippetID string) (int, error)

DeleteCollectorConfigurationSnippet deletes a collector configuration snippet from the mock server.

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) DeleteLDAPSetting added in v0.6.0

func (lgc *Logic) DeleteLDAPSetting() (int, error)

DeleteLDAPSetting deletes a LDAP Setting.

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) GetAlarmCallbacks added in v0.5.0

func (lgc *Logic) GetAlarmCallbacks() ([]graylog.AlarmCallback, int, int, error)

GetAlarmCallbacks returns a list of inputs.

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) GetCollectorConfiguration added in v0.7.0

func (lgc *Logic) GetCollectorConfiguration(id string) (*graylog.CollectorConfiguration, int, error)

GetCollectorConfiguration returns a collector configuration. If a collector configuration is not found, returns an error.

func (*Logic) GetCollectorConfigurations added in v0.7.0

func (lgc *Logic) GetCollectorConfigurations() ([]graylog.CollectorConfiguration, int, int, error)

GetCollectorConfigurations returns a list of collector configurations.

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) GetLDAPSetting added in v0.6.0

func (lgc *Logic) GetLDAPSetting() (*graylog.LDAPSetting, int, error)

GetLDAPSetting returns a LDAP Setting.

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) HasCollectorConfiguration added in v0.7.0

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

HasCollectorConfiguration returns whether the collector configuration exists.

func (*Logic) HasCollectorConfigurationInput added in v0.7.0

func (lgc *Logic) HasCollectorConfigurationInput(cfgID, inputID string) (bool, error)

HasCollectorConfigurationInput returns whether the collector configuration exists.

func (*Logic) HasCollectorConfigurationOutput added in v0.7.0

func (lgc *Logic) HasCollectorConfigurationOutput(cfgID, outputID string) (bool, error)

HasCollectorConfigurationOutput returns whether the collector configuration exists.

func (*Logic) HasCollectorConfigurationSnippet added in v0.7.0

func (lgc *Logic) HasCollectorConfigurationSnippet(cfgID, snippetID string) (bool, error)

HasCollectorConfigurationSnippet returns whether the collector configuration exists.

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) RenameCollectorConfiguration added in v0.7.0

func (lgc *Logic) RenameCollectorConfiguration(id, name string) (*graylog.CollectorConfiguration, int, error)

RenameCollectorConfiguration renames a collector configuration.

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) UpdateCollectorConfigurationInput added in v0.7.0

func (lgc *Logic) UpdateCollectorConfigurationInput(
	cfgID, inputID string, input *graylog.CollectorConfigurationInput,
) (int, error)

UpdateCollectorConfigurationInput updates a collector configuration input.

func (*Logic) UpdateCollectorConfigurationOutput added in v0.7.0

func (lgc *Logic) UpdateCollectorConfigurationOutput(
	cfgID, outputID string, output *graylog.CollectorConfigurationOutput,
) (int, error)

UpdateCollectorConfigurationOutput updates a collector configuration output.

func (*Logic) UpdateCollectorConfigurationSnippet added in v0.7.0

func (lgc *Logic) UpdateCollectorConfigurationSnippet(
	cfgID, snippetID string, snippet *graylog.CollectorConfigurationSnippet,
) (int, error)

UpdateCollectorConfigurationSnippet updates a collector configuration snippet.

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) UpdateLDAPSetting added in v0.6.0

func (lgc *Logic) UpdateLDAPSetting(prms *graylog.LDAPSetting) (int, error)

UpdateLDAPSetting updates a LDAP Setting.

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