tokens

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

Token metadata storage

IAM Zero allows users to create tokens for developers or services. These tokens allow an IAM Zero client to send IAM events to the IAM Zero server.

We implement a Golang interface called TokenStorer for token storage. Any storage driver (e.g. a database or cache like Postgres, Redis, DynamoDB) can implement this interface, so that we have some flexibility.

Our initial implementation uses DynamoDB. We will list some operational requirements for DynamoDB below; eventually these will be pushed into the main IAM Zero documentation and our reference deployment architecture.

DynamoDB token storage

The DynamoDB table must have a primary key called id.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenNotFound = errors.New("token not found")

Functions

This section is empty.

Types

type DynamoDBTokenStorer

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

DynamoDBTokenStorer is a token storage backend which uses DynamoDB

func NewDynamoDBTokenStorer

func NewDynamoDBTokenStorer(ctx context.Context, tableName string, log *zap.SugaredLogger, tracer trace.Tracer) (*DynamoDBTokenStorer, error)

NewDynamoDBTokenStorer initialises the AWS DynamoDB client and returns a new DynamoDBTokenStorer

func (*DynamoDBTokenStorer) Create

func (s *DynamoDBTokenStorer) Create(ctx context.Context, name string) (*Token, error)

Create a Token and store it in the database

func (*DynamoDBTokenStorer) Delete

func (s *DynamoDBTokenStorer) Delete(ctx context.Context, id string) error

Delete a token from the database

func (*DynamoDBTokenStorer) Get

func (s *DynamoDBTokenStorer) Get(ctx context.Context, id string) (*Token, error)

Get a token from the database

func (*DynamoDBTokenStorer) List

func (s *DynamoDBTokenStorer) List(ctx context.Context) ([]Token, error)

List all tokens TODO: currently this implementation uses DynamoDB scan To improve performance moving forwards to a production ready service we should paginate this and use Query instead.

type InMemoryTokenStorer

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

InMemoryTokenStorer is a token storage backend which stores tokens in memory. Should only be used for development and testing.

func NewInMemoryTokenStorer

func NewInMemoryTokenStorer(ctx context.Context, log *zap.SugaredLogger, tracer trace.Tracer) *InMemoryTokenStorer

NewInMemoryTokenStorer initialises the in memory token storage

func (*InMemoryTokenStorer) Create

func (s *InMemoryTokenStorer) Create(ctx context.Context, name string) (*Token, error)

Create a Token and store it in memory

func (*InMemoryTokenStorer) Delete

func (s *InMemoryTokenStorer) Delete(ctx context.Context, id string) error

Delete a token

func (*InMemoryTokenStorer) Get

func (s *InMemoryTokenStorer) Get(ctx context.Context, id string) (*Token, error)

Get a token

func (*InMemoryTokenStorer) List

func (s *InMemoryTokenStorer) List(ctx context.Context) ([]Token, error)

List all tokens

type Token

type Token struct {
	ID   string `dynamodbav:"id" json:"id"`
	Name string `dynamodbav:"name" json:"name"`
}

Token is a token which allows IAM Zero clients to send events to IAM Zero

type TokenStorer

type TokenStorer interface {
	Create(ctx context.Context, name string) (*Token, error)
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context, id string) (*Token, error)
	List(ctx context.Context) ([]Token, error)
}

TokenStorer stores and loads Tokens

Jump to

Keyboard shortcuts

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