admin

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package admin defines and implements store for admin-level data like secret key, list of admins and so on

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType int

EventType indicates type of the event

const (
	EvCreate EventType = iota
	EvDelete
	EvUpdate
	EvVote
)

enum of all event types

type RPC

type RPC struct {
	jrpc.Client
}

RPC implements remote engine and delegates all Calls to remote http server

func (*RPC) Admins

func (r *RPC) Admins(siteID string) (ids []string, err error)

Admins returns list of admin's ids for given site

func (*RPC) Email

func (r *RPC) Email(siteID string) (email string, err error)

Email gets email address for given site

func (*RPC) Enabled

func (r *RPC) Enabled(siteID string) (ok bool, err error)

Enabled returns true if allowed

func (*RPC) Key

func (r *RPC) Key(siteID string) (key string, err error)

Key returns the key, same for all sites

func (*RPC) OnEvent

func (r *RPC) OnEvent(siteID string, et EventType) error

OnEvent reacts (register) events about data modification

type StaticStore

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

StaticStore implements keys.Store with a single set of admins and email for all sites

func NewStaticKeyStore

func NewStaticKeyStore(key string) *StaticStore

NewStaticKeyStore is a shortcut for making StaticStore for key consumers only

func NewStaticStore

func NewStaticStore(key string, sites, adminIDs []string, email string) *StaticStore

NewStaticStore makes StaticStore instance with given key

func (*StaticStore) Admins

func (s *StaticStore) Admins(string) (ids []string, err error)

Admins returns static list of admin ids, the same for all sites

func (*StaticStore) Email

func (s *StaticStore) Email(string) (email string, err error)

Email gets static email address

func (*StaticStore) Enabled

func (s *StaticStore) Enabled(site string) (ok bool, err error)

Enabled if always true for StaticStore

func (*StaticStore) Key

func (s *StaticStore) Key(_ string) (key string, err error)

Key returns static key, same for all sites

func (*StaticStore) OnEvent

func (s *StaticStore) OnEvent(_ string, _ EventType) error

OnEvent does nothing for StaticStore

type Store

type Store interface {
	Key(siteID string) (key string, err error)
	Admins(siteID string) (ids []string, err error)
	Email(siteID string) (email string, err error)
	Enabled(siteID string) (ok bool, err error)
	OnEvent(siteID string, et EventType) error
}

Store defines interface returning admins info for given site

type StoreMock added in v1.13.0

type StoreMock struct {
	// AdminsFunc mocks the Admins method.
	AdminsFunc func(siteID string) ([]string, error)

	// EmailFunc mocks the Email method.
	EmailFunc func(siteID string) (string, error)

	// EnabledFunc mocks the Enabled method.
	EnabledFunc func(siteID string) (bool, error)

	// KeyFunc mocks the Key method.
	KeyFunc func(siteID string) (string, error)

	// OnEventFunc mocks the OnEvent method.
	OnEventFunc func(siteID string, et EventType) error
	// contains filtered or unexported fields
}

StoreMock is a mock implementation of Store.

func TestSomethingThatUsesStore(t *testing.T) {

	// make and configure a mocked Store
	mockedStore := &StoreMock{
		AdminsFunc: func(siteID string) ([]string, error) {
			panic("mock out the Admins method")
		},
		EmailFunc: func(siteID string) (string, error) {
			panic("mock out the Email method")
		},
		EnabledFunc: func(siteID string) (bool, error) {
			panic("mock out the Enabled method")
		},
		KeyFunc: func(siteID string) (string, error) {
			panic("mock out the Key method")
		},
		OnEventFunc: func(siteID string, et EventType) error {
			panic("mock out the OnEvent method")
		},
	}

	// use mockedStore in code that requires Store
	// and then make assertions.

}

func (*StoreMock) Admins added in v1.13.0

func (mock *StoreMock) Admins(siteID string) ([]string, error)

Admins calls AdminsFunc.

func (*StoreMock) AdminsCalls added in v1.13.0

func (mock *StoreMock) AdminsCalls() []struct {
	SiteID string
}

AdminsCalls gets all the calls that were made to Admins. Check the length with:

len(mockedStore.AdminsCalls())

func (*StoreMock) Email added in v1.13.0

func (mock *StoreMock) Email(siteID string) (string, error)

Email calls EmailFunc.

func (*StoreMock) EmailCalls added in v1.13.0

func (mock *StoreMock) EmailCalls() []struct {
	SiteID string
}

EmailCalls gets all the calls that were made to Email. Check the length with:

len(mockedStore.EmailCalls())

func (*StoreMock) Enabled added in v1.13.0

func (mock *StoreMock) Enabled(siteID string) (bool, error)

Enabled calls EnabledFunc.

func (*StoreMock) EnabledCalls added in v1.13.0

func (mock *StoreMock) EnabledCalls() []struct {
	SiteID string
}

EnabledCalls gets all the calls that were made to Enabled. Check the length with:

len(mockedStore.EnabledCalls())

func (*StoreMock) Key added in v1.13.0

func (mock *StoreMock) Key(siteID string) (string, error)

Key calls KeyFunc.

func (*StoreMock) KeyCalls added in v1.13.0

func (mock *StoreMock) KeyCalls() []struct {
	SiteID string
}

KeyCalls gets all the calls that were made to Key. Check the length with:

len(mockedStore.KeyCalls())

func (*StoreMock) OnEvent added in v1.13.0

func (mock *StoreMock) OnEvent(siteID string, et EventType) error

OnEvent calls OnEventFunc.

func (*StoreMock) OnEventCalls added in v1.13.0

func (mock *StoreMock) OnEventCalls() []struct {
	SiteID string
	Et     EventType
}

OnEventCalls gets all the calls that were made to OnEvent. Check the length with:

len(mockedStore.OnEventCalls())

Jump to

Keyboard shortcuts

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