influxdb/user.go

99 lines
2.5 KiB
Go
Raw Normal View History

package influxdb
feat(platform): add generic kv store Co-authored-by: Leonardo Di Donato <leodidonato@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(kv): add kv store interface for services feat(bolt): add boltdb implementation of kv.Store spike(platform): add kv backed user service feat(kv): add static cursor Note here that this operation cannot be transactionally done. This poses a bit of issues that will need to be worked out. fix(bolt): use error explicit error message squash: play with interface a bit fix(kv): remove commit and rollback from kv interface feat(inmem): add inmem kv store chore: add note for inmem transactions fix(bolt): remove call to tx in kv store tests feat(kv): add tests for static cursor doc(kv): add comments to store and associated interfaces doc(bolt): add comments to key value store feat(testing): add kv store tests test(testing): add conformance test for kv.Store test(inmem): add kv.Store conformance tests doc(inmem): add comments to key value store feat(inmem): remove CreateBucketIfNotExists from Tx interface feat(bolt): remove CreateBucketIfNotExists from Tx feat(inmem): remove CreateBucketIfNotExists from Tx doc(kv): add note to bucket interface about conditions methods can be called feat(kv): add context methods to kv.Tx feat(bolt): add context methods to bolt.Tx feat(inmem): add context methods to inmem.Tx test(kv): add contract tests for view/update transactions feat(kv): ensure that static cursor is always valid Co-authored-by: Leonardo Di Donato <leodidonato@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(kv): remove error from cursor methods test(kv): remove want errors from cursor test test(testing): add concurrent update test for kv.Store feat(kv): make kv user service an example service fix(testing): add concurrnent update test to the kv.Store contract tests test(platform): fix example kv service tests dep(platform): make platform tidy
2018-12-18 15:44:25 +00:00
import (
"context"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
feat(platform): add generic kv store Co-authored-by: Leonardo Di Donato <leodidonato@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> feat(kv): add kv store interface for services feat(bolt): add boltdb implementation of kv.Store spike(platform): add kv backed user service feat(kv): add static cursor Note here that this operation cannot be transactionally done. This poses a bit of issues that will need to be worked out. fix(bolt): use error explicit error message squash: play with interface a bit fix(kv): remove commit and rollback from kv interface feat(inmem): add inmem kv store chore: add note for inmem transactions fix(bolt): remove call to tx in kv store tests feat(kv): add tests for static cursor doc(kv): add comments to store and associated interfaces doc(bolt): add comments to key value store feat(testing): add kv store tests test(testing): add conformance test for kv.Store test(inmem): add kv.Store conformance tests doc(inmem): add comments to key value store feat(inmem): remove CreateBucketIfNotExists from Tx interface feat(bolt): remove CreateBucketIfNotExists from Tx feat(inmem): remove CreateBucketIfNotExists from Tx doc(kv): add note to bucket interface about conditions methods can be called feat(kv): add context methods to kv.Tx feat(bolt): add context methods to bolt.Tx feat(inmem): add context methods to inmem.Tx test(kv): add contract tests for view/update transactions feat(kv): ensure that static cursor is always valid Co-authored-by: Leonardo Di Donato <leodidonato@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> fix(kv): remove error from cursor methods test(kv): remove want errors from cursor test test(testing): add concurrent update test for kv.Store feat(kv): make kv user service an example service fix(testing): add concurrnent update test to the kv.Store contract tests test(platform): fix example kv service tests dep(platform): make platform tidy
2018-12-18 15:44:25 +00:00
)
2019-09-18 20:19:51 +00:00
// UserStatus indicates whether a user is active or inactive
type UserStatus string
// Valid validates user status
func (u *UserStatus) Valid() error {
if *u != "active" && *u != "inactive" {
return &errors.Error{Code: errors.EInvalid, Msg: "Invalid user status"}
2019-09-18 20:19:51 +00:00
}
return nil
}
2018-08-01 18:54:32 +00:00
// User is a user. 🎉
type User struct {
ID platform.ID `json:"id,omitempty"`
Name string `json:"name"`
OAuthID string `json:"oauthID,omitempty"`
Status Status `json:"status"`
2019-09-18 20:19:51 +00:00
}
// Valid validates user
func (u *User) Valid() error {
return u.Status.Valid()
}
2018-12-07 18:12:24 +00:00
// Ops for user errors and op log.
const (
OpFindUserByID = "FindUserByID"
OpFindUser = "FindUser"
OpFindUsers = "FindUsers"
OpCreateUser = "CreateUser"
OpUpdateUser = "UpdateUser"
OpDeleteUser = "DeleteUser"
)
// UserService represents a service for managing user data.
type UserService interface {
// Returns a single user by ID.
FindUserByID(ctx context.Context, id platform.ID) (*User, error)
// Returns the first user that matches filter.
FindUser(ctx context.Context, filter UserFilter) (*User, error)
// Returns a list of users that match filter and the total count of matching users.
// Additional options provide pagination & sorting.
FindUsers(ctx context.Context, filter UserFilter, opt ...FindOptions) ([]*User, int, error)
// Creates a new user and sets u.ID with the new identifier.
CreateUser(ctx context.Context, u *User) error
// Updates a single user with changeset.
// Returns the new user state after update.
UpdateUser(ctx context.Context, id platform.ID, upd UserUpdate) (*User, error)
// Removes a user by ID.
DeleteUser(ctx context.Context, id platform.ID) error
// FindPermissionForUser
FindPermissionForUser(ctx context.Context, UserID platform.ID) (PermissionSet, error)
}
// UserUpdate represents updates to a user.
// Only fields which are set are updated.
type UserUpdate struct {
2019-09-18 20:19:51 +00:00
Name *string `json:"name"`
Status *Status `json:"status"`
}
// Valid validates UserUpdate
func (uu UserUpdate) Valid() error {
if uu.Status == nil {
return nil
}
return uu.Status.Valid()
}
// UserFilter represents a set of filter that restrict the returned results.
type UserFilter struct {
ID *platform.ID
Name *string
}
// UserResponse is the response of user
type UserResponse struct {
Links map[string]string `json:"links"`
User
}