identity

package
v0.0.0-...-1643519 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 36

Documentation

Overview

Package identity defines Identity type and related types and constants. Identity represents a caller that makes requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Glob

type Glob string

Glob is glob like pattern that matches identity strings of some kind.

It is a string of the form "kind:<pattern>" where 'kind' is one of Kind constants and 'pattern' is a wildcard pattern to apply to identity name.

The only supported glob syntax is '*', which matches zero or more characters.

Case sensitive. Doesn't support multi-line strings or patterns. There's no way to match '*' itself.

func MakeGlob

func MakeGlob(glob string) (Glob, error)

MakeGlob ensures 'glob' string looks like a valid identity glob and returns it as Glob value.

func (Glob) Kind

func (g Glob) Kind() Kind

Kind returns identity glob kind. If identity glob string is invalid returns Anonymous.

func (Glob) Match

func (g Glob) Match(id Identity) bool

Match returns true if glob matches an identity. If identity string or identity glob string are invalid, returns false.

func (Glob) Pattern

func (g Glob) Pattern() string

Pattern returns a pattern part of the identity glob. If the identity glob string is invalid returns empty string.

func (Glob) Validate

func (g Glob) Validate() error

Validate checks that the identity glob string is well-formed.

type Identity

type Identity string

Identity represents a caller that makes requests. A string of the form "kind:value" where 'kind' is one of Kind constant and meaning of 'value' depends on a kind (see comments for Kind values).

const AnonymousIdentity Identity = "anonymous:anonymous"

AnonymousIdentity represents anonymous user.

func MakeIdentity

func MakeIdentity(identity string) (Identity, error)

MakeIdentity ensures 'identity' string looks like a valid identity and returns it as Identity value.

func (Identity) Email

func (id Identity) Email() string

Email returns user's email for identity with kind User or empty string for all other identity kinds. If identity string is undefined returns "".

func (Identity) Kind

func (id Identity) Kind() Kind

Kind returns identity kind. If identity string is invalid returns Anonymous.

func (Identity) Validate

func (id Identity) Validate() error

Validate checks that the identity string is well-formed.

func (Identity) Value

func (id Identity) Value() string

Value returns a valued encoded in the identity, e.g. for User identity kind it is user's email address.If identity string is invalid returns "anonymous".

type Kind

type Kind string

Kind is enumeration of known identity kinds. See Identity.

const (
	// Anonymous kind means no identity information is provided. Identity value
	// is always 'anonymous'.
	Anonymous Kind = "anonymous"

	// Bot is used for bots authenticated via IP whitelist. Identity value is
	// bot's IP address (IPv4 or IPv6).
	Bot Kind = "bot"

	// Service is used for GAE apps using X-Appengine-Inbound-Appid header for
	// authentication. Identity value is GAE app id.
	Service Kind = "service"

	// User is used for regular users. Identity value is email address.
	User Kind = "user"
)

Jump to

Keyboard shortcuts

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