tenant

package
v0.0.0-...-a30bb73 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIDGenerationN = 100
View Source
const MinPasswordLen int = 8

Variables

View Source
var (
	// ErrNameisEmpty is when a name is empty
	ErrNameisEmpty = &errors.Error{
		Code: errors.EInvalid,
		Msg:  "name is empty",
	}

	// ErrIDNotUnique is used when attempting to create an org or bucket that already
	// exists.
	ErrIDNotUnique = &errors.Error{
		Code: errors.EConflict,
		Msg:  "ID already exists",
	}

	// ErrFailureGeneratingID occurs ony when the random number generator
	// cannot generate an ID in MaxIDGenerationN times.
	ErrFailureGeneratingID = &errors.Error{
		Code: errors.EInternal,
		Msg:  "unable to generate valid id",
	}

	// ErrOnboardingNotAllowed occurs when request to onboard comes in and we are not allowing this request
	ErrOnboardingNotAllowed = &errors.Error{
		Code: errors.EConflict,
		Msg:  "onboarding has already been completed",
	}

	ErrNotFound = &errors.Error{
		Code: errors.ENotFound,
		Msg:  "not found",
	}
)
View Source
var (
	ErrBucketNotFound = &errors.Error{
		Code: errors.ENotFound,
		Msg:  "bucket not found",
	}

	ErrBucketNameNotUnique = &errors.Error{
		Code: errors.EConflict,
		Msg:  "bucket name is not unique",
	}
)
View Source
var (
	// ErrInvalidURMID is used when the service was provided
	// an invalid ID format.
	ErrInvalidURMID = &errors.Error{
		Code: errors.EInvalid,
		Msg:  "provided user resource mapping ID has invalid format",
	}

	// ErrURMNotFound is used when the user resource mapping is not found.
	ErrURMNotFound = &errors.Error{
		Msg:  "user to resource mapping not found",
		Code: errors.ENotFound,
	}
)
View Source
var (
	// ErrUserNotFound is used when the user is not found.
	ErrUserNotFound = &errors.Error{
		Msg:  "user not found",
		Code: errors.ENotFound,
	}

	// EIncorrectPassword is returned when any password operation fails in which
	// we do not want to leak information.
	EIncorrectPassword = &errors.Error{
		Code: errors.EForbidden,
		Msg:  "your username or password is incorrect",
	}

	// EIncorrectUser is returned when any user is failed to be found which indicates
	// the userID provided is for a user that does not exist.
	EIncorrectUser = &errors.Error{
		Code: errors.EForbidden,
		Msg:  "your userID is incorrect",
	}

	// EShortPassword is used when a password is less than the minimum
	// acceptable password length.
	EShortPassword = &errors.Error{
		Code: errors.EInvalid,
		Msg:  fmt.Sprintf("passwords must be at least %d characters long", MinPasswordLen),
	}
)
View Source
var (
	// ErrOrgNotFound is used when the user is not found.
	ErrOrgNotFound = &errors.Error{
		Msg:  "organization not found",
		Code: errors.ENotFound,
	}
)

Functions

func BucketAlreadyExistsError

func BucketAlreadyExistsError(n string) *errors.Error

BucketAlreadyExistsError is used when attempting to create a user with a name that already exists.

func CorruptURMError

func CorruptURMError(err error) *errors.Error

CorruptURMError is used when the config cannot be unmarshalled from the bytes stored in the kv.

func ErrBucketNotFoundByName

func ErrBucketNotFoundByName(n string) *errors.Error

ErrBucketNotFoundByName is used when the user is not found.

func ErrCorruptBucket

func ErrCorruptBucket(err error) *errors.Error

ErrCorruptBucket is used when the user cannot be unmarshalled from the bytes stored in the kv.

func ErrCorruptOrg

func ErrCorruptOrg(err error) *errors.Error

ErrCorruptOrg is used when the user cannot be unmarshalled from the bytes stored in the kv.

func ErrCorruptUser

func ErrCorruptUser(err error) *errors.Error

ErrCorruptUser is used when the user cannot be unmarshalled from the bytes stored in the kv.

