Documentation ¶
Index ¶
- Constants
- Variables
- func GetCategories(actions []UserAction) []category.Category
- func NewContext(ctx context.Context, u *User) context.Context
- type Options
- type User
- func (u *User) CanAccessCluster() (bool, error)
- func (u *User) CanAccessIndex(name string) (bool, error)
- func (u *User) CanAccessIndices(indices ...string) (bool, error)
- func (u *User) GetPatch() (map[string]interface{}, error)
- func (u *User) HasACL(acl acl.ACL) bool
- func (u *User) HasAction(action UserAction) bool
- func (u *User) HasCategory(category category.Category) bool
- func (u *User) Id() string
- func (u *User) ValidateACLs(acls ...acl.ACL) error
- type UserAction
Constants ¶
const ( // Credential is a value stored against request.Credential key in the context. // It basically acts as an identifier that tells whether the request uses user // credentials. Credential = contextKey("user_credential") )
Variables ¶
var ActionToCategories = map[UserAction][]category.Category{ Develop: developCategories, Analytics: { category.Analytics, category.Logs, category.Cat, }, CuratedInsights: {}, Pipelines: append([]category.Category{category.Pipelines}, searchRelevancyCategories...), SearchRelevancy: searchRelevancyCategories, AccessControl: { category.Auth, category.Permission, }, UserManagement: { category.User, }, Billing: {}, DowntimeAlerts: {}, UIBuilder: append([]category.Category{ category.UIBuilder, }, searchRelevancyCategories...), Speed: {category.Cache, category.Cat}, }
Functions ¶
func GetCategories ¶
func GetCategories(actions []UserAction) []category.Category
GetCategories extracts the categories from the actions
Types ¶
type Options ¶
Options is a function type used to define a user's properties.
func SetACLs ¶
SetACLs sets the acls a user can have access to. ACLs must always be set after setting the Categories.
func SetAllowedActions ¶
func SetAllowedActions(actions []UserAction) Options
SetAllowedActions sets the actions a user can have access to. It also sets the categories based on the allowed actions Categories must always be set before setting the ACLs.
func SetIndices ¶
SetIndices sets the indices or index patterns a user can have access to.
func SetIsAdmin ¶
SetIsAdmin defines whether a user is an admin or not. It sets the default actions for admin users
func SetSources ¶
SetSources sets the sources from which the permission can make request from. Sources are accepted and parsed in CIDR notation.
func SetSourcesXffValue ¶
SetIncludes sets the sources_xff_value fields
type User ¶
type User struct { Username string `json:"username"` Password string `json:"password"` PasswordHashType string `json:"password_hash_type"` IsAdmin *bool `json:"is_admin"` Categories []category.Category `json:"categories"` AllowedActions *[]UserAction `json:"allowed_actions"` ACLs []acl.ACL `json:"acls"` Email string `json:"email"` Indices []string `json:"indices"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` Sources *[]string `json:"sources"` SourcesXffValue *int `json:"sources_xff_value"` }
User defines a user type.
func FromContext ¶
FromContext retrieves the *user.User stored against user.CtxKey from the context.
func New ¶
New creates a new user by running the Options on it. It returns a default user in case no Options are provided.
func NewAdmin ¶
NewAdmin create a new user by running the Options on it. It returns a user with admin defaults in case no Options are provided.
func (*User) CanAccessCluster ¶
CanAccessCluster checks whether the user can access cluster level routes.
func (*User) CanAccessIndex ¶
CanAccessIndex checks whether the user has access to the given index or index pattern.
func (*User) CanAccessIndices ¶
CanAccessIndices checks whether the user has access to the given indices.
func (*User) HasAction ¶
func (u *User) HasAction(action UserAction) bool
func (*User) HasCategory ¶
HasCategory checks whether the user has access to the given category.
type UserAction ¶
type UserAction int
const ( Develop UserAction = iota Analytics CuratedInsights SearchRelevancy AccessControl UserManagement Billing DowntimeAlerts UIBuilder Speed Pipelines )
func (UserAction) MarshalJSON ¶
func (o UserAction) MarshalJSON() ([]byte, error)
MarshalJSON is the implementation of the Marshaler interface for marshaling UserAction type.
func (UserAction) String ¶
func (o UserAction) String() string
String is the implementation of Stringer interface that returns the string representation of UserAction type.
func (*UserAction) UnmarshalJSON ¶
func (o *UserAction) UnmarshalJSON(bytes []byte) error
UnmarshalJSON is the implementation of the Unmarshaler interface for unmarshaling UserAction type.