identity

package
v1.9.2-0...-dc4060b Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidNamespaceID       = errutil.BadRequest("auth.identity.invalid-namespace-id")
	ErrNotIntIdentifier         = errors.New("identifier is not an int64")
	ErrIdentifierNotInitialized = errors.New("identifier is not initialized")
)
View Source
var AnonymousNamespaceID = NewNamespaceID(NamespaceAnonymous, 0)

Functions

func IntIdentifier

func IntIdentifier(namespace Namespace, identifier string) (int64, error)

IntIdentifier converts a string identifier to an int64. Applicable for users, service accounts, api keys and renderer service. Errors if the identifier is not initialized or if namespace is not recognized.

func IsNamespace

func IsNamespace(namespace Namespace, expected ...Namespace) bool

IsNamespace returns true if namespace matches any expected namespace

func UserIdentifier

func UserIdentifier(namespace Namespace, identifier string) (int64, error)

UserIdentifier converts a string identifier to an int64. Errors if the identifier is not initialized or if namespace is not recognized. Returns 0 if the namespace is not user or service account

Types

type Namespace

type Namespace string
const (
	NamespaceUser           Namespace = "user"
	NamespaceAPIKey         Namespace = "api-key"
	NamespaceServiceAccount Namespace = "service-account"
	NamespaceAnonymous      Namespace = "anonymous"
	NamespaceRenderService  Namespace = "render"
	NamespaceAccessPolicy   Namespace = "access-policy"
	NamespaceEmpty          Namespace = ""
)

func ParseNamespace

func ParseNamespace(str string) (Namespace, error)

func (Namespace) String

func (n Namespace) String() string

type NamespaceID

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

FIXME: use this instead of encoded string through the codebase

func MustParseNamespaceID

func MustParseNamespaceID(str string) NamespaceID

MustParseNamespaceID parses namespace id, it will panic if it fails to do so. Suitable to use in tests or when we can guarantee that we pass a correct format.

func NewNamespaceID

func NewNamespaceID(namespace Namespace, id int64) NamespaceID

func NewNamespaceIDString

func NewNamespaceIDString(namespace Namespace, id string) NamespaceID

NewNamespaceIDString creates a new NamespaceID with a string id

func ParseNamespaceID

func ParseNamespaceID(str string) (NamespaceID, error)

func (NamespaceID) ID

func (ni NamespaceID) ID() string

func (NamespaceID) IsNamespace

func (ni NamespaceID) IsNamespace(expected ...Namespace) bool

func (NamespaceID) Namespace

func (ni NamespaceID) Namespace() Namespace

func (NamespaceID) ParseInt

func (ni NamespaceID) ParseInt() (int64, error)

ParseInt will try to parse the id as an int64 identifier.

func (NamespaceID) String

func (ni NamespaceID) String() string

func (NamespaceID) UserID

func (ni NamespaceID) UserID() (int64, error)

UserID will try to parse and int64 identifier if namespace is either user or service-account. For all other namespaces '0' will be returned.

type Requester

type Requester interface {
	// GetID returns namespaced id for the entity
	GetID() NamespaceID
	// GetNamespacedID returns the namespace and ID of the active entity.
	// The namespace is one of the constants defined in pkg/services/auth/identity.
	// Deprecated: use GetID instead
	GetNamespacedID() (namespace Namespace, identifier string)
	// GetUID returns namespaced uid for the entity
	GetUID() NamespaceID
	// GetDisplayName returns the display name of the active entity.
	// The display name is the name if it is set, otherwise the login or email.
	GetDisplayName() string
	// GetEmail returns the email of the active entity.
	// Can be empty.
	GetEmail() string
	// IsEmailVerified returns if email is verified for entity.
	IsEmailVerified() bool
	// GetIsGrafanaAdmin returns true if the user is a server admin
	GetIsGrafanaAdmin() bool
	// GetLogin returns the login of the active entity
	// Can be empty.
	GetLogin() string
	// GetOrgID returns the ID of the active organization
	GetOrgID() int64
	// GetOrgRole returns the role of the active entity in the active organization.
	GetOrgRole() roletype.RoleType
	// GetPermissions returns the permissions of the active entity.
	GetPermissions() map[string][]string
	// GetGlobalPermissions returns the permissions of the active entity that are available across all organizations.
	GetGlobalPermissions() map[string][]string
	// DEPRECATED: GetTeams returns the teams the entity is a member of.
	// Retrieve the teams from the team service instead of using this method.
	GetTeams() []int64
	// DEPRECATED: GetOrgName returns the name of the active organization.
	// Retrieve the organization name from the organization service instead of using this method.
	GetOrgName() string
	// GetAuthID returns external id for entity.
	GetAuthID() string
	// GetAuthenticatedBy returns the authentication method used to authenticate the entity.
	GetAuthenticatedBy() string
	// IsAuthenticatedBy returns true if entity was authenticated by any of supplied providers.
	IsAuthenticatedBy(providers ...string) bool
	// IsNil returns true if the identity is nil
	// FIXME: remove this method once all services are using an interface
	IsNil() bool

	// HasRole returns true if the active entity has the given role in the active organization.
	HasRole(role roletype.RoleType) bool
	// GetCacheKey returns a unique key for the entity.
	// Add an extra prefix to avoid collisions with other caches
	GetCacheKey() string
	// HasUniqueId returns true if the entity has a unique id
	HasUniqueId() bool
	// GetIDToken returns a signed token representing the identity that can be forwarded to plugins and external services.
	// Will only be set when featuremgmt.FlagIdForwarding is enabled.
	GetIDToken() string
}

Jump to

Keyboard shortcuts

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