domain

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

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

func NewDomain

func NewDomain(st Storage) Domain

func (*Domain) GenerateAndSaveToken

func (d *Domain) GenerateAndSaveToken(ctx context.Context, channelID string, channelName string) (GenerateResult, error)

GenerateAndSaveToken returns a GenerateResult which contains secure random string as token. Then it saves the generated token to storage. This checks existing generated token in storage. If found, returns the generated token.

func (*Domain) GetTokens

func (d *Domain) GetTokens(ctx context.Context, channelName string) ([]Entry, error)

func (*Domain) RegenerateToken

func (d *Domain) RegenerateToken(ctx context.Context, channelID string, channelName string) (RegenerateResult, error)

RegenerateToken allows generate another token for the given channel. If another token has been already generated, it returns "too many token" result. So users can have 2 tokens for each channel name maximum.

func (*Domain) RevokeRenamedToken

func (d *Domain) RevokeRenamedToken(ctx context.Context, channelID string, givenChannelName string, givenToken string) (RevokeRenamedResult, error)

Revoke given token for the given channel name. If then token is not linked to another channel's id, treat as permission error.

func (*Domain) RevokeToken

func (d *Domain) RevokeToken(ctx context.Context, channelName string, givenToken string) (RevokeResult, error)

func (*Domain) VerifyToken

func (d *Domain) VerifyToken(ctx context.Context, channelName string, givenToken string) (VerifyResult, error)

VerifyToken checks given token and existin token. It returns VerifyResult. Need to check the returned VerifyResult.NotFound and .Unmatch. Returns an error when underlying storage goes wrong.

type Entry

type Entry struct {
	Token     string
	Version   int
	CreatedAt time.Time
}

type GenerateResult

type GenerateResult struct {
	IsGenerated bool
	Token       string
}

type RegenerateResult

type RegenerateResult struct {
	NoTokenFound bool
	TooManyToken bool
	Token        string
}

type RevokeRenamedResult

type RevokeRenamedResult struct {
	NotFound         bool
	ChannelIDUnmatch bool
	LinkedChannelID  string
}

type RevokeResult

type RevokeResult struct {
	NotFound bool
}

type Storage

type Storage interface {
	Save(ctx context.Context, record storage.Record) error
	// QueryByChannelName returns found records having the same channel name.
	// It returns empty slice when no record found.
	QueryByChannelName(ctx context.Context, channelName string) ([]storage.Record, error)
	Delete(ctx context.Context, record storage.Record) error
}

type VerifyResult

type VerifyResult struct {
	NotFound    bool
	Unmatch     bool
	ChannelID   string
	ChannelName string
}

Jump to

Keyboard shortcuts

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