token

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllTypes []Type = maps.Keys(TypeTypeNumber)
View Source
var ErrInvalidToken = errors.New("invalid token format")
View Source
var ErrParentTokenExpired = errors.New("parent token expired")
View Source
var ErrParentTokenNotFound = errors.New("parent token not found")
View Source
var ErrTTLOutOfRange = errors.New("ttl out of range")
View Source
var TypePrefix map[Type]string = map[Type]string{
	Root:             "ro",
	Parent:           "pa",
	ServerCert:       "sc",
	ClientCert:       "cc",
	ClientServerCert: "cs",
}

Functions

func IsValidType added in v2.0.6

func IsValidType(t Type) bool

Types

type CreateStruct

type CreateStruct struct {
	Type      Type              `json:"type" example:"client_cert"`
	Policies  []string          `json:"Policies" example:"policy1,policy2"`
	Meta      map[string]string `json:"meta" example:"key1:value1,key2:value2"`
	TTL       string            `json:"ttl" example:"1000h"`
	MaxTTL    string            `json:"maxttl" example:"3h"`
	Renewable bool              `json:"renewable" example:"false"`
}

type Manager

type Manager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewManager

func NewManager(store Store, xor uint64, tokenMaxTTL time.Duration, certMaxTTL time.Duration, parentMaxTTL time.Duration, rndSize int) *Manager

func (*Manager) Create

func (m *Manager) Create(parent string, options *CreateStruct) (string, error)

func (*Manager) Delete

func (m *Manager) Delete(name string) error

func (*Manager) Get

func (m *Manager) Get(name string) (*Token, error)

type Store

type Store interface {
	io.Closer
	Get(ctx context.Context, tokenID string) ([]byte, error)
	Put(ctx context.Context, tokenID string, token []byte, ttl time.Duration) error
	Delete(ctx context.Context, tokenID string) error
}

type Token

type Token struct {
	Type       Type
	Expiration time.Time
	Policies   []string
	Parent     string
	Metadata   map[string]string
	MaxTTL     time.Duration
}

func NewToken

func NewToken(t Type, expiration time.Time, maxTTL time.Duration, policies []string, meta map[string]string) *Token

func (*Token) GetExpiration

func (t *Token) GetExpiration() time.Time

func (*Token) GetMetadata

func (t *Token) GetMetadata() map[string]string

func (*Token) GetParent

func (t *Token) GetParent() string

func (*Token) GetPolicies

func (t *Token) GetPolicies() []string

func (*Token) GetType

func (t *Token) GetType() Type

func (*Token) MarshalBinary

func (t *Token) MarshalBinary() ([]byte, error)

func (*Token) UnmarshalBinary

func (t *Token) UnmarshalBinary(data []byte) error

type Type

type Type string
const (
	Root             Type = "root"
	Parent           Type = "Parent"
	ServerCert       Type = "server_cert"
	ClientCert       Type = "client_cert"
	ClientServerCert Type = "client_server_cert"
)

type TypeNumber added in v2.0.6

type TypeNumber uint16
const (
	RootNumber TypeNumber = iota
	ParentNumber
	ServerCertNumber
	ClientCertNumber
	ClientServerCertNumber
)

Jump to

Keyboard shortcuts

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