func ErrInternalServiceError

func ErrInternalServiceError(err error) *errors.Error

ErrInternalServiceError is used when the error comes from an internal system.

func ErrUnprocessableBucket

func ErrUnprocessableBucket(err error) *errors.Error

ErrUnprocessableBucket is used when a org is not able to be processed.

func ErrUnprocessableMapping

func ErrUnprocessableMapping(err error) *errors.Error

ErrUnprocessableMapping is used when a user resource mapping is not able to be converted to JSON.

func ErrUnprocessableOrg

func ErrUnprocessableOrg(err error) *errors.Error

ErrUnprocessableOrg is used when a org is not able to be processed.

func ErrUnprocessableUser

func ErrUnprocessableUser(err error) *errors.Error

ErrUnprocessableUser is used when a user is not able to be processed.

func InvalidOrgIDError

func InvalidOrgIDError(err error) *errors.Error

InvalidOrgIDError is used when a service was provided an invalid ID. This is some sort of internal server error.

func InvalidUserIDError

func InvalidUserIDError(err error) *errors.Error

InvalidUserIDError is used when a service was provided an invalid ID. This is some sort of internal server error.

func NewBucketResponse

func NewBucketResponse(b *influxdb.Bucket, labels ...*influxdb.Label) *bucketResponse

func NonUniqueMappingError

func NonUniqueMappingError(userID platform.ID) error

NonUniqueMappingError is an internal error when a user already has been mapped to a resource

func OrgAlreadyExistsError

func OrgAlreadyExistsError(name string) error

OrgAlreadyExistsError is used when creating a new organization with a name that has already been used. Organization names must be unique.

func OrgNotFoundByName

func OrgNotFoundByName(name string) error

func UnavailablePasswordServiceError

func UnavailablePasswordServiceError(err error) *errors.Error

UnavailablePasswordServiceError is used if we aren't able to add the password to the store, it means the store is not available at the moment (e.g. network).

func UnavailableURMServiceError

func UnavailableURMServiceError(err error) *errors.Error

UnavailableURMServiceError is used if we aren't able to interact with the store, it means the store is not available at the moment (e.g. network).

func UnexpectedUserBucketError

func UnexpectedUserBucketError(err error) *errors.Error

UnexpectedUserBucketError is used when the error comes from an internal system.

func UnexpectedUserIndexError

func UnexpectedUserIndexError(err error) *errors.Error

UnexpectedUserIndexError is used when the error comes from an internal system.

func UserAlreadyExistsError

func UserAlreadyExistsError(n string) *errors.Error

UserAlreadyExistsError is used when attempting to create a user with a name that already exists.

func UserIDAlreadyExistsError

func UserIDAlreadyExistsError(id string) *errors.Error

UserIDAlreadyExistsError is used when attempting to create a user with an ID that already exists.

Types

type AggregateError

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

AggregateError enables composing multiple errors. This is ideal in the case that you are applying functions with side effects to a slice of elements. E.g., deleting/updating a slice of resources.

func NewAggregateError

func NewAggregateError() *AggregateError

NewAggregateError returns a new AggregateError.

func (*AggregateError) Add

func (e *AggregateError) Add(err error)

Add adds an error to the aggregate.

func (*AggregateError) Err

func (e *AggregateError) Err() error

Err returns a proper error from this aggregate error.

type BucketFilter

type BucketFilter struct {
	Name           *string
	OrganizationID *platform.ID
}

type BucketHandler

type BucketHandler struct {
	chi.Router
	// contains filtered or unexported fields
}

BucketHandler represents an HTTP API handler for users.

func NewHTTPBucketHandler

func NewHTTPBucketHandler(log *zap.Logger, bucketSvc influxdb.BucketService, labelSvc influxdb.LabelService, urmHandler, labelHandler http.Handler) *BucketHandler

NewHTTPBucketHandler constructs a new http server.

func (*BucketHandler) Prefix

func (h *BucketHandler) Prefix() string

type BucketSvc

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

func NewBucketSvc

func NewBucketSvc(st *Store, svc *Service) *BucketSvc

func (*BucketSvc) CreateBucket

