2019-01-08 00:37:16 +00:00
|
|
|
package influxdb
|
2018-05-14 16:26:38 +00:00
|
|
|
|
2018-12-18 15:44:25 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2021-03-30 18:10:02 +00:00
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
2018-12-18 15:44:25 +00:00
|
|
|
)
|
2018-05-14 16:26:38 +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" {
|
2021-03-30 18:10:02 +00:00
|
|
|
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. 🎉
|
2018-05-14 16:26:38 +00:00
|
|
|
type User struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
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-05-14 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2018-05-14 16:26:38 +00:00
|
|
|
// UserService represents a service for managing user data.
|
|
|
|
type UserService interface {
|
2018-10-03 14:51:14 +00:00
|
|
|
|
2018-05-14 16:26:38 +00:00
|
|
|
// Returns a single user by ID.
|
2021-03-30 18:10:02 +00:00
|
|
|
FindUserByID(ctx context.Context, id platform.ID) (*User, error)
|
2018-05-14 16:26:38 +00:00
|
|
|
|
|
|
|
// 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.
|
2021-03-30 18:10:02 +00:00
|
|
|
UpdateUser(ctx context.Context, id platform.ID, upd UserUpdate) (*User, error)
|
2018-05-14 16:26:38 +00:00
|
|
|
|
|
|
|
// Removes a user by ID.
|
2021-03-30 18:10:02 +00:00
|
|
|
DeleteUser(ctx context.Context, id platform.ID) error
|
2020-07-13 20:47:58 +00:00
|
|
|
|
|
|
|
// FindPermissionForUser
|
2021-03-30 18:10:02 +00:00
|
|
|
FindPermissionForUser(ctx context.Context, UserID platform.ID) (PermissionSet, error)
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UserFilter represents a set of filter that restrict the returned results.
|
|
|
|
type UserFilter struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
ID *platform.ID
|
2018-05-14 16:26:38 +00:00
|
|
|
Name *string
|
|
|
|
}
|
2021-12-20 20:17:18 +00:00
|
|
|
|
|
|
|
// UserResponse is the response of user
|
|
|
|
type UserResponse struct {
|
|
|
|
Links map[string]string `json:"links"`
|
|
|
|
User
|
|
|
|
}
|