user

package
v0.0.0-...-f94be1b Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func NewContext

func NewContext(ctx context.Context, u *User) context.Context

NewContext returns the context with the given User.

Types

type Options

type Options func(u *User) error

Options is a function type used to define a user's properties.

func SetACLs

func SetACLs(acls []acl.ACL) Options

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 SetEmail

func SetEmail(email string) Options

SetEmail sets the user email.

func SetIndices

func SetIndices(indices []string) Options

SetIndices sets the indices or index patterns a user can have access to.

func SetIsAdmin

func SetIsAdmin(isAdmin bool) Options

SetIsAdmin defines whether a user is an admin or not. It sets the default actions for admin users

func SetSources

func SetSources(sources []string) Options

SetSources sets the sources from which the permission can make request from. Sources are accepted and parsed in CIDR notation.

func SetSourcesXffValue

func SetSourcesXffValue(value *int) Options

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

func FromContext(ctx context.Context) (*User, error)

FromContext retrieves the *user.User stored against user.CtxKey from the context.

func New

func New(username, password string, opts ...Options) (*User, error)

New creates a new user by running the Options on it. It returns a default user in case no Options are provided.

func NewAdmin

func NewAdmin(username, password string, opts ...Options) (*User, error)

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

func (u *User) CanAccessCluster() (bool, error)

CanAccessCluster checks whether the user can access cluster level routes.

func (*User) CanAccessIndex

func (u *User) CanAccessIndex(name string) (bool, error)

CanAccessIndex checks whether the user has access to the given index or index pattern.

func (*User) CanAccessIndices

func (u *User) CanAccessIndices(indices ...string) (bool, error)

CanAccessIndices checks whether the user has access to the given indices.

func (*User) GetPatch

func (u *User) GetPatch() (map[string]interface{}, error)

GetPatch generates a patch doc from the non-zero fields set in the user.

func (*User) HasACL

func (u *User) HasACL(acl acl.ACL) bool

HasACL checks whether the user has access to the given acl.

func (*User) HasAction

func (u *User) HasAction(action UserAction) bool

func (*User) HasCategory

func (u *User) HasCategory(category category.Category) bool

HasCategory checks whether the user has access to the given category.

func (*User) Id

func (u *User) Id() string

func (*User) ValidateACLs

func (u *User) ValidateACLs(acls ...acl.ACL) error

ValidateACLs checks if the user can possess the given set of acls.

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.

Jump to

Keyboard shortcuts

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