func (s *BucketSvc) CreateBucket(ctx context.Context, b *influxdb.Bucket) error

CreateBucket creates a new bucket and sets b.ID with the new identifier.

func (*BucketSvc) DeleteBucket

func (s *BucketSvc) DeleteBucket(ctx context.Context, id platform.ID) error

DeleteBucket removes a bucket by ID.

func (*BucketSvc) FindBucket

func (s *BucketSvc) FindBucket(ctx context.Context, filter influxdb.BucketFilter) (*influxdb.Bucket, error)

FindBucket returns the first bucket that matches filter.

func (*BucketSvc) FindBucketByID

func (s *BucketSvc) FindBucketByID(ctx context.Context, id platform.ID) (*influxdb.Bucket, error)

FindBucketByID returns a single bucket by ID.

func (*BucketSvc) FindBucketByName

func (s *BucketSvc) FindBucketByName(ctx context.Context, orgID platform.ID, name string) (*influxdb.Bucket, error)

func (*BucketSvc) FindBuckets

func (s *BucketSvc) FindBuckets(ctx context.Context, filter influxdb.BucketFilter, opt ...influxdb.FindOptions) ([]*influxdb.Bucket, int, error)

FindBuckets returns a list of buckets that match filter and the total count of matching buckets. Additional options provide pagination & sorting.

func (*BucketSvc) UpdateBucket

func (s *BucketSvc) UpdateBucket(ctx context.Context, id platform.ID, upd influxdb.BucketUpdate) (*influxdb.Bucket, error)

UpdateBucket updates a single bucket with changeset. Returns the new bucket state after update.

type Service

type Service struct {
	influxdb.UserService
	influxdb.PasswordsService
	influxdb.UserResourceMappingService
	influxdb.OrganizationService
	influxdb.BucketService
	// contains filtered or unexported fields
}

func NewService

func NewService(st *Store) *Service

NewService creates a new base tenant service.

func NewSystem

func NewSystem(store *Store, log *zap.Logger) *Service

creates a new Service with logging and metrics middleware wrappers.

func (*Service) RLock

func (s *Service) RLock()

func (*Service) RUnlock

func (s *Service) RUnlock()

type Store

type Store struct {
	IDGen       platform.IDGenerator
	OrgIDGen    platform.IDGenerator
	BucketIDGen platform.IDGenerator
	// contains filtered or unexported fields
}

func NewStore

func NewStore(kvStore kv.Store, opts ...StoreOption) *Store

func (*Store) CreateBucket

func (s *Store) CreateBucket(ctx context.Context, tx kv.Tx, bucket *influxdb.Bucket) (err error)

func (*Store) DeleteBucket

func (s *Store) DeleteBucket(ctx context.Context, tx kv.Tx, id platform.ID) error

func (*Store) GetBucket

func (s *Store) GetBucket(ctx context.Context, tx kv.Tx, id platform.ID) (*influxdb.Bucket, error)

func (*Store) GetBucketByName

func (s *Store) GetBucketByName(ctx context.Context, tx kv.Tx, orgID platform.ID, n string) (*influxdb.Bucket, error)

func (*Store) ListBuckets

func (s *Store) ListBuckets(ctx context.Context, tx kv.Tx, filter BucketFilter, opt ...influxdb.FindOptions) ([]*influxdb.Bucket, error)

func (*Store) RLock

func (s *Store) RLock()

func (*Store) RUnlock

func (s *Store) RUnlock()

func (*Store) Update

func (s *Store) Update(ctx context.Context, fn func(kv.Tx) error) error

Update opens up a transaction that will mutate data.

func (*Store) UpdateBucket

func (s *Store) UpdateBucket(ctx context.Context, tx kv.Tx, id platform.ID, upd influxdb.BucketUpdate) (*influxdb.Bucket, error)

func (*Store) View

func (s *Store) View(ctx context.Context, fn func(kv.Tx) error) error

View opens up a transaction that will not write to any data. Implementing interfaces should take care to ensure that all view transactions do not mutate any data.

type StoreOption

type StoreOption func(*Store)

Jump to

Keyboard shortcuts